Skip to content

Commit 1f11d6f

Browse files
committed
Add Rubinius MLIR scaffolding.
1 parent 6c97b2e commit 1f11d6f

53 files changed

Lines changed: 458 additions & 120 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
add_llvm_component_group(Rubinius)
2+
13
# TableGen setup: all Rubinius .td defs should be rooted at Rubinius.td
24
set(LLVM_TARGET_DEFINITIONS Rubinius.td)
35

4-
# Generate the minimal set of backend inc files we actually use.
6+
# Generate the backend's TableGen outputs.
57
tablegen(LLVM RubiniusGenRegisterInfo.inc -gen-register-info)
68
tablegen(LLVM RubiniusGenInstrInfo.inc -gen-instr-info)
79
tablegen(LLVM RubiniusGenSubtargetInfo.inc -gen-subtarget)
@@ -12,51 +14,33 @@ tablegen(LLVM RubiniusGenMCCodeEmitter.inc -gen-emitter)
1214
add_public_tablegen_target(RubiniusCommonTableGen)
1315

1416
# The core codegen library for the Rubinius backend.
15-
# Name must match the component in llvm/lib/Target/Rubinius/LLVMBuild.txt
16-
# (RubiniusCodeGen).
17+
# Name must match the component in llvm/lib/Target/Rubinius/LLVMBuild.txt (RubiniusCodeGen).
1718
add_llvm_target(RubiniusCodeGen
1819
RubiniusAsmPrinter.cpp
19-
RubiniusInstrInfo.cpp
2020
RubiniusISelDAGToDAG.cpp
2121
RubiniusISelLowering.cpp
22+
RubiniusInstrInfo.cpp
2223
RubiniusMCInstLower.cpp
2324
RubiniusRegisterInfo.cpp
2425
RubiniusSubtarget.cpp
26+
RubiniusTargetInfo.cpp
2527
RubiniusTargetMachine.cpp
26-
)
27-
28-
add_llvm_component_library(LLVMRubiniusCodeGen
29-
RubiniusTargetMachine.cpp
30-
RubiniusISelLowering.cpp
31-
RubiniusSubtarget.cpp
32-
RubiniusAsmPrinter.cpp
33-
34-
DEPENDS
35-
RubiniusCommonTableGen
36-
37-
LINK_COMPONENTS
38-
AsmPrinter
39-
Core
40-
CodeGen
41-
MC
42-
SelectionDAG
43-
Support
44-
Target
45-
)
46-
47-
add_llvm_component_library(LLVMRubiniusDesc
48-
MCTargetDesc/RubiniusMCTargetDesc.cpp
49-
MCTargetDesc/RubiniusMCAsmInfo.cpp
50-
51-
DEPENDS
52-
RubiniusCommonTableGen
5328

5429
LINK_COMPONENTS
55-
MC
56-
MCDisassembler
57-
Support
30+
AsmPrinter
31+
CodeGen
32+
Core
33+
MC
34+
SelectionDAG
35+
Support
36+
Target
37+
RubiniusDesc
38+
RubiniusInfo
39+
40+
ADD_TO_COMPONENT
41+
Rubinius
5842
)
5943

