[ORC] Add signext on @sum() arguments in test. (#113308)
Make sure the inlined @sum() function has the right extension attributes on its arguments. A new struct TargetI32ArgExtensions is added that sets the Ret/Arg extension strings given a string TargetTriple. This might be used elsewhere as well for this purpose if needed. Fixes: #112503
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "llvm-c/Orc.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "llvm/Analysis/TargetLibraryInfo.h"
|
||||
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
|
||||
@@ -32,6 +33,20 @@ using namespace llvm::orc;
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectLayer, LLVMOrcObjectLayerRef)
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef)
|
||||
|
||||
// A class that sets strings for extension attributes by querying
|
||||
// TargetLibraryInfo.
|
||||
struct TargetI32ArgExtensions {
|
||||
std::string Ret;
|
||||
std::string Arg;
|
||||
TargetI32ArgExtensions(std::string TargetTriple, bool Signed = true) {
|
||||
Triple T(TargetTriple);
|
||||
if (auto AK = TargetLibraryInfo::getExtAttrForI32Return(T, Signed))
|
||||
Ret = Attribute::getNameFromAttrKind(AK).str() + " ";
|
||||
if (auto AK = TargetLibraryInfo::getExtAttrForI32Param(T, Signed))
|
||||
Arg = Attribute::getNameFromAttrKind(AK).str() + " ";
|
||||
}
|
||||
};
|
||||
|
||||
// OrcCAPITestBase contains several helper methods and pointers for unit tests
|
||||
// written for the LLVM-C API. It provides the following helpers:
|
||||
//
|
||||
@@ -90,6 +105,31 @@ public:
|
||||
|
||||
LLVMOrcDisposeLLJIT(J);
|
||||
TargetSupported = true;
|
||||
|
||||
// Create test functions in text format, with the proper extension
|
||||
// attributes.
|
||||
if (SumExample.empty()) {
|
||||
TargetI32ArgExtensions ArgExt(TargetTriple);
|
||||
std::ostringstream OS;
|
||||
OS << "define " << ArgExt.Ret << "i32 "
|
||||
<< "@sum(i32 " << ArgExt.Arg << "%x, i32 " << ArgExt.Arg << "%y)"
|
||||
<< R"( {
|
||||
entry:
|
||||
%r = add nsw i32 %x, %y
|
||||
ret i32 %r
|
||||
}
|
||||
)";
|
||||
SumExample = OS.str();
|
||||
|
||||
OS << R"(
|
||||
!llvm.module.flags = !{!0}
|
||||
!llvm.dbg.cu = !{!1}
|
||||
!0 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, emissionKind: FullDebug)
|
||||
!2 = !DIFile(filename: "sum.c", directory: "/tmp")
|
||||
)";
|
||||
SumDebugExample = OS.str();
|
||||
}
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
@@ -199,37 +239,16 @@ protected:
|
||||
|
||||
static std::string TargetTriple;
|
||||
static bool TargetSupported;
|
||||
|
||||
static std::string SumExample;
|
||||
static std::string SumDebugExample;
|
||||
};
|
||||
|
||||
std::string OrcCAPITestBase::TargetTriple;
|
||||
bool OrcCAPITestBase::TargetSupported = false;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr StringRef SumExample =
|
||||
R"(
|
||||
define i32 @sum(i32 %x, i32 %y) {
|
||||
entry:
|
||||
%r = add nsw i32 %x, %y
|
||||
ret i32 %r
|
||||
}
|
||||
)";
|
||||
|
||||
constexpr StringRef SumDebugExample =
|
||||
R"(
|
||||
define i32 @sum(i32 %x, i32 %y) {
|
||||
entry:
|
||||
%r = add nsw i32 %x, %y
|
||||
ret i32 %r
|
||||
}
|
||||
!llvm.module.flags = !{!0}
|
||||
!llvm.dbg.cu = !{!1}
|
||||
!0 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, emissionKind: FullDebug)
|
||||
!2 = !DIFile(filename: "sum.c", directory: "/tmp")
|
||||
)";
|
||||
|
||||
} // end anonymous namespace.
|
||||
std::string OrcCAPITestBase::SumExample;
|
||||
std::string OrcCAPITestBase::SumDebugExample;
|
||||
|
||||
// Consumes the given error ref and returns the string error message.
|
||||
static std::string toString(LLVMErrorRef E) {
|
||||
|
||||
Reference in New Issue
Block a user