13
13
#include " llvm-c/Orc.h"
14
14
#include " gtest/gtest.h"
15
15
16
+ #include " llvm/Analysis/TargetLibraryInfo.h"
16
17
#include " llvm/ExecutionEngine/Orc/CompileUtils.h"
17
18
#include " llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
18
19
#include " llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
@@ -32,6 +33,20 @@ using namespace llvm::orc;
32
33
DEFINE_SIMPLE_CONVERSION_FUNCTIONS (ObjectLayer, LLVMOrcObjectLayerRef)
33
34
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef)
34
35
36
+ // A class that sets strings for extension attributes by querying
37
+ // TargetLibraryInfo.
38
+ struct TargetI32ArgExtensions {
39
+ std::string Ret;
40
+ std::string Arg;
41
+ TargetI32ArgExtensions (std::string TargetTriple, bool Signed = true ) {
42
+ Triple T (TargetTriple);
43
+ if (auto AK = TargetLibraryInfo::getExtAttrForI32Return (T, Signed))
44
+ Ret = Attribute::getNameFromAttrKind (AK).str () + " " ;
45
+ if (auto AK = TargetLibraryInfo::getExtAttrForI32Param (T, Signed))
46
+ Arg = Attribute::getNameFromAttrKind (AK).str () + " " ;
47
+ }
48
+ };
49
+
35
50
// OrcCAPITestBase contains several helper methods and pointers for unit tests
36
51
// written for the LLVM-C API. It provides the following helpers:
37
52
//
@@ -90,6 +105,31 @@ class OrcCAPITestBase : public testing::Test {
90
105
91
106
LLVMOrcDisposeLLJIT (J);
92
107
TargetSupported = true ;
108
+
109
+ // Create test functions in text format, with the proper extension
110
+ // attributes.
111
+ if (SumExample.empty ()) {
112
+ TargetI32ArgExtensions ArgExt (TargetTriple);
113
+ std::ostringstream OS;
114
+ OS << " define " << ArgExt.Ret << " i32 "
115
+ << " @sum(i32 " << ArgExt.Arg << " %x, i32 " << ArgExt.Arg << " %y)"
116
+ << R"( {
117
+ entry:
118
+ %r = add nsw i32 %x, %y
119
+ ret i32 %r
120
+ }
121
+ )" ;
122
+ SumExample = OS.str ();
123
+
124
+ OS << R"(
125
+ !llvm.module.flags = !{!0}
126
+ !llvm.dbg.cu = !{!1}
127
+ !0 = !{i32 2, !"Debug Info Version", i32 3}
128
+ !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, emissionKind: FullDebug)
129
+ !2 = !DIFile(filename: "sum.c", directory: "/tmp")
130
+ )" ;
131
+ SumDebugExample = OS.str ();
132
+ }
93
133
}
94
134
95
135
void SetUp () override {
@@ -199,37 +239,16 @@ class OrcCAPITestBase : public testing::Test {
199
239
200
240
static std::string TargetTriple;
201
241
static bool TargetSupported;
242
+
243
+ static std::string SumExample;
244
+ static std::string SumDebugExample;
202
245
};
203
246
204
247
std::string OrcCAPITestBase::TargetTriple;
205
248
bool OrcCAPITestBase::TargetSupported = false ;
206
249
207
- namespace {
208
-
209
- constexpr StringRef SumExample =
210
- R"(
211
- define i32 @sum(i32 %x, i32 %y) {
212
- entry:
213
- %r = add nsw i32 %x, %y
214
- ret i32 %r
215
- }
216
- )" ;
217
-
218
- constexpr StringRef SumDebugExample =
219
- R"(
220
- define i32 @sum(i32 %x, i32 %y) {
221
- entry:
222
- %r = add nsw i32 %x, %y
223
- ret i32 %r
224
- }
225
- !llvm.module.flags = !{!0}
226
- !llvm.dbg.cu = !{!1}
227
- !0 = !{i32 2, !"Debug Info Version", i32 3}
228
- !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, emissionKind: FullDebug)
229
- !2 = !DIFile(filename: "sum.c", directory: "/tmp")
230
- )" ;
231
-
232
- } // end anonymous namespace.
250
+ std::string OrcCAPITestBase::SumExample;
251
+ std::string OrcCAPITestBase::SumDebugExample;
233
252
234
253
// Consumes the given error ref and returns the string error message.
235
254
static std::string toString (LLVMErrorRef E) {
0 commit comments