@@ -59,11 +59,12 @@ class WriteDXILPass : public llvm::ModulePass {
59
59
60
60
static void legalizeLifetimeIntrinsics (Module &M) {
61
61
LLVMContext &Ctx = M.getContext ();
62
+ Type *I64Ty = IntegerType::get (Ctx, 64 );
63
+ Type *PtrTy = PointerType::get (Ctx, 0 );
62
64
Intrinsic::ID LifetimeIIDs[2 ] = {Intrinsic::lifetime_start,
63
65
Intrinsic::lifetime_end};
64
66
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));
67
68
if (!F)
68
69
continue ;
69
70
@@ -73,8 +74,7 @@ static void legalizeLifetimeIntrinsics(Module &M) {
73
74
AttributeList Attr;
74
75
Attr = Attr.addFnAttribute (Ctx, Attribute::NoUnwind);
75
76
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);
78
78
79
79
// Replace all calls to lifetime intrinsics with calls to the
80
80
// LLVM 3.7-compliant version of the lifetime intrinsic
@@ -86,9 +86,9 @@ static void legalizeLifetimeIntrinsics(Module &M) {
86
86
// LLVM 3.7 lifetime intrinics require an i8* operand, so we insert
87
87
// a bitcast to ensure that is the case
88
88
Value *PtrOperand = CI->getArgOperand (0 );
89
- PointerType *PtrTy = cast<PointerType>(PtrOperand->getType ());
89
+ PointerType *PtrOpPtrTy = cast<PointerType>(PtrOperand->getType ());
90
90
Value *NoOpBitCast = CastInst::Create (Instruction::BitCast, PtrOperand,
91
- PtrTy , " " , CI->getIterator ());
91
+ PtrOpPtrTy , " " , CI->getIterator ());
92
92
93
93
// LLVM 3.7 lifetime intrinsics have an explicit size operand, whose value
94
94
// we can obtain from the pointer operand which must be an AllocaInst (as
@@ -101,12 +101,11 @@ static void legalizeLifetimeIntrinsics(Module &M) {
101
101
AI->getAllocationSize (CI->getDataLayout ());
102
102
assert (AllocSize.has_value () &&
103
103
" 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 ());
110
109
for (Attribute ParamAttr : CI->getParamAttributes (0 ))
111
110
NewCI->addParamAttr (1 , ParamAttr);
112
111
0 commit comments