Remove unneeded RegionSimplify pass.

We now support regions with multiple entries and multiple exits natively.
Regions are not needed to be simplified to single entry and single exit.

We need to XFAIL two test cases as this change increases the scop coverage
and uncoveres two failures in the independent blocks pass. The first failure
will be fixed in a subsequent commit, the second one is in the non-default
-polly-codegen-scev mode and still needs to be fixed.

Contributed-by: Star Tan <tanmx_star@yeah.net>
llvm-svn: 179673
This commit is contained in:
Tobias Grosser 2013-04-17 07:20:30 +00:00
parent 36a01b0a28
commit b5f92892d1
16 changed files with 9 additions and 301 deletions

View File

@ -45,7 +45,6 @@ llvm::Pass *createJSONImporterPass();
#ifdef PLUTO_FOUND
llvm::Pass *createPlutoOptimizerPass();
#endif
llvm::Pass *createRegionSimplifyPass();
llvm::Pass *createScopDetectionPass();
llvm::Pass *createScopInfoPass();
llvm::Pass *createIslAstInfoPass();
@ -96,7 +95,6 @@ struct PollyForcePassLinking {
createIndVarSimplifyPass();
createJSONExporterPass();
createJSONImporterPass();
createRegionSimplifyPass();
createScopDetectionPass();
createScopInfoPass();
#ifdef PLUTO_FOUND
@ -141,7 +139,6 @@ void initializePlutoOptimizerPass(llvm::PassRegistry &);
void initializePoccPass(llvm::PassRegistry &);
#endif
void initializePollyIndVarSimplifyPass(llvm::PassRegistry &);
void initializeRegionSimplifyPass(llvm::PassRegistry &);
}
#endif

View File

