diff options
Diffstat (limited to 'llvm/lib/IR/ReplaceConstant.cpp')
| -rw-r--r-- | llvm/lib/IR/ReplaceConstant.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/llvm/lib/IR/ReplaceConstant.cpp b/llvm/lib/IR/ReplaceConstant.cpp index 9b07bd804049..c55a80acf0b5 100644 --- a/llvm/lib/IR/ReplaceConstant.cpp +++ b/llvm/lib/IR/ReplaceConstant.cpp @@ -49,13 +49,22 @@ static SmallVector<Instruction *, 4> expandUser(BasicBlock::iterator InsertPt, return NewInsts; } -bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts) { +bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts, + Function *RestrictToFunc, + bool RemoveDeadConstants, + bool IncludeSelf) { // Find all expandable direct users of Consts. SmallVector<Constant *> Stack; - for (Constant *C : Consts) - for (User *U : C->users()) - if (isExpandableUser(U)) - Stack.push_back(cast<Constant>(U)); + for (Constant *C : Consts) { + if (IncludeSelf) { + assert(isExpandableUser(C) && "One of the constants is not expandable"); + Stack.push_back(C); + } else { + for (User *U : C->users()) + if (isExpandableUser(U)) + Stack.push_back(cast<Constant>(U)); + } + } // Include transitive users. SetVector<Constant *> ExpandableUsers; @@ -74,7 +83,8 @@ bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts) { for (Constant *C : ExpandableUsers) for (User *U : C->users()) if (auto *I = dyn_cast<Instruction>(U)) - InstructionWorklist.insert(I); + if (!RestrictToFunc || I->getFunction() == RestrictToFunc) + InstructionWorklist.insert(I); // Replace those expandable operands with instructions bool Changed = false; @@ -102,8 +112,9 @@ bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts) { } } - for (Constant *C : Consts) - C->removeDeadConstantUsers(); + if (RemoveDeadConstants) + for (Constant *C : Consts) + C->removeDeadConstantUsers(); return Changed; } |
