[PATCH] D76845: [GlobalISel] add helper function to create arbitrary libcalls
Dominik Montada via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 26 07:33:40 PDT 2020
gargaroff created this revision.
gargaroff added reviewers: aditya_nandakumar, t.p.northover, rovka, arsenm, dsanders.
Herald added subscribers: llvm-commits, volkan, hiraditya, wdng.
Herald added a project: LLVM.
gargaroff added a comment.
Our downstream target requires this function to lower llvm.trap to a libcall to abort.
The existing helper function can only create a libcall to functions available in
RTLIB. Add a helper function that can create a libcall to a given function name
using the provided calling convention.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D76845
Files:
llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
Index: llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
===================================================================
--- llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
+++ llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
@@ -2722,4 +2722,30 @@
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
}
+TEST_F(AArch64GISelMITest, CreateLibcall) {
+ setUp();
+ if (!TM)
+ return;
+
+ DefineLegalizerInfo(A, {});
+
+ AInfo Info(MF->getSubtarget());
+ DummyGISelObserver Observer;
+
+ LLVMContext &Ctx = MF->getFunction().getContext();
+ auto *RetTy = Type::getVoidTy(Ctx);
+
+ EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized,
+ createLibcall(B, "abort", {{}, RetTy}, {}, CallingConv::C));
+
+ auto CheckStr = R"(
+ CHECK: ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
+ CHECK: BL &abort
+ CHECK: ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
+ )";
+
+ // Check
+ EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
+}
+
} // namespace
Index: llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -489,15 +489,14 @@
}
LegalizerHelper::LegalizeResult
-llvm::createLibcall(MachineIRBuilder &MIRBuilder, RTLIB::Libcall Libcall,
+llvm::createLibcall(MachineIRBuilder &MIRBuilder, const char *Name,
const CallLowering::ArgInfo &Result,
- ArrayRef<CallLowering::ArgInfo> Args) {
+ ArrayRef<CallLowering::ArgInfo> Args,
+ const CallingConv::ID CC) {
auto &CLI = *MIRBuilder.getMF().getSubtarget().getCallLowering();
- auto &TLI = *MIRBuilder.getMF().getSubtarget().getTargetLowering();
- const char *Name = TLI.getLibcallName(Libcall);
CallLowering::CallLoweringInfo Info;
- Info.CallConv = TLI.getLibcallCallingConv(Libcall);
+ Info.CallConv = CC;
Info.Callee = MachineOperand::CreateES(Name);
Info.OrigRet = Result;
std::copy(Args.begin(), Args.end(), std::back_inserter(Info.OrigArgs));
@@ -507,6 +506,16 @@
return LegalizerHelper::Legalized;
}
+LegalizerHelper::LegalizeResult
+llvm::createLibcall(MachineIRBuilder &MIRBuilder, RTLIB::Libcall Libcall,
+ const CallLowering::ArgInfo &Result,
+ ArrayRef<CallLowering::ArgInfo> Args) {
+ auto &TLI = *MIRBuilder.getMF().getSubtarget().getTargetLowering();
+ const char *Name = TLI.getLibcallName(Libcall);
+ const CallingConv::ID CC = TLI.getLibcallCallingConv(Libcall);
+ return createLibcall(MIRBuilder, Name, Result, Args, CC);
+}
+
// Useful for libcalls where all operands have the same type.
static LegalizerHelper::LegalizeResult
simpleLibcall(MachineInstr &MI, MachineIRBuilder &MIRBuilder, unsigned Size,
Index: llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h
===================================================================
--- llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h
+++ llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h
@@ -304,6 +304,13 @@
GISelChangeObserver &Observer;
};
+/// Helper function that creates a libcall to the given \p Name using the given
+/// calling convention \p CC.
+LegalizerHelper::LegalizeResult
+createLibcall(MachineIRBuilder &MIRBuilder, const char *Name,
+ const CallLowering::ArgInfo &Result,
+ ArrayRef<CallLowering::ArgInfo> Args, CallingConv::ID CC);
+
/// Helper function that creates the given libcall.
LegalizerHelper::LegalizeResult
createLibcall(MachineIRBuilder &MIRBuilder, RTLIB::Libcall Libcall,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76845.252832.patch
Type: text/x-patch
Size: 3675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200326/461cb087/attachment.bin>
More information about the llvm-commits
mailing list