Skip to content

Commit 4b547ad

Browse files
committed
[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.
1 parent 04e648b commit 4b547ad

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

bolt/lib/Target/PowerPC/CMakeLists.txt

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
add_llvm_library(LLVMBOLTTargetPowerPC
2-
PPCMCPlusBuilder.cpp
1+
set(LLVM_LINK_COMPONENTS
2+
MC
3+
MCDisassembler
4+
Support
5+
PowerPCDesc
36
)
47

5-
target_include_directories(LLVMBOLTTargetPowerPC PRIVATE
6-
${LLVM_BINARY_DIR}/include
7-
${LLVM_SOURCE_DIR}/include
8+
if(BOLT_BUILT_STANDALONE)
9+
set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_SRC_DIR}/lib/Target/PowerPC/PPC.td)
10+
list(APPEND LLVM_TABLEGEN_FLAGS -I ${LLVM_MAIN_SRC_DIR}/lib/Target/PowerPC)
11+
tablegen(LLVM PPCGenInstrInfo.inc -gen-instr-info)
12+
tablegen(LLVM PPCGenRegisterInfo.inc -gen-register-info)
13+
tablegen(LLVM PPCGenSubtargetInfo.inc -gen-subtarget)
14+
add_public_tablegen_target(PowerPCCommonTableGen)
15+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
16+
endif()
17+
18+
add_llvm_library(LLVMBOLTTargetPowerPC
19+
PPCMCPlusBuilder.cpp
20+
21+
NO_EXPORT
22+
DISABLE_LLVM_LINK_LLVM_DYLIB
23+
24+
DEPENDS
25+
PowerPCCommonTableGen
826
)
927

10-
file(MAKE_DIRECTORY "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC")
28+
target_link_libraries(LLVMBOLTTargetPowerPC PRIVATE LLVMBOLTCore)
1129

12-
foreach(incfile IN ITEMS
13-
PPCGenInstrInfo.inc
14-
PPCGenRegisterInfo.inc
30+
include_directories(
31+
${LLVM_MAIN_SRC_DIR}/lib/Target/PowerPC
32+
${LLVM_BINARY_DIR}/lib/Target/PowerPC
1533
)
16-
add_custom_command(
17-
OUTPUT "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/${incfile}"
18-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
19-
"${LLVM_BINARY_DIR}/lib/Target/PowerPC/${incfile}"
20-
"${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/${incfile}"
21-
DEPENDS "${LLVM_BINARY_DIR}/lib/Target/PowerPC/${incfile}"
22-
COMMENT "Copying ${incfile} to include directory"
23-
)
24-
add_custom_target(
25-
"BoltCopy${incfile}" ALL
26-
DEPENDS "${LLVM_BINARY_DIR}/include/llvm/Target/PowerPC/${incfile}"
27-
)
28-
add_dependencies(LLVMBOLTTargetPowerPC "BoltCopy${incfile}")
29-
endforeach()

bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,17 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "bolt/Target/PowerPC/PPCMCPlusBuilder.h"
14-
#include "bolt/Core/MCPlusBuilder.h"
14+
#include "MCTargetDesc/PPCMCTargetDesc.h"
1515
#include "llvm/MC/MCInst.h"
1616
#include "llvm/MC/MCRegisterInfo.h"
17-
#define GET_INSTRINFO_ENUM
18-
#include "llvm/Target/PowerPC/PPCGenInstrInfo.inc"
19-
#define GET_REGINFO_ENUM
20-
#include "llvm/Target/PowerPC/PPCGenRegisterInfo.inc"
2117

22-
namespace llvm {
23-
namespace bolt {
18+
using namespace llvm;
19+
using namespace bolt;
2420

2521
// Create instructions to push two registers onto the stack
2622
void PPCMCPlusBuilder::createPushRegisters(MCInst &Inst1, MCInst &Inst2,
2723
MCPhysReg Reg1, MCPhysReg /*Reg2*/) {
24+
2825
Inst1.clear();
2926
Inst1.setOpcode(PPC::STDU);
3027
Inst1.addOperand(MCOperand::createReg(PPC::R1)); // destination (SP)
@@ -38,6 +35,9 @@ void PPCMCPlusBuilder::createPushRegisters(MCInst &Inst1, MCInst &Inst2,
3835
Inst2.addOperand(MCOperand::createImm(0)); // offset
3936
}
4037

38+
namespace llvm {
39+
namespace bolt {
40+
4141
MCPlusBuilder *createPowerPCMCPlusBuilder(const MCInstrAnalysis *Analysis,
4242
const MCInstrInfo *Info,
4343
const MCRegisterInfo *RegInfo,
@@ -46,4 +46,4 @@ MCPlusBuilder *createPowerPCMCPlusBuilder(const MCInstrAnalysis *Analysis,
4646
}
4747

4848
} // namespace bolt
49-
} // namespace llvm
49+
} // namespace llvm

bolt/unittests/Target/PowerPC/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ target_include_directories(BOLTTargetPowerPCTests PRIVATE
1717
${LLVM_SOURCE_DIR}/bolt/include
1818
${LLVM_BINARY_DIR}/tools/bolt/include
1919
${CMAKE_SOURCE_DIR}
20+
${LLVM_MAIN_SRC_DIR}/lib/Target/PowerPC
21+
${LLVM_BINARY_DIR}/lib/Target/PowerPC
2022
)

bolt/unittests/Target/PowerPC/PPCMCPlusBuilderTest.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88
//===----------------------------------------------------------------------===//
99

1010
#include "bolt/Target/PowerPC/PPCMCPlusBuilder.h"
11+
#include "MCTargetDesc/PPCMCTargetDesc.h"
1112
#include "bolt/Core/MCPlusBuilder.h"
1213
#include "llvm/MC/MCInst.h"
1314
#include "gtest/gtest.h"
14-
#define GET_INSTRINFO_ENUM
15-
#include "llvm/Target/PowerPC/PPCGenInstrInfo.inc"
16-
#define GET_REGINFO_ENUM
17-
#include "llvm/Target/PowerPC/PPCGenRegisterInfo.inc"
1815

1916
using namespace llvm;
2017
using namespace bolt;

0 commit comments

Comments
 (0)