summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2015-09-30 11:56:19 +0000
committerTobias Grosser <tobias@grosser.es>2015-09-30 11:56:19 +0000
commit33cb9f9419b6b3c81fe3507f2b7a75463d6e373b (patch)
tree8f26fd34526f764b6744153fdf09a20964bfb679
parent029d8531e651a0c21626117af7b6ad980cae193a (diff)
downloadbcm5719-llvm-33cb9f9419b6b3c81fe3507f2b7a75463d6e373b.tar.gz
bcm5719-llvm-33cb9f9419b6b3c81fe3507f2b7a75463d6e373b.zip
BlockGenerator: Extract value synthesis into its own function [NFC]
This will allow us to reuse this code in a subsequent commit. llvm-svn: 248893
-rw-r--r--polly/include/polly/CodeGen/BlockGenerators.h25
-rw-r--r--polly/lib/CodeGen/BlockGenerators.cpp52
2 files changed, 56 insertions, 21 deletions
diff --git a/polly/include/polly/CodeGen/BlockGenerators.h b/polly/include/polly/CodeGen/BlockGenerators.h
index c2aa42fd892..25187b0db3e 100644
--- a/polly/include/polly/CodeGen/BlockGenerators.h
+++ b/polly/include/polly/CodeGen/BlockGenerators.h
@@ -404,6 +404,31 @@ protected:
/// the original value in the non-optimized SCoP.
void createScalarFinalization(Region &R);
+ /// @brief Try to synthesize a new value
+ ///
+ /// Given an old value, we try to synthesize it in a new context from its
+ /// original SCEV expression. We start from the original SCEV expression,
+ /// then replace outdated parameter and loop references, and finally
+ /// expand it to code that computes this updated expression.
+ ///
+ /// @param Stmt The statement to code generate
+ /// @param Old The old Value
+ /// @param BBMap A mapping from old values to their new values
+ /// (for values recalculated within this basic block)
+ /// @param LTS A mapping from loops virtual canonical induction
+ /// variable to their new values
+ /// (for values recalculated in the new ScoP, but not
+ /// within this basic block)
+ /// @param L The loop that surrounded the instruction that referenced
+ /// this value in the original code. This loop is used to
+ /// evaluate the scalar evolution at the right scope.
+ ///
+ /// @returns o A newly synthesized value.
+ /// o NULL, if synthesizing the value failed.
+ Value *trySynthesizeNewValue(ScopStmt &Stmt, const Value *Old,
+ ValueMapT &BBMap, LoopToScevMapT &LTS,
+ Loop *L) const;
+
/// @brief Get the new version of a value.
///
/// Given an old value, we first check if a new version of this value is
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp
index dc6c519ee18..652ad8b5dec 100644
--- a/polly/lib/CodeGen/BlockGenerators.cpp
+++ b/polly/lib/CodeGen/BlockGenerators.cpp
@@ -99,27 +99,10 @@ BlockGenerator::BlockGenerator(PollyIRBuilder &B, LoopInfo &LI,
EntryBB(nullptr), PHIOpMap(PHIOpMap), ScalarMap(ScalarMap),
EscapeMap(EscapeMap), GlobalMap(GlobalMap) {}
-Value *BlockGenerator::getNewValue(ScopStmt &Stmt, const Value *Old,
- ValueMapT &BBMap, LoopToScevMapT &LTS,
- Loop *L) const {
- // We assume constants never change.
- // This avoids map lookups for many calls to this function.
- if (isa<Constant>(Old))
- return const_cast<Value *>(Old);
-
- if (Value *New = GlobalMap.lookup(Old)) {
- if (Value *NewRemapped = GlobalMap.lookup(New))
- New = NewRemapped;
- if (Old->getType()->getScalarSizeInBits() <
- New->getType()->getScalarSizeInBits())
- New = Builder.CreateTruncOrBitCast(New, Old->getType());
-
- return New;
- }
-
- if (Value *New = BBMap.lookup(Old))
- return New;
-
+Value *BlockGenerator::trySynthesizeNewValue(ScopStmt &Stmt, const Value *Old,
+ ValueMapT &BBMap,
+ LoopToScevMapT &LTS,
+ Loop *L) const {
if (SE.isSCEVable(Old->getType()))
if (const SCEV *Scev = SE.getSCEVAtScope(const_cast<Value *>(Old), L)) {
if (!isa<SCEVCouldNotCompute>(Scev)) {
@@ -144,6 +127,33 @@ Value *BlockGenerator::getNewValue(ScopStmt &Stmt, const Value *Old,
}
}
+ return nullptr;
+}
+
+Value *BlockGenerator::getNewValue(ScopStmt &Stmt, const Value *Old,
+ ValueMapT &BBMap, LoopToScevMapT &LTS,
+ Loop *L) const {
+ // We assume constants never change.
+ // This avoids map lookups for many calls to this function.
+ if (isa<Constant>(Old))
+ return const_cast<Value *>(Old);
+
+ if (Value *New = GlobalMap.lookup(Old)) {
+ if (Value *NewRemapped = GlobalMap.lookup(New))
+ New = NewRemapped;
+ if (Old->getType()->getScalarSizeInBits() <
+ New->getType()->getScalarSizeInBits())
+ New = Builder.CreateTruncOrBitCast(New, Old->getType());
+
+ return New;
+ }
+
+ if (Value *New = BBMap.lookup(Old))
+ return New;
+
+ if (Value *New = trySynthesizeNewValue(Stmt, Old, BBMap, LTS, L))
+ return New;
+
// A scop-constant value defined by a global or a function parameter.
if (isa<GlobalValue>(Old) || isa<Argument>(Old))
return const_cast<Value *>(Old);
OpenPOWER on IntegriCloud