1313#include " llvm-c/Orc.h"
1414#include " gtest/gtest.h"
1515
16+ #include " llvm/Analysis/TargetLibraryInfo.h"
1617#include " llvm/ExecutionEngine/Orc/CompileUtils.h"
1718#include " llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
1819#include " llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
@@ -32,6 +33,20 @@ using namespace llvm::orc;
3233DEFINE_SIMPLE_CONVERSION_FUNCTIONS (ObjectLayer, LLVMOrcObjectLayerRef)
3334DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef)
3435
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) {
42+ Triple T (TargetTriple);
43+ if (auto AK = TargetLibraryInfo::getExtAttrForI32Return (T))
44+ Ret = Attribute::getNameFromAttrKind (AK);
45+ if (auto AK = TargetLibraryInfo::getExtAttrForI32Param (T))
46+ Arg = Attribute::getNameFromAttrKind (AK);
47+ }
48+ };
49+
3550// OrcCAPITestBase contains several helper methods and pointers for unit tests
3651// written for the LLVM-C API. It provides the following helpers:
3752//
@@ -94,14 +109,10 @@ class OrcCAPITestBase : public testing::Test {
94109 // Create test functions in text format, with the proper extension
95110 // attributes.
96111 if (SumExample.empty ()) {
97- std::string I32RetExt = " " ;
98- std::string I32ArgExt = " " ;
99- if (StringRef (TargetTriple).starts_with (" s390x-ibm-linux" ))
100- I32RetExt = I32ArgExt = " signext " ;
101-
112+ TargetI32ArgExtensions ArgExt (TargetTriple);
102113 std::ostringstream OS;
103- OS << " define " << I32RetExt << " i32 "
104- << R"( @sum()" << " i32 " << I32ArgExt << " %x, i32 " << I32ArgExt << " %y)"
114+ OS << " define " << ArgExt. Ret << " i32 "
115+ << " @sum(i32 " << ArgExt. Arg << " %x, i32 " << ArgExt. Arg << " %y)"
105116 << R"( {
106117 entry:
107118 %r = add nsw i32 %x, %y
@@ -231,7 +242,6 @@ class OrcCAPITestBase : public testing::Test {
231242
232243 static std::string SumExample;
233244 static std::string SumDebugExample;
234-
235245};
236246
237247std::string OrcCAPITestBase::TargetTriple;
0 commit comments