[llvm] BOLT PowerPC Port (PR #140894)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 24 01:59:21 PDT 2025


https://github.com/kostasalv updated https://github.com/llvm/llvm-project/pull/140894

>From 1089e1955f7c02fe8df7136638e320cc7cdc5449 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 16:24:48 +0100
Subject: [PATCH 01/18] Work in Progress: BOLT PPC support

---
 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp | 11 +++++++++++
 bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp  |  0
 bolt/lib/Target/PowerPC/PPCMCSymbolizer.h    |  0
 3 files changed, 11 insertions(+)
 create mode 100644 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
 create mode 100644 bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp
 create mode 100644 bolt/lib/Target/PowerPC/PPCMCSymbolizer.h

diff --git a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
new file mode 100644
index 0000000000000..6402e84ae2097
--- /dev/null
+++ b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
@@ -0,0 +1,11 @@
+//===- bolt/Target/PowerPC/PPCMCPlusBuilder.cpp -----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides PowerPC-specific MCPlus builder.
+//
+//===----------------------------------------------------------------------===//
diff --git a/bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp b/bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/bolt/lib/Target/PowerPC/PPCMCSymbolizer.h b/bolt/lib/Target/PowerPC/PPCMCSymbolizer.h
new file mode 100644
index 0000000000000..e69de29bb2d1d

>From 36c392b7f8512d5eb5f344bcaf2f60603c741b00 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 17:12:43 +0100
Subject: [PATCH 02/18] [PPC][BOLT] Port createPushRegisters for PowerPC

---
 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp | 33 ++++++++++++++++++++
 bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp  |  7 +++++
 bolt/lib/Target/PowerPC/PPCMCSymbolizer.h    |  7 +++++
 3 files changed, 47 insertions(+)

diff --git a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
index 6402e84ae2097..7757ea141313b 100644
--- a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
+++ b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
@@ -9,3 +9,36 @@
 // This file provides PowerPC-specific MCPlus builder.
 //
 //===----------------------------------------------------------------------===//
+
+#include "bolt/Core/MCPlusBuilder.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCPhysReg.h"
+#include "llvm/Target/PowerPC/PPCInstrInfo.h"
+#include "llvm/Target/PowerPC/PPCRegisterInfo.h"
+
+namespace llvm {
+namespace bolt {
+
+class PPCMCPlusBuilder : public MCPlusBuilder{
+public:
+    using MCPlusBuilder::MCPlusBuilder;
+
+    // Create instructions to push two registers onto the stack
+    static void createPushRegisters(MCInst &Inst1, MCInst &Inst2, MCPhysReg Reg1, MCPhysReg /*Reg2*/){
+
+        Inst1.clear();
+        Inst1.setOpcode(PPC::STDU);
+        Inst1.addOperand(MCOperand::createReg(PPC::R1)); // destination (SP)
+        Inst1.addOperand(MCOperand::createReg(PPC::R1)); // base (SP)
+        Inst1.addOperand(MCOperand::createImm(-16));     // offset
+
+        Inst2.clear();
+        Inst2.setOpcode(PPC::STD);
+        Inst2.addOperand(MCOperand::createReg(Reg1));     // source register
+        Inst2.addOperand(MCOperand::createReg(PPC::R1));  // base (SP)
+        Inst2.addOperand(MCOperand::createImm(0));        // offset
+    }
+};
+
+} // namespace bolt
+} // namespace llvm
\ No newline at end of file
diff --git a/bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp b/bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp
index e69de29bb2d1d..c5edc77e191f3 100644
--- a/bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp
+++ b/bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp
@@ -0,0 +1,7 @@
+//===- bolt/Target/PowerPC/PPCMCSymbolizer.cpp ------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
\ No newline at end of file
diff --git a/bolt/lib/Target/PowerPC/PPCMCSymbolizer.h b/bolt/lib/Target/PowerPC/PPCMCSymbolizer.h
index e69de29bb2d1d..b4bfe7e1593c9 100644
--- a/bolt/lib/Target/PowerPC/PPCMCSymbolizer.h
+++ b/bolt/lib/Target/PowerPC/PPCMCSymbolizer.h
@@ -0,0 +1,7 @@
+//===- bolt/Target/PowerPC/PPCMCSymbolizer.cpp --------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
\ No newline at end of file

>From fc449b94cbd6250895d3707a01482493a5c5945b Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 18:42:52 +0100
Subject: [PATCH 03/18] [PPC][BOLT] Add CMakeLists

---
 bolt/lib/Target/PowerPC/CMakeLists.txt | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 bolt/lib/Target/PowerPC/CMakeLists.txt

diff --git a/bolt/lib/Target/PowerPC/CMakeLists.txt b/bolt/lib/Target/PowerPC/CMakeLists.txt
new file mode 100644
index 0000000000000..cafb951702cae
--- /dev/null
+++ b/bolt/lib/Target/PowerPC/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_llvm_library(BoltPPC
+    PPCMCPlusBuilder.cpp
+  )
\ No newline at end of file

>From 85c2d642c74e57bf6053d5414dee03d8091636d8 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 18:47:08 +0100
Subject: [PATCH 04/18] [PPC][BOLT] Adding PowerPC in parent CMakeLists

---
 bolt/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/CMakeLists.txt b/bolt/CMakeLists.txt
index 52c796518ac05..c18216d760808 100644
--- a/bolt/CMakeLists.txt
+++ b/bolt/CMakeLists.txt
@@ -58,7 +58,7 @@ endif() # standalone
 
 # Determine default set of targets to build -- the intersection of
 # those BOLT supports and those LLVM is targeting.
-set(BOLT_TARGETS_TO_BUILD_all "AArch64;X86;RISCV")
+set(BOLT_TARGETS_TO_BUILD_all "AArch64;X86;RISCV;PowerPC")
 set(BOLT_TARGETS_TO_BUILD_default)
 foreach (tgt ${BOLT_TARGETS_TO_BUILD_all})
   if (tgt IN_LIST LLVM_TARGETS_TO_BUILD)

>From b793ee265c2905b2c50e8a55232d3ca2b3a30676 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 19:21:48 +0100
Subject: [PATCH 05/18] [PPC][BOLT] Adding factory function

---
 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
index 7757ea141313b..a43ddd4bfc413 100644
--- a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
+++ b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
@@ -40,5 +40,13 @@ class PPCMCPlusBuilder : public MCPlusBuilder{
     }
 };
 
