summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <florian.hahn@arm.com>2018-03-06 14:00:58 +0000
committerFlorian Hahn <florian.hahn@arm.com>2018-03-06 14:00:58 +0000
commit517dc51c488739e45b9a6ad67c31f85778f43459 (patch)
treebecd57dda7ddd648168b4255343df6aae7e7bfa0 /llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp
parent446d6ec996c6c397d4576d9608e1dd01a97e0064 (diff)
downloadbcm5719-llvm-517dc51c488739e45b9a6ad67c31f85778f43459.tar.gz
bcm5719-llvm-517dc51c488739e45b9a6ad67c31f85778f43459.zip
[CallSiteSplitting] Do not crash when BB's terminator changes.
Change doCallSiteSplitting to iterate until we reach the terminator instruction. tryToSplitCallSite can replace BB's terminator in case BB is a successor of itself. Then IE will be invalidated and we also have to check the current terminator. Reviewers: junbuml, davidxl, davide, fhahn Reviewed By: fhahn, junbuml Differential Revision: https://reviews.llvm.org/D43824 llvm-svn: 326793
Diffstat (limited to 'llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp b/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp
index dcd21e843c6..ddebaf67f66 100644
--- a/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp
+++ b/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp
@@ -469,7 +469,13 @@ static bool doCallSiteSplitting(Function &F, TargetLibraryInfo &TLI,
bool Changed = false;
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE;) {
BasicBlock &BB = *BI++;
- for (BasicBlock::iterator II = BB.begin(), IE = BB.end(); II != IE;) {
+ auto II = BB.getFirstNonPHIOrDbg()->getIterator();
+ auto IE = BB.getTerminator()->getIterator();
+ // Iterate until we reach the terminator instruction. tryToSplitCallSite
+ // can replace BB's terminator in case BB is a successor of itself. In that
+ // case, IE will be invalidated and we also have to check the current
+ // terminator.
+ while (II != IE && &*II != BB.getTerminator()) {
Instruction *I = &*II++;
CallSite CS(cast<Value>(I));
if (!CS || isa<IntrinsicInst>(I) || isInstructionTriviallyDead(I, &TLI))
OpenPOWER on IntegriCloud