Polly 20.0.0git
|
Generator for new versions of polyhedral region statements. More...
#include <BlockGenerators.h>
Public Member Functions | |
RegionGenerator (BlockGenerator &BlockGen) | |
Create a generator for regions. | |
virtual | ~RegionGenerator () |
void | copyStmt (ScopStmt &Stmt, LoopToScevMapT <S, __isl_keep isl_id_to_ast_expr *IdToAstExp) |
Copy the region statement Stmt . | |
Private Types | |
using | PHINodePairTy = std::pair< PHINode *, PHINode * > |
Mapping to remember PHI nodes that still need incoming values. | |
Private Types inherited from polly::BlockGenerator | |
typedef llvm::SmallVector< ValueMapT, 8 > | VectorValueMapT |
using | AllocaMapTy = DenseMap< const ScopArrayInfo *, AssertingVH< AllocaInst > > |
Map types to resolve scalar dependences. | |
using | EscapeUserVectorTy = SmallVector< Instruction *, 4 > |
Simple vector of instructions to store escape users. | |
using | EscapeUsersAllocaMapTy = MapVector< Instruction *, std::pair< AssertingVH< Value >, EscapeUserVectorTy > > |
Map type to resolve escaping users for scalar instructions. | |
Private Member Functions | |
BasicBlock * | repairDominance (BasicBlock *BB, BasicBlock *BBCopy) |
Repair the dominance tree after we created a copy block for BB . | |
void | addOperandToPHI (ScopStmt &Stmt, PHINode *PHI, PHINode *PHICopy, BasicBlock *IncomingBB, LoopToScevMapT <S) |
Add the new operand from the copy of IncomingBB to PHICopy . | |
PHINode * | buildExitPHI (MemoryAccess *MA, LoopToScevMapT <S, ValueMapT &BBMap, Loop *L) |
Create a PHI that combines the incoming values from all incoming blocks that are in the subregion. | |
Value * | getExitScalar (MemoryAccess *MA, LoopToScevMapT <S, ValueMapT &BBMap) |
void | generateScalarStores (ScopStmt &Stmt, LoopToScevMapT <S, ValueMapT &BBMAp, __isl_keep isl_id_to_ast_expr *NewAccesses) override |
Generate the scalar stores for the given statement. | |
void | copyPHIInstruction (ScopStmt &Stmt, PHINode *Inst, ValueMapT &BBMap, LoopToScevMapT <S) override |
Copy a single PHI instruction. | |
Private Member Functions inherited from polly::BlockGenerator | |
BlockGenerator (PollyIRBuilder &Builder, LoopInfo &LI, ScalarEvolution &SE, DominatorTree &DT, AllocaMapTy &ScalarMap, EscapeUsersAllocaMapTy &EscapeMap, ValueMapT &GlobalMap, IslExprBuilder *ExprBuilder, BasicBlock *StartBlock) | |
Create a generator for basic blocks. | |
void | copyStmt (ScopStmt &Stmt, LoopToScevMapT <S, isl_id_to_ast_expr *NewAccesses) |
Copy the basic block. | |
void | freeScalarAlloc (ScopArrayInfo *Array) |
Remove a ScopArrayInfo's allocation from the ScalarMap. | |
Value * | getOrCreateAlloca (const MemoryAccess &Access) |
Return the alloca for Access . | |
Value * | getOrCreateAlloca (const ScopArrayInfo *Array) |
Return the alloca for Array . | |
void | finalizeSCoP (Scop &S) |
Finalize the code generation for the SCoP S . | |
virtual | ~BlockGenerator () |
An empty destructor. | |
BlockGenerator (const BlockGenerator &)=default | |
BasicBlock * | splitBB (BasicBlock *BB) |
Split BB to create a new one we can use to clone BB in. | |
void | switchGeneratedFunc (Function *GenFn, DominatorTree *GenDT, LoopInfo *GenLI, ScalarEvolution *GenSE) |
Change the function that code is emitted into. | |
BasicBlock * | copyBB (ScopStmt &Stmt, BasicBlock *BB, ValueMapT &BBMap, LoopToScevMapT <S, isl_id_to_ast_expr *NewAccesses) |
Copy the given basic block. | |
void | copyBB (ScopStmt &Stmt, BasicBlock *BB, BasicBlock *BBCopy, ValueMapT &BBMap, LoopToScevMapT <S, isl_id_to_ast_expr *NewAccesses) |
Copy the given basic block. | |
void | generateScalarLoads (ScopStmt &Stmt, LoopToScevMapT <S, ValueMapT &BBMap, __isl_keep isl_id_to_ast_expr *NewAccesses) |
Generate reload of scalars demoted to memory and needed by Stmt . | |
void | generateBeginStmtTrace (ScopStmt &Stmt, LoopToScevMapT <S, ValueMapT &BBMap) |
When statement tracing is enabled, build the print instructions for printing the current statement instance. | |
Value * | buildContainsCondition (ScopStmt &Stmt, const isl::set &Subdomain) |
Generate instructions that compute whether one instance of Set is executed. | |
void | generateConditionalExecution (ScopStmt &Stmt, const isl::set &Subdomain, StringRef Subject, const std::function< void()> &GenThenFunc) |
Generate code that executes in a subset of Stmt's domain. | |
virtual void | generateScalarStores (ScopStmt &Stmt, LoopToScevMapT <S, ValueMapT &BBMap, __isl_keep isl_id_to_ast_expr *NewAccesses) |
Generate the scalar stores for the given statement. | |
void | handleOutsideUsers (const Scop &S, ScopArrayInfo *Array) |
Handle users of Array outside the SCoP. | |
void | findOutsideUsers (Scop &S) |
Find scalar statements that have outside users. | |
void | createScalarInitialization (Scop &S) |
Initialize the memory of demoted scalars. | |
void | createExitPHINodeMerges (Scop &S) |
Create exit PHI node merges for PHI nodes with more than two edges from inside the scop. | |
void | createScalarFinalization (Scop &S) |
Promote the values of demoted scalars after the SCoP. | |
Value * | trySynthesizeNewValue (ScopStmt &Stmt, Value *Old, ValueMapT &BBMap, LoopToScevMapT <S, Loop *L) const |
Try to synthesize a new value. | |
Value * | getNewValue (ScopStmt &Stmt, Value *Old, ValueMapT &BBMap, LoopToScevMapT <S, Loop *L) const |
Get the new version of a value. | |
void | copyInstScalar (ScopStmt &Stmt, Instruction *Inst, ValueMapT &BBMap, LoopToScevMapT <S) |
Loop * | getLoopForStmt (const ScopStmt &Stmt) const |
Get the innermost loop that surrounds the statement Stmt . | |
Value * | generateLocationAccessed (ScopStmt &Stmt, MemAccInst Inst, ValueMapT &BBMap, LoopToScevMapT <S, isl_id_to_ast_expr *NewAccesses) |
Generate the operand address. | |
Value * | generateLocationAccessed (ScopStmt &Stmt, Loop *L, Value *Pointer, ValueMapT &BBMap, LoopToScevMapT <S, isl_id_to_ast_expr *NewAccesses, __isl_take isl_id *Id, Type *ExpectedType) |
Generate the operand address. | |
Value * | getImplicitAddress (MemoryAccess &Access, Loop *L, LoopToScevMapT <S, ValueMapT &BBMap, __isl_keep isl_id_to_ast_expr *NewAccesses) |
Generate the pointer value that is accesses by Access . | |
Value * | generateArrayLoad (ScopStmt &Stmt, LoadInst *load, ValueMapT &BBMap, LoopToScevMapT <S, isl_id_to_ast_expr *NewAccesses) |
void | generateArrayStore (ScopStmt &Stmt, StoreInst *store, ValueMapT &BBMap, LoopToScevMapT <S, isl_id_to_ast_expr *NewAccesses) |
virtual void | copyPHIInstruction (ScopStmt &, PHINode *, ValueMapT &, LoopToScevMapT &) |
Copy a single PHI instruction. | |
void | copyInstruction (ScopStmt &Stmt, Instruction *Inst, ValueMapT &BBMap, LoopToScevMapT <S, isl_id_to_ast_expr *NewAccesses) |
Copy a single Instruction. | |
bool | canSyntheziseInStmt (ScopStmt &Stmt, Instruction *Inst) |
Helper to determine if Inst can be synthesized in Stmt . | |
void | removeDeadInstructions (BasicBlock *BB, ValueMapT &BBMap) |
Remove dead instructions generated for BB. | |
void | invalidateScalarEvolution (Scop &S) |
Invalidate the scalar evolution expressions for a scop. | |
Private Attributes | |
DenseMap< BasicBlock *, BasicBlock * > | StartBlockMap |
A map from old to the first new block in the region, that was created to model the old basic block. | |
DenseMap< BasicBlock *, BasicBlock * > | EndBlockMap |
A map from old to the last new block in the region, that was created to model the old basic block. | |
DenseMap< BasicBlock *, ValueMapT > | RegionMaps |
The "BBMaps" for the whole region (one for each block). | |
DenseMap< BasicBlock *, SmallVector< PHINodePairTy, 4 > > | IncompletePHINodeMap |
Private Attributes inherited from polly::BlockGenerator | |
AllocaMapTy & | ScalarMap |
Map to resolve scalar dependences for PHI operands and scalars. | |
EscapeUsersAllocaMapTy & | EscapeMap |
Map from instructions to their escape users as well as the alloca. | |
ValueMapT & | GlobalMap |
A map from llvm::Values referenced in the old code to a new set of llvm::Values, which is used to replace these old values during code generation. | |
BasicBlock * | StartBlock |
The first basic block after the RTC. | |
PollyIRBuilder & | Builder |
LoopInfo & | LI |
ScalarEvolution & | SE |
IslExprBuilder * | ExprBuilder |
DominatorTree & | DT |
The dominator tree of this function. | |
DominatorTree * | GenDT |
Relates to the region where the code is emitted into. | |
LoopInfo * | GenLI |
ScalarEvolution * | GenSE |
Generator for new versions of polyhedral region statements.
Definition at line 635 of file BlockGenerators.h.
|
private |
Mapping to remember PHI nodes that still need incoming values.
Definition at line 670 of file BlockGenerators.h.
|
inline |
Create a generator for regions.
BlockGen | A generator for basic blocks. |
Definition at line 640 of file BlockGenerators.h.
|
inlinevirtual |
Definition at line 642 of file BlockGenerators.h.
|
private |
Add the new operand from the copy of IncomingBB
to PHICopy
.
PHI nodes, which may have (multiple) edges that enter from outside the non-affine subregion and even from outside the scop, are code generated as follows:
Region: A-> exit NonAffine Stmt: nonaffB -> D (includes nonaffB, nonaffC)
pre: val = add i64 1, 1
A: br label nonaff
nonaffB: phi = phi i64 [val, A], [valC, nonAffC], [valD, D] cmp = <nonaff> br i1 cmp, label C, label nonaffC
nonaffC: valC = add i64 1, 1 br i1 undef, label D, label nonaffB
D: valD = ... exit_cond = <loopexit> br i1 exit_cond, label nonaffB, label exit
exit: ...
polly.A: store i64 val, i64* phi.phiops br label polly.nonaffA.entry
polly.nonaffB.entry: phi.phiops.reload = load i64, i64* phi.phiops br label nonaffB
polly.nonaffB: polly.phi = [phi.phiops.reload, nonaffB.entry], [p.valC, polly.nonaffC]
polly.nonaffC: p.valC = add i64 1, 1 br i1 undef, label polly.D, label polly.nonaffB
polly.D: p.valD = ... store i64 p.valD, i64* phi.phiops p.exit_cond = <loopexit> br i1 p.exit_cond, label polly.nonaffB, label exit
Values that enter the PHI from outside the non-affine region are stored into the stack slot phi.phiops by statements polly.A and polly.D and reloaded in polly.nonaffB.entry, a basic block generated before the actual non-affine region.
When generating the PHI node of the non-affine region in polly.nonaffB, incoming edges from outside the region are combined into a single branch from polly.nonaffB.entry which has as incoming value the value reloaded from the phi.phiops stack slot. Incoming edges from within the region refer to the copied instructions (p.valC) and basic blocks (polly.nonaffC) of the non-affine region.
Stmt | The statement to code generate. |
PHI | The original PHI we copy. |
PHICopy | The copy of PHI . |
IncomingBB | An incoming block of PHI . |
LTS | A map from old loops to new induction variables as SCEVs. |
Definition at line 1339 of file BlockGenerators.cpp.
References assert, polly::BlockGenerator::Builder, EndBlockMap, polly::BlockGenerator::getLoopForStmt(), polly::BlockGenerator::getNewValue(), IncompletePHINodeMap, polly::PHI, RegionMaps, polly::ScopStmt::represents(), StartBlockMap, and polly::Value.
Referenced by copyPHIInstruction(), and copyStmt().
|
private |
Create a PHI that combines the incoming values from all incoming blocks that are in the subregion.
PHIs in the subregion's exit block can have incoming edges from within and outside the subregion. This function combines the incoming values from within the subregion to appear as if there is only one incoming edge from the subregion (an additional exit block is created by RegionGenerator). This is to avoid that a value is written to the .phiops location without leaving the subregion because the exiting block as an edge back into the subregion.
MA | The WRITE of MemoryKind::PHI/MemoryKindExitPHI for a PHI in the subregion's exit block. |
LTS | Virtual induction variable mapping. |
BBMap | A mapping from old values to their new values in this block. |
L | Loop surrounding this region statement. |
Definition at line 1223 of file BlockGenerators.cpp.
References assert, polly::BlockGenerator::Builder, EndBlockMap, polly::MemoryAccess::getAccessInstruction(), polly::MemoryAccess::getIncoming(), polly::BlockGenerator::getNewValue(), polly::ScopStmt::getRegion(), polly::MemoryAccess::getStatement(), RegionMaps, StartBlockMap, and polly::Value.
Referenced by getExitScalar().
|
overrideprivatevirtual |
Copy a single PHI instruction.
This copies a single PHI instruction and updates references to old values with references to new values, as defined by GlobalMap and BBMap.
Stmt | The statement to code generate. |
PHI | The PHI instruction to copy. |
BBMap | A mapping from old values to their new values (for values recalculated within this basic block). |
LTS | A map from old loops to new induction variables as SCEVs. |
Reimplemented from polly::BlockGenerator.
Definition at line 1387 of file BlockGenerators.cpp.
References addOperandToPHI(), polly::BlockGenerator::Builder, and polly::PHI.
void RegionGenerator::copyStmt | ( | ScopStmt & | Stmt, |
LoopToScevMapT & | LTS, | ||
__isl_keep isl_id_to_ast_expr * | IdToAstExp | ||
) |
Copy the region statement Stmt
.
This copies the entire region represented by Stmt
and updates references to old values with references to new values, as defined by GlobalMap.
Stmt | The statement to code generate. |
LTS | A map from old loops to new induction variables as SCEVs. |
Definition at line 1058 of file BlockGenerators.cpp.
References addOperandToPHI(), assert, polly::BlockGenerator::Builder, polly::BlockGenerator::copyBB(), polly::BlockGenerator::copyInstScalar(), polly::BlockGenerator::DT, EndBlockMap, findExitDominator(), polly::BlockGenerator::generateBeginStmtTrace(), polly::BlockGenerator::generateScalarLoads(), generateScalarStores(), polly::ScopStmt::getRegion(), IncompletePHINodeMap, isDominatingSubregionExit(), polly::ScopStmt::isRegionStmt(), polly::BlockGenerator::LI, RegionMaps, repairDominance(), polly::BlockGenerator::SE, polly::BlockGenerator::splitBB(), StartBlockMap, and polly::Value.
Referenced by polly::IslNodeBuilder::createUser().
|
overrideprivatevirtual |
Generate the scalar stores for the given statement.
After the statement Stmt
was copied all inner-SCoP scalar dependences starting in Stmt
(hence all scalar write accesses in Stmt
) need to be demoted to memory.
Stmt | The statement we generate code for. |
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) |
BBMap | A mapping from old values to their new values in this block. |
LTS | A mapping from loops virtual canonical induction variable to their new values. |
Reimplemented from polly::BlockGenerator.
Definition at line 1291 of file BlockGenerators.cpp.
References assert, polly::BlockGenerator::generateConditionalExecution(), getExitScalar(), polly::ScopStmt::getRegion(), and polly::Value.
Referenced by copyStmt().
|
private |
Return | the new value of a scalar write, creating a PHINode if necessary. |
MA | A scalar WRITE MemoryAccess. |
LTS | Virtual induction variable mapping. |
BBMap | A mapping from old values to their new values in this block. |
MA's
written value when leaving the subregion. Definition at line 1264 of file BlockGenerators.cpp.
References assert, buildExitPHI(), polly::MemoryAccess::getAccessValue(), polly::MemoryAccess::getIncoming(), polly::BlockGenerator::getNewValue(), polly::ScopStmt::getRegion(), polly::MemoryAccess::getStatement(), polly::MemoryAccess::isAnyPHIKind(), polly::BlockGenerator::LI, and polly::Value.
Referenced by generateScalarStores().
|
private |
Repair the dominance tree after we created a copy block for BB
.
BBCopy
if in the region. Definition at line 1002 of file BlockGenerators.cpp.
References polly::BlockGenerator::DT, EndBlockMap, and StartBlockMap.
Referenced by copyStmt().
|
private |
A map from old to the last new block in the region, that was created to model the old basic block.
Definition at line 662 of file BlockGenerators.h.
Referenced by addOperandToPHI(), buildExitPHI(), copyStmt(), and repairDominance().
|
private |
Definition at line 671 of file BlockGenerators.h.
Referenced by addOperandToPHI(), and copyStmt().
|
private |
The "BBMaps" for the whole region (one for each block).
In case a basic block is code generated to multiple basic blocks (e.g., for partial writes), the StartBasic is used as index for the RegionMap.
Definition at line 667 of file BlockGenerators.h.
Referenced by addOperandToPHI(), buildExitPHI(), and copyStmt().
|
private |
A map from old to the first new block in the region, that was created to model the old basic block.
Definition at line 658 of file BlockGenerators.h.
Referenced by addOperandToPHI(), buildExitPHI(), copyStmt(), and repairDominance().