llvm-project/llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td
Matt Arsenault 19ebfa6d0b
RuntimeLibcalls: Move exception call config to tablegen (#151948)
Also starts pruning out these calls if the exception model is
forced to none.

I worked backwards from the logic in addPassesToHandleExceptions
and the pass content. There appears to be some tolerance
for mixing and matching exception modes inside of a single module.
As far as I can tell _Unwind_CallPersonality is only relevant for
wasm, so just add it there.

As usual, the arm64ec case makes things difficult and is
missing test coverage. The set of calls in list form is necessary
to use foreach for the duplication, but in every other context a
dag is more convenient. You cannot use foreach over a dag, and I
haven't found a way to flatten a dag into a list.

This removes the last manual setLibcallImpl call in generic code.
2025-08-19 10:35:59 +09:00

97 lines
3.6 KiB
TableGen

// RUN: llvm-tblgen -gen-runtime-libcalls -I %p/../../include %s | FileCheck %s
include "llvm/IR/RuntimeLibcallsImpl.td"
def SDIVREM_I8 : RuntimeLibcall;
def UDIVREM_I16 : RuntimeLibcall;
def MALLOC : RuntimeLibcall;
def TARGET_OVERRIDE_CC : RuntimeLibcall;
def __divmodqi4 : RuntimeLibcallImpl<SDIVREM_I8>;
def __udivmodhi4 : RuntimeLibcallImpl<UDIVREM_I16>;
// Test a case where a target wants to set a different calling
// convention on a generic builtin
def __target_override_cc : RuntimeLibcallImpl<TARGET_OVERRIDE_CC>;
def malloc : RuntimeLibcallImpl<MALLOC>;
def isAVR : RuntimeLibcallPredicate<[{TT.getArch() == Triple::avr}]>;
def isAVRHurd : RuntimeLibcallPredicate<
[{TT.getArch() == Triple::avr && TT.isOSHurd()}]>;
def AVRLibrary : SystemRuntimeLibrary<isAVR,
(add malloc, LibcallsWithCC<(add __divmodqi4, __udivmodhi4), AVR_BUILTIN>)
>;
// Test with default calling convention
def AVRHurdLibrary : SystemRuntimeLibrary<isAVRHurd,
(add malloc, LibcallsWithCC<(add __divmodqi4, __udivmodhi4), AVR_BUILTIN>)> {
let DefaultLibcallCallingConv
= LibcallCallingConv<[{isFoo() ? CallingConv::Fast : CallingConv::GHC}]>;
}
def isMSP430 : RuntimeLibcallPredicate<[{TT.getArch() == Triple::msp430}]>;
def MSP430LibraryWithCondCC : SystemRuntimeLibrary<isMSP430,
(add malloc,
LibcallsWithCC<(add __divmodqi4), AVR_BUILTIN, RuntimeLibcallPredicate<[{ isFoo() }]>>,
LibcallsWithCC<(add __udivmodhi4), MSP430_BUILTIN, RuntimeLibcallPredicate<[{ isBar() }]>>)
>;
// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, ExceptionHandling ExceptionModel, FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName) {
// CHECK: if (TT.getArch() == Triple::avr && TT.isOSHurd()) {
// CHECK-NEXT: const CallingConv::ID DefaultCC = isFoo() ? CallingConv::Fast : CallingConv::GHC;
// CHECK-NEXT: for (CallingConv::ID &Entry : LibcallImplCallingConvs) {
// CHECK-NEXT: Entry = DefaultCC;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: setLibcallsImpl({
// CHECK-NEXT: {RTLIB::MALLOC, RTLIB::malloc}, // malloc
// CHECK-NEXT: });
// CHECK-EMPTY:
// CHECK-NEXT: setLibcallsImpl({
// CHECK-NEXT: {RTLIB::SDIVREM_I8, RTLIB::__divmodqi4}, // __divmodqi4
// CHECK-NEXT: {RTLIB::UDIVREM_I16, RTLIB::__udivmodhi4}, // __udivmodhi4
// CHECK-NEXT: }, CallingConv::AVR_BUILTIN);
// CHECK-EMPTY:
// CHECK-NEXT: return;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: if (TT.getArch() == Triple::avr) {
// CHECK-NEXT: setLibcallsImpl({
// CHECK-NEXT: {RTLIB::MALLOC, RTLIB::malloc}, // malloc
// CHECK-NEXT: });
// CHECK-EMPTY:
// CHECK-NEXT: setLibcallsImpl({
// CHECK-NEXT: {RTLIB::SDIVREM_I8, RTLIB::__divmodqi4}, // __divmodqi4
// CHECK-NEXT: {RTLIB::UDIVREM_I16, RTLIB::__udivmodhi4}, // __udivmodhi4
// CHECK-NEXT: }, CallingConv::AVR_BUILTIN);
// CHECK-EMPTY:
// CHECK-NEXT: return;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: if (TT.getArch() == Triple::msp430) {
// CHECK-NEXT: setLibcallsImpl({
// CHECK-NEXT: {RTLIB::MALLOC, RTLIB::malloc}, // malloc
// CHECK-NEXT: });
// CHECK-EMPTY:
// CHECK-NEXT: if ( isFoo() ) {
// CHECK-NEXT: setLibcallsImpl({
// CHECK-NEXT: {RTLIB::SDIVREM_I8, RTLIB::__divmodqi4}, // __divmodqi4
// CHECK-NEXT: }, CallingConv::AVR_BUILTIN);
// CHECK-EMPTY:
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: if ( isBar() ) {
// CHECK-NEXT: setLibcallsImpl({
// CHECK-NEXT: {RTLIB::UDIVREM_I16, RTLIB::__udivmodhi4}, // __udivmodhi4
// CHECK-NEXT: }, CallingConv::MSP430_BUILTIN);
// CHECK-EMPTY:
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: return;
// CHECK-NEXT: }