[llvm] [BOLT] [PowerPC] Port (PR #140894)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 27 12:10:46 PDT 2025


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

>From b483e87ee11fcc982078941a335a3ab84582d0a6 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/20] 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 facd2bdd75621a105da4b00c365050accfd7a050 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/20] [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 85cabae4ef11e62012b4a9f020564c2b5be1b20d 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/20] [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 8bf79060440a765add07081d2bcd6da4bfb39027 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/20] [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 5c7d51e1e398c..0ac3286ecef65 100644
--- a/bolt/CMakeLists.txt
+++ b/bolt/CMakeLists.txt
@@ -62,7 +62,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 b057403327d8fdffbb547da4f6de7ad646841bfb 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/20] [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 4d90320220f70a4eddc87f16e7387c917560846e 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/20] [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 ae04891e791f9..32ccc21a4be59 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -2346,6 +2346,11 @@ MCPlusBuilder *createRISCVMCPlusBuilder(const MCInstrAnalysis *,
                                         const MCRegisterInfo *,
                                         const MCSubtargetInfo *);
 
+MCPlusBuilder *createPowerPCMCPlusBuilder(const MCInstrAnalysis *,
+                                        const MCInstrInfo *,
+                                        const MCRegisterInfo *,
+                                        const MCSubtargetInfo *);
+
 } // namespace bolt
 } // namespace llvm
 

>From 6a6810a6440044d2e9862c440b5da41cc0d675c1 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/20] [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 4f5a75b770ce6..b6ed356422abb 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -334,6 +334,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 2b48d3093dd5563aa345860db87e15ec7704a2a9 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/20] [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 164879bf7a7646f8be8799388de24bc75288f298 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/20] [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 9ed7cf146dcd7ca3cba61790ee23cbdc939bd10a 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/20] [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 e60277f751e517243e115ac8a0975ba0febf26a5 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/20] [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 85176fa1f87d3c6913853a05004fcf5e9f077672 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/20] 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 047b8e9dd4728795b0b546e1c30568b7d3171285 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/20] 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 f47568a18416c9425dd60e592798249331d64598 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/20] 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 a186e01ce6ec7c1facf0598104b5e7009b99ac11 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/20] [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 55f92f895c9cec7eb187302c5136dd1d37fbed1b 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/20] [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 0a5a418701d6897a4d5846d7fda3ee75fe6628e8 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/20] [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 4cc0f46c8cd781e751335380b520721ec3464f95 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/20] [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 32ccc21a4be59..c4ac81f88600b 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -2347,9 +2347,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
-

>From d65bf757982731d5d1833eef6e64935f459d2a0b Mon Sep 17 00:00:00 2001
From: Kostas <konstantinos.alvertis at gmail.com>
Date: Fri, 13 Jun 2025 00:16:49 +0100
Subject: [PATCH 19/20] [BOLT][PPC] Add unit test.

---
 .../bolt/Target/PowerPC/PPCMCPlusBuilder.h    | 17 ++++++
 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp  | 37 ++++++-------
 bolt/unittests/CMakeLists.txt                 |  1 +
 bolt/unittests/Target/CMakeLists.txt          |  1 +
 bolt/unittests/Target/PowerPC/CMakeLists.txt  | 20 +++++++
 .../Target/PowerPC/PPCMCPlusBuilderTest.cpp   | 53 +++++++++++++++++++
 6 files changed, 108 insertions(+), 21 deletions(-)
 create mode 100644 bolt/include/bolt/Target/PowerPC/PPCMCPlusBuilder.h
 create mode 100644 bolt/unittests/Target/CMakeLists.txt
 create mode 100644 bolt/unittests/Target/PowerPC/CMakeLists.txt
 create mode 100644 bolt/unittests/Target/PowerPC/PPCMCPlusBuilderTest.cpp

diff --git a/bolt/include/bolt/Target/PowerPC/PPCMCPlusBuilder.h b/bolt/include/bolt/Target/PowerPC/PPCMCPlusBuilder.h
new file mode 100644
index 0000000000000..570c38a99d0c6
--- /dev/null
+++ b/bolt/include/bolt/Target/PowerPC/PPCMCPlusBuilder.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "bolt/Core/MCPlusBuilder.h"
+
+namespace llvm {
+namespace bolt {
+
+class PPCMCPlusBuilder : public MCPlusBuilder {
+public:
+  using MCPlusBuilder::MCPlusBuilder;
+
+  static void createPushRegisters(MCInst &Inst1, MCInst &Inst2, MCPhysReg Reg1,
+                                  MCPhysReg Reg2);
+};
+
+} // namespace bolt
+} // namespace llvm
\ No newline at end of file
diff --git a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
index 39d5ed2d3e36e..096ef106f3e16 100644
--- a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
+++ b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
@@ -10,6 +10,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "bolt/Target/PowerPC/PPCMCPlusBuilder.h"
 #include "bolt/Core/MCPlusBuilder.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCRegisterInfo.h"
@@ -21,27 +22,21 @@
 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
-  }
-};
+// Create instructions to push two registers onto the stack
+void PPCMCPlusBuilder::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,
                                           const MCInstrInfo *Info,
