Skip to content

Commit b9f8be2

Browse files
committed
Updated/reworked per review
1 parent 041adb0 commit b9f8be2

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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;
3233
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectLayer, LLVMOrcObjectLayerRef)
3334
DEFINE_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

237247
std::string OrcCAPITestBase::TargetTriple;

0 commit comments

Comments
 (0)