[llvm] Revert "[IR] Don't store switch case values as operands" (PR #170962)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 5 18:40:19 PST 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm-c/Core.h llvm/include/llvm/IR/Instructions.h llvm/include/llvm/IR/User.h llvm/lib/Bitcode/Writer/ValueEnumerator.cpp llvm/lib/CodeGen/TypePromotion.cpp llvm/lib/IR/Core.cpp llvm/lib/IR/Instructions.cpp llvm/lib/IR/User.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp llvm/unittests/IR/InstructionsTest.cpp llvm/unittests/IR/VerifierTest.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index 8bd060ae8..ccb312e80 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -3299,7 +3299,7 @@ public:
void setValue(ConstantInt *V) const {
assert((unsigned)Index < SI->getNumCases() &&
"Index out the number of cases.");
- SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
+ SI->setOperand(2 + Index * 2, reinterpret_cast<Value *>(V));
}
/// Sets the new successor for current case.
@@ -3406,9 +3406,7 @@ public:
/// Return the number of 'cases' in this switch instruction, excluding the
/// default case.
- unsigned getNumCases() const {
- return getNumOperands()/2 - 1;
- }
+ unsigned getNumCases() const { return getNumOperands() / 2 - 1; }
/// Returns a read/write iterator that points to the first case in the
/// SwitchInst.
@@ -3510,10 +3508,10 @@ public:
/// case.
LLVM_ABI CaseIt removeCase(CaseIt I);
- unsigned getNumSuccessors() const { return getNumOperands()/2; }
+ unsigned getNumSuccessors() const { return getNumOperands() / 2; }
BasicBlock *getSuccessor(unsigned idx) const {
assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
- return cast<BasicBlock>(getOperand(idx*2+1));
+ return cast<BasicBlock>(getOperand(idx * 2 + 1));
}
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 85d3690dd..461a95046 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -4076,7 +4076,7 @@ SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(Value->getContext()), Instruction::Switch,
AllocMarker, InsertBefore) {
- init(Value, Default, 2+NumCases*2);
+ init(Value, Default, 2 + NumCases * 2);
}
SwitchInst::SwitchInst(const SwitchInst &SI)
@@ -4087,7 +4087,7 @@ SwitchInst::SwitchInst(const SwitchInst &SI)
const Use *InOL = SI.getOperandList();
for (unsigned i = 2, E = SI.getNumOperands(); i != E; i += 2) {
OL[i] = InOL[i];
- OL[i+1] = InOL[i+1];
+ OL[i + 1] = InOL[i + 1];
}
SubclassOptionalData = SI.SubclassOptionalData;
}
@@ -4097,11 +4097,11 @@ SwitchInst::SwitchInst(const SwitchInst &SI)
void SwitchInst::addCase(ConstantInt *OnVal, BasicBlock *Dest) {
unsigned NewCaseIdx = getNumCases();
unsigned OpNo = getNumOperands();
- if (OpNo+2 > ReservedSpace)
+ if (OpNo + 2 > ReservedSpace)
growOperands(); // Get more space!
// Initialize some new operands.
- assert(OpNo+1 < ReservedSpace && "Growing didn't work!");
- setNumHungOffUseOperands(OpNo+2);
+ assert(OpNo + 1 < ReservedSpace && "Growing didn't work!");
+ setNumHungOffUseOperands(OpNo + 2);
CaseHandle Case(this, NewCaseIdx);
Case.setValue(OnVal);
Case.setSuccessor(Dest);
@@ -4112,7 +4112,7 @@ void SwitchInst::addCase(ConstantInt *OnVal, BasicBlock *Dest) {
SwitchInst::CaseIt SwitchInst::removeCase(CaseIt I) {
unsigned idx = I->getCaseIndex();
- assert(2 + idx*2 < getNumOperands() && "Case index out of range!!!");
+ assert(2 + idx * 2 < getNumOperands() && "Case index out of range!!!");
unsigned NumOps = getNumOperands();
Use *OL = getOperandList();
@@ -4124,9 +4124,9 @@ SwitchInst::CaseIt SwitchInst::removeCase(CaseIt I) {
}
// Nuke the last value.
- OL[NumOps-2].set(nullptr);
- OL[NumOps-2+1].set(nullptr);
- setNumHungOffUseOperands(NumOps-2);
+ OL[NumOps - 2].set(nullptr);
+ OL[NumOps - 2 + 1].set(nullptr);
+ setNumHungOffUseOperands(NumOps - 2);
return CaseIt(this, idx);
}
diff --git a/llvm/lib/IR/User.cpp b/llvm/lib/IR/User.cpp
index 9bb7c1298..460003105 100644
--- a/llvm/lib/IR/User.cpp
+++ b/llvm/lib/IR/User.cpp
@@ -92,7 +92,6 @@ void User::growHungoffUses(unsigned NewNumUses, bool IsPhi) {
Use::zap(OldOps, OldOps + OldNumUses, true);
}
-
// This is a private struct used by `User` to track the co-allocated descriptor
// section.
struct DescriptorInfo {
``````````
</details>
https://github.com/llvm/llvm-project/pull/170962
More information about the llvm-commits
mailing list