Debian Codegraph @

llvm/unittests/CodeGen/MFCommon.inc

raw
1 // Add a few Bogus backend classes so we can create MachineInstrs without
2 // depending on a real target.
3 class BogusTargetLowering : public TargetLowering {
4 public:
5 BogusTargetLowering(TargetMachine &TM) : TargetLowering(TM) {}
6 };
7
8 class BogusFrameLowering : public TargetFrameLowering {
9 public:
10 BogusFrameLowering()
11 : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, Align(4), 4) {}
12
13 void emitPrologue(MachineFunction &MF,
14 MachineBasicBlock &MBB) const override {}
15 void emitEpilogue(MachineFunction &MF,
16 MachineBasicBlock &MBB) const override {}
17
18 protected:
19 bool hasFPImpl(const MachineFunction &MF) const override { return false; }
20 };
21
22 static TargetRegisterClass *const BogusRegisterClasses[] = {nullptr};
23
24 class BogusRegisterInfo : public TargetRegisterInfo {
25 public:
26 BogusRegisterInfo()
27 : TargetRegisterInfo(nullptr, BogusRegisterClasses, BogusRegisterClasses,
28 nullptr, nullptr, nullptr, LaneBitmask(~0u), nullptr,
29 nullptr) {
30 InitMCRegisterInfo(nullptr, 0, 0, 0, nullptr, 0, nullptr, 0, nullptr,
31 nullptr, nullptr, nullptr, nullptr, 0, nullptr);
32 }
33
34 const MCPhysReg *
35 getCalleeSavedRegs(const MachineFunction *MF) const override {
36 return nullptr;
37 }
38 ArrayRef<const uint32_t *> getRegMasks() const override { return {}; }
39 ArrayRef<const char *> getRegMaskNames() const override { return {}; }
40 BitVector getReservedRegs(const MachineFunction &MF) const override {
41 return BitVector();
42 }
43 const RegClassWeight &
44 getRegClassWeight(const TargetRegisterClass *RC) const override {
45 static RegClassWeight Bogus{1, 16};
46 return Bogus;
47 }
48 unsigned getRegUnitWeight(unsigned RegUnit) const override { return 1; }
49 unsigned getNumRegPressureSets() const override { return 0; }
50 const char *getRegPressureSetName(unsigned Idx) const override {
51 return "bogus";
52 }
53 unsigned getRegPressureSetLimit(const MachineFunction &MF,
54 unsigned Idx) const override {
55 return 0;
56 }
57 const int *
58 getRegClassPressureSets(const TargetRegisterClass *RC) const override {
59 static const int Bogus[] = {0, -1};
60 return &Bogus[0];
61 }
62 const int *getRegUnitPressureSets(unsigned RegUnit) const override {
63 static const int Bogus[] = {0, -1};
64 return &Bogus[0];
65 }
66
67 Register getFrameRegister(const MachineFunction &MF) const override {
68 return 0;
69 }
70 bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj,
71 unsigned FIOperandNum,
72 RegScavenger *RS = nullptr) const override {
73 return false;
74
75 }
76 };
77
78 class BogusSubtarget : public TargetSubtargetInfo {
79 public:
80 BogusSubtarget(TargetMachine &TM)
81 : TargetSubtargetInfo(Triple(""), "", "", "", {}, {}, {}, nullptr,
82 nullptr, nullptr, nullptr, nullptr, nullptr),
83 FL(), TL(TM) {}
84 ~BogusSubtarget() override {}
85
86 const TargetFrameLowering *getFrameLowering() const override { return &FL; }
87
88 const TargetLowering *getTargetLowering() const override { return &TL; }
89
90 const TargetInstrInfo *getInstrInfo() const override { return &TII; }
91
92 const TargetRegisterInfo *getRegisterInfo() const override { return &TRI; }
93
94 private:
95 BogusFrameLowering FL;
96 BogusRegisterInfo TRI;
97 BogusTargetLowering TL;
98 TargetInstrInfo TII;
99 };
100
101 static TargetOptions getTargetOptionsForBogusMachine() {
102 TargetOptions Opts;
103 Opts.EmitCallSiteInfo = true;
104 return Opts;
105 }
106
107 class BogusTargetMachine : public CodeGenTargetMachineImpl {
108 public:
109 BogusTargetMachine()
110 : CodeGenTargetMachineImpl(
111 Target(), "", Triple(""), "", "", getTargetOptionsForBogusMachine(),
112 Reloc::Static, CodeModel::Small, CodeGenOptLevel::Default),
113 ST(*this) {}
114
115 ~BogusTargetMachine() override {}
116
117 const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override {
118 return &ST;
119 }
120
121 private:
122 BogusSubtarget ST;
123 };
124
125 BogusTargetMachine *createTargetMachine() {
126 static BogusTargetMachine BogusTM;
127 return &BogusTM;
128 }
129
130 std::unique_ptr<MachineFunction> createMachineFunction(LLVMContext &Ctx,
131 Module &M) {
132 auto Type = FunctionType::get(Type::getVoidTy(Ctx), false);
133 auto F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &M);
134
135 auto TM = createTargetMachine();
136 unsigned FunctionNum = 42;
137 MachineModuleInfo MMI(TM);
138 const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(*F);
139
140 return std::make_unique<MachineFunction>(*F, *TM, STI, MMI.getContext(),
141 FunctionNum);
142 }
143