[llvm] [ORC] Add signext on @sum() arguments in test. (PR #113308)

Jonas Paulsson via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 29 05:53:05 PDT 2024


https://github.com/JonPsson1 updated https://github.com/llvm/llvm-project/pull/113308

>From 041adb088f7d58a01ae38c799cdfd382f1464efe Mon Sep 17 00:00:00 2001
From: Jonas Paulsson <paulson1 at linux.ibm.com>
Date: Tue, 22 Oct 2024 09:57:05 +0200
Subject: [PATCH 1/3] Add signext on @sum() arguments.

---
 .../ExecutionEngine/Orc/OrcCAPITest.cpp       | 61 +++++++++++--------
 1 file changed, 35 insertions(+), 26 deletions(-)

diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
index 4d67daf2def5bc..c50e36a8c23eb1 100644
--- a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
@@ -90,6 +90,35 @@ class OrcCAPITestBase : public testing::Test {
 
     LLVMOrcDisposeLLJIT(J);
     TargetSupported = true;
+
+    // Create test functions in text format, with the proper extension
+    // attributes.
+    if (SumExample.empty()) {
+      std::string I32RetExt = "";
+      std::string I32ArgExt = "";
+      if (StringRef(TargetTriple).starts_with("s390x-ibm-linux"))
+        I32RetExt = I32ArgExt = "signext ";
+
+      std::ostringstream OS;
+      OS << "define " << I32RetExt << " i32 "
+         << R"(@sum()" << "i32 " << I32ArgExt << "%x, i32 " << I32ArgExt << "%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 +228,17 @@ class OrcCAPITestBase : public testing::Test {
 
   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) {

>From b9f8be2b109b97d3f4bf670a58ea172d2c5dbb4d Mon Sep 17 00:00:00 2001
From: Jonas Paulsson <paulson1 at linux.ibm.com>
Date: Tue, 29 Oct 2024 12:08:46 +0100
Subject: [PATCH 2/3] Updated/reworked per review

---
 .../ExecutionEngine/Orc/OrcCAPITest.cpp       | 26 +++++++++++++------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
index c50e36a8c23eb1..ca04949462eda4 100644
--- a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
@@ -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) {
+    Triple T(TargetTriple);
+    if (auto AK = TargetLibraryInfo::getExtAttrForI32Return(T))
+      Ret = Attribute::getNameFromAttrKind(AK);
+    if (auto AK = TargetLibraryInfo::getExtAttrForI32Param(T))
+      Arg = Attribute::getNameFromAttrKind(AK);
+  }
+};
+
 // OrcCAPITestBase contains several helper methods and pointers for unit tests
 // written for the LLVM-C API. It provides the following helpers:
 //
@@ -94,14 +109,10 @@ class OrcCAPITestBase : public testing::Test {
     // Create test functions in text format, with the proper extension
     // attributes.
     if (SumExample.empty()) {
-      std::string I32RetExt = "";
-      std::string I32ArgExt = "";
-      if (StringRef(TargetTriple).starts_with("s390x-ibm-linux"))
-        I32RetExt = I32ArgExt = "signext ";
-
+      TargetI32ArgExtensions ArgExt(TargetTriple);
       std::ostringstream OS;
-      OS << "define " << I32RetExt << " i32 "
-         << R"(@sum()" << "i32 " << I32ArgExt << "%x, i32 " << I32ArgExt << "%y)"
+      OS << "define " << ArgExt.Ret << " i32 "
+         << "@sum(i32 " << ArgExt.Arg << "%x, i32 " << ArgExt.Arg << "%y)"
          << R"( {
           entry:
           %r = add nsw i32 %x, %y
@@ -231,7 +242,6 @@ class OrcCAPITestBase : public testing::Test {
 
   static std::string SumExample;
   static std::string SumDebugExample;
-
 };
 
 std::string OrcCAPITestBase::TargetTriple;

>From 786c9254d2e1ce28a514711b733141d811035ddf Mon Sep 17 00:00:00 2001
From: Jonas Paulsson <paulson1 at linux.ibm.com>
Date: Tue, 29 Oct 2024 13:48:41 +0100
Subject: [PATCH 3/3] Also pass Signed arg to helper class constructor.

---
 llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
index ca04949462eda4..ed6a5834442483 100644
--- a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
@@ -38,11 +38,11 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef)
 struct TargetI32ArgExtensions {
   std::string Ret;
   std::string Arg;
-  TargetI32ArgExtensions(std::string TargetTriple) {
+  TargetI32ArgExtensions(std::string TargetTriple, bool Signed = true) {
     Triple T(TargetTriple);
-    if (auto AK = TargetLibraryInfo::getExtAttrForI32Return(T))
+    if (auto AK = TargetLibraryInfo::getExtAttrForI32Return(T, Signed))
       Ret = Attribute::getNameFromAttrKind(AK);
-    if (auto AK = TargetLibraryInfo::getExtAttrForI32Param(T))
+    if (auto AK = TargetLibraryInfo::getExtAttrForI32Param(T, Signed))
       Arg = Attribute::getNameFromAttrKind(AK);
   }
 };



More information about the llvm-commits mailing list