+MCPlusBuilder *createPowerPCMCPlusBuilder(const MCInstrAnalysis *Analysis,
+                                          const MCInstrInfo *Info,
+                                          const MCRegisterInfo *RegInfo,
+                                          const MCSubtargetInfo *STI) {
+  return new PPCMCPlusBuilder(Analysis, Info, RegInfo, STI);
+}
+
 } // namespace bolt
-} // namespace llvm
\ No newline at end of file
+} // namespace llvm
+

>From 507ffdd3c16659b22ee45f0fd4f214f58d9656a9 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 19:50:15 +0100
Subject: [PATCH 06/18] [PPC][BOLT] Adding PCC factory function declaration

---
 bolt/include/bolt/Core/MCPlusBuilder.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h
index 132d58f3f9f79..d290251ddcb1d 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -2293,6 +2293,11 @@ MCPlusBuilder *createRISCVMCPlusBuilder(const MCInstrAnalysis *,
                                         const MCRegisterInfo *,
                                         const MCSubtargetInfo *);
 
+MCPlusBuilder *createPowerPCMCPlusBuilder(const MCInstrAnalysis *,
+                                        const MCInstrInfo *,
+                                        const MCRegisterInfo *,
+                                        const MCSubtargetInfo *);
+
 } // namespace bolt
 } // namespace llvm
 

>From 747cfcb12b7ef722011c96bd838d813986bdbd92 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 19:57:20 +0100
Subject: [PATCH 07/18] [PPC][BOLT] Update selection logic to invoke the PCC
 factory when PCC architecture is selected

---
 bolt/lib/Rewrite/RewriteInstance.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index ad062ea3622d1..dbd9ecbaf1c66 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -304,6 +304,11 @@ MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch,
     return createRISCVMCPlusBuilder(Analysis, Info, RegInfo, STI);
 #endif
 
+#ifdef POWERPC_AVAILABLE
+  if (Arch == Triple::ppc64 || Arch == Triple::ppc64le)
+    return createPowerPCMCPlusBuilder(Analysis, Info, RegInfo, STI);
+#endif
+
   llvm_unreachable("architecture unsupported by MCPlusBuilder");
 }
 

