Skip to content

Commit 009cd4e

Browse files
committed
[PPC][GlobalISel] Add initial GlobalIsel infrastructure
This adds the initial GlobalISel skeleton for PowerPC. It can only run ir-translator and legalizer for `ret void`. This is largely based on the initial GlobalISel patch for RISCV (https://reviews.llvm.org/D65219). Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D83100
1 parent be7cef7 commit 009cd4e

17 files changed

Lines changed: 441 additions & 15 deletions

‎llvm/lib/Target/PowerPC/CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ tablegen(LLVM PPCGenMCCodeEmitter.inc -gen-emitter)
1111
tablegen(LLVM PPCGenRegisterInfo.inc -gen-register-info)
1212
tablegen(LLVM PPCGenSubtargetInfo.inc -gen-subtarget)
1313
tablegen(LLVM PPCGenExegesis.inc -gen-exegesis)
14+
tablegen(LLVM PPCGenRegisterBank.inc -gen-register-bank)
15+
tablegen(LLVM PPCGenGlobalISel.inc -gen-global-isel)
1416

1517
add_public_tablegen_target(PowerPCCommonTableGen)
1618

1719
add_llvm_target(PowerPCCodeGen
20+
GISel/PPCInstructionSelector.cpp
1821
PPCBoolRetToInt.cpp
1922
PPCAsmPrinter.cpp
2023
PPCBranchSelector.cpp
@@ -49,6 +52,9 @@ add_llvm_target(PowerPCCodeGen
4952
PPCExpandISEL.cpp
5053
PPCPreEmitPeephole.cpp
5154
PPCLowerMASSVEntries.cpp
55+
GISel/PPCCallLowering.cpp
56+
GISel/PPCRegisterBankInfo.cpp
57+
GISel/PPCLegalizerInfo.cpp
5258
)
5359

5460
add_subdirectory(AsmParser)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===-- PPCCallLowering.h - Call lowering for GlobalISel -------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// This file implements the lowering of LLVM calls to machine code calls for
11+
/// GlobalISel.
12+
///
13+
//===----------------------------------------------------------------------===//
14+
15+
#include "PPCCallLowering.h"
16+
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
17+
#include "llvm/Support/Debug.h"
18+
19+
#define DEBUG_TYPE "ppc-call-lowering"
20+
21+
using namespace llvm;
22+
23+
PPCCallLowering::PPCCallLowering(const PPCTargetLowering &TLI)
24+
: CallLowering(&TLI) {}
25+
26+
bool PPCCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
27+
const Value *Val, ArrayRef<Register> VRegs,
28+
Register SwiftErrorVReg) const {
29+
assert(((Val && !VRegs.empty()) || (!Val && VRegs.empty())) &&
30+
"Return value without a vreg");
31+
if (VRegs.size() > 0)
32+
return false;
33+
34+
MIRBuilder.buildInstr(PPC::BLR8);
35+
return true;
36+
}
37+
38+
bool PPCCallLowering::lowerFormalArguments(
39+
MachineIRBuilder &MIRBuilder, const Function &F,
40+
ArrayRef<ArrayRef<Register>> VRegs) const {
41+
42+
// If VRegs is empty, then there are no formal arguments to lower and thus can
43+
// always return true. If there are formal arguments, we currently do not
44+
// handle them and thus return false.
45+
return VRegs.empty();
46+
}
47+
48+
bool PPCCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
49+
CallLoweringInfo &Info) const {
50+
return false;
51+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===-- PPCCallLowering.h - Call lowering for GlobalISel -------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// This file describes how to lower LLVM calls to machine code calls.
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_LIB_TARGET_POWERPC_GISEL_PPCCALLLOWERING_H
15+
#define LLVM_LIB_TARGET_POWERPC_GISEL_PPCCALLLOWERING_H
16+
17+
#include "PPCISelLowering.h"
18+
#include "llvm/CodeGen/GlobalISel/CallLowering.h"
19+
#include "llvm/IR/CallingConv.h"
20+
21+
namespace llvm {
22+
23+
class PPCTargetLowering;
24+
25+
class PPCCallLowering : public CallLowering {
26+
public:
27+
PPCCallLowering(const PPCTargetLowering &TLI);
28+
29+
bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val,
30+
ArrayRef<Register> VRegs,
31+
Register SwiftErrorVReg) const override;
32+
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F,
33+
ArrayRef<ArrayRef<Register>> VRegs) const override;
34+
bool lowerCall(MachineIRBuilder &MIRBuilder,
35+
CallLoweringInfo &Info) const override;
36+
};
37+
} // end namespace llvm
38+
39+
#endif
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//===- PPCInstructionSelector.cpp --------------------------------*- C++ -*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
/// \file
9+
/// This file implements the targeting of the InstructionSelector class for
10+
/// PowerPC.
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "PPCInstrInfo.h"
14+
#include "PPCRegisterBankInfo.h"
15+
#include "PPCSubtarget.h"
16+
#include "PPCTargetMachine.h"
17+
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
18+
#include "llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h"
19+
#include "llvm/CodeGen/MachineFunction.h"
20+
#include "llvm/IR/IntrinsicsPowerPC.h"
21+
#include "llvm/Support/Debug.h"
22+
23+
#define DEBUG_TYPE "ppc-gisel"
24+
25+
using namespace llvm;
26+
27+
namespace {
28+
29+
#define GET_GLOBALISEL_PREDICATE_BITSET
30+
#include "PPCGenGlobalISel.inc"
31+
#undef GET_GLOBALISEL_PREDICATE_BITSET
32+
33+
class PPCInstructionSelector : public InstructionSelector {
34+
public:
35+
PPCInstructionSelector(const PPCTargetMachine &TM, const PPCSubtarget &STI,
36+
const PPCRegisterBankInfo &RBI);
37+
38+
bool select(MachineInstr &I) override;
39+
static const char *getName() { return DEBUG_TYPE; }
40+
41+
private:
42+
/// tblgen generated 'select' implementation that is used as the initial
43+
/// selector for the patterns that do not require complex C++.
44+
bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;
45+
46+
const PPCInstrInfo &TII;
47+
const PPCRegisterInfo &TRI;
48+
const PPCRegisterBankInfo &RBI;
49+
50+
#define GET_GLOBALISEL_PREDICATES_DECL
51+
#include "PPCGenGlobalISel.inc"
52+
#undef GET_GLOBALISEL_PREDICATES_DECL
53+
54+
#define GET_GLOBALISEL_TEMPORARIES_DECL
55+
#include "PPCGenGlobalISel.inc"
56+
#undef GET_GLOBALISEL_TEMPORARIES_DECL
57+
};
58+
59+
} // end anonymous namespace
60+
61+
#define GET_GLOBALISEL_IMPL
62+
#include "PPCGenGlobalISel.inc"
63+
#undef GET_GLOBALISEL_IMPL
64+
65+
PPCInstructionSelector::PPCInstructionSelector(const PPCTargetMachine &TM,
66+
const PPCSubtarget &STI,
67+
const PPCRegisterBankInfo &RBI)
68+
: InstructionSelector(), TII(*STI.getInstrInfo()),
69+
TRI(*STI.getRegisterInfo()), RBI(RBI),
70+
#define GET_GLOBALISEL_PREDICATES_INIT
71+
#include "PPCGenGlobalISel.inc"
72+
#undef GET_GLOBALISEL_PREDICATES_INIT
73+
#define GET_GLOBALISEL_TEMPORARIES_INIT
74+
#include "PPCGenGlobalISel.inc"
75+
#undef GET_GLOBALISEL_TEMPORARIES_INIT
76+
{
77+
}
78+
79+
bool PPCInstructionSelector::select(MachineInstr &I) {
80+
if (selectImpl(I, *CoverageInfo))
81+
return true;
82+
return false;
83+
}
84+
85+
namespace llvm {
86+
InstructionSelector *
87+
createPPCInstructionSelector(const PPCTargetMachine &TM,
88+
const PPCSubtarget &Subtarget,
89+
const PPCRegisterBankInfo &RBI) {
90+
return new PPCInstructionSelector(TM, Subtarget, RBI);
91+
}
92+
} // end namespace llvm
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===- PPCLegalizerInfo.h ----------------------------------------*- C++ -*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
/// \file
9+
/// This file implements the targeting of the Machinelegalizer class for PowerPC
10+
//===----------------------------------------------------------------------===//
11+
12+
#include "PPCLegalizerInfo.h"
13+
#include "llvm/Support/Debug.h"
14+
15+
#define DEBUG_TYPE "ppc-legalinfo"
16+
17+
using namespace llvm;
18+
using namespace LegalizeActions;
19+
20+
PPCLegalizerInfo::PPCLegalizerInfo(const PPCSubtarget &ST) { computeTables(); }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===- PPCLegalizerInfo.h ----------------------------------------*- C++ -*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
/// \file
9+
/// This file declares the targeting of the Machinelegalizer class for PowerPC
10+
//===----------------------------------------------------------------------===//
11+
12+
#ifndef LLVM_LIB_TARGET_POWERPC_GISEL_PPCMACHINELEGALIZER_H
13+
#define LLVM_LIB_TARGET_POWERPC_GISEL_PPCMACHINELEGALIZER_H
14+
15+
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
16+
17+
namespace llvm {
18+
19+
class PPCSubtarget;
20+
21+
/// This class provides the information for the PowerPC target legalizer for
22+
/// GlobalISel.
23+
class PPCLegalizerInfo : public LegalizerInfo {
24+
public:
25+
PPCLegalizerInfo(const PPCSubtarget &ST);
26+
};
27+
} // namespace llvm
28+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===- PPCRegisterBankInfo.cpp --------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
/// \file
9+
/// This file implements the targeting of the RegisterBankInfo class for
10+
/// PowerPC.
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "PPCRegisterBankInfo.h"
14+
#include "PPCRegisterInfo.h"
15+
#include "llvm/CodeGen/MachineFunction.h"
16+
#include "llvm/CodeGen/MachineRegisterInfo.h"
17+
#include "llvm/Support/Debug.h"
18+
19+
#define DEBUG_TYPE "ppc-reg-bank-info"
20+
21+
#define GET_TARGET_REGBANK_IMPL
22+
#include "PPCGenRegisterBank.inc"
23+
24+
using namespace llvm;
25+
26+
PPCRegisterBankInfo::PPCRegisterBankInfo(const TargetRegisterInfo &TRI)
27+
: PPCGenRegisterBankInfo() {}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===-- PPCRegisterBankInfo.h -----------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// This file declares the targeting of the RegisterBankInfo class for PowerPC.
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_LIB_TARGET_PPC_GISEL_PPCREGISTERBANKINFO_H
15+
#define LLVM_LIB_TARGET_PPC_GISEL_PPCREGISTERBANKINFO_H
16+
17+
#include "llvm/CodeGen/GlobalISel/RegisterBank.h"
18+
#include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
19+
#include "llvm/CodeGen/TargetRegisterInfo.h"
20+
21+
#define GET_REGBANK_DECLARATIONS
22+
#include "PPCGenRegisterBank.inc"
23+
24+
namespace llvm {
25+
class TargetRegisterInfo;
26+
27+
class PPCGenRegisterBankInfo : public RegisterBankInfo {
28+
protected:
29+
#define GET_TARGET_REGBANK_CLASS
30+
#include "PPCGenRegisterBank.inc"
31+
};
32+
33+
class PPCRegisterBankInfo final : public PPCGenRegisterBankInfo {
34+
public:
35+
PPCRegisterBankInfo(const TargetRegisterInfo &TRI);
36+
};
37+
} // namespace llvm
38+
39+
#endif
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===-- PPCRegisterBanks.td - Describe the PPC Banks -------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// Define the PPC register banks used for GlobalISel.
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
/// General Purpose Registers
15+
def GPRRegBank : RegisterBank<"GPR", [G8RC]>;

‎llvm/lib/Target/PowerPC/LLVMBuild.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ has_jit = 1
3030
type = Library
3131
name = PowerPCCodeGen
3232
parent = PowerPC
33-
required_libraries = Analysis AsmPrinter CodeGen Core MC PowerPCDesc PowerPCInfo Scalar SelectionDAG Support Target TransformUtils
33+
required_libraries = Analysis AsmPrinter CodeGen Core MC PowerPCDesc PowerPCInfo Scalar SelectionDAG Support Target TransformUtils GlobalISel
3434
add_to_library_groups = PowerPC

0 commit comments

Comments
 (0)