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 {}
17 bool hasFP(const MachineFunction &MF) const override { return false; }
20 static TargetRegisterClass *const BogusRegisterClasses[] = {nullptr};
22 class BogusRegisterInfo : public TargetRegisterInfo {
25 : TargetRegisterInfo(nullptr, BogusRegisterClasses, BogusRegisterClasses,
26 nullptr, nullptr, LaneBitmask(~0u), nullptr) {
27 InitMCRegisterInfo(nullptr, 0, 0, 0, nullptr, 0, nullptr, 0, nullptr,
28 nullptr, nullptr, nullptr, nullptr, 0, nullptr, nullptr);
32 getCalleeSavedRegs(const MachineFunction *MF) const override {
35 ArrayRef<const uint32_t *> getRegMasks() const override { return None; }
36 ArrayRef<const char *> getRegMaskNames() const override { return None; }
37 BitVector getReservedRegs(const MachineFunction &MF) const override {
40 const RegClassWeight &
41 getRegClassWeight(const TargetRegisterClass *RC) const override {
42 static RegClassWeight Bogus{1, 16};
45 unsigned getRegUnitWeight(unsigned RegUnit) const override { return 1; }
46 unsigned getNumRegPressureSets() const override { return 0; }
47 const char *getRegPressureSetName(unsigned Idx) const override {
50 unsigned getRegPressureSetLimit(const MachineFunction &MF,
51 unsigned Idx) const override {
55 getRegClassPressureSets(const TargetRegisterClass *RC) const override {
56 static const int Bogus[] = {0, -1};
59 const int *getRegUnitPressureSets(unsigned RegUnit) const override {
60 static const int Bogus[] = {0, -1};
64 Register getFrameRegister(const MachineFunction &MF) const override {
67 void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj,
68 unsigned FIOperandNum,
69 RegScavenger *RS = nullptr) const override {}
72 class BogusSubtarget : public TargetSubtargetInfo {
74 BogusSubtarget(TargetMachine &TM)
75 : TargetSubtargetInfo(Triple(""), "", "", "", {}, {}, nullptr, nullptr,
76 nullptr, nullptr, nullptr, nullptr),
78 ~BogusSubtarget() override {}
80 const TargetFrameLowering *getFrameLowering() const override { return &FL; }
82 const TargetLowering *getTargetLowering() const override { return &TL; }
84 const TargetInstrInfo *getInstrInfo() const override { return &TII; }
86 const TargetRegisterInfo *getRegisterInfo() const override { return &TRI; }
89 BogusFrameLowering FL;
90 BogusRegisterInfo TRI;
91 BogusTargetLowering TL;
95 static TargetOptions getTargetOptionsForBogusMachine() {
97 Opts.EmitCallSiteInfo = true;
101 class BogusTargetMachine : public LLVMTargetMachine {
104 : LLVMTargetMachine(Target(), "", Triple(""), "", "",
105 getTargetOptionsForBogusMachine(), Reloc::Static,
106 CodeModel::Small, CodeGenOpt::Default),
109 ~BogusTargetMachine() override {}
111 const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override {
119 BogusTargetMachine *createTargetMachine() {
120 static BogusTargetMachine BogusTM;
124 std::unique_ptr<MachineFunction> createMachineFunction(LLVMContext &Ctx,
126 auto Type = FunctionType::get(Type::getVoidTy(Ctx), false);
127 auto F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &M);
129 auto TM = createTargetMachine();
130 unsigned FunctionNum = 42;
131 MachineModuleInfo MMI(TM);
132 const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(*F);
134 return std::make_unique<MachineFunction>(*F, *TM, STI, FunctionNum, MMI);