diff --git a/bolt/unittests/CMakeLists.txt b/bolt/unittests/CMakeLists.txt
index 64414b83d39fe..7582f5bf80c9e 100644
--- a/bolt/unittests/CMakeLists.txt
+++ b/bolt/unittests/CMakeLists.txt
@@ -7,3 +7,4 @@ endfunction()
 
 add_subdirectory(Core)
 add_subdirectory(Profile)
+add_subdirectory(Target)
\ No newline at end of file
diff --git a/bolt/unittests/Target/CMakeLists.txt b/bolt/unittests/Target/CMakeLists.txt
new file mode 100644
index 0000000000000..6837a2c945fb3
--- /dev/null
+++ b/bolt/unittests/Target/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(PowerPC)
\ No newline at end of file
diff --git a/bolt/unittests/Target/PowerPC/CMakeLists.txt b/bolt/unittests/Target/PowerPC/CMakeLists.txt
new file mode 100644
index 0000000000000..3aa6c9f866c5f
--- /dev/null
+++ b/bolt/unittests/Target/PowerPC/CMakeLists.txt
@@ -0,0 +1,20 @@
+set(BOLTTargetPowerPCTestsSources
+    PPCMCPlusBuilderTest.cpp)
+
+add_bolt_unittest(BOLTTargetPowerPCTests
+  ${BOLTTargetPowerPCTestsSources}
+)
+
+target_link_libraries(BOLTTargetPowerPCTests PRIVATE
+  LLVMBOLTTargetPowerPC
+  LLVMBOLTCore
+  LLVMCore
+)
+
+target_include_directories(BOLTTargetPowerPCTests PRIVATE
+  ${LLVM_BINARY_DIR}/include
+  ${LLVM_SOURCE_DIR}/include
+  ${LLVM_SOURCE_DIR}/bolt/include
+  ${LLVM_BINARY_DIR}/tools/bolt/include
+  ${CMAKE_SOURCE_DIR}
+)
diff --git a/bolt/unittests/Target/PowerPC/PPCMCPlusBuilderTest.cpp b/bolt/unittests/Target/PowerPC/PPCMCPlusBuilderTest.cpp
new file mode 100644
index 0000000000000..e069ca4b618f6
--- /dev/null
+++ b/bolt/unittests/Target/PowerPC/PPCMCPlusBuilderTest.cpp
@@ -0,0 +1,53 @@
+//===- bolt/unittest/Target/PowerPC/PPCMCPlusBuilderTest.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
+//
+//===----------------------------------------------------------------------===//
+
+#include "bolt/Target/PowerPC/PPCMCPlusBuilder.h"
+#include "bolt/Core/MCPlusBuilder.h"
+#include "llvm/MC/MCInst.h"
+#include "gtest/gtest.h"
+#define GET_INSTRINFO_ENUM
+#include "llvm/Target/PowerPC/PPCGenInstrInfo.inc"
+#define GET_REGINFO_ENUM
+#include "llvm/Target/PowerPC/PPCGenRegisterInfo.inc"
+
+using namespace llvm;
+using namespace bolt;
+
+namespace {
+
+TEST(PPCMCPlusBuilderTest, CreatePushRegisters) {
+  // Set up dummy input registers
+  MCInst Inst1, Inst2;
+  MCPhysReg Reg1 = PPC::R3; // Arbitary register
+
+  // Call the method under test
+  PPCMCPlusBuilder::createPushRegisters(Inst1, Inst2, Reg1, /*Reg2=*/PPC::R4);
+
+  // Check Inst1 is STDU R1, R1, -16
+  EXPECT_EQ(Inst1.getOpcode(), PPC::STDU);
+  ASSERT_EQ(Inst1.getNumOperands(), 3u);
+  EXPECT_TRUE(Inst1.getOperand(0).isReg());
+  EXPECT_EQ(Inst1.getOperand(0).getReg(), PPC::R1);
+  EXPECT_TRUE(Inst1.getOperand(1).isReg());
+  EXPECT_EQ(Inst1.getOperand(1).getReg(), PPC::R1);
+  EXPECT_TRUE(Inst1.getOperand(2).isImm());
+  EXPECT_EQ(Inst1.getOperand(2).getImm(), -16);
+
+  // Check Inst2 is STD Reg1, R1, 0
+  EXPECT_EQ(Inst2.getOpcode(), PPC::STD);
+  ASSERT_EQ(Inst2.getNumOperands(), 3u);
+  EXPECT_TRUE(Inst2.getOperand(0).isReg());
+  EXPECT_EQ(Inst2.getOperand(0).getReg(), Reg1);
+  EXPECT_TRUE(Inst2.getOperand(1).isReg());
+  EXPECT_EQ(Inst2.getOperand(1).getReg(), PPC::R1);
+  EXPECT_TRUE(Inst2.getOperand(2).isImm());
+  EXPECT_EQ(Inst2.getOperand(2).getImm(), 0);
+}
+
+} // end anonymous namespace
\ No newline at end of file

