1 //===-- M68kSubtarget.h - Define Subtarget for the M68k -----*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// 9 /// \file 10 /// This file declares the M68k specific subclass of TargetSubtargetInfo. 11 /// 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_LIB_TARGET_CPU0_M68KSUBTARGET_H 15 #define LLVM_LIB_TARGET_CPU0_M68KSUBTARGET_H 16 17 #include "M68kFrameLowering.h" 18 #include "M68kISelLowering.h" 19 #include "M68kInstrInfo.h" 20 21 #include "llvm/ADT/BitVector.h" 22 #include "llvm/CodeGen/SelectionDAGTargetInfo.h" 23 #include "llvm/CodeGen/TargetSubtargetInfo.h" 24 #include "llvm/IR/DataLayout.h" 25 #include "llvm/MC/MCInstrItineraries.h" 26 #include "llvm/Support/Alignment.h" 27 28 #include <string> 29 30 #define GET_SUBTARGETINFO_HEADER 31 #include "M68kGenSubtargetInfo.inc" 32 33 extern bool M68kReserveGP; 34 extern bool M68kNoCpload; 35 36 namespace llvm { 37 class StringRef; 38 39 class M68kTargetMachine; 40 41 class M68kSubtarget : public M68kGenSubtargetInfo { 42 virtual void anchor(); 43 44 protected: 45 // These define which ISA is supported. Since each Motorola M68k ISA is 46 // built on top of the previous one whenever an ISA is selected the previous 47 // selected as well. 48 enum SubtargetEnum { M00, M10, M20, M30, M40, M60 }; 49 SubtargetEnum SubtargetKind = M00; 50 51 BitVector UserReservedRegister; 52 53 InstrItineraryData InstrItins; 54 55 /// Small section is used. 56 bool UseSmallSection = true; 57 58 const M68kTargetMachine &TM; 59 60 SelectionDAGTargetInfo TSInfo; 61 M68kInstrInfo InstrInfo; 62 M68kFrameLowering FrameLowering; 63 M68kTargetLowering TLInfo; 64 65 /// The minimum alignment known to hold of the stack frame on 66 /// entry to the function and which must be maintained by every function. 67 unsigned stackAlignment = 8; 68 69 Triple TargetTriple; 70 71 public: 72 /// This constructor initializes the data members to match that 73 /// of the specified triple. 74 M68kSubtarget(const Triple &TT, StringRef CPU, StringRef FS, 75 const M68kTargetMachine &_TM); 76 77 /// Parses features string setting specified subtarget options. Definition 78 /// of function is auto generated by tblgen. 79 void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS); 80 atLeastM68000()81 bool atLeastM68000() const { return SubtargetKind >= M00; } atLeastM68010()82 bool atLeastM68010() const { return SubtargetKind >= M10; } atLeastM68020()83 bool atLeastM68020() const { return SubtargetKind >= M20; } atLeastM68030()84 bool atLeastM68030() const { return SubtargetKind >= M30; } atLeastM68040()85 bool atLeastM68040() const { return SubtargetKind >= M40; } atLeastM68060()86 bool atLeastM68060() const { return SubtargetKind >= M60; } 87 useSmallSection()88 bool useSmallSection() const { return UseSmallSection; } 89 90 bool abiUsesSoftFloat() const; 91 getTargetTriple()92 const Triple &getTargetTriple() const { return TargetTriple; } 93 isTargetELF()94 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); } 95 96 /// Return true if the subtarget allows calls to immediate address. 97 bool isLegalToCallImmediateAddr() const; 98 99 bool isPositionIndependent() const; 100 isRegisterReservedByUser(Register R)101 bool isRegisterReservedByUser(Register R) const { 102 assert(R < M68k::NUM_TARGET_REGS && "Register out of range"); 103 return UserReservedRegister[R]; 104 } 105 106 /// Classify a global variable reference for the current subtarget according 107 /// to how we should reference it in a non-pcrel context. 108 unsigned char classifyLocalReference(const GlobalValue *GV) const; 109 110 /// Classify a global variable reference for the current subtarget according 111 /// to how we should reference it in a non-pcrel context. 112 unsigned char classifyGlobalReference(const GlobalValue *GV, 113 const Module &M) const; 114 unsigned char classifyGlobalReference(const GlobalValue *GV) const; 115 116 /// Classify a external variable reference for the current subtarget according 117 /// to how we should reference it in a non-pcrel context. 118 unsigned char classifyExternalReference(const Module &M) const; 119 120 /// Classify a global function reference for the current subtarget. 121 unsigned char classifyGlobalFunctionReference(const GlobalValue *GV, 122 const Module &M) const; 123 unsigned char classifyGlobalFunctionReference(const GlobalValue *GV) const; 124 125 /// Classify a blockaddress reference for the current subtarget according to 126 /// how we should reference it in a non-pcrel context. 127 unsigned char classifyBlockAddressReference() const; 128 129 unsigned getJumpTableEncoding() const; 130 131 /// TODO this must be controlled by options like -malign-int and -mshort getStackAlignment()132 Align getStackAlignment() const { return Align(stackAlignment); } 133 134 /// getSlotSize - Stack slot size in bytes. getSlotSize()135 unsigned getSlotSize() const { return 4; } 136 137 M68kSubtarget &initializeSubtargetDependencies(StringRef CPU, Triple TT, 138 StringRef FS, 139 const M68kTargetMachine &TM); 140 getSelectionDAGInfo()141 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override { 142 return &TSInfo; 143 } 144 getInstrInfo()145 const M68kInstrInfo *getInstrInfo() const override { return &InstrInfo; } 146 getFrameLowering()147 const M68kFrameLowering *getFrameLowering() const override { 148 return &FrameLowering; 149 } 150 getRegisterInfo()151 const M68kRegisterInfo *getRegisterInfo() const override { 152 return &InstrInfo.getRegisterInfo(); 153 } 154 getTargetLowering()155 const M68kTargetLowering *getTargetLowering() const override { 156 return &TLInfo; 157 } 158 getInstrItineraryData()159 const InstrItineraryData *getInstrItineraryData() const override { 160 return &InstrItins; 161 } 162 }; 163 } // namespace llvm 164 165 #endif 166