Skip to content

Commit 287500e

Browse files
committed
llvm-11: Usual LLVM version shenanigans
This time, LLVM simply changed the interface for indirect calls. In an incompatible way, of course. Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
1 parent b17ce75 commit 287500e

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/llvm-crap.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,11 @@ void *JIT::ExecutableCode(JIT::Function_p f)
12651265
// Return an executable pointer to the function
12661266
// ----------------------------------------------------------------------------
12671267
{
1268+
#if LLVM_VERSION < 1100
12681269
JITTargetAddress address = p.Address(f->getName());
1270+
#else // LLVM_VERSION >= 1100
1271+
JITTargetAddress address = p.Address(f->getName().str());
1272+
#endif // LLVM_VERSION
12691273
record(llvm_functions, "Address of %v is %p", f, (void *) address);
12701274
return (void *) address;
12711275
}
@@ -1292,7 +1296,11 @@ JIT::Function_p JIT::Prototype(JIT::Function_p function)
12921296
// If the function is in this module, return it, else return prototype for it
12931297
{
12941298
JIT::Module_p module = p.Module();
1299+
#if LLVM_VERSION < 1100
12951300
text name = function->getName();
1301+
#else // LLVM_VERSION >= 1100
1302+
text name = function->getName().str();
1303+
#endif
12961304

12971305
// First check if we don't already have it in the current module
12981306
if (module)
@@ -1583,13 +1591,38 @@ void JITBlock::SwitchTo(JIT::BasicBlock_p block)
15831591
}
15841592

15851593

1594+
#if LLVM_VERSION < 1100
1595+
#define Callee(V) (V)
1596+
#else // LLVM_VERSION >= 1100
1597+
static inline llvm::FunctionCallee Callee(JIT::Value_p callee)
1598+
// ----------------------------------------------------------------------------
1599+
// Another totally useless wrapper with more damage to come
1600+
// ----------------------------------------------------------------------------
1601+
{
1602+
JIT::Type_p type = callee->getType();
1603+
if (type->isFunctionTy())
1604+
{
1605+
JIT::FunctionType_p ftype = (JIT::FunctionType_p) type;
1606+
return llvm::FunctionCallee(ftype, callee);
1607+
}
1608+
1609+
assert(type->isPointerTy() && "Callee requires a callable value");
1610+
JIT::PointerType_p ptype = (JIT::PointerType_p) type;
1611+
type = ptype->getElementType();
1612+
assert(type->isFunctionTy() && "Callee require function type for callee");
1613+
JIT::FunctionType_p ftype = (JIT::FunctionType_p) type;
1614+
return llvm::FunctionCallee(ftype, callee);
1615+
}
1616+
#endif
1617+
1618+
15861619
JIT::Value_p JITBlock::Call(JIT::Value_p callee, JIT::Value_p arg1)
15871620
// ----------------------------------------------------------------------------
15881621
// Create a call with one argument
15891622
// ----------------------------------------------------------------------------
15901623
{
15911624
JIT::Value_p proto = b.jit.Prototype(callee);
1592-
JIT::Value_p result = b->CreateCall(proto, {arg1});
1625+
JIT::Value_p result = b->CreateCall(Callee(proto), {arg1});
15931626
record(llvm_ir, "Call %v(%v) = %v", callee, arg1, result);
15941627
return result;
15951628
}
@@ -1603,7 +1636,7 @@ JIT::Value_p JITBlock::Call(JIT::Value_p callee,
16031636
// ----------------------------------------------------------------------------
16041637
{
16051638
JIT::Value_p proto = b.jit.Prototype(callee);
1606-
JIT::Value_p result = b->CreateCall(proto, {arg1, arg2});
1639+
JIT::Value_p result = b->CreateCall(Callee(proto), {arg1, arg2});
16071640
record(llvm_ir, "Call %v(%v, %v) = %v", callee, arg1, arg2, result);
16081641
return result;
16091642
}
@@ -1618,7 +1651,7 @@ JIT::Value_p JITBlock::Call(JIT::Value_p callee,
16181651
// ----------------------------------------------------------------------------
16191652
{
16201653
JIT::Value_p proto = b.jit.Prototype(callee);
1621-
JIT::Value_p result = b->CreateCall(proto, {arg1, arg2, arg3});
1654+
JIT::Value_p result = b->CreateCall(Callee(proto), {arg1, arg2, arg3});
16221655
record(llvm_ir, "Call %v(%v, %v, %v) = %v", callee, arg1,arg2,arg3, result);
16231656
return result;
16241657
}
@@ -1631,7 +1664,8 @@ JIT::Value_p JITBlock::Call(JIT::Value_p callee,
16311664
// ----------------------------------------------------------------------------
16321665
{
16331666
JIT::Value_p proto = b.jit.Prototype(callee);
1634-
JIT::Value_p result = b->CreateCall(proto, ArrayRef<JIT::Value_p>(args));
1667+
JIT::Value_p result = b->CreateCall(Callee(proto),
1668+
ArrayRef<JIT::Value_p>(args));
16351669
record(llvm_ir, "Call %v(#%u) = %v", callee, args.size(), result);
16361670
return result;
16371671
}

0 commit comments

Comments
 (0)