Skip to content

Commit 6d64c93

Browse files
author
Marek Sedlacek
committed
Added call for inline assembly and global alias
1 parent 463609b commit 6d64c93

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

llvm/tools/ir2builder/ir2builder.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,14 +1515,40 @@ void IR2Builder::convert(const Instruction *I, raw_ostream &OS) {
15151515
Fun = FcI->getCalledFunction();
15161516

15171517
if (!Fun) {
1518-
assert(FcI->isIndirectCall() && "sanity check");
1519-
if (ArgDecl.empty()) {
1520-
Call = "CreateCall(" + asStr(FcI->getFunctionType()) + ", " +
1518+
if (auto InA = dyn_cast<InlineAsm>(FcI->getCalledOperand())) {
1519+
if (ArgDecl.empty()) {
1520+
Call = "CreateCall(" + asStr(InA->getFunctionType()) + ", " +
15211521
asStr(I->getOperand(I->getNumOperands() - 1)) + ")";
1522-
} else {
1523-
Call = "CreateCall(" + asStr(FcI->getFunctionType()) + ", " +
1524-
asStr(I->getOperand(I->getNumOperands() - 1)) + ", " + ArgDecl +
1525-
")";
1522+
} else {
1523+
Call = "CreateCall(" + asStr(InA->getFunctionType()) + ", " +
1524+
asStr(I->getOperand(I->getNumOperands() - 1)) + ", " + ArgDecl +
1525+
")";
1526+
}
1527+
}
1528+
else if (FcI->isIndirectCall()) {
1529+
if (ArgDecl.empty()) {
1530+
Call = "CreateCall(" + asStr(FcI->getFunctionType()) + ", " +
1531+
asStr(I->getOperand(I->getNumOperands() - 1)) + ")";
1532+
} else {
1533+
Call = "CreateCall(" + asStr(FcI->getFunctionType()) + ", " +
1534+
asStr(I->getOperand(I->getNumOperands() - 1)) + ", " + ArgDecl +
1535+
")";
1536+
}
1537+
}
1538+
else if (auto GA = dyn_cast<GlobalAlias>(FcI->getCalledOperand())) {
1539+
Fun = dyn_cast<Function>(GA->getAliaseeObject());
1540+
assert(Fun && "Global alias is not a function");
1541+
OS << "auto " << FunDecl << " = " << ModName << "->getOrInsertFunction(\""
1542+
<< Fun->getName() << "\", " << asStr(Fun->getFunctionType())
1543+
<< ");\n";
1544+
if (!ArgDecl.empty())
1545+
Call = "CreateCall(" + FunDecl + ", " + ArgDecl + ")";
1546+
else
1547+
Call = "CreateCall(" + FunDecl + ")";
1548+
}
1549+
else {
1550+
OS << "/* TODO: Unknown CallBase type in Call instruction */\n";
1551+
return;
15261552
}
15271553
} else {
15281554
// No need to save this variable as it is a temporary one.

0 commit comments

Comments
 (0)