-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ConstantFolding] Constify ConstantFoldInstOperands and ConstantFoldInstruction argument. NFC #138108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…nstruction. NFC 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.
@llvm/pr-subscribers-llvm-analysis Author: Luke Lau (lukel97) ChangesI 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. Full diff: https://github.com/llvm/llvm-project/pull/138108.diff 2 Files Affected:
diff --git a/llvm/include/llvm/Analysis/ConstantFolding.h b/llvm/include/llvm/Analysis/ConstantFolding.h
index 58b38fb8b0367..706ba0d835cb1 100644
--- a/llvm/include/llvm/Analysis/ConstantFolding.h
+++ b/llvm/include/llvm/Analysis/ConstantFolding.h
@@ -53,7 +53,7 @@ bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV, APInt &Offset,
/// Note that this fails if not all of the operands are constant. Otherwise,
/// this function can only fail when attempting to fold instructions like loads
/// and stores, which have no constant expression form.
-Constant *ConstantFoldInstruction(Instruction *I, const DataLayout &DL,
+Constant *ConstantFoldInstruction(const Instruction *I, const DataLayout &DL,
const TargetLibraryInfo *TLI = nullptr);
/// ConstantFoldConstant - Fold the constant using the specified DataLayout.
@@ -74,7 +74,8 @@ Constant *ConstantFoldConstant(const Constant *C, const DataLayout &DL,
/// all uses of the original operation are replaced by the constant-folded
/// result. The \p AllowNonDeterministic parameter controls whether this is
/// allowed.
-Constant *ConstantFoldInstOperands(Instruction *I, ArrayRef<Constant *> Ops,
+Constant *ConstantFoldInstOperands(const Instruction *I,
+ ArrayRef<Constant *> Ops,
const DataLayout &DL,
const TargetLibraryInfo *TLI = nullptr,
bool AllowNonDeterministic = true);
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index dc905ab03e861..5b329e2f898f3 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1123,7 +1123,8 @@ ConstantFoldConstantImpl(const Constant *C, const DataLayout &DL,
} // end anonymous namespace
-Constant *llvm::ConstantFoldInstruction(Instruction *I, const DataLayout &DL,
+Constant *llvm::ConstantFoldInstruction(const Instruction *I,
+ const DataLayout &DL,
const TargetLibraryInfo *TLI) {
// Handle PHI nodes quickly here...
if (auto *PN = dyn_cast<PHINode>(I)) {
@@ -1156,7 +1157,7 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I, const DataLayout &DL,
// Scan the operand list, checking to see if they are all constants, if so,
// hand off to ConstantFoldInstOperandsImpl.
- if (!all_of(I->operands(), [](Use &U) { return isa<Constant>(U); }))
+ if (!all_of(I->operands(), [](const Use &U) { return isa<Constant>(U); }))
return nullptr;
SmallDenseMap<Constant *, Constant *> FoldedOps;
@@ -1177,7 +1178,7 @@ Constant *llvm::ConstantFoldConstant(const Constant *C, const DataLayout &DL,
return ConstantFoldConstantImpl(C, DL, TLI, FoldedOps);
}
-Constant *llvm::ConstantFoldInstOperands(Instruction *I,
+Constant *llvm::ConstantFoldInstOperands(const Instruction *I,
ArrayRef<Constant *> Ops,
const DataLayout &DL,
const TargetLibraryInfo *TLI,
|
dtcxzyw
approved these changes
May 1, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…nstruction argument. NFC (llvm#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.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…nstruction argument. NFC (llvm#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.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
…nstruction argument. NFC (llvm#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.
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
…nstruction argument. NFC (llvm#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.
Ankur-0429
pushed a commit
to Ankur-0429/llvm-project
that referenced
this pull request
May 9, 2025
…nstruction argument. NFC (llvm#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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.