60-
# These must exist and have their own CMakeLists.txt files.
44+
# These subdirectories define the MC-layer and target-info libraries.
6145
add_subdirectory(MCTargetDesc)
6246
add_subdirectory(TargetInfo)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[component_0]
2+
type = TargetGroup
3+
name = Rubinius
4+
parent = Target
5+
6+
[component_1]
7+
type = Library
8+
name = RubiniusCodeGen
9+
parent = Rubinius
10+
11+
[component_2]
12+
type = Library
13+
name = RubiniusDesc
14+
parent = Rubinius
15+
16+
[component_3]
17+
type = Library
18+
name = RubiniusInfo
19+
parent = Rubinius
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
add_llvm_library(LLVMRubiniusInfo
1+
add_llvm_component_library(LLVMRubiniusDesc
22
RubiniusMCTargetDesc.cpp
33
RubiniusMCAsmInfo.cpp
4+
RubiniusMCCodeEmitter.cpp
5+
6+
DEPENDS
7+
RubiniusCommonTableGen
48

59
LINK_COMPONENTS
6-
MC
7-
Support
10+
MC
11+
Support
12+
13+
ADD_TO_COMPONENT
14+
Rubinius
815
)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "RubiniusMCAsmInfo.h"
22
using namespace llvm;
33

4-
RubiniusMCAsmInfo::RubiniusMCAsmInfo() {
4+
RubiniusMCAsmInfo::RubiniusMCAsmInfo(const Triple &TT,
5+
const MCTargetOptions &)
6+
: MCAsmInfoELF() {
57
CommentString = "#";
68
MinInstAlignment = 4;
79
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RubiniusMCCodeEmitter.cpp
2+
#include "llvm/MC/MCCodeEmitter.h"
3+
#include "llvm/MC/MCInst.h"
4+
#include "llvm/Support/raw_ostream.h"
5+
6+
using namespace llvm;
7+
8+
namespace {
9+
class RubiniusMCCodeEmitter : public MCCodeEmitter {
10+
public:
11+
RubiniusMCCodeEmitter(const MCInstrInfo &, MCContext &) {}
12+
void encodeInstruction(const MCInst &, raw_ostream &, SmallVectorImpl<MCFixup> &,
13+
const MCSubtargetInfo &) const override {
14+
llvm_unreachable("RubiniusMCCodeEmitter not implemented yet");
15+
}
16+
};
17+
} // namespace
18+
19+
MCCodeEmitter *createRubiniusMCCodeEmitter(const MCInstrInfo &II,
20+
MCContext &Ctx) {
21+
return new RubiniusMCCodeEmitter(II, Ctx);
22+
}
Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,43 @@
11
include "llvm/Target/Target.td"
22

3+
// --- Subtarget / Instruction Set -----------------------------------------
4+
5+
def RubiniusInstrInfo : InstrInfo;
6+
7+
class RubiniusProc<string Name>
8+
: Processor<Name, NoItineraries, []>;
9+
def : RubiniusProc<"generic">;
10+
11+
// --- Target ---------------------------------------------------------------
12+
313
def Rubinius : Target {
4-
let InstructionSet = "Rubinius";
14+
let InstructionSet = RubiniusInstrInfo;
15+
}
16+
17+
// --- Registers ------------------------------------------------------------
18+
19+
class RReg<string N, int Enc> : Register<N> {
20+
let HWEncoding = Enc;
21+
let Namespace = "Rubinius";
522
}
23+
24+
def R0 : RReg<"r0", 0>;
25+
def R1 : RReg<"r1", 1>;
26+
def R2 : RReg<"r2", 2>;
27+
def R3 : RReg<"r3", 3>;
28+
29+
def GPR : RegisterClass<"Rubinius", [i64], 32,
30+
(add R0, R1, R2, R3)>;
31+
32+
// --- Instructions ---------------------------------------------------------
33+
34+
class RInst<string Asm> : Instruction {
35+
let Namespace = "Rubinius";
36+
let OutOperandList = (outs);
37+
let InOperandList = (ins);
38+
let AsmString = Asm;
39+
field bits<32> Inst;
40+
let Size = 4;
41+
}
42+
43+
def NOP : RInst<"nop"> { let Inst = 0; }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "llvm/MC/TargetRegistry.h"
2+
using namespace llvm;
3+
4+
Target &getTheRubiniusTarget() {
5+
static Target T;
6+
return T;
7+
}
8+
9+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRubiniusTargetInfo() {
10+
RegisterTarget<False>(getTheRubiniusTarget(), "rubinius", "Rubinius", "Rubinius");
11+
}
Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1-
#include "RubiniusTargetMachine.h"
2-
#include "RubiniusGenSubtargetInfo.inc"
3-
#include "RubiniusISelLowering.h"
4-
#include "llvm/CodeGen/Passes.h"
5-
#include "llvm/CodeGen/TargetPassConfig.h"
1+
#include "llvm/Target/TargetMachine.h"
62
#include "llvm/MC/TargetRegistry.h"
7-
using namespace llvm;
83

9-
static Target &getTheRubiniusTarget(); // from RubiniusTargetInfo.cpp
4+
using namespace llvm;
105

11-
RubiniusTargetMachine::RubiniusTargetMachine(const Target &T, const Triple &TT,
12-
StringRef CPU, StringRef FS,
13-
const TargetOptions &Options,
14-
Optional<Reloc::Model> RM,
15-
Optional<CodeModel::Model> CM,
16-
CodeGenOptLevel OL)
17-
: LLVMTargetMachine(T, "e", TT, CPU, FS, Options, RM.value_or(Reloc::Static),
18-
CM.value_or(CodeModel::Small), OL),
19-
Subtarget(TT, CPU, FS, *this) {}
6+
extern Target &getTheRubiniusTarget();
207

21-
const RubiniusSubtarget *
22-
RubiniusTargetMachine::getSubtargetImpl(const Function &) const {
23-
return &Subtarget;
24-
}
8+
class RubiniusTargetMachine : public LLVMTargetMachine {
9+
public:
10+
RubiniusTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
11+
StringRef FS, const TargetOptions &Options,
12+
std::optional<Reloc::Model> RM,
13+
std::optional<CodeModel::Model> CM,
14+
CodeGenOptLevel OL)
15+
: LLVMTargetMachine(T, "e", TT, CPU, FS, Options, RM, CM, OL) {}
16+
};
2517

2618
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRubiniusTarget() {
27-
RegisterTargetMachine<RubiniusTargetMachine> X(getTheRubiniusTarget());
19+
Target &T = getTheRubiniusTarget();
20+
RegisterTargetMachine<RubiniusTargetMachine> X(T);
2821
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
add_llvm_library(LLVMRubiniusTargetInfo
1+
add_llvm_component_library(LLVMRubiniusInfo
22
RubiniusTargetInfo.cpp
33

44
LINK_COMPONENTS
5-
Support
5+
Support
6+
7+
ADD_TO_COMPONENT
8+
Rubinius
69
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(IR)

0 commit comments

Comments
 (0)