187 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file declares the M68k specific subclass of TargetSubtargetInfo.11///12//===----------------------------------------------------------------------===//13 14#ifndef LLVM_LIB_TARGET_M68K_M68KSUBTARGET_H15#define LLVM_LIB_TARGET_M68K_M68KSUBTARGET_H16 17#include "M68kFrameLowering.h"18#include "M68kISelLowering.h"19#include "M68kInstrInfo.h"20 21#include "llvm/CodeGen/GlobalISel/CallLowering.h"22#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"23#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"24#include "llvm/CodeGen/RegisterBankInfo.h"25#include "llvm/CodeGen/TargetSubtargetInfo.h"26#include "llvm/IR/DataLayout.h"27#include "llvm/MC/MCInstrItineraries.h"28#include "llvm/Support/Alignment.h"29 30#define GET_SUBTARGETINFO_HEADER31#include "M68kGenSubtargetInfo.inc"32 33extern bool M68kReserveGP;34extern bool M68kNoCpload;35 36namespace llvm {37class StringRef;38 39class M68kTargetMachine;40 41class M68kSubtarget : public M68kGenSubtargetInfo {42 virtual void anchor();43 44protected:45 // These define which ISA is supported. Since each Motorola M68k ISA is46 // built on top of the previous one whenever an ISA is selected the previous47 // selected as well.48 enum SubtargetEnum { M00, M10, M20, M30, M40, M60 };49 SubtargetEnum SubtargetKind = M00;50 51 enum FPKindEnum { M881, M882 };52 std::optional<FPKindEnum> FPUKind;53 54 std::bitset<M68k::NUM_TARGET_REGS> UserReservedRegister;55 56 InstrItineraryData InstrItins;57 58 /// Small section is used.59 bool UseSmallSection = true;60 61 const M68kTargetMachine &TM;62 63 M68kInstrInfo InstrInfo;64 M68kFrameLowering FrameLowering;65 M68kTargetLowering TLInfo;66 67 /// The minimum alignment known to hold of the stack frame on68 /// entry to the function and which must be maintained by every function.69 unsigned stackAlignment = 8;70 71 Triple TargetTriple;72 73public:74 /// This constructor initializes the data members to match that75 /// of the specified triple.76 M68kSubtarget(const Triple &TT, StringRef CPU, StringRef FS,77 const M68kTargetMachine &_TM);78 79 ~M68kSubtarget() override;80 81 /// Parses features string setting specified subtarget options. Definition82 /// of function is auto generated by tblgen.83 void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);84 85 bool atLeastM68000() const { return SubtargetKind >= M00; }86 bool atLeastM68010() const { return SubtargetKind >= M10; }87 bool atLeastM68020() const { return SubtargetKind >= M20; }88 bool atLeastM68030() const { return SubtargetKind >= M30; }89 bool atLeastM68040() const { return SubtargetKind >= M40; }90 bool atLeastM68060() const { return SubtargetKind >= M60; }91 92 /// Floating point support93 bool hasFPU() const { return FPUKind.has_value(); }94 bool atLeastM68881() const { return hasFPU() && *FPUKind >= M881; }95 bool atLeastM68882() const { return hasFPU() && *FPUKind >= M882; }96 97 bool useSmallSection() const { return UseSmallSection; }98 99 const Triple &getTargetTriple() const { return TargetTriple; }100 101 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }102 103 /// Return true if the subtarget allows calls to immediate address.104 bool isLegalToCallImmediateAddr() const;105 106 bool isPositionIndependent() const;107 108 bool isRegisterReservedByUser(Register R) const override {109 assert(R < M68k::NUM_TARGET_REGS && "Register out of range");110 return UserReservedRegister[R];111 }112 113 /// Classify a global variable reference for the current subtarget according114 /// to how we should reference it in a non-pcrel context.115 unsigned char classifyLocalReference(const GlobalValue *GV) const;116 117 /// Classify a global variable reference for the current subtarget according118 /// to how we should reference it in a non-pcrel context.119 unsigned char classifyGlobalReference(const GlobalValue *GV,120 const Module &M) const;121 unsigned char classifyGlobalReference(const GlobalValue *GV) const;122 123 /// Classify a external variable reference for the current subtarget according124 /// to how we should reference it in a non-pcrel context.125 unsigned char classifyExternalReference(const Module &M) const;126 127 /// Classify a global function reference for the current subtarget.128 unsigned char classifyGlobalFunctionReference(const GlobalValue *GV,129 const Module &M) const;130 unsigned char131 classifyGlobalFunctionReference(const GlobalValue *GV) const override;132 133 /// Classify a blockaddress reference for the current subtarget according to134 /// how we should reference it in a non-pcrel context.135 unsigned char classifyBlockAddressReference() const;136 137 unsigned getJumpTableEncoding() const;138 139 /// TODO this must be controlled by options like -malign-int and -mshort140 Align getStackAlignment() const { return Align(stackAlignment); }141 142 /// getSlotSize - Stack slot size in bytes.143 unsigned getSlotSize() const { return 4; }144 145 M68kSubtarget &initializeSubtargetDependencies(StringRef CPU, Triple TT,146 StringRef FS,147 const M68kTargetMachine &TM);148 149 const M68kInstrInfo *getInstrInfo() const override { return &InstrInfo; }150 151 const M68kFrameLowering *getFrameLowering() const override {152 return &FrameLowering;153 }154 155 const M68kRegisterInfo *getRegisterInfo() const override {156 return &InstrInfo.getRegisterInfo();157 }158 159 const M68kTargetLowering *getTargetLowering() const override {160 return &TLInfo;161 }162 163 const InstrItineraryData *getInstrItineraryData() const override {164 return &InstrItins;165 }166 167protected:168 // SelectionDAGISel related APIs.169 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;170 171 // GlobalISel related APIs.172 std::unique_ptr<CallLowering> CallLoweringInfo;173 std::unique_ptr<InstructionSelector> InstSelector;174 std::unique_ptr<LegalizerInfo> Legalizer;175 std::unique_ptr<RegisterBankInfo> RegBankInfo;176 177public:178 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;179 const CallLowering *getCallLowering() const override;180 InstructionSelector *getInstructionSelector() const override;181 const LegalizerInfo *getLegalizerInfo() const override;182 const RegisterBankInfo *getRegBankInfo() const override;183};184} // namespace llvm185 186#endif // LLVM_LIB_TARGET_M68K_M68KSUBTARGET_H187