>From 11679b639a79d2b5ea3e9aab908be1ffd8539f3c Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 20:59:34 +0100
Subject: [PATCH 08/18] [PPC][BOLT] Define macro for POWERPC_AVAILABLE

---
 bolt/lib/Target/CMakeLists.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Target/CMakeLists.txt b/bolt/lib/Target/CMakeLists.txt
index eae8ebdddbf3f..38d423ac9483c 100644
--- a/bolt/lib/Target/CMakeLists.txt
+++ b/bolt/lib/Target/CMakeLists.txt
@@ -1,3 +1,5 @@
 foreach (tgt ${BOLT_TARGETS_TO_BUILD})
   add_subdirectory(${tgt})
-endforeach()
+  string(TOUPPER ${tgt} TGT_UPPER)
+  add_definitions(-D${TGT_UPPER}_AVAILABLE)
+endforeach()
\ No newline at end of file

>From 666867694dc0ea18bd016fd2060aa3b8db37a74b Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 22:05:45 +0100
Subject: [PATCH 09/18] [PPC][BOLT]Fixing build

---
 bolt/lib/Target/PowerPC/CMakeLists.txt      | 2 +-
 bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp | 7 -------
 bolt/lib/Target/PowerPC/PPCMCSymbolizer.h   | 7 -------
 3 files changed, 1 insertion(+), 15 deletions(-)
 delete mode 100644 bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp
 delete mode 100644 bolt/lib/Target/PowerPC/PPCMCSymbolizer.h