>From 802fcb1a450f26ce7a39e8b7bcec9fde19812c12 Mon Sep 17 00:00:00 2001
From: Kostas <konstantinos.alvertis at gmail.com>
Date: Tue, 26 Aug 2025 21:30:31 +0100
Subject: [PATCH 20/20] [PPC][BOLT] Use PPCMCTargetDesc.h to include generated
 .inc files

Replace direct inclusion of PPCGenInstrInfo.inc and PPCGenRegisterInfo.inc with PPCMCTargetDesc.h, which pulls in the necessary enums. This aligns the PowerPC target with the AArch64 and X86 patterns and follows the guidance from initial code review.
---
 bolt/lib/Target/PowerPC/CMakeLists.txt        | 50 ++++++++++---------
 bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp  | 21 ++------
 bolt/unittests/Target/PowerPC/CMakeLists.txt  |  2 +
 .../Target/PowerPC/PPCMCPlusBuilderTest.cpp   |  5 +-
 4 files changed, 34 insertions(+), 44 deletions(-)

diff --git a/bolt/lib/Target/PowerPC/CMakeLists.txt b/bolt/lib/Target/PowerPC/CMakeLists.txt
index c1d2a054396d7..eebb8120a1644 100644
--- a/bolt/lib/Target/PowerPC/CMakeLists.txt
+++ b/bolt/lib/Target/PowerPC/CMakeLists.txt
@@ -1,29 +1,33 @@
-add_llvm_library(LLVMBOLTTargetPowerPC
-    PPCMCPlusBuilder.cpp
+set(LLVM_LINK_COMPONENTS
+  MC
+  MCDisassembler
+  Support
+  PowerPCDesc
 )
 
-target_include_directories(LLVMBOLTTargetPowerPC PRIVATE
-    ${LLVM_BINARY_DIR}/include
-    ${LLVM_SOURCE_DIR}/include
+if(BOLT_BUILT_STANDALONE)
+  set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_SRC_DIR}/lib/Target/PowerPC/PPC.td)
+  list(APPEND LLVM_TABLEGEN_FLAGS -I ${LLVM_MAIN_SRC_DIR}/lib/Target/PowerPC)
+  tablegen(LLVM PPCGenInstrInfo.inc      -gen-instr-info)
+  tablegen(LLVM PPCGenRegisterInfo.inc   -gen-register-info)
+  tablegen(LLVM PPCGenSubtargetInfo.inc  -gen-subtarget)
+  add_public_tablegen_target(PowerPCCommonTableGen)
+  include_directories(${CMAKE_CURRENT_BINARY_DIR})
+endif()
+
+add_llvm_library(LLVMBOLTTargetPowerPC
+  PPCMCPlusBuilder.cpp
+
+  NO_EXPORT
+  DISABLE_LLVM_LINK_LLVM_DYLIB
+
+  DEPENDS
+  PowerPCCommonTableGen
 )
 
