Skip to content

Commit 99f5417

Browse files
committed
Sink routine for replacing a operand bundle to CallBase [NFC]
We had equivalent code for both CallInst and InvokeInst, but never cared about the result type.
1 parent 8051156 commit 99f5417

File tree

4 files changed

+23
-51
lines changed

4 files changed

+23
-51
lines changed

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,15 @@ class CallBase : public Instruction {
12141214
static CallBase *Create(CallBase *CB, ArrayRef<OperandBundleDef> Bundles,
12151215
Instruction *InsertPt = nullptr);
12161216

1217+
/// Create a clone of \p CB with the operand bundle with the tag matching
1218+
/// \p Bundle's tag replaced with Bundle, and insert it before \p InsertPt.
1219+
///
1220+
/// The returned call instruction is identical \p CI in every way except that
1221+
/// the specified operand bundle has been replaced.
1222+
static CallBase *Create(CallBase *CB,
1223+
OperandBundleDef Bundle,
1224+
Instruction *InsertPt = nullptr);
1225+
12171226
static bool classof(const Instruction *I) {
12181227
return I->getOpcode() == Instruction::Call ||
12191228
I->getOpcode() == Instruction::Invoke ||

llvm/include/llvm/IR/Instructions.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,16 +1585,6 @@ class CallInst : public CallBase {
15851585
static CallInst *Create(CallInst *CI, ArrayRef<OperandBundleDef> Bundles,
15861586
Instruction *InsertPt = nullptr);
15871587

1588-
/// Create a clone of \p CI with a different set of operand bundles and
1589-
/// insert it before \p InsertPt.
1590-
///
1591-
/// The returned call instruction is identical \p CI in every way except that
1592-
/// the operand bundle for the new instruction is set to the operand bundle
1593-
/// in \p Bundle.
1594-
static CallInst *CreateWithReplacedBundle(CallInst *CI,
1595-
OperandBundleDef Bundle,
1596-
Instruction *InsertPt = nullptr);
1597-
15981588
/// Generate the IR for a call to malloc:
15991589
/// 1. Compute the malloc call's argument as the specified type's size,
16001590
/// possibly multiplied by the array size if the array size is not
@@ -3824,16 +3814,6 @@ class InvokeInst : public CallBase {
38243814
static InvokeInst *Create(InvokeInst *II, ArrayRef<OperandBundleDef> Bundles,
38253815
Instruction *InsertPt = nullptr);
38263816

3827-
/// Create a clone of \p II with a different set of operand bundles and
3828-
/// insert it before \p InsertPt.
3829-
///
3830-
/// The returned invoke instruction is identical to \p II in every way except
3831-
/// that the operand bundle for the new instruction is set to the operand
3832-
/// bundle in \p Bundle.
3833-
static InvokeInst *CreateWithReplacedBundle(InvokeInst *II,
3834-
OperandBundleDef Bundles,
3835-
Instruction *InsertPt = nullptr);
3836-
38373817
// get*Dest - Return the destination basic blocks...
38383818
BasicBlock *getNormalDest() const {
38393819
return cast<BasicBlock>(Op<NormalDestOpEndIdx>());

llvm/lib/IR/Instructions.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,19 @@ CallBase *CallBase::Create(CallBase *CB, ArrayRef<OperandBundleDef> Bundles,
262262
}
263263
}
264264

265+
CallBase *CallBase::Create(CallBase *CI, OperandBundleDef OpB,
266+
Instruction *InsertPt) {
267+
SmallVector<OperandBundleDef, 2> OpDefs;
268+
for (unsigned i = 0, e = CI->getNumOperandBundles(); i < e; ++i) {
269+
auto ChildOB = CI->getOperandBundleAt(i);
270+
if (ChildOB.getTagName() != OpB.getTag())
271+
OpDefs.emplace_back(ChildOB);
272+
}
273+
OpDefs.emplace_back(OpB);
274+
return CallBase::Create(CI, OpDefs, InsertPt);
275+
}
276+
277+
265278
Function *CallBase::getCaller() { return getParent()->getParent(); }
266279

267280
unsigned CallBase::getNumSubclassExtraOperandsDynamic() const {
@@ -506,18 +519,6 @@ CallInst *CallInst::Create(CallInst *CI, ArrayRef<OperandBundleDef> OpB,
506519
return NewCI;
507520
}
508521

509-
CallInst *CallInst::CreateWithReplacedBundle(CallInst *CI, OperandBundleDef OpB,
510-
Instruction *InsertPt) {
511-
SmallVector<OperandBundleDef, 2> OpDefs;
512-
for (unsigned i = 0, e = CI->getNumOperandBundles(); i < e; ++i) {
513-
auto ChildOB = CI->getOperandBundleAt(i);
514-
if (ChildOB.getTagName() != OpB.getTag())
515-
OpDefs.emplace_back(ChildOB);
516-
}
517-
OpDefs.emplace_back(OpB);
518-
return CallInst::Create(CI, OpDefs, InsertPt);
519-
}
520-
521522
// Update profile weight for call instruction by scaling it using the ratio
522523
// of S/T. The meaning of "branch_weights" meta data for call instruction is
523524
// transfered to represent call count.
@@ -830,19 +831,6 @@ InvokeInst *InvokeInst::Create(InvokeInst *II, ArrayRef<OperandBundleDef> OpB,
830831
return NewII;
831832
}
832833

833-
InvokeInst *InvokeInst::CreateWithReplacedBundle(InvokeInst *II,
834-
OperandBundleDef OpB,
835-
Instruction *InsertPt) {
836-
SmallVector<OperandBundleDef, 2> OpDefs;
837-
for (unsigned i = 0, e = II->getNumOperandBundles(); i < e; ++i) {
838-
auto ChildOB = II->getOperandBundleAt(i);
839-
if (ChildOB.getTagName() != OpB.getTag())
840-
OpDefs.emplace_back(ChildOB);
841-
}
842-
OpDefs.emplace_back(OpB);
843-
return InvokeInst::Create(II, OpDefs, InsertPt);
844-
}
845-
846834
LandingPadInst *InvokeInst::getLandingPadInst() const {
847835
return cast<LandingPadInst>(getUnwindDest()->getFirstNonPHI());
848836
}

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,12 +1763,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
17631763
}
17641764
// Create new statepoint instruction.
17651765
OperandBundleDef NewBundle("gc-live", NewLiveGc);
1766-
if (isa<CallInst>(II))
1767-
return CallInst::CreateWithReplacedBundle(cast<CallInst>(II), NewBundle);
1768-
else
1769-
return InvokeInst::CreateWithReplacedBundle(cast<InvokeInst>(II),
1770-
NewBundle);
1771-
break;
1766+
return CallBase::Create(II, NewBundle);
17721767
}
17731768
case Intrinsic::experimental_guard: {
17741769
// Is this guard followed by another guard? We scan forward over a small

0 commit comments

Comments
 (0)