Skip to content

Commit c0a264e

Browse files
authored
[IntrinsicInst] Remove MemCpyInlineInst and MemSetInlineInst [nfc] (llvm#138568)
I'm looking for ways to simplify the Mem*Inst class structure, and these two seem to have fairly minimal justification, so let's remove them.
1 parent 00e7a02 commit c0a264e

File tree

10 files changed

+47
-86
lines changed

10 files changed

+47
-86
lines changed

llvm/include/llvm/IR/InstVisitor.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,10 @@ class InstVisitor {
207207
RetTy visitDbgLabelInst(DbgLabelInst &I) { DELEGATE(DbgInfoIntrinsic);}
208208
RetTy visitDbgInfoIntrinsic(DbgInfoIntrinsic &I){ DELEGATE(IntrinsicInst); }
209209
RetTy visitMemSetInst(MemSetInst &I) { DELEGATE(MemIntrinsic); }
210-
RetTy visitMemSetInlineInst(MemSetInlineInst &I){ DELEGATE(MemSetInst); }
211210
RetTy visitMemSetPatternInst(MemSetPatternInst &I) {
212211
DELEGATE(IntrinsicInst);
213212
}
214213
RetTy visitMemCpyInst(MemCpyInst &I) { DELEGATE(MemTransferInst); }
215-
RetTy visitMemCpyInlineInst(MemCpyInlineInst &I){ DELEGATE(MemCpyInst); }
216214
RetTy visitMemMoveInst(MemMoveInst &I) { DELEGATE(MemTransferInst); }
217215
RetTy visitMemTransferInst(MemTransferInst &I) { DELEGATE(MemIntrinsic); }
218216
RetTy visitMemIntrinsic(MemIntrinsic &I) { DELEGATE(IntrinsicInst); }
@@ -291,13 +289,13 @@ class InstVisitor {
291289
case Intrinsic::dbg_declare: DELEGATE(DbgDeclareInst);
292290
case Intrinsic::dbg_value: DELEGATE(DbgValueInst);
293291
case Intrinsic::dbg_label: DELEGATE(DbgLabelInst);
294-
case Intrinsic::memcpy: DELEGATE(MemCpyInst);
292+
case Intrinsic::memcpy:
295293
case Intrinsic::memcpy_inline:
296-
DELEGATE(MemCpyInlineInst);
294+
DELEGATE(MemCpyInst);
297295
case Intrinsic::memmove: DELEGATE(MemMoveInst);
298-
case Intrinsic::memset: DELEGATE(MemSetInst);
296+
case Intrinsic::memset:
299297
case Intrinsic::memset_inline:
300-
DELEGATE(MemSetInlineInst);
298+
DELEGATE(MemSetInst);
301299
case Intrinsic::experimental_memset_pattern:
302300
DELEGATE(MemSetPatternInst);
303301
case Intrinsic::vastart: DELEGATE(VAStartInst);

llvm/include/llvm/IR/IntrinsicInst.h

+10-24
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,16 @@ class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
12151215

12161216
void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); }
12171217

1218+
bool isForceInlined() const {
1219+
switch (getIntrinsicID()) {
1220+
case Intrinsic::memset_inline:
1221+
case Intrinsic::memcpy_inline:
1222+
return true;
1223+
default:
1224+
return false;
1225+
}
1226+
}
1227+
12181228
// Methods for support type inquiry through isa, cast, and dyn_cast:
12191229
static bool classof(const IntrinsicInst *I) {
12201230
switch (I->getIntrinsicID()) {
@@ -1251,18 +1261,6 @@ class MemSetInst : public MemSetBase<MemIntrinsic> {
12511261
}
12521262
};
12531263

1254-
/// This class wraps the llvm.memset.inline intrinsic.
1255-
class MemSetInlineInst : public MemSetInst {
1256-
public:
1257-
// Methods for support type inquiry through isa, cast, and dyn_cast:
1258-
static bool classof(const IntrinsicInst *I) {
1259-
return I->getIntrinsicID() == Intrinsic::memset_inline;
1260-
}
1261-
static bool classof(const Value *V) {
1262-
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1263-
}
1264-
};
1265-
12661264
/// This is the base class for llvm.experimental.memset.pattern
12671265
class MemSetPatternIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
12681266
private:
@@ -1342,18 +1340,6 @@ class MemMoveInst : public MemTransferInst {
13421340
}
13431341
};
13441342

1345-
/// This class wraps the llvm.memcpy.inline intrinsic.
1346-
class MemCpyInlineInst : public MemCpyInst {
1347-
public:
1348-
// Methods for support type inquiry through isa, cast, and dyn_cast:
1349-
static bool classof(const IntrinsicInst *I) {
1350-
return I->getIntrinsicID() == Intrinsic::memcpy_inline;
1351-
}
1352-
static bool classof(const Value *V) {
1353-
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1354-
}
1355-
};
1356-
13571343
// The common base class for any memset/memmove/memcpy intrinsics;
13581344
// whether they be atomic or non-atomic.
13591345
// i.e. llvm.element.unordered.atomic.memset/memcpy/memmove

llvm/lib/Analysis/Lint.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -344,19 +344,13 @@ void Lint::visitCallBase(CallBase &I) {
344344
MMI->getSourceAlign(), nullptr, MemRef::Read);
345345
break;
346346
}
347-
case Intrinsic::memset: {
347+
case Intrinsic::memset:
348+
case Intrinsic::memset_inline: {
348349
MemSetInst *MSI = cast<MemSetInst>(&I);
349350
visitMemoryReference(I, MemoryLocation::getForDest(MSI),
350351
MSI->getDestAlign(), nullptr, MemRef::Write);
351352
break;
352353
}
353-
case Intrinsic::memset_inline: {
354-
MemSetInlineInst *MSII = cast<MemSetInlineInst>(&I);
355-
visitMemoryReference(I, MemoryLocation::getForDest(MSII),
356-
MSII->getDestAlign(), nullptr, MemRef::Write);
357-
break;
358-
}
359-
360354
case Intrinsic::vastart:
361355
// vastart in non-varargs function is rejected by the verifier
362356
visitMemoryReference(I, MemoryLocation::getForArgument(&I, 0, TLI),

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -1734,10 +1734,6 @@ bool IRTranslator::translateMemFunc(const CallInst &CI,
17341734
DstAlign = MCI->getDestAlign().valueOrOne();
17351735
SrcAlign = MCI->getSourceAlign().valueOrOne();
17361736
CopySize = dyn_cast<ConstantInt>(MCI->getArgOperand(2));
1737-
} else if (auto *MCI = dyn_cast<MemCpyInlineInst>(&CI)) {
1738-
DstAlign = MCI->getDestAlign().valueOrOne();
1739-
SrcAlign = MCI->getSourceAlign().valueOrOne();
1740-
CopySize = dyn_cast<ConstantInt>(MCI->getArgOperand(2));
17411737
} else if (auto *MMI = dyn_cast<MemMoveInst>(&CI)) {
17421738
DstAlign = MMI->getDestAlign().valueOrOne();
17431739
SrcAlign = MMI->getSourceAlign().valueOrOne();

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(Function &F) const {
319319
// Only expand llvm.memcpy.inline with non-constant length in this
320320
// codepath, leaving the current SelectionDAG expansion for constant
321321
// length memcpy intrinsics undisturbed.
322-
auto *Memcpy = cast<MemCpyInlineInst>(Inst);
322+
auto *Memcpy = cast<MemCpyInst>(Inst);
323323
if (isa<ConstantInt>(Memcpy->getLength()))
324324
break;
325325

@@ -367,7 +367,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(Function &F) const {
367367
// Only expand llvm.memset.inline with non-constant length in this
368368
// codepath, leaving the current SelectionDAG expansion for constant
369369
// length memset intrinsics undisturbed.
370-
auto *Memset = cast<MemSetInlineInst>(Inst);
370+
auto *Memset = cast<MemSetInst>(Inst);
371371
if (isa<ConstantInt>(Memset->getLength()))
372372
break;
373373

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

+8-22
Original file line numberDiff line numberDiff line change
@@ -6483,7 +6483,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
64836483
return;
64846484
}
64856485
case Intrinsic::memcpy_inline: {
6486-
const auto &MCI = cast<MemCpyInlineInst>(I);
6486+
const auto &MCI = cast<MemCpyInst>(I);
64876487
SDValue Dst = getValue(I.getArgOperand(0));
64886488
SDValue Src = getValue(I.getArgOperand(1));
64896489
SDValue Size = getValue(I.getArgOperand(2));
@@ -6503,35 +6503,21 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
65036503
updateDAGForMaybeTailCall(MC);
65046504
return;
65056505
}
6506-
case Intrinsic::memset: {
6507-
const auto &MSI = cast<MemSetInst>(I);
6508-
SDValue Op1 = getValue(I.getArgOperand(0));
6509-
SDValue Op2 = getValue(I.getArgOperand(1));
6510-
SDValue Op3 = getValue(I.getArgOperand(2));
6511-
// @llvm.memset defines 0 and 1 to both mean no alignment.
6512-
Align Alignment = MSI.getDestAlign().valueOrOne();
6513-
bool isVol = MSI.isVolatile();
6514-
SDValue Root = isVol ? getRoot() : getMemoryRoot();
6515-
SDValue MS = DAG.getMemset(
6516-
Root, sdl, Op1, Op2, Op3, Alignment, isVol, /* AlwaysInline */ false,
6517-
&I, MachinePointerInfo(I.getArgOperand(0)), I.getAAMetadata());
6518-
updateDAGForMaybeTailCall(MS);
6519-
return;
6520-
}
6506+
case Intrinsic::memset:
65216507
case Intrinsic::memset_inline: {
6522-
const auto &MSII = cast<MemSetInlineInst>(I);
6508+
const auto &MSII = cast<MemSetInst>(I);
65236509
SDValue Dst = getValue(I.getArgOperand(0));
65246510
SDValue Value = getValue(I.getArgOperand(1));
65256511
SDValue Size = getValue(I.getArgOperand(2));
6526-
assert(isa<ConstantSDNode>(Size) && "memset_inline needs constant size");
6512+
assert((!MSII.isForceInlined() || isa<ConstantSDNode>(Size)) &&
6513+
"memset_inline needs constant size");
65276514
// @llvm.memset defines 0 and 1 to both mean no alignment.
65286515
Align DstAlign = MSII.getDestAlign().valueOrOne();
65296516
bool isVol = MSII.isVolatile();
65306517
SDValue Root = isVol ? getRoot() : getMemoryRoot();
6531-
SDValue MC = DAG.getMemset(Root, sdl, Dst, Value, Size, DstAlign, isVol,
6532-
/* AlwaysInline */ true, &I,
6533-
MachinePointerInfo(I.getArgOperand(0)),
6534-
I.getAAMetadata());
6518+
SDValue MC = DAG.getMemset(
6519+
Root, sdl, Dst, Value, Size, DstAlign, isVol, MSII.isForceInlined(),
6520+
&I, MachinePointerInfo(I.getArgOperand(0)), I.getAAMetadata());
65356521
updateDAGForMaybeTailCall(MC);
65366522
return;
65376523
}

llvm/lib/IR/IRBuilder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ CallInst *IRBuilderBase::CreateMemSetInline(Value *Dst, MaybeAlign DstAlign,
203203
CallInst *CI = CreateIntrinsic(Intrinsic::memset_inline, Tys, Ops);
204204

205205
if (DstAlign)
206-
cast<MemSetInlineInst>(CI)->setDestAlignment(*DstAlign);
206+
cast<MemSetInst>(CI)->setDestAlignment(*DstAlign);
207207

208208
// Set the TBAA info if present.
209209
if (TBAATag)

llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -1142,18 +1142,18 @@ static bool handleMemIntrinsicPtrUse(MemIntrinsic *MI, Value *OldV,
11421142
if (Dest == OldV)
11431143
Dest = NewV;
11441144

1145-
if (isa<MemCpyInlineInst>(MTI)) {
1145+
if (auto *MCI = dyn_cast<MemCpyInst>(MTI)) {
11461146
MDNode *TBAAStruct = MTI->getMetadata(LLVMContext::MD_tbaa_struct);
1147-
B.CreateMemCpyInline(Dest, MTI->getDestAlign(), Src,
1148-
MTI->getSourceAlign(), MTI->getLength(),
1149-
false, // isVolatile
1150-
TBAA, TBAAStruct, ScopeMD, NoAliasMD);
1151-
} else if (isa<MemCpyInst>(MTI)) {
1152-
MDNode *TBAAStruct = MTI->getMetadata(LLVMContext::MD_tbaa_struct);
1153-
B.CreateMemCpy(Dest, MTI->getDestAlign(), Src, MTI->getSourceAlign(),
1154-
MTI->getLength(),
1155-
false, // isVolatile
1156-
TBAA, TBAAStruct, ScopeMD, NoAliasMD);
1147+
if (MCI->isForceInlined())
1148+
B.CreateMemCpyInline(Dest, MTI->getDestAlign(), Src,
1149+
MTI->getSourceAlign(), MTI->getLength(),
1150+
false, // isVolatile
1151+
TBAA, TBAAStruct, ScopeMD, NoAliasMD);
1152+
else
1153+
B.CreateMemCpy(Dest, MTI->getDestAlign(), Src, MTI->getSourceAlign(),
1154+
MTI->getLength(),
1155+
false, // isVolatile
1156+
TBAA, TBAAStruct, ScopeMD, NoAliasMD);
11571157
} else {
11581158
assert(isa<MemMoveInst>(MTI));
11591159
B.CreateMemMove(Dest, MTI->getDestAlign(), Src, MTI->getSourceAlign(),

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ bool LoopIdiomRecognize::processLoopMemCpy(MemCpyInst *MCI,
780780
return false;
781781

782782
// If we're not allowed to hack on memcpy, we fail.
783-
if ((!HasMemcpy && !isa<MemCpyInlineInst>(MCI)) || DisableLIRP::Memcpy)
783+
if ((!HasMemcpy && !MCI->isForceInlined()) || DisableLIRP::Memcpy)
784784
return false;
785785

786786
Value *Dest = MCI->getDest();
@@ -1267,7 +1267,7 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(
12671267
// FIXME: until llvm.memcpy.inline supports dynamic sizes, we need to
12681268
// conservatively bail here, since otherwise we may have to transform
12691269
// llvm.memcpy.inline into llvm.memcpy which is illegal.
1270-
if (isa<MemCpyInlineInst>(TheStore))
1270+
if (auto *MCI = dyn_cast<MemCpyInst>(TheStore); MCI && MCI->isForceInlined())
12711271
return false;
12721272

12731273
// The trip count of the loop and the base pointer of the addrec SCEV is

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M,
12121212
// Don't convert llvm.memcpy.inline into memmove because memmove can be
12131213
// lowered as a call, and that is not allowed for llvm.memcpy.inline (and
12141214
// there is no inline version of llvm.memmove)
1215-
if (isa<MemCpyInlineInst>(M))
1215+
if (M->isForceInlined())
12161216
return false;
12171217
UseMemMove = true;
12181218
}
@@ -1229,17 +1229,18 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M,
12291229
NewM =
12301230
Builder.CreateMemMove(M->getDest(), M->getDestAlign(), CopySource,
12311231
CopySourceAlign, M->getLength(), M->isVolatile());
1232-
else if (isa<MemCpyInlineInst>(M)) {
1232+
else if (M->isForceInlined())
12331233
// llvm.memcpy may be promoted to llvm.memcpy.inline, but the converse is
12341234
// never allowed since that would allow the latter to be lowered as a call
12351235
// to an external function.
12361236
NewM = Builder.CreateMemCpyInline(M->getDest(), M->getDestAlign(),
12371237
CopySource, CopySourceAlign,
12381238
M->getLength(), M->isVolatile());
1239-
} else
1240-
NewM =
1241-
Builder.CreateMemCpy(M->getDest(), M->getDestAlign(), CopySource,
1242-
CopySourceAlign, M->getLength(), M->isVolatile());
1239+
else
1240+
NewM = Builder.CreateMemCpy(M->getDest(), M->getDestAlign(), CopySource,
1241+
CopySourceAlign, M->getLength(),
1242+
M->isVolatile());
1243+
12431244
NewM->copyMetadata(*M, LLVMContext::MD_DIAssignID);
12441245

12451246
assert(isa<MemoryDef>(MSSA->getMemoryAccess(M)));

0 commit comments

Comments
 (0)