[llvm] [AIX] Add git revision to .file string (PR #88164)

Jake Egan via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 26 03:21:00 PDT 2024


https://github.com/jakeegan updated https://github.com/llvm/llvm-project/pull/88164

>From 4dc5015fb04cd8c3b21d02b778c653947703438f Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Tue, 9 Apr 2024 12:41:14 -0400
Subject: [PATCH 1/4] [AIX] Add git revision to .file string

---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 12 ++++++++----
 llvm/test/CodeGen/PowerPC/git_revision.ll  | 13 +++++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)
 create mode 100644 llvm/test/CodeGen/PowerPC/git_revision.ll

diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 721d144d7f4c67..1072fce89e3099 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -114,6 +114,7 @@
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Timer.h"
+#include "llvm/Support/VCSRevision.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetLoweringObjectFile.h"
 #include "llvm/Target/TargetMachine.h"
@@ -497,12 +498,15 @@ bool AsmPrinter::doInitialization(Module &M) {
     else
       FileName = M.getSourceFileName();
     if (MAI->hasFourStringsDotFile()) {
-#ifdef PACKAGE_VENDOR
       const char VerStr[] =
-          PACKAGE_VENDOR " " PACKAGE_NAME " version " PACKAGE_VERSION;
-#else
-      const char VerStr[] = PACKAGE_NAME " version " PACKAGE_VERSION;
+#ifdef PACKAGE_VENDOR
+      PACKAGE_VENDOR " "
+#endif
+      PACKAGE_NAME " version " PACKAGE_VERSION
+#ifdef LLVM_REVISION
+      " (" LLVM_REVISION ")"
 #endif
+      ;
       // TODO: Add timestamp and description.
       OutStreamer->emitFileDirective(FileName, VerStr, "", "");
     } else {
diff --git a/llvm/test/CodeGen/PowerPC/git_revision.ll b/llvm/test/CodeGen/PowerPC/git_revision.ll
new file mode 100644
index 00000000000000..280c311c8bd7c8
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/git_revision.ll
@@ -0,0 +1,13 @@
+; Check that the git revision is contained in the assembly/object files
+
+; RUN: cd %S && git rev-parse HEAD > %t
+
+; RUN: llc < %s > %t.a.o
+; RUN: sed -n -e "/$(cat %t)/p" %t.a.o
+
+; RUN: llc -filetype=obj < %s > %t.b.o
+; RUN: sed -n -e "/$(cat %t)/p" %t.b.o
+
+source_filename = "git_revision.cpp"
+target datalayout = "E-m:a-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512"
+target triple = "powerpc64-ibm-aix7.2.0.0"

>From bcd2d6731bf32da075d0c0c24dbbff7708b669bd Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Wed, 10 Apr 2024 09:31:40 -0400
Subject: [PATCH 2/4] Apply clang-format changes

---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 1072fce89e3099..869670d43a1785 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -500,13 +500,13 @@ bool AsmPrinter::doInitialization(Module &M) {
     if (MAI->hasFourStringsDotFile()) {
       const char VerStr[] =
 #ifdef PACKAGE_VENDOR
-      PACKAGE_VENDOR " "
+          PACKAGE_VENDOR " "
 #endif
-      PACKAGE_NAME " version " PACKAGE_VERSION
+          PACKAGE_NAME " version " PACKAGE_VERSION
 #ifdef LLVM_REVISION
-      " (" LLVM_REVISION ")"
+                         " (" LLVM_REVISION ")"
 #endif
-      ;
+          ;
       // TODO: Add timestamp and description.
       OutStreamer->emitFileDirective(FileName, VerStr, "", "");
     } else {

>From 7589c933f24871426815704add311609b4d7f48c Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Thu, 18 Apr 2024 13:21:45 -0400
Subject: [PATCH 3/4] Add test infrastructure for test

---
 llvm/test/CMakeLists.txt                  |  1 +
 llvm/test/CodeGen/PowerPC/git_revision.ll |  9 ++++-----
 llvm/test/CodeGen/PowerPC/lit.local.cfg   | 14 ++++++++++++++
 llvm/test/lit.site.cfg.py.in              |  2 ++
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt
index 6127b76db06b7f..eb401351141641 100644
--- a/llvm/test/CMakeLists.txt
+++ b/llvm/test/CMakeLists.txt
@@ -25,6 +25,7 @@ llvm_canonicalize_cmake_booleans(
   LLVM_INCLUDE_DXIL_TESTS
   LLVM_TOOL_LLVM_DRIVER_BUILD
   LLVM_INCLUDE_SPIRV_TOOLS_TESTS
+  LLVM_APPEND_VC_REV
   )
 
 configure_lit_site_cfg(
diff --git a/llvm/test/CodeGen/PowerPC/git_revision.ll b/llvm/test/CodeGen/PowerPC/git_revision.ll
index 280c311c8bd7c8..86dcc5048425e4 100644
--- a/llvm/test/CodeGen/PowerPC/git_revision.ll
+++ b/llvm/test/CodeGen/PowerPC/git_revision.ll
@@ -1,12 +1,11 @@
 ; Check that the git revision is contained in the assembly/object files
 
-; RUN: cd %S && git rev-parse HEAD > %t
+; REQUIRES: vc-rev-enabled 
 
-; RUN: llc < %s > %t.a.o
-; RUN: sed -n -e "/$(cat %t)/p" %t.a.o
+; RUN: llc < %s | FileCheck %s -DREVISION=git-revision
+; RUN: llc -filetype=obj < %s | FileCheck %s -DREVISION=git-revision
 
-; RUN: llc -filetype=obj < %s > %t.b.o
-; RUN: sed -n -e "/$(cat %t)/p" %t.b.o
+; CHECK: ([[REVISION]])
 
 source_filename = "git_revision.cpp"
 target datalayout = "E-m:a-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512"
diff --git a/llvm/test/CodeGen/PowerPC/lit.local.cfg b/llvm/test/CodeGen/PowerPC/lit.local.cfg
index 3e8c0f8b184201..884906b630a261 100644
--- a/llvm/test/CodeGen/PowerPC/lit.local.cfg
+++ b/llvm/test/CodeGen/PowerPC/lit.local.cfg
@@ -1,4 +1,18 @@
 if not "PowerPC" in config.root.targets:
     config.unsupported = True
 
+import subprocess
+
 config.suffixes.add(".py")
+
+def get_revision(repo_path):
+  cmd = ['git', '-C', repo_path, 'rev-parse', 'HEAD']
+  return subprocess.run(cmd, stdout=subprocess.PIPE).stdout.decode('ascii')
+
+if config.have_vc_rev:
+  config.available_features.add("vc-rev-enabled")
+  if config.force_vc_rev:
+    git_revision = config.force_vc_rev
+  else:
+    git_revision = get_revision(config.llvm_src_root)
+  config.substitutions.append(("git-revision", git_revision))
diff --git a/llvm/test/lit.site.cfg.py.in b/llvm/test/lit.site.cfg.py.in
index b6f255d472d16f..60a68b0edaf933 100644
--- a/llvm/test/lit.site.cfg.py.in
+++ b/llvm/test/lit.site.cfg.py.in
@@ -61,6 +61,8 @@ config.reverse_iteration = @LLVM_ENABLE_REVERSE_ITERATION@
 config.dxil_tests = @LLVM_INCLUDE_DXIL_TESTS@
 config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
 config.spirv_tools_tests = @LLVM_INCLUDE_SPIRV_TOOLS_TESTS@
+config.have_vc_rev = @LLVM_APPEND_VC_REV@
+config.force_vc_rev = "@LLVM_FORCE_VC_REVISION@"
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

>From a7429930a84a81b083ce1b66889e75e5dcfe79ea Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Fri, 26 Apr 2024 06:19:06 -0400
Subject: [PATCH 4/4] Improve lit config

---
 llvm/test/CodeGen/PowerPC/lit.local.cfg | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/llvm/test/CodeGen/PowerPC/lit.local.cfg b/llvm/test/CodeGen/PowerPC/lit.local.cfg
index 884906b630a261..7c09c01eeec39b 100644
--- a/llvm/test/CodeGen/PowerPC/lit.local.cfg
+++ b/llvm/test/CodeGen/PowerPC/lit.local.cfg
@@ -6,13 +6,17 @@ import subprocess
 config.suffixes.add(".py")
 
 def get_revision(repo_path):
-  cmd = ['git', '-C', repo_path, 'rev-parse', 'HEAD']
-  return subprocess.run(cmd, stdout=subprocess.PIPE).stdout.decode('ascii')
+    cmd = ['git', '-C', repo_path, 'rev-parse', 'HEAD']
+    try:
+        return subprocess.run(cmd, stdout=subprocess.PIPE, check=True).stdout.decode('ascii')
+    except subprocess.CalledProcessError:
+        print("An error occured retrieving the git revision")
+        raise
 
 if config.have_vc_rev:
-  config.available_features.add("vc-rev-enabled")
-  if config.force_vc_rev:
-    git_revision = config.force_vc_rev
-  else:
-    git_revision = get_revision(config.llvm_src_root)
-  config.substitutions.append(("git-revision", git_revision))
+    if config.force_vc_rev:
+        git_revision = config.force_vc_rev
+    else:
+        git_revision = get_revision(config.llvm_src_root)
+    config.substitutions.append(("git-revision", git_revision))
+    config.available_features.add("vc-rev-enabled")



More information about the llvm-commits mailing list