@ -30,7 +30,6 @@ add_polly_loadable_module(LLVMPolly
IndVarSimplify.cpp
MayAliasSet.cpp
Pocc.cpp
RegionSimplify.cpp
RegisterPasses.cpp
ScheduleOptimizer.cpp
${POLLY_SCOPLIB_FILES}

View File

@ -1,223 +0,0 @@
//===- RegionSimplify.cpp -------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file converts refined regions detected by the RegionInfo analysis
// into simple regions.
//
//===----------------------------------------------------------------------===//
#include "polly/LinkAllPasses.h"
#include "llvm/IR/Instructions.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/RegionPass.h"
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#define DEBUG_TYPE "region-simplify"
#include "llvm/Support/Debug.h"
using namespace llvm;
STATISTIC(NumEntries, "The # of created entry edges");
STATISTIC(NumExits, "The # of created exit edges");
namespace {
class RegionSimplify : public RegionPass {
// Remember the modified region.
Region *r;
void createSingleEntryEdge(Region *R);
void createSingleExitEdge(Region *R);
public:
static char ID;
explicit RegionSimplify() : RegionPass(ID), r(0) {}
virtual void print(raw_ostream &O, const Module *M) const;
virtual bool runOnRegion(Region *R, RGPassManager &RGM);
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
};
}
char RegionSimplify::ID = 0;
namespace polly {
Pass *createRegionSimplifyPass() { return new RegionSimplify(); }
}
void RegionSimplify::print(raw_ostream &O, const Module *M) const {
if (r == 0)
return;
BasicBlock *enteringBlock = r->getEnteringBlock();
BasicBlock *exitingBlock = r->getExitingBlock();
O << "Region: " << r->getNameStr() << " Edges:\t";
if (enteringBlock)
O << "Entering: [" << enteringBlock->getName() << " -> "
<< r->getEntry()->getName() << "], ";
if (exitingBlock) {
O << "Exiting: [" << exitingBlock->getName() << " -> ";
if (r->getExit())
O << r->getExit()->getName();
else
O << "<return>";
O << "]";
}
O << "\n";
}
void RegionSimplify::getAnalysisUsage(AnalysisUsage &AU) const {
// Function SplitBlockPredecessors currently updates/preserves AliasAnalysis,
/// DominatorTree, LoopInfo, and LCCSA but no other analyses.
//AU.addPreserved<AliasAnalysis>(); Break SCEV-AA
AU.addPreserved<DominatorTree>();
AU.addPreserved<LoopInfo>();
AU.addPreservedID(LCSSAID);
AU.addPreserved<RegionInfo>();
AU.addRequired<RegionInfo>();
}
// createSingleEntryEdge - Split the entry basic block of the given
// region after the last PHINode to form a single entry edge.
void RegionSimplify::createSingleEntryEdge(Region *R) {
BasicBlock *oldEntry = R->getEntry();
SmallVector<BasicBlock *, 4> Preds;
for (pred_iterator PI = pred_begin(oldEntry), PE = pred_end(oldEntry);
PI != PE; ++PI)
if (!R->contains(*PI))
Preds.push_back(*PI);
assert(Preds.size() && "This region has already a single entry edge");
BasicBlock *newEntry =
SplitBlockPredecessors(oldEntry, Preds, ".single_entry", this);
RegionInfo *RI = &getAnalysis<RegionInfo>();
// We do not update entry node for children of this region.
// This make it easier to extract children regions because they do not share
// the entry node with their parents.
// all parent regions whose entry is oldEntry are updated with newEntry
Region *r = R->getParent();
// Put the new entry to R's parent.
RI->setRegionFor(newEntry, r);
while (r->getEntry() == oldEntry && !r->isTopLevelRegion()) {
r->replaceEntry(newEntry);
r = r->getParent();
}
// We do not update exit node for children of this region for the same reason
// of not updating entry node.
// All other regions whose exit is oldEntry are updated with new exit node
r = RI->getTopLevelRegion();
std::vector<Region *> RQ;
RQ.push_back(r);
while (!RQ.empty()) {
r = RQ.back();
RQ.pop_back();
for (Region::const_iterator RI = r->begin(), RE = r->end(); RI != RE; ++RI)
RQ.push_back(*RI);
if (r->getExit() == oldEntry && !R->contains(r))
r->replaceExit(newEntry);
}
}
// createSingleExitEdge - Split the exit basic of the given region
// to form a single exit edge.
void RegionSimplify::createSingleExitEdge(Region *R) {
BasicBlock *oldExit = R->getExit();
SmallVector<BasicBlock *, 4> Preds;
for (pred_iterator PI = pred_begin(oldExit), PE = pred_end(oldExit); PI != PE;
++PI)
if (R->contains(*PI))
Preds.push_back(*PI);
DEBUG(dbgs() << "Going to create single exit for:\n");
DEBUG(R->print(dbgs(), true, 0, Region::PrintRN));
BasicBlock *newExit =
SplitBlockPredecessors(oldExit, Preds, ".single_exit", this);
RegionInfo *RI = &getAnalysis<RegionInfo>();
// We do not need to update entry nodes because this split happens inside
// this region and it affects only this region and all of its children.
// The new split node belongs to this region
RI->setRegionFor(newExit, R);
DEBUG(dbgs() << "Adding new exiting block: " << newExit->getName() << '\n');
// all children of this region whose exit is oldExit is changed to newExit
std::vector<Region *> RQ;
for (Region::const_iterator RI = R->begin(), RE = R->end(); RI != RE; ++RI)
RQ.push_back(*RI);
while (!RQ.empty()) {
R = RQ.back();
RQ.pop_back();
if (R->getExit() != oldExit)
continue;
for (Region::const_iterator RI = R->begin(), RE = R->end(); RI != RE; ++RI)
RQ.push_back(*RI);
R->replaceExit(newExit);
DEBUG(dbgs() << "Replacing exit for:\n");
DEBUG(R->print(dbgs(), true, 0, Region::PrintRN));
}
DEBUG(dbgs() << "After split exit:\n");
DEBUG(R->print(dbgs(), true, 0, Region::PrintRN));
}
bool RegionSimplify::runOnRegion(Region *R, RGPassManager &RGM) {
r = 0;
if (!R->isTopLevelRegion()) {
// split entry node if the region has multiple entry edges
if (!(R->getEnteringBlock()) &&
(pred_begin(R->getEntry()) != pred_end(R->getEntry()))) {
createSingleEntryEdge(R);
r = R;
++NumEntries;
}
// split exit node if the region has multiple exit edges
if (!(R->getExitingBlock())) {
createSingleExitEdge(R);
r = R;
++NumExits;
}
}
return r != 0;
}
INITIALIZE_PASS_BEGIN(RegionSimplify, "polly-region-simplify",
"Transform refined regions into simple regions", false,
false);
INITIALIZE_PASS_DEPENDENCY(RegionInfo);
INITIALIZE_PASS_END(RegionSimplify, "polly-region-simplify",
"Transform refined regions into simple regions", false,
false)

View File

@ -160,7 +160,6 @@ static void initializePollyPasses(PassRegistry &Registry) {
initializePoccPass(Registry);
#endif
initializePollyIndVarSimplifyPass(Registry);
initializeRegionSimplifyPass(Registry);
initializeScopDetectionPass(Registry);
initializeScopInfoPass(Registry);
initializeTempScopInfoPass(Registry);
@ -201,22 +200,6 @@ static void registerCanonicalicationPasses(llvm::PassManagerBase &PM) {
PM.add(polly::createIndVarSimplifyPass());
PM.add(polly::createCodePreparationPass());
PM.add(polly::createRegionSimplifyPass());
// FIXME: The next two passes should not be necessary here. They are currently
// because of two problems:
//
// 1. The RegionSimplifyPass destroys the canonical form of induction
// variables,as it produces PHI nodes with incorrectly ordered
// operands. To fix this we run IndVarSimplify.
//
// 2. IndVarSimplify does not preserve the region information and
// the regioninfo pass does currently not recover simple regions.
// As a result we need to run the RegionSimplify pass again to
// recover them
if (!SCEVCodegen) {
PM.add(polly::createIndVarSimplifyPass());
PM.add(polly::createRegionSimplifyPass());
}
}
/// @brief Register Polly passes such that they form a polyhedral optimizer.

View File

@ -1,4 +1,7 @@
; RUN: opt %loadPolly %defaultOpts -polly-codegen-isl %s
; -polly-indenpendent causes: Cannot generate independent blocks
; XFAIL:*
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"

View File

@ -1,41 +0,0 @@
; RUN: opt %loadPolly -polly-region-simplify -polly-codegen-isl -polly-codegen-scev < %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define void @kernel_cholesky(double* %p, [128 x double]* %A) #0 {
entry:
br i1 undef, label %for.body, label %for.end57
for.body: ; preds = %for.inc55, %entry
%i.070 = phi i32 [ %inc56, %for.inc55 ], [ 0, %entry ]
br i1 undef, label %for.body22, label %for.inc55
for.body22: ; preds = %for.end44, %for.body
%sub28 = add nsw i32 %i.070, -1
%cmp2961 = icmp slt i32 %sub28, 0
%idxprom45 = sext i32 %i.070 to i64
br i1 %cmp2961, label %for.end44, label %for.inc42
for.inc42: ; preds = %for.inc42, %for.body22
%k.062 = phi i32 [ %inc43, %for.inc42 ], [ 0, %for.body22 ]
%inc43 = add nsw i32 %k.062, 1
%cmp29 = icmp sgt i32 %inc43, %sub28
br i1 %cmp29, label %for.end44, label %for.inc42
for.end44: ; preds = %for.inc42, %for.body22
%arrayidx46 = getelementptr inbounds double* %p, i64 %idxprom45
%0 = load double* %arrayidx46, align 8
%mul47 = fmul double undef, %0
%arrayidx51 = getelementptr inbounds [128 x double]* %A, i64 undef, i64 undef
store double %mul47, double* %arrayidx51, align 8
br i1 undef, label %for.body22, label %for.inc55
for.inc55: ; preds = %for.end44, %for.body
%inc56 = add nsw i32 %i.070, 1
br i1 undef, label %for.body, label %for.end57
for.end57: ; preds = %for.inc55, %entry
ret void
}
attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-frame-pointer-elim-non-leaf"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }

View File

@ -1,4 +1,7 @@
; RUN: opt %loadPolly -polly-region-simplify -polly-codegen-isl -polly-codegen-scev %s
; RUN: opt %loadPolly -polly-codegen-isl -polly-codegen-scev %s
; -polly-independent causes: Cannot generate independent blocks
;
; XFAIL:*
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"

View File

@ -1,4 +1,4 @@
; RUN: opt %loadPolly -polly-region-simplify -polly-opt-isl -analyze < %s | FileCheck %s
; RUN: opt %loadPolly -polly-opt-isl -analyze < %s | FileCheck %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

View File

@ -1,7 +1,5 @@
; RUN: opt %loadPolly -polly-detect -analyze < %s | FileCheck %s
; RUN: opt %loadPolly -polly-region-simplify -polly-detect -analyze < %s | FileCheck %s
; RUN: opt %loadPolly -polly-detect -polly-codegen-isl -analyze < %s | FileCheck %s
; RUN: opt %loadPolly -polly-region-simplify -polly-detect -polly-codegen-isl -analyze < %s | FileCheck %s
; void f(long A[], long N) {
; long i, j;

View File

@ -1,7 +1,5 @@
; RUN: opt %loadPolly -polly-detect -analyze < %s | FileCheck %s
; RUN: opt %loadPolly -polly-region-simplify -polly-detect -analyze < %s | FileCheck %s
; RUN: opt %loadPolly -polly-detect -polly-codegen-scev -analyze < %s | FileCheck %s
; RUN: opt %loadPolly -polly-region-simplify -polly-detect -polly-codegen-scev -analyze < %s | FileCheck %s
; void f(long A[], long N) {
; long i;

View File

@ -1,7 +1,5 @@
; RUN: opt %loadPolly -polly-detect -analyze < %s | FileCheck %s
; RUN: opt %loadPolly -polly-region-simplify -polly-detect -analyze < %s | FileCheck %s
; RUN: opt %loadPolly -polly-detect -polly-codegen-scev -analyze < %s | FileCheck %s
; RUN: opt %loadPolly -polly-region-simplify -polly-detect -polly-codegen-scev -analyze < %s | FileCheck %s
; void f(long A[], long N) {
; long i;

View File

@ -27,7 +27,7 @@ except KeyError,e:
config.substitutions.append(('%loadPolly', '-load '
+ config.polly_lib_dir + '/LLVMPolly@LLVM_SHLIBEXT@'))
config.substitutions.append(('%defaultOpts', ' -basicaa -polly-prepare -polly-region-simplify'))
config.substitutions.append(('%defaultOpts', ' -basicaa -polly-prepare'))
config.substitutions.append(('%polybenchOpts', ' -O3 -loop-simplify -indvars '))
config.substitutions.append(('%vector-opt', '-polly-vectorizer=polly'))

View File

@ -1,6 +1,4 @@
; RUN: opt %loadPolly %defaultOpts -polly-detect -analyze %s | FileCheck %s
; region-simplify make polly fail to detect the canonical induction variable.
; XFAIL:*
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"

View File

@ -1,6 +1,4 @@
; RUN: opt %loadPolly %defaultOpts -polly-detect -polly-ast -analyze %s | FileCheck %s
; region-simplify make polly fail to detect the canonical induction variable.
; XFAIL:*
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"

View File

@ -1,6 +1,4 @@
; RUN: opt %loadPolly %defaultOpts -polly-detect -analyze %s | FileCheck %s
; region-simplify causes: Non canonical PHI node found
; XFAIL:*
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"

View File

@ -20,7 +20,6 @@
<h2>Front End</h2>
<ul>
<li><em>polly-prepare</em> Prepare code for Polly</li>
<li><em>polly-region-simplify</em> Transform refined regions into simple regions</li>
<li><em>polly-detect</em> Detect SCoPs in functions</li>
<li><em>polly-analyze-ir</em> Analyse the LLVM-IR in the detected SCoPs</li>
<li><em>polly-independent</em> Create independent blocks</li>