diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 721d144d7f4c6..869670d43a178 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/CMakeLists.txt b/llvm/test/CMakeLists.txt index 6127b76db06b7..eb40135114164 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 new file mode 100644 index 0000000000000..86dcc5048425e --- /dev/null +++ b/llvm/test/CodeGen/PowerPC/git_revision.ll @@ -0,0 +1,12 @@ +; Check that the git revision is contained in the assembly/object files + +; REQUIRES: vc-rev-enabled + +; RUN: llc < %s | FileCheck %s -DREVISION=git-revision +; RUN: llc -filetype=obj < %s | FileCheck %s -DREVISION=git-revision + +; CHECK: ([[REVISION]]) + +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" diff --git a/llvm/test/CodeGen/PowerPC/lit.local.cfg b/llvm/test/CodeGen/PowerPC/lit.local.cfg index 3e8c0f8b18420..4cc802afef4a0 100644 --- a/llvm/test/CodeGen/PowerPC/lit.local.cfg +++ b/llvm/test/CodeGen/PowerPC/lit.local.cfg @@ -1,4 +1,23 @@ 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'] + try: + return subprocess.run(cmd, stdout=subprocess.PIPE, check=True).stdout.decode() + except subprocess.CalledProcessError: + print("An error occurred retrieving the git revision.") + return None + +if config.have_vc_rev: + if config.force_vc_rev: + git_revision = config.force_vc_rev + else: + git_revision = get_revision(config.llvm_src_root) + if git_revision: + config.substitutions.append(("git-revision", git_revision)) + config.available_features.add("vc-rev-enabled") diff --git a/llvm/test/lit.site.cfg.py.in b/llvm/test/lit.site.cfg.py.in index b6f255d472d16..60a68b0edaf93 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)