summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHongbin Zheng <etherzhhb@gmail.com>2013-07-25 09:12:07 +0000
committerHongbin Zheng <etherzhhb@gmail.com>2013-07-25 09:12:07 +0000
commit5b463ceaf5fc07201a866dc0cabf584b755f5804 (patch)
tree03606a28652e5ef8b4287a8f8455afe8f6651129
parentf2404164ba35251ba649d8c25cd90d6c43a7df93 (diff)
downloadbcm5719-llvm-5b463ceaf5fc07201a866dc0cabf584b755f5804.tar.gz
bcm5719-llvm-5b463ceaf5fc07201a866dc0cabf584b755f5804.zip
BlockGenerator: Split getNewValue.
Split the old getNewValue into two parts: 1. The function "lookupAvailableValue" that return the new version of the instruction which is already available. 2. The function calls "lookupAvailableValue", and tries to generate the new version if it is not available yet. llvm-svn: 187114
-rw-r--r--polly/include/polly/CodeGen/BlockGenerators.h13
-rw-r--r--polly/lib/CodeGen/BlockGenerators.cpp36
2 files changed, 37 insertions, 12 deletions
diff --git a/polly/include/polly/CodeGen/BlockGenerators.h b/polly/include/polly/CodeGen/BlockGenerators.h
index 51ded140ac8..077236df326 100644
--- a/polly/include/polly/CodeGen/BlockGenerators.h
+++ b/polly/include/polly/CodeGen/BlockGenerators.h
@@ -106,6 +106,19 @@ protected:
Value *getNewValue(const Value *Old, ValueMapT &BBMap, ValueMapT &GlobalMap,
LoopToScevMapT &LTS, Loop *L);
+ /// @brief Get the new version of a Value if it is available.
+ ///
+ /// @param Old The old Value.
+ /// @param BBMap A mapping from old values to their new values
+ /// (for values recalculated within this basic block).
+ /// @param GlobalMap A mapping from old values to their new values
+ /// (for values recalculated in the new ScoP, but not
+ /// within this basic block).
+ ///
+ /// @returns The new value, if available.
+ Value *lookupAvailableValue(const Value *Old, ValueMapT &BBMap,
+ ValueMapT &GlobalMap) const;
+
void copyInstScalar(const Instruction *Inst, ValueMapT &BBMap,
ValueMapT &GlobalMap, LoopToScevMapT &LTS);
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp
index 6eb0a81d3ad..b66b03494a9 100644
--- a/polly/lib/CodeGen/BlockGenerators.cpp
+++ b/polly/lib/CodeGen/BlockGenerators.cpp
@@ -158,9 +158,8 @@ BlockGenerator::BlockGenerator(IRBuilder<> &B, ScopStmt &Stmt, Pass *P)
: Builder(B), Statement(Stmt), P(P), SE(P->getAnalysis<ScalarEvolution>()) {
}
-Value *BlockGenerator::getNewValue(const Value *Old, ValueMapT &BBMap,
- ValueMapT &GlobalMap, LoopToScevMapT &LTS,
- Loop *L) {
+Value *BlockGenerator::lookupAvailableValue(const Value *Old, ValueMapT &BBMap,
+ ValueMapT &GlobalMap) const {
// We assume constants never change.
// This avoids map lookups for many calls to this function.
if (isa<Constant>(Old))
@@ -174,9 +173,27 @@ Value *BlockGenerator::getNewValue(const Value *Old, ValueMapT &BBMap,
return New;
}
+ // Or it is probably a scop-constant value defined as global, function
+ // parameter or an instruction not within the scop.
+ if (isa<GlobalValue>(Old) || isa<Argument>(Old))
+ return const_cast<Value *>(Old);
+
+ if (const Instruction *Inst = dyn_cast<Instruction>(Old))
+ if (!Statement.getParent()->getRegion().contains(Inst->getParent()))
+ return const_cast<Value *>(Old);
+
if (Value *New = BBMap.lookup(Old))
return New;
+ return NULL;
+}
+
+Value *BlockGenerator::getNewValue(const Value *Old, ValueMapT &BBMap,
+ ValueMapT &GlobalMap, LoopToScevMapT &LTS,
+ Loop *L) {
+ if (Value *New = lookupAvailableValue(Old, BBMap, GlobalMap))
+ return New;
+
if (SCEVCodegen && SE.isSCEVable(Old->getType()))
if (const SCEV *Scev = SE.getSCEVAtScope(const_cast<Value *>(Old), L)) {
if (!isa<SCEVCouldNotCompute>(Scev)) {
@@ -194,15 +211,10 @@ Value *BlockGenerator::getNewValue(const Value *Old, ValueMapT &BBMap,
}
}
- if (const Instruction *Inst = dyn_cast<Instruction>(Old)) {
- (void)Inst;
- assert(!Statement.getParent()->getRegion().contains(Inst->getParent()) &&
- "unexpected scalar dependence in region");
- }
-
- // Everything else is probably a scop-constant value defined as global,
- // function parameter or an instruction not within the scop.
- return const_cast<Value *>(Old);
+ // Now the scalar dependence is neither available nor SCEVCodegenable, this
+ // should never happen in the current code generator.
+ llvm_unreachable("Unexpected scalar dependence in region!");
+ return NULL;
}
void BlockGenerator::copyInstScalar(const Instruction *Inst, ValueMapT &BBMap,
OpenPOWER on IntegriCloud