Skip to content

Commit f3ce7c0

Browse files
committed
restrict constant -> instruction upgrade to kernel/a specified function
1 parent 476c9ba commit f3ce7c0

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

llvm/include/llvm/IR/ReplaceConstant.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ namespace llvm {
1818

1919
template <typename T> class ArrayRef;
2020
class Constant;
21+
class Function;
2122

2223
/// Replace constant expressions users of the given constants with
2324
/// instructions. Return whether anything was changed.
2425
bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts,
26+
Function *RestrictToFunc = nullptr,
2527
bool RemoveDeadConstants = true);
2628

2729
} // end namespace llvm

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5187,7 +5187,7 @@ static Function *createOutlinedFunction(
51875187
// from MLIR to LLVM-IR and the MLIR lowering may still require the original
51885188
// constants we have created rewritten versions of.
51895189
if (auto *Const = dyn_cast<Constant>(Input))
5190-
convertUsersOfConstantsToInstructions({Const}, false);
5190+
convertUsersOfConstantsToInstructions({Const}, Func, false);
51915191

51925192
// Collect all the instructions
51935193
for (User *User : make_early_inc_range(Input->users()))

llvm/lib/IR/ReplaceConstant.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static SmallVector<Instruction *, 4> expandUser(BasicBlock::iterator InsertPt,
5050
}
5151

5252
bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts,
53+
Function *RestrictToFunc,
5354
bool RemoveDeadConstants) {
5455
// Find all expandable direct users of Consts.
5556
SmallVector<Constant *> Stack;
@@ -75,7 +76,8 @@ bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts,
7576
for (Constant *C : ExpandableUsers)
7677
for (User *U : C->users())
7778
if (auto *I = dyn_cast<Instruction>(U))
78-
InstructionWorklist.insert(I);
79+
if (!RestrictToFunc || I->getFunction() == RestrictToFunc)
80+
InstructionWorklist.insert(I);
7981

8082
// Replace those expandable operands with instructions
8183
bool Changed = false;

0 commit comments

Comments
 (0)