Skip to content

Commit 34ec1d9

Browse files
committed
TableGen: Generate enum for runtime libcall implementations
Work towards separating the ABI existence of libcalls vs. the lowering selection. Set libcall selection through enums, rather than through raw string names.
1 parent 456f081 commit 34ec1d9

File tree

12 files changed

+1217
-538
lines changed

12 files changed

+1217
-538
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3558,13 +3558,8 @@ class LLVM_ABI TargetLoweringBase {
35583558
return nullptr;
35593559
}
35603560

3561-
/// Rename the default libcall routine name for the specified libcall.
3562-
void setLibcallName(RTLIB::Libcall Call, const char *Name) {
3563-
Libcalls.setLibcallName(Call, Name);
3564-
}
3565-
3566-
void setLibcallName(ArrayRef<RTLIB::Libcall> Calls, const char *Name) {
3567-
Libcalls.setLibcallName(Calls, Name);
3561+
void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
3562+
Libcalls.setLibcallImpl(Call, Impl);
35683563
}
35693564

35703565
/// Get the libcall routine name for the specified libcall.

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include "llvm/Support/Compiler.h"
2424
#include "llvm/TargetParser/Triple.h"
2525

26+
/// TableGen will produce 2 enums, RTLIB::Libcall and
27+
/// RTLIB::LibcallImpl. RTLIB::Libcall describes abstract functionality the
28+
/// compiler may choose to access, RTLIB::LibcallImpl describes a particular ABI
29+
/// implementation, which includes a name and type signature.
2630
#define GET_RUNTIME_LIBCALL_ENUM
2731
#include "llvm/IR/RuntimeLibcalls.inc"
2832
#undef GET_RUNTIME_LIBCALL_ENUM
@@ -48,38 +52,46 @@ struct RuntimeLibcallsInfo {
4852
FloatABI::ABIType FloatABI = FloatABI::Default,
4953
EABI EABIVersion = EABI::Default, StringRef ABIName = "") {
5054
initSoftFloatCmpLibcallPredicates();
51-
initDefaultLibCallNames();
55+
initDefaultLibCallImpls();
5256
initLibcalls(TT, ExceptionModel, FloatABI, EABIVersion, ABIName);
5357
}
5458

5559
/// Rename the default libcall routine name for the specified libcall.
56-
void setLibcallName(RTLIB::Libcall Call, const char *Name) {
57-
LibcallRoutineNames[Call] = Name;
58-
}
59-
60-
void setLibcallName(ArrayRef<RTLIB::Libcall> Calls, const char *Name) {
61-
for (auto Call : Calls)
62-
setLibcallName(Call, Name);
60+
void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
61+
LibcallImpls[Call] = Impl;
6362
}
6463

6564
/// Get the libcall routine name for the specified libcall.
65+
// FIXME: This should be removed. Only LibcallImpl should have a name.
6666
const char *getLibcallName(RTLIB::Libcall Call) const {
67-
return LibcallRoutineNames[Call];
67+
return LibCallImplNames[LibcallImpls[Call]];
68+
}
69+
70+
/// Get the libcall routine name for the specified libcall implementation.
71+
const char *getLibcallImplName(RTLIB::LibcallImpl CallImpl) const {
72+
return LibCallImplNames[CallImpl];
73+
}
74+
75+
/// Return the lowering's selection of implementation call for \p Call
76+
RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const {
77+
return LibcallImpls[Call];
6878
}
6979

7080
/// Set the CallingConv that should be used for the specified libcall.
81+
// FIXME: This should be a function of RTLIB::LibcallImpl
7182
void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
7283
LibcallCallingConvs[Call] = CC;
7384
}
7485

7586
/// Get the CallingConv that should be used for the specified libcall.
87+
// FIXME: This should be a function of RTLIB::LibcallImpl
7688
CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
7789
return LibcallCallingConvs[Call];
7890
}
7991

80-
ArrayRef<const char *> getLibcallNames() const {
81-
// Trim UNKNOWN_LIBCALL from the end
82-
return ArrayRef(LibcallRoutineNames).drop_back();
92+
ArrayRef<RTLIB::LibcallImpl> getLibcallImpls() const {
93+
// Trim Unsupported from the start
94+
return ArrayRef(LibcallImpls).drop_front();
8395
}
8496

8597
/// Get the comparison predicate that's to be used to test the result of the
@@ -91,6 +103,7 @@ struct RuntimeLibcallsInfo {
91103
}
92104

93105
// FIXME: This should be removed. This should be private constant.
106+
// FIXME: This should be a function of RTLIB::LibcallImpl
94107
void setSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call,
95108
CmpInst::Predicate Pred) {
96109
SoftFloatCompareLibcallPredicates[Call] = Pred;
@@ -107,11 +120,12 @@ struct RuntimeLibcallsInfo {
107120
}
108121

109122
private:
110-
static const char *const
111-
DefaultLibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1];
123+
static const RTLIB::LibcallImpl
124+
DefaultLibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1];
112125

113-
/// Stores the name each libcall.
114-
const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr};
126+
/// Stores the implementation choice for each each libcall.
127+
RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
128+
RTLIB::Unsupported};
115129

116130
static_assert(static_cast<int>(CallingConv::C) == 0,
117131
"default calling conv should be encoded as 0");
@@ -127,6 +141,13 @@ struct RuntimeLibcallsInfo {
127141
// opcode.
128142
CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL];
129143

144+
/// Names of concrete implementations of runtime calls. e.g. __ashlsi3 for
145+
/// SHL_I32
146+
static const char *const LibCallImplNames[RTLIB::NumLibcallImpls];
147+
148+
/// Map from a concrete LibcallImpl implementation to its RTLIB::Libcall kind.
149+
static const RTLIB::Libcall ImplToLibcall[RTLIB::NumLibcallImpls];
150+
130151
static bool darwinHasSinCosStret(const Triple &TT) {
131152
assert(TT.isOSDarwin() && "should be called with darwin triple");
132153
// Don't bother with 32 bit x86.
@@ -148,7 +169,7 @@ struct RuntimeLibcallsInfo {
148169
(TT.isAndroid() && !TT.isAndroidVersionLT(9));
149170
}
150171

151-
void initDefaultLibCallNames();
172+
void initDefaultLibCallImpls();
152173

153174
/// Generated by tablegen.
154175
void setPPCLibCallNameOverrides();

0 commit comments

Comments
 (0)