diff --git a/bolt/lib/Target/PowerPC/CMakeLists.txt b/bolt/lib/Target/PowerPC/CMakeLists.txt
index cafb951702cae..2276ced53a3a1 100644
--- a/bolt/lib/Target/PowerPC/CMakeLists.txt
+++ b/bolt/lib/Target/PowerPC/CMakeLists.txt
@@ -1,3 +1,3 @@
-add_llvm_library(BoltPPC
+add_llvm_library(LLVMBOLTTargetPowerPC
     PPCMCPlusBuilder.cpp
   )
\ No newline at end of file
diff --git a/bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp b/bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp
deleted file mode 100644
index c5edc77e191f3..0000000000000
--- a/bolt/lib/Target/PowerPC/PPCMCSymbolizer.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-//===- bolt/Target/PowerPC/PPCMCSymbolizer.cpp ------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
\ No newline at end of file
diff --git a/bolt/lib/Target/PowerPC/PPCMCSymbolizer.h b/bolt/lib/Target/PowerPC/PPCMCSymbolizer.h
deleted file mode 100644
index b4bfe7e1593c9..0000000000000
--- a/bolt/lib/Target/PowerPC/PPCMCSymbolizer.h
+++ /dev/null
@@ -1,7 +0,0 @@
-//===- bolt/Target/PowerPC/PPCMCSymbolizer.cpp --------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
\ No newline at end of file

>From 0b0527d32e5aaa6559e5601f0a08474f8b632686 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 22:20:11 +0100
Subject: [PATCH 10/18] [PPC][BOLT] Fix deprecated include

---
 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
index a43ddd4bfc413..a47cd409848c2 100644
--- a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
+++ b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
@@ -12,7 +12,7 @@
 
 #include "bolt/Core/MCPlusBuilder.h"
 #include "llvm/MC/MCInst.h"
-#include "llvm/MC/MCPhysReg.h"
+#include "llvm/MC/MCRegisterInfo.h"
 #include "llvm/Target/PowerPC/PPCInstrInfo.h"
 #include "llvm/Target/PowerPC/PPCRegisterInfo.h"
 

>From cbae40af16d0809f56ce9decd4d7fd2154039096 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 22:34:42 +0100
Subject: [PATCH 11/18] [PPC][BOLT] Cleaning includes to fix build error

---
 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
index a47cd409848c2..6b972f4c4c3ff 100644
--- a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
+++ b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
@@ -13,8 +13,6 @@
 #include "bolt/Core/MCPlusBuilder.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCRegisterInfo.h"
-#include "llvm/Target/PowerPC/PPCInstrInfo.h"
-#include "llvm/Target/PowerPC/PPCRegisterInfo.h"
 
 namespace llvm {
 namespace bolt {

>From c9097654282180e8f9b5857fb83974c0a06434a5 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 22:46:48 +0100
Subject: [PATCH 12/18] Fix build error, include generated headers, to resolve
 the undeclared opcode enums

---
 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
index 6b972f4c4c3ff..179f4625e5435 100644
--- a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
+++ b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
@@ -13,6 +13,8 @@
 #include "bolt/Core/MCPlusBuilder.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCRegisterInfo.h"
+#include "llvm/Target/PowerPC/PPCGenInstrInfo.inc"
+#include "llvm/Target/PowerPC/PPCGenRegisterInfo.inc"
 
 namespace llvm {
 namespace bolt {

>From 9ef27512608069bfddfa3a7abb1f20cc8112d75e Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Tue, 20 May 2025 23:25:16 +0100
Subject: [PATCH 13/18] Fix build error, include generated headers

---
 bolt/lib/Target/PowerPC/CMakeLists.txt | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Target/PowerPC/CMakeLists.txt b/bolt/lib/Target/PowerPC/CMakeLists.txt
index 2276ced53a3a1..5611cec22210b 100644
--- a/bolt/lib/Target/PowerPC/CMakeLists.txt
+++ b/bolt/lib/Target/PowerPC/CMakeLists.txt
@@ -1,3 +1,8 @@
 add_llvm_library(LLVMBOLTTargetPowerPC
     PPCMCPlusBuilder.cpp
-  )
\ No newline at end of file
+  )
+
+target_include_directories(LLVMBOLTTargetPowerPC PRIVATE
+    ${LLVM_BINARY_DIR}/include
+    ${LLVM_SOURCE_DIR}/include
+)
\ No newline at end of file

>From f7c72ae74758ae927a82a2a99c3335a39aff7040 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Wed, 21 May 2025 00:03:18 +0100
Subject: [PATCH 14/18] Fix build error, include generated headers

---
 bolt/lib/Target/PowerPC/CMakeLists.txt | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Target/PowerPC/CMakeLists.txt b/bolt/lib/Target/PowerPC/CMakeLists.txt
index 5611cec22210b..80dd29a58b355 100644
--- a/bolt/lib/Target/PowerPC/CMakeLists.txt
+++ b/bolt/lib/Target/PowerPC/CMakeLists.txt
@@ -1,8 +1,16 @@
 add_llvm_library(LLVMBOLTTargetPowerPC
     PPCMCPlusBuilder.cpp
-  )
+)
 
 target_include_directories(LLVMBOLTTargetPowerPC PRIVATE
     ${LLVM_BINARY_DIR}/include
     ${LLVM_SOURCE_DIR}/include
+)
+
+file(MAKE_DIRECTORY "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC")
+
+add_custom_command(TARGET LLVMBOLTTargetPowerPC POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+        "${LLVM_BINARY_DIR}/lib/Target/PowerPC/PPCGenInstrInfo.inc"
+        "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/PPCGenInstrInfo.inc"
 )
\ No newline at end of file

>From b413cd70cc685ad694947ee228b0d7723e2c9d45 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Wed, 21 May 2025 08:53:32 +0100
Subject: [PATCH 15/18] [PPC][BOLT] Fix build error, copy PPGenInstrInfo.inc to
 include dir as soon as it is generated, before any compilation step tries to
 include it

---
 bolt/lib/Target/PowerPC/CMakeLists.txt | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/bolt/lib/Target/PowerPC/CMakeLists.txt b/bolt/lib/Target/PowerPC/CMakeLists.txt
index 80dd29a58b355..6a4df66e554aa 100644
--- a/bolt/lib/Target/PowerPC/CMakeLists.txt
+++ b/bolt/lib/Target/PowerPC/CMakeLists.txt
@@ -7,10 +7,24 @@ target_include_directories(LLVMBOLTTargetPowerPC PRIVATE
     ${LLVM_SOURCE_DIR}/include
 )
 
+# Ensure the destination directory exists
 file(MAKE_DIRECTORY "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC")
 
-add_custom_command(TARGET LLVMBOLTTargetPowerPC POST_BUILD
+# Custom command to copy the .inc file when it's generated
+add_custom_command(
+    OUTPUT "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/PPCGenInstrInfo.inc"
     COMMAND ${CMAKE_COMMAND} -E copy_if_different
         "${LLVM_BINARY_DIR}/lib/Target/PowerPC/PPCGenInstrInfo.inc"
         "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/PPCGenInstrInfo.inc"
-)
\ No newline at end of file
+    DEPENDS "${LLVM_BINARY_DIR}/lib/Target/PowerPC/PPCGenInstrInfo.inc"
+    COMMENT "Copying PPCGenInstrInfo.inc to include directory"
+)
+
+# Custom target to represent the copied .inc file
+add_custom_target(
+    BoltCopyPPCGenInstrInfoInc ALL
+    DEPENDS "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/PPCGenInstrInfo.inc"
+)
+
+# Make your library depend on the copy
+add_dependencies(LLVMBOLTTargetPowerPC BoltCopyPPCGenInstrInfoInc)
\ No newline at end of file

>From 3fe3a7c63615234c9d3c3c767def7d3c33e7d881 Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Wed, 21 May 2025 09:09:43 +0100
Subject: [PATCH 16/18] [PPC][BOLT] Fix build error, copy
 PPCGenRegisterInfo.inc to include dir as soon as it is generated, before any
 compilation step tries to include it

---
 bolt/lib/Target/PowerPC/CMakeLists.txt | 35 +++++++++++++-------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/bolt/lib/Target/PowerPC/CMakeLists.txt b/bolt/lib/Target/PowerPC/CMakeLists.txt
index 6a4df66e554aa..c1d2a054396d7 100644
--- a/bolt/lib/Target/PowerPC/CMakeLists.txt
+++ b/bolt/lib/Target/PowerPC/CMakeLists.txt
@@ -7,24 +7,23 @@ target_include_directories(LLVMBOLTTargetPowerPC PRIVATE
     ${LLVM_SOURCE_DIR}/include
 )
 
-# Ensure the destination directory exists
 file(MAKE_DIRECTORY "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC")
 
-# Custom command to copy the .inc file when it's generated
-add_custom_command(
-    OUTPUT "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/PPCGenInstrInfo.inc"
-    COMMAND ${CMAKE_COMMAND} -E copy_if_different
-        "${LLVM_BINARY_DIR}/lib/Target/PowerPC/PPCGenInstrInfo.inc"
-        "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/PPCGenInstrInfo.inc"
-    DEPENDS "${LLVM_BINARY_DIR}/lib/Target/PowerPC/PPCGenInstrInfo.inc"
-    COMMENT "Copying PPCGenInstrInfo.inc to include directory"
+foreach(incfile IN ITEMS
+    PPCGenInstrInfo.inc
+    PPCGenRegisterInfo.inc
 )
-
-# Custom target to represent the copied .inc file
-add_custom_target(
-    BoltCopyPPCGenInstrInfoInc ALL
-    DEPENDS "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/PPCGenInstrInfo.inc"
-)
-
-# Make your library depend on the copy
-add_dependencies(LLVMBOLTTargetPowerPC BoltCopyPPCGenInstrInfoInc)
\ No newline at end of file
+    add_custom_command(
+        OUTPUT "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/${incfile}"
+        COMMAND ${CMAKE_COMMAND} -E copy_if_different
+            "${LLVM_BINARY_DIR}/lib/Target/PowerPC/${incfile}"
+            "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/${incfile}"
+        DEPENDS "${LLVM_BINARY_DIR}/lib/Target/PowerPC/${incfile}"
+        COMMENT "Copying ${incfile} to include directory"
+    )
+    add_custom_target(
+        "BoltCopy${incfile}" ALL
+        DEPENDS "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/${incfile}"
+    )
+    add_dependencies(LLVMBOLTTargetPowerPC "BoltCopy${incfile}")
+endforeach()
\ No newline at end of file

>From 4a214f67c349903090a11faf212c7297fefb1eca Mon Sep 17 00:00:00 2001
From: Kostas Alvertis <konstantinos.alvertis at gmail.com>
Date: Wed, 21 May 2025 09:57:01 +0100
Subject: [PATCH 17/18] [PPC][BOLT] Make enums STDU, PCC visible

---
 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
index 179f4625e5435..0bbbef985264e 100644
--- a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
+++ b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
@@ -13,7 +13,9 @@
 #include "bolt/Core/MCPlusBuilder.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCRegisterInfo.h"
+#define GET_INSTRINFO_ENUM
 #include "llvm/Target/PowerPC/PPCGenInstrInfo.inc"
+#define GET_REGINFO_ENUM
 #include "llvm/Target/PowerPC/PPCGenRegisterInfo.inc"
 
 namespace llvm {

>From c3e650270cdcb7a67274c9777acfd3708c79d3a6 Mon Sep 17 00:00:00 2001
From: Kostas <konstantinos.alvertis at gmail.com>
Date: Wed, 21 May 2025 17:45:19 +0100
Subject: [PATCH 18/18] [PPC][BOLT] clang-format

---
 bolt/include/bolt/Core/MCPlusBuilder.h       |  6 ++--
 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp | 38 ++++++++++----------
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h
index d290251ddcb1d..fa043a49bb87e 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -2294,9 +2294,9 @@ MCPlusBuilder *createRISCVMCPlusBuilder(const MCInstrAnalysis *,
                                         const MCSubtargetInfo *);
 
 MCPlusBuilder *createPowerPCMCPlusBuilder(const MCInstrAnalysis *,
-                                        const MCInstrInfo *,
-                                        const MCRegisterInfo *,
-                                        const MCSubtargetInfo *);
+                                          const MCInstrInfo *,
+                                          const MCRegisterInfo *,
+                                          const MCSubtargetInfo *);
 
 } // namespace bolt
 } // namespace llvm
diff --git a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
index 0bbbef985264e..39d5ed2d3e36e 100644
--- a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
+++ b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
@@ -21,25 +21,26 @@
 namespace llvm {
 namespace bolt {
 
-class PPCMCPlusBuilder : public MCPlusBuilder{
+class PPCMCPlusBuilder : public MCPlusBuilder {
 public:
-    using MCPlusBuilder::MCPlusBuilder;
-
-    // Create instructions to push two registers onto the stack
-    static void createPushRegisters(MCInst &Inst1, MCInst &Inst2, MCPhysReg Reg1, MCPhysReg /*Reg2*/){
-
-        Inst1.clear();
-        Inst1.setOpcode(PPC::STDU);
-        Inst1.addOperand(MCOperand::createReg(PPC::R1)); // destination (SP)
-        Inst1.addOperand(MCOperand::createReg(PPC::R1)); // base (SP)
-        Inst1.addOperand(MCOperand::createImm(-16));     // offset
-
-        Inst2.clear();
-        Inst2.setOpcode(PPC::STD);
-        Inst2.addOperand(MCOperand::createReg(Reg1));     // source register
-        Inst2.addOperand(MCOperand::createReg(PPC::R1));  // base (SP)
-        Inst2.addOperand(MCOperand::createImm(0));        // offset
-    }
+  using MCPlusBuilder::MCPlusBuilder;
+
+  // Create instructions to push two registers onto the stack
+  static void createPushRegisters(MCInst &Inst1, MCInst &Inst2, MCPhysReg Reg1,
+                                  MCPhysReg /*Reg2*/) {
+
+    Inst1.clear();
+    Inst1.setOpcode(PPC::STDU);
+    Inst1.addOperand(MCOperand::createReg(PPC::R1)); // destination (SP)
+    Inst1.addOperand(MCOperand::createReg(PPC::R1)); // base (SP)
+    Inst1.addOperand(MCOperand::createImm(-16));     // offset
+
+    Inst2.clear();
+    Inst2.setOpcode(PPC::STD);
+    Inst2.addOperand(MCOperand::createReg(Reg1));    // source register
+    Inst2.addOperand(MCOperand::createReg(PPC::R1)); // base (SP)
+    Inst2.addOperand(MCOperand::createImm(0));       // offset
+  }
 };
 
 MCPlusBuilder *createPowerPCMCPlusBuilder(const MCInstrAnalysis *Analysis,
@@ -51,4 +52,3 @@ MCPlusBuilder *createPowerPCMCPlusBuilder(const MCInstrAnalysis *Analysis,
 
 } // namespace bolt
 } // namespace llvm
-



More information about the llvm-commits mailing list