Skip to content

Commit 062c395

Browse files
committed
Define and reuse I64Ty and PtrTy in legalizeLifetimeIntrinsics function for better readability
1 parent 18e57db commit 062c395

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ class WriteDXILPass : public llvm::ModulePass {
5959

6060
static void legalizeLifetimeIntrinsics(Module &M) {
6161
LLVMContext &Ctx = M.getContext();
62+
Type *I64Ty = IntegerType::get(Ctx, 64);
63+
Type *PtrTy = PointerType::get(Ctx, 0);
6264
Intrinsic::ID LifetimeIIDs[2] = {Intrinsic::lifetime_start,
6365
Intrinsic::lifetime_end};
6466
for (Intrinsic::ID &IID : LifetimeIIDs) {
65-
Function *F =
66-
M.getFunction(Intrinsic::getName(IID, {PointerType::get(Ctx, 0)}, &M));
67+
Function *F = M.getFunction(Intrinsic::getName(IID, {PtrTy}, &M));
6768
if (!F)
6869
continue;
6970

@@ -73,8 +74,7 @@ static void legalizeLifetimeIntrinsics(Module &M) {
7374
AttributeList Attr;
7475
Attr = Attr.addFnAttribute(Ctx, Attribute::NoUnwind);
7576
FunctionCallee LifetimeCallee = M.getOrInsertFunction(
76-
Intrinsic::getBaseName(IID), Attr, Type::getVoidTy(Ctx),
77-
IntegerType::get(Ctx, 64), PointerType::get(Ctx, 0));
77+
Intrinsic::getBaseName(IID), Attr, Type::getVoidTy(Ctx), I64Ty, PtrTy);
7878

7979
// Replace all calls to lifetime intrinsics with calls to the
8080
// LLVM 3.7-compliant version of the lifetime intrinsic
@@ -86,9 +86,9 @@ static void legalizeLifetimeIntrinsics(Module &M) {
8686
// LLVM 3.7 lifetime intrinics require an i8* operand, so we insert
8787
// a bitcast to ensure that is the case
8888
Value *PtrOperand = CI->getArgOperand(0);
89-
PointerType *PtrTy = cast<PointerType>(PtrOperand->getType());
89+
PointerType *PtrOpPtrTy = cast<PointerType>(PtrOperand->getType());
9090
Value *NoOpBitCast = CastInst::Create(Instruction::BitCast, PtrOperand,
91-
PtrTy, "", CI->getIterator());
91+
PtrOpPtrTy, "", CI->getIterator());
9292

9393
// LLVM 3.7 lifetime intrinsics have an explicit size operand, whose value
9494
// we can obtain from the pointer operand which must be an AllocaInst (as
@@ -101,12 +101,11 @@ static void legalizeLifetimeIntrinsics(Module &M) {
101101
AI->getAllocationSize(CI->getDataLayout());
102102
assert(AllocSize.has_value() &&
103103
"Expected the allocation size of AllocaInst to be known");
104-
CallInst *NewCI =
105-
CallInst::Create(LifetimeCallee,
106-
{ConstantInt::get(IntegerType::get(Ctx, 64),
107-
AllocSize.value().getFixedValue()),
108-
NoOpBitCast},
109-
"", CI->getIterator());
104+
CallInst *NewCI = CallInst::Create(
105+
LifetimeCallee,
106+
{ConstantInt::get(I64Ty, AllocSize.value().getFixedValue()),
107+
NoOpBitCast},
108+
"", CI->getIterator());
110109
for (Attribute ParamAttr : CI->getParamAttributes(0))
111110
NewCI->addParamAttr(1, ParamAttr);
112111

0 commit comments

Comments
 (0)