1 //===-- ARMTargetMachine.h - Define TargetMachine for ARM -------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file declares the ARM specific subclass of TargetMachine. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef ARMTARGETMACHINE_H 15 #define ARMTARGETMACHINE_H 16 17 #include "ARMFrameLowering.h" 18 #include "ARMISelLowering.h" 19 #include "ARMInstrInfo.h" 20 #include "ARMJITInfo.h" 21 #include "ARMSelectionDAGInfo.h" 22 #include "ARMSubtarget.h" 23 #include "Thumb1FrameLowering.h" 24 #include "Thumb1InstrInfo.h" 25 #include "Thumb2InstrInfo.h" 26 #include "llvm/IR/DataLayout.h" 27 #include "llvm/MC/MCStreamer.h" 28 #include "llvm/Target/TargetMachine.h" 29 30 namespace llvm { 31 32 class ARMBaseTargetMachine : public LLVMTargetMachine { 33 protected: 34 ARMSubtarget Subtarget; 35 public: 36 ARMBaseTargetMachine(const Target &T, StringRef TT, 37 StringRef CPU, StringRef FS, 38 const TargetOptions &Options, 39 Reloc::Model RM, CodeModel::Model CM, 40 CodeGenOpt::Level OL, 41 bool isLittle); 42 43 const ARMSubtarget *getSubtargetImpl() const override { return &Subtarget; } 44 const ARMTargetLowering *getTargetLowering() const override { 45 // Implemented by derived classes 46 llvm_unreachable("getTargetLowering not implemented"); 47 } 48 const InstrItineraryData *getInstrItineraryData() const override { 49 return &getSubtargetImpl()->getInstrItineraryData(); 50 } 51 const DataLayout *getDataLayout() const override { 52 return getSubtargetImpl()->getDataLayout(); 53 } 54 ARMJITInfo *getJITInfo() override { return Subtarget.getJITInfo(); } 55 56 /// \brief Register ARM analysis passes with a pass manager. 57 void addAnalysisPasses(PassManagerBase &PM) override; 58 59 // Pass Pipeline Configuration 60 TargetPassConfig *createPassConfig(PassManagerBase &PM) override; 61 62 bool addCodeEmitter(PassManagerBase &PM, JITCodeEmitter &MCE) override; 63 }; 64 65 /// ARMTargetMachine - ARM target machine. 66 /// 67 class ARMTargetMachine : public ARMBaseTargetMachine { 68 virtual void anchor(); 69 ARMInstrInfo InstrInfo; 70 ARMTargetLowering TLInfo; 71 ARMFrameLowering FrameLowering; 72 public: 73 ARMTargetMachine(const Target &T, StringRef TT, 74 StringRef CPU, StringRef FS, 75 const TargetOptions &Options, 76 Reloc::Model RM, CodeModel::Model CM, 77 CodeGenOpt::Level OL, 78 bool isLittle); 79 80 const ARMRegisterInfo *getRegisterInfo() const override { 81 return &InstrInfo.getRegisterInfo(); 82 } 83 84 const ARMTargetLowering *getTargetLowering() const override { 85 return &TLInfo; 86 } 87 88 const ARMSelectionDAGInfo *getSelectionDAGInfo() const override { 89 return getSubtargetImpl()->getSelectionDAGInfo(); 90 } 91 const ARMFrameLowering *getFrameLowering() const override { 92 return &FrameLowering; 93 } 94 const ARMInstrInfo *getInstrInfo() const override { return &InstrInfo; } 95 }; 96 97 /// ARMLETargetMachine - ARM little endian target machine. 98 /// 99 class ARMLETargetMachine : public ARMTargetMachine { 100 void anchor() override; 101 public: 102 ARMLETargetMachine(const Target &T, StringRef TT, 103 StringRef CPU, StringRef FS, const TargetOptions &Options, 104 Reloc::Model RM, CodeModel::Model CM, 105 CodeGenOpt::Level OL); 106 }; 107 108 /// ARMBETargetMachine - ARM big endian target machine. 109 /// 110 class ARMBETargetMachine : public ARMTargetMachine { 111 void anchor() override; 112 public: 113 ARMBETargetMachine(const Target &T, StringRef TT, 114 StringRef CPU, StringRef FS, const TargetOptions &Options, 115 Reloc::Model RM, CodeModel::Model CM, 116 CodeGenOpt::Level OL); 117 }; 118 119 /// ThumbTargetMachine - Thumb target machine. 120 /// Due to the way architectures are handled, this represents both 121 /// Thumb-1 and Thumb-2. 122 /// 123 class ThumbTargetMachine : public ARMBaseTargetMachine { 124 virtual void anchor(); 125 // Either Thumb1InstrInfo or Thumb2InstrInfo. 126 std::unique_ptr<ARMBaseInstrInfo> InstrInfo; 127 ARMTargetLowering TLInfo; 128 // Either Thumb1FrameLowering or ARMFrameLowering. 129 std::unique_ptr<ARMFrameLowering> FrameLowering; 130 public: 131 ThumbTargetMachine(const Target &T, StringRef TT, 132 StringRef CPU, StringRef FS, 133 const TargetOptions &Options, 134 Reloc::Model RM, CodeModel::Model CM, 135 CodeGenOpt::Level OL, 136 bool isLittle); 137 138 /// returns either Thumb1RegisterInfo or Thumb2RegisterInfo 139 const ARMBaseRegisterInfo *getRegisterInfo() const override { 140 return &InstrInfo->getRegisterInfo(); 141 } 142 143 const ARMTargetLowering *getTargetLowering() const override { 144 return &TLInfo; 145 } 146 147 const ARMSelectionDAGInfo *getSelectionDAGInfo() const override { 148 return getSubtargetImpl()->getSelectionDAGInfo(); 149 } 150 151 /// returns either Thumb1InstrInfo or Thumb2InstrInfo 152 const ARMBaseInstrInfo *getInstrInfo() const override { 153 return InstrInfo.get(); 154 } 155 /// returns either Thumb1FrameLowering or ARMFrameLowering 156 const ARMFrameLowering *getFrameLowering() const override { 157 return FrameLowering.get(); 158 } 159 }; 160 161 /// ThumbLETargetMachine - Thumb little endian target machine. 162 /// 163 class ThumbLETargetMachine : public ThumbTargetMachine { 164 void anchor() override; 165 public: 166 ThumbLETargetMachine(const Target &T, StringRef TT, 167 StringRef CPU, StringRef FS, const TargetOptions &Options, 168 Reloc::Model RM, CodeModel::Model CM, 169 CodeGenOpt::Level OL); 170 }; 171 172 /// ThumbBETargetMachine - Thumb big endian target machine. 173 /// 174 class ThumbBETargetMachine : public ThumbTargetMachine { 175 void anchor() override; 176 public: 177 ThumbBETargetMachine(const Target &T, StringRef TT, StringRef CPU, 178 StringRef FS, const TargetOptions &Options, 179 Reloc::Model RM, CodeModel::Model CM, 180 CodeGenOpt::Level OL); 181 }; 182 183 } // end namespace llvm 184 185 #endif 186