-file(MAKE_DIRECTORY "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC")
+target_link_libraries(LLVMBOLTTargetPowerPC PRIVATE LLVMBOLTCore)
 
-foreach(incfile IN ITEMS
-    PPCGenInstrInfo.inc
-    PPCGenRegisterInfo.inc
+include_directories(
+  ${LLVM_MAIN_SRC_DIR}/lib/Target/PowerPC
+  ${LLVM_BINARY_DIR}/lib/Target/PowerPC
 )
-    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
diff --git a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
index 096ef106f3e16..a5675e9d9bd62 100644
--- a/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
+++ b/bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp
@@ -11,20 +11,17 @@
 //===----------------------------------------------------------------------===//
 
 #include "bolt/Target/PowerPC/PPCMCPlusBuilder.h"
-#include "bolt/Core/MCPlusBuilder.h"
+#include "MCTargetDesc/PPCMCTargetDesc.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 {
-namespace bolt {
+using namespace llvm;
+using namespace bolt;
 
 // Create instructions to push two registers onto the stack
 void PPCMCPlusBuilder::createPushRegisters(MCInst &Inst1, MCInst &Inst2,
                                            MCPhysReg Reg1, MCPhysReg /*Reg2*/) {
+
   Inst1.clear();
   Inst1.setOpcode(PPC::STDU);
   Inst1.addOperand(MCOperand::createReg(PPC::R1)); // destination (SP)
@@ -37,13 +34,3 @@ void PPCMCPlusBuilder::createPushRegisters(MCInst &Inst1, MCInst &Inst2,
   Inst2.addOperand(MCOperand::createReg(PPC::R1)); // base (SP)
   Inst2.addOperand(MCOperand::createImm(0));       // offset
 }
-
-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
diff --git a/bolt/unittests/Target/PowerPC/CMakeLists.txt b/bolt/unittests/Target/PowerPC/CMakeLists.txt
index 3aa6c9f866c5f..182d6a78456e2 100644
--- a/bolt/unittests/Target/PowerPC/CMakeLists.txt
+++ b/bolt/unittests/Target/PowerPC/CMakeLists.txt
@@ -17,4 +17,6 @@ target_include_directories(BOLTTargetPowerPCTests PRIVATE
   ${LLVM_SOURCE_DIR}/bolt/include
   ${LLVM_BINARY_DIR}/tools/bolt/include
   ${CMAKE_SOURCE_DIR}
+  ${LLVM_MAIN_SRC_DIR}/lib/Target/PowerPC
+  ${LLVM_BINARY_DIR}/lib/Target/PowerPC
 )
diff --git a/bolt/unittests/Target/PowerPC/PPCMCPlusBuilderTest.cpp b/bolt/unittests/Target/PowerPC/PPCMCPlusBuilderTest.cpp
index e069ca4b618f6..787257e0a2f3b 100644
--- a/bolt/unittests/Target/PowerPC/PPCMCPlusBuilderTest.cpp
+++ b/bolt/unittests/Target/PowerPC/PPCMCPlusBuilderTest.cpp
@@ -8,13 +8,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "bolt/Target/PowerPC/PPCMCPlusBuilder.h"
+#include "MCTargetDesc/PPCMCTargetDesc.h"
 #include "bolt/Core/MCPlusBuilder.h"
 #include "llvm/MC/MCInst.h"
 #include "gtest/gtest.h"
-#define GET_INSTRINFO_ENUM
-#include "llvm/Target/PowerPC/PPCGenInstrInfo.inc"
-#define GET_REGINFO_ENUM
-#include "llvm/Target/PowerPC/PPCGenRegisterInfo.inc"
 
 using namespace llvm;
 using namespace bolt;



More information about the llvm-commits mailing list