diff options
author | Johannes Doerfert <doerfert@cs.uni-saarland.de> | 2015-09-29 23:43:40 +0000 |
---|---|---|
committer | Johannes Doerfert <doerfert@cs.uni-saarland.de> | 2015-09-29 23:43:40 +0000 |
commit | f6343d74eff61e909e05b3d0fc4ec7483e922e0c (patch) | |
tree | 4874b84a96c170add77776f1edc2c372dbaa2b35 /polly/lib/CodeGen/BlockGenerators.cpp | |
parent | 10c7e148c4f27cd7759cc409892e40e701db7fc0 (diff) | |
download | bcm5719-llvm-f6343d74eff61e909e05b3d0fc4ec7483e922e0c.tar.gz bcm5719-llvm-f6343d74eff61e909e05b3d0fc4ec7483e922e0c.zip |
Revert "BlockGenerator: Generate synthesisable instructions only on-demand"
This reverts commit 07830c18d789ee72812d5b5b9b4f8ce72ebd4207.
The commit broke at least one test in lnt,
MultiSource/Benchmarks/Ptrdist/bc/number.c
was miss compiled and the test produced a wrong result.
One Polly test case that was added later was adjusted too.
llvm-svn: 248860
Diffstat (limited to 'polly/lib/CodeGen/BlockGenerators.cpp')
-rw-r--r-- | polly/lib/CodeGen/BlockGenerators.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index 5b576e1657d..bae65907a41 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -270,7 +270,8 @@ void BlockGenerator::copyInstruction(ScopStmt &Stmt, const Instruction *Inst, Loop *L = getLoopForInst(Inst); if ((Stmt.isBlockStmt() || !Stmt.getRegion()->contains(L)) && canSynthesize(Inst, &LI, &SE, &Stmt.getParent()->getRegion())) { - // Synthesizable statements will be generated on-demand. + Value *NewValue = getNewValue(Stmt, Inst, BBMap, LTS, L); + BBMap[Inst] = NewValue; return; } @@ -300,6 +301,28 @@ void BlockGenerator::copyInstruction(ScopStmt &Stmt, const Instruction *Inst, copyInstScalar(Stmt, Inst, BBMap, LTS); } +/// @brief Remove trivially dead instructions from BB +/// +/// This function drops trivially dead instructions from a basic block. It +/// on purpose does _not_ recurse into other BBs even if the deletion of +/// instructions in this basic block can make instructions in other basic blocks +/// triviall dead. +static void simplifyInstsInBlockOnly(BasicBlock *BB) { + auto BI = --BB->end(), BE = BB->begin(); + bool Exit = false; + while (!Exit) { + auto ToRemove = BI; + if (BI != BE) + BI--; + else + Exit = true; + + if (!isInstructionTriviallyDead(ToRemove)) + continue; + ToRemove->eraseFromParent(); + } +} + void BlockGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT <S, isl_id_to_ast_expr *NewAccesses) { assert(Stmt.isBlockStmt() && @@ -309,6 +332,16 @@ void BlockGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT <S, BasicBlock *BB = Stmt.getBasicBlock(); copyBB(Stmt, BB, BBMap, LTS, NewAccesses); + + auto CopyBB = Builder.GetInsertBlock(); + // Delete trivially dead instructions in CopyBB, but not in any other BB. + // Only for copyBB we know that there will _never_ be any future uses of + // instructions that have no use after copyBB has finished. Other instructions + // in the AST that have been generated by IslNodeBuilder may look dead at + // the moment, but may possibly still be referenced by GlobalMaps. If we + // delete them now, later uses would break surprisingly. + simplifyInstsInBlockOnly(CopyBB); + Builder.SetInsertPoint(CopyBB->getTerminator()); } BasicBlock *BlockGenerator::splitBB(BasicBlock *BB) { @@ -1099,6 +1132,15 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT <S, LTS[L] = SE.getUnknown(LoopPHI); } + // Delete trivially dead instructions in CopyBB, but not in any other BB. + // Only for copyBB we know that there will _never_ be any future uses of + // instructions that have no use after copyBB has finished. Other instructions + // in the AST that have been generated by IslNodeBuilder may look dead at + // the moment, but may possibly still be referenced by GlobalMaps. If we + // delete them now, later uses would break surprisingly. + for (auto *BB : SeenBlocks) + simplifyInstsInBlockOnly(BlockMap[BB]); + // Reset the old insert point for the build. Builder.SetInsertPoint(ExitBBCopy->begin()); } |