1 // Add a few Bogus backend classes so we can create MachineInstrs without
2 // depending on a real target.
3 class BogusTargetLowering : public TargetLowering {
5 BogusTargetLowering(TargetMachine &TM) : TargetLowering(TM) {}
8 class BogusFrameLowering : public TargetFrameLowering {
11 : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, Align(4), 4) {}
13 void emitPrologue(MachineFunction &MF,
14 MachineBasicBlock &MBB) const override {}
15 void emitEpilogue(MachineFunction &MF,
16 MachineBasicBlock &MBB) const override {}
19 bool hasFPImpl(const MachineFunction &MF) const override { return false; }
22 static TargetRegisterClass *const BogusRegisterClasses[] = {nullptr};
24 class BogusRegisterInfo : public TargetRegisterInfo {
27 : TargetRegisterInfo(nullptr, BogusRegisterClasses, BogusRegisterClasses,
28 nullptr, nullptr, nullptr, LaneBitmask(~0u), nullptr,
30 InitMCRegisterInfo(nullptr, 0, 0, 0, nullptr, 0, nullptr, 0, nullptr,
31 nullptr, nullptr, nullptr, nullptr, 0, nullptr);
35 getCalleeSavedRegs(const MachineFunction *MF) const override {
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 {
43 const RegClassWeight &
44 getRegClassWeight(const TargetRegisterClass *RC) const override {
45 static RegClassWeight Bogus{1, 16};
48 unsigned getRegUnitWeight(unsigned RegUnit) const override { return 1; }
49 unsigned getNumRegPressureSets() const override { return 0; }
50 const char *getRegPressureSetName(unsigned Idx) const override {
53 unsigned getRegPressureSetLimit(const MachineFunction &MF,
54 unsigned Idx) const override {
58 getRegClassPressureSets(const TargetRegisterClass *RC) const override {
59 static const int Bogus[] = {0, -1};
62 const int *getRegUnitPressureSets(unsigned RegUnit) const override {
63 static const int Bogus[] = {0, -1};
67 Register getFrameRegister(const MachineFunction &MF) const override {
70 bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj,
71 unsigned FIOperandNum,
72 RegScavenger *RS = nullptr) const override {
78 class BogusSubtarget : public TargetSubtargetInfo {
80 BogusSubtarget(TargetMachine &TM)
81 : TargetSubtargetInfo(Triple(""), "", "", "", {}, {}, nullptr, nullptr,
82 nullptr, nullptr, nullptr, nullptr),
84 ~BogusSubtarget() override {}
86 const TargetFrameLowering *getFrameLowering() const override { return &FL; }
88 const TargetLowering *getTargetLowering() const override { return &TL; }
90 const TargetInstrInfo *getInstrInfo() const override { return &TII; }
92 const TargetRegisterInfo *getRegisterInfo() const override { return &TRI; }
95 BogusFrameLowering FL;
96 BogusRegisterInfo TRI;
97 BogusTargetLowering TL;
101 static TargetOptions getTargetOptionsForBogusMachine() {
103 Opts.EmitCallSiteInfo = true;
107 class BogusTargetMachine : public CodeGenTargetMachineImpl {
110 : CodeGenTargetMachineImpl(
111 Target(), "", Triple(""), "", "", getTargetOptionsForBogusMachine(),
112 Reloc::Static, CodeModel::Small, CodeGenOptLevel::Default),
115 ~BogusTargetMachine() override {}
117 const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override {
125 BogusTargetMachine *createTargetMachine() {
126 static BogusTargetMachine BogusTM;
130 std::unique_ptr<MachineFunction> createMachineFunction(LLVMContext &Ctx,
132 auto Type = FunctionType::get(Type::getVoidTy(Ctx), false);
133 auto F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &M);
135 auto TM = createTargetMachine();
136 unsigned FunctionNum = 42;
137 MachineModuleInfo MMI(TM);
138 const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(*F);
140 return std::make_unique<MachineFunction>(*F, *TM, STI, MMI.getContext(),