Skip to content

Commit d33c676

Browse files
authored
[ConstantFolding] Constify ConstantFoldInstOperands and ConstantFoldInstruction argument. NFC (#138108)
I tried to use these with a const reference in a separate patch, but the pointers weren't marked as const. It turns out that these don't mutate the instruction.
1 parent b877cfa commit d33c676

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

llvm/include/llvm/Analysis/ConstantFolding.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV, APInt &Offset,
5353
/// Note that this fails if not all of the operands are constant. Otherwise,
5454
/// this function can only fail when attempting to fold instructions like loads
5555
/// and stores, which have no constant expression form.
56-
Constant *ConstantFoldInstruction(Instruction *I, const DataLayout &DL,
56+
Constant *ConstantFoldInstruction(const Instruction *I, const DataLayout &DL,
5757
const TargetLibraryInfo *TLI = nullptr);
5858

5959
/// ConstantFoldConstant - Fold the constant using the specified DataLayout.
@@ -74,7 +74,8 @@ Constant *ConstantFoldConstant(const Constant *C, const DataLayout &DL,
7474
/// all uses of the original operation are replaced by the constant-folded
7575
/// result. The \p AllowNonDeterministic parameter controls whether this is
7676
/// allowed.
77-
Constant *ConstantFoldInstOperands(Instruction *I, ArrayRef<Constant *> Ops,
77+
Constant *ConstantFoldInstOperands(const Instruction *I,
78+
ArrayRef<Constant *> Ops,
7879
const DataLayout &DL,
7980
const TargetLibraryInfo *TLI = nullptr,
8081
bool AllowNonDeterministic = true);

llvm/lib/Analysis/ConstantFolding.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,8 @@ ConstantFoldConstantImpl(const Constant *C, const DataLayout &DL,
11231123

11241124
} // end anonymous namespace
11251125

1126-
Constant *llvm::ConstantFoldInstruction(Instruction *I, const DataLayout &DL,
1126+
Constant *llvm::ConstantFoldInstruction(const Instruction *I,
1127+
const DataLayout &DL,
11271128
const TargetLibraryInfo *TLI) {
11281129
// Handle PHI nodes quickly here...
11291130
if (auto *PN = dyn_cast<PHINode>(I)) {
@@ -1156,7 +1157,7 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I, const DataLayout &DL,
11561157

11571158
// Scan the operand list, checking to see if they are all constants, if so,
11581159
// hand off to ConstantFoldInstOperandsImpl.
1159-
if (!all_of(I->operands(), [](Use &U) { return isa<Constant>(U); }))
1160+
if (!all_of(I->operands(), [](const Use &U) { return isa<Constant>(U); }))
11601161
return nullptr;
11611162

11621163
SmallDenseMap<Constant *, Constant *> FoldedOps;
@@ -1177,7 +1178,7 @@ Constant *llvm::ConstantFoldConstant(const Constant *C, const DataLayout &DL,
11771178
return ConstantFoldConstantImpl(C, DL, TLI, FoldedOps);
11781179
}
11791180

1180-
Constant *llvm::ConstantFoldInstOperands(Instruction *I,
1181+
Constant *llvm::ConstantFoldInstOperands(const Instruction *I,
11811182
ArrayRef<Constant *> Ops,
11821183
const DataLayout &DL,
11831184
const TargetLibraryInfo *TLI,

0 commit comments

Comments
 (0)