[PATCH] D85037: [LCSSA] Use IRBuilder for PHI creation.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 1 10:47:03 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa9b06a2c14f9: [LCSSA] Use IRBuilder for PHI creation. (authored by fhahn).
Changed prior to commit:
https://reviews.llvm.org/D85037?vs=282260&id=282406#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85037/new/
https://reviews.llvm.org/D85037
Files:
llvm/include/llvm/Transforms/Utils/LoopUtils.h
llvm/lib/Transforms/Utils/LCSSA.cpp
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
Index: llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
===================================================================
--- llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -1951,11 +1951,8 @@
// a defining loop. Fix LCSSA from for each operand of the new instruction,
// if required.
for (unsigned OpIdx = 0, OpEnd = Inst->getNumOperands(); OpIdx != OpEnd;
- OpIdx++) {
- auto *V = fixupLCSSAFormFor(Inst, OpIdx);
- if (V != I)
- DoInsert(V);
- }
+ OpIdx++)
+ fixupLCSSAFormFor(Inst, OpIdx);
}
}
@@ -2540,7 +2537,7 @@
return OpV;
ToUpdate.push_back(OpI);
- formLCSSAForInstructions(ToUpdate, SE.DT, SE.LI, &SE);
+ formLCSSAForInstructions(ToUpdate, SE.DT, SE.LI, &SE, Builder);
return User->getOperand(OpIdx);
}
Index: llvm/lib/Transforms/Utils/LCSSA.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LCSSA.cpp
+++ llvm/lib/Transforms/Utils/LCSSA.cpp
@@ -40,6 +40,7 @@
#include "llvm/IR/Constants.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/PredIteratorCache.h"
@@ -77,12 +78,15 @@
/// rewrite the uses.
bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
const DominatorTree &DT, const LoopInfo &LI,
- ScalarEvolution *SE) {
+ ScalarEvolution *SE,
+ IRBuilderBase &Builder) {
SmallVector<Use *, 16> UsesToRewrite;
SmallSetVector<PHINode *, 16> PHIsToRemove;
PredIteratorCache PredCache;
bool Changed = false;
+ IRBuilderBase::InsertPointGuard InsertPtGuard(Builder);
+
// Cache the Loop ExitBlocks across this loop. We expect to get a lot of
// instructions within the same loops, computing the exit blocks is
// expensive, and we're not mutating the loop structure.
@@ -151,9 +155,9 @@
// If we already inserted something for this BB, don't reprocess it.
if (SSAUpdate.HasValueForBlock(ExitBB))
continue;
-
- PHINode *PN = PHINode::Create(I->getType(), PredCache.size(ExitBB),
- I->getName() + ".lcssa", &ExitBB->front());
+ Builder.SetInsertPoint(&ExitBB->front());
+ PHINode *PN = Builder.CreatePHI(I->getType(), PredCache.size(ExitBB),
+ I->getName() + ".lcssa");
// Get the debug location from the original instruction.
PN->setDebugLoc(I->getDebugLoc());
// Add inputs from inside the loop for this PHI.
@@ -369,7 +373,9 @@
Worklist.push_back(&I);
}
}
- Changed = formLCSSAForInstructions(Worklist, DT, *LI, SE);
+
+ IRBuilder<> Builder(L.getHeader()->getContext());
+ Changed = formLCSSAForInstructions(Worklist, DT, *LI, SE, Builder);
// If we modified the code, remove any caches about the loop from SCEV to
// avoid dangling entries.
Index: llvm/include/llvm/Transforms/Utils/LoopUtils.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -76,7 +76,7 @@
/// Returns true if any modifications are made.
bool formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
const DominatorTree &DT, const LoopInfo &LI,
- ScalarEvolution *SE);
+ ScalarEvolution *SE, IRBuilderBase &Builder);
/// Put loop into LCSSA form.
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85037.282406.patch
Type: text/x-patch
Size: 3758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200801/0989032a/attachment.bin>
More information about the llvm-commits
mailing list