Skip to content

Commit 133049d

Browse files
committed
[opaque pointers] Fix uses of deprecated CreateCall/CreateInvoke.
1 parent 8345b86 commit 133049d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

llvm/unittests/Transforms/Utils/LocalTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,12 +1019,12 @@ TEST(Local, CanReplaceOperandWithVariable) {
10191019
BasicBlock *BB0 = BasicBlock::Create(Ctx, "", TestBody);
10201020
B.SetInsertPoint(BB0);
10211021

1022-
Value *Intrin = M.getOrInsertFunction("llvm.foo", FnType).getCallee();
1023-
Value *Func = M.getOrInsertFunction("foo", FnType).getCallee();
1024-
Value *VarArgFunc
1025-
= M.getOrInsertFunction("foo.vararg", VarArgFnType).getCallee();
1026-
Value *VarArgIntrin
1027-
= M.getOrInsertFunction("llvm.foo.vararg", VarArgFnType).getCallee();
1022+
FunctionCallee Intrin = M.getOrInsertFunction("llvm.foo", FnType);
1023+
FunctionCallee Func = M.getOrInsertFunction("foo", FnType);
1024+
FunctionCallee VarArgFunc
1025+
= M.getOrInsertFunction("foo.vararg", VarArgFnType);
1026+
FunctionCallee VarArgIntrin
1027+
= M.getOrInsertFunction("llvm.foo.vararg", VarArgFnType);
10281028

10291029
auto *CallToIntrin = B.CreateCall(Intrin);
10301030
auto *CallToFunc = B.CreateCall(Func);

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,12 @@ LogicalResult ModuleTranslation::convertOperation(Operation &opInst,
334334
return builder.CreateCall(functionMapping.lookup(attr.getValue()),
335335
operandsRef);
336336
} else {
337-
return builder.CreateCall(operandsRef.front(), operandsRef.drop_front());
337+
auto *calleePtrType =
338+
cast<llvm::PointerType>(operandsRef.front()->getType());
339+
auto *calleeType =
340+
cast<llvm::FunctionType>(calleePtrType->getElementType());
341+
return builder.CreateCall(calleeType, operandsRef.front(),
342+
operandsRef.drop_front());
338343
}
339344
};
340345

@@ -353,14 +358,19 @@ LogicalResult ModuleTranslation::convertOperation(Operation &opInst,
353358
if (auto invOp = dyn_cast<LLVM::InvokeOp>(opInst)) {
354359
auto operands = lookupValues(opInst.getOperands());
355360
ArrayRef<llvm::Value *> operandsRef(operands);
356-
if (auto attr = opInst.getAttrOfType<FlatSymbolRefAttr>("callee"))
361+
if (auto attr = opInst.getAttrOfType<FlatSymbolRefAttr>("callee")) {
357362
builder.CreateInvoke(functionMapping.lookup(attr.getValue()),
358363
blockMapping[invOp.getSuccessor(0)],
359364
blockMapping[invOp.getSuccessor(1)], operandsRef);
360-
else
365+
} else {
366+
auto *calleePtrType =
367+
cast<llvm::PointerType>(operandsRef.front()->getType());
368+
auto *calleeType =
369+
cast<llvm::FunctionType>(calleePtrType->getElementType());
361370
builder.CreateInvoke(
362-
operandsRef.front(), blockMapping[invOp.getSuccessor(0)],
371+
calleeType, operandsRef.front(), blockMapping[invOp.getSuccessor(0)],
363372
blockMapping[invOp.getSuccessor(1)], operandsRef.drop_front());
373+
}
364374
return success();
365375
}
366376

0 commit comments

Comments
 (0)