Move remapping functionality in the ScopExpander

Because we handle more than SCEV does it is not possible to rewrite an
  expression on the top-level using the SCEVParameterRewriter only. With
  this patch we will do the rewriting on demand only and also
  recursively, thus not only on the top-level.

llvm-svn: 248916
This commit is contained in:
Johannes Doerfert 2015-09-30 16:52:03 +00:00
parent 6206d7a67c
commit c0729a3216
4 changed files with 24 additions and 12 deletions

View File

@ -17,10 +17,10 @@
#define POLLY_BLOCK_GENERATORS_H
#include "polly/CodeGen/IRBuilder.h"
#include "polly/Support/ScopHelper.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "isl/map.h"
#include <vector>
struct isl_ast_build;
struct isl_id_to_ast_expr;
@ -37,9 +37,6 @@ class ScopStmt;
class MemoryAccess;
class IslExprBuilder;
typedef DenseMap<const Value *, Value *> ValueMapT;
typedef std::vector<ValueMapT> VectorValueMapT;
/// @brief Check whether a value an be synthesized by the code generator.
///
/// Some value will be recalculated only from information that is code generated

View File

@ -14,6 +14,11 @@
#ifndef POLLY_SUPPORT_IRHELPER_H
#define POLLY_SUPPORT_IRHELPER_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/AliasAnalysis.h"
namespace llvm {
class Type;
class Instruction;
@ -36,6 +41,9 @@ class ScalarEvolution;
namespace polly {
class Scop;
typedef llvm::DenseMap<const llvm::Value *, llvm::Value *> ValueMapT;
typedef llvm::SmallVector<ValueMapT, 8> VectorValueMapT;
/// Temporary Hack for extended regiontree.
///
/// @brief Cast the region to loop.
@ -99,7 +107,7 @@ void splitEntryBlockForAlloca(llvm::BasicBlock *EntryBlock, llvm::Pass *P);
llvm::Value *expandCodeFor(Scop &S, llvm::ScalarEvolution &SE,
const llvm::DataLayout &DL, const char *Name,
const llvm::SCEV *E, llvm::Type *Ty,
llvm::Instruction *IP);
llvm::Instruction *IP, ValueMapT *VMap = nullptr);
/// @brief Check if the block is a error block.
///

View File

@ -110,7 +110,6 @@ Value *BlockGenerator::trySynthesizeNewValue(ScopStmt &Stmt, const Value *Old,
ValueToValueMap VTV;
VTV.insert(BBMap.begin(), BBMap.end());
VTV.insert(GlobalMap.begin(), GlobalMap.end());
NewScev = SCEVParameterRewriter::rewrite(NewScev, SE, VTV);
Scop &S = *Stmt.getParent();
const DataLayout &DL =
@ -119,8 +118,8 @@ Value *BlockGenerator::trySynthesizeNewValue(ScopStmt &Stmt, const Value *Old,
assert(IP != Builder.GetInsertBlock()->end() &&
"Only instructions can be insert points for SCEVExpander");
Value *Expanded =
expandCodeFor(S, SE, DL, "polly", NewScev, Old->getType(), IP);
Value *Expanded = expandCodeFor(S, SE, DL, "polly", NewScev,
Old->getType(), IP, &VTV);
BBMap[Old] = Expanded;
return Expanded;

View File

@ -235,8 +235,9 @@ struct ScopExpander : SCEVVisitor<ScopExpander, const SCEV *> {
friend struct SCEVVisitor<ScopExpander, const SCEV *>;
explicit ScopExpander(const Region &R, ScalarEvolution &SE,
const DataLayout &DL, const char *Name)
: Expander(SCEVExpander(SE, DL, Name)), SE(SE), Name(Name), R(R) {}
const DataLayout &DL, const char *Name, ValueMapT *VMap)
: Expander(SCEVExpander(SE, DL, Name)), SE(SE), Name(Name), R(R),
VMap(VMap) {}
Value *expandCodeFor(const SCEV *E, Type *Ty, Instruction *I) {
// If we generate code in the region we will immediately fall back to the
@ -252,8 +253,15 @@ private:
ScalarEvolution &SE;
const char *Name;
const Region &R;
ValueMapT *VMap;
const SCEV *visitUnknown(const SCEVUnknown *E) {
// If a value mapping was given try if the underlying value is remapped.
if (VMap)
if (Value *NewVal = VMap->lookup(E->getValue()))
return visit(SE.getSCEV(NewVal));
Instruction *Inst = dyn_cast<Instruction>(E->getValue());
if (!Inst || (Inst->getOpcode() != Instruction::SRem &&
Inst->getOpcode() != Instruction::SDiv))
@ -327,8 +335,8 @@ private:
Value *polly::expandCodeFor(Scop &S, ScalarEvolution &SE, const DataLayout &DL,
const char *Name, const SCEV *E, Type *Ty,
Instruction *IP) {
ScopExpander Expander(S.getRegion(), SE, DL, Name);
Instruction *IP, ValueMapT *VMap) {
ScopExpander Expander(S.getRegion(), SE, DL, Name, VMap);
return Expander.expandCodeFor(E, Ty, IP);
}