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) {
5054 initSoftFloatCmpLibcallPredicates ();
51- initDefaultLibCallNames ();
55+ initDefaultLibCallImpls ();
5256 initLibcalls (TT, ExceptionModel, FloatABI, EABIVersion);
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
109122private:
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