Path: blob/main/contrib/llvm-project/llvm/lib/Target/M68k/M68kSubtarget.h
35266 views
//===-- M68kSubtarget.h - Define Subtarget for the M68k ---------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file declares the M68k specific subclass of TargetSubtargetInfo.10///11//===----------------------------------------------------------------------===//1213#ifndef LLVM_LIB_TARGET_M68K_M68KSUBTARGET_H14#define LLVM_LIB_TARGET_M68K_M68KSUBTARGET_H1516#include "M68kFrameLowering.h"17#include "M68kISelLowering.h"18#include "M68kInstrInfo.h"1920#include "llvm/CodeGen/GlobalISel/CallLowering.h"21#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"22#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"23#include "llvm/CodeGen/RegisterBankInfo.h"24#include "llvm/CodeGen/SelectionDAGTargetInfo.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"2930#include <string>3132#define GET_SUBTARGETINFO_HEADER33#include "M68kGenSubtargetInfo.inc"3435extern bool M68kReserveGP;36extern bool M68kNoCpload;3738namespace llvm {39class StringRef;4041class M68kTargetMachine;4243class M68kSubtarget : public M68kGenSubtargetInfo {44virtual void anchor();4546protected:47// These define which ISA is supported. Since each Motorola M68k ISA is48// built on top of the previous one whenever an ISA is selected the previous49// selected as well.50enum SubtargetEnum { M00, M10, M20, M30, M40, M60 };51SubtargetEnum SubtargetKind = M00;5253enum FPKindEnum { M881, M882 };54std::optional<FPKindEnum> FPUKind;5556std::bitset<M68k::NUM_TARGET_REGS> UserReservedRegister;5758InstrItineraryData InstrItins;5960/// Small section is used.61bool UseSmallSection = true;6263const M68kTargetMachine &TM;6465SelectionDAGTargetInfo TSInfo;66M68kInstrInfo InstrInfo;67M68kFrameLowering FrameLowering;68M68kTargetLowering TLInfo;6970/// The minimum alignment known to hold of the stack frame on71/// entry to the function and which must be maintained by every function.72unsigned stackAlignment = 8;7374Triple TargetTriple;7576public:77/// This constructor initializes the data members to match that78/// of the specified triple.79M68kSubtarget(const Triple &TT, StringRef CPU, StringRef FS,80const M68kTargetMachine &_TM);8182/// Parses features string setting specified subtarget options. Definition83/// of function is auto generated by tblgen.84void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);8586bool atLeastM68000() const { return SubtargetKind >= M00; }87bool atLeastM68010() const { return SubtargetKind >= M10; }88bool atLeastM68020() const { return SubtargetKind >= M20; }89bool atLeastM68030() const { return SubtargetKind >= M30; }90bool atLeastM68040() const { return SubtargetKind >= M40; }91bool atLeastM68060() const { return SubtargetKind >= M60; }9293/// Floating point support94bool hasFPU() const { return FPUKind.has_value(); }95bool atLeastM68881() const { return hasFPU() && *FPUKind >= M881; }96bool atLeastM68882() const { return hasFPU() && *FPUKind >= M882; }9798bool useSmallSection() const { return UseSmallSection; }99100const Triple &getTargetTriple() const { return TargetTriple; }101102bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }103104/// Return true if the subtarget allows calls to immediate address.105bool isLegalToCallImmediateAddr() const;106107bool isPositionIndependent() const;108109bool isRegisterReservedByUser(Register R) const {110assert(R < M68k::NUM_TARGET_REGS && "Register out of range");111return UserReservedRegister[R];112}113114/// Classify a global variable reference for the current subtarget according115/// to how we should reference it in a non-pcrel context.116unsigned char classifyLocalReference(const GlobalValue *GV) const;117118/// Classify a global variable reference for the current subtarget according119/// to how we should reference it in a non-pcrel context.120unsigned char classifyGlobalReference(const GlobalValue *GV,121const Module &M) const;122unsigned char classifyGlobalReference(const GlobalValue *GV) const;123124/// Classify a external variable reference for the current subtarget according125/// to how we should reference it in a non-pcrel context.126unsigned char classifyExternalReference(const Module &M) const;127128/// Classify a global function reference for the current subtarget.129unsigned char classifyGlobalFunctionReference(const GlobalValue *GV,130const Module &M) const;131unsigned char132classifyGlobalFunctionReference(const GlobalValue *GV) const override;133134/// Classify a blockaddress reference for the current subtarget according to135/// how we should reference it in a non-pcrel context.136unsigned char classifyBlockAddressReference() const;137138unsigned getJumpTableEncoding() const;139140/// TODO this must be controlled by options like -malign-int and -mshort141Align getStackAlignment() const { return Align(stackAlignment); }142143/// getSlotSize - Stack slot size in bytes.144unsigned getSlotSize() const { return 4; }145146M68kSubtarget &initializeSubtargetDependencies(StringRef CPU, Triple TT,147StringRef FS,148const M68kTargetMachine &TM);149150const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {151return &TSInfo;152}153154const M68kInstrInfo *getInstrInfo() const override { return &InstrInfo; }155156const M68kFrameLowering *getFrameLowering() const override {157return &FrameLowering;158}159160const M68kRegisterInfo *getRegisterInfo() const override {161return &InstrInfo.getRegisterInfo();162}163164const M68kTargetLowering *getTargetLowering() const override {165return &TLInfo;166}167168const InstrItineraryData *getInstrItineraryData() const override {169return &InstrItins;170}171172protected:173// GlobalISel related APIs.174std::unique_ptr<CallLowering> CallLoweringInfo;175std::unique_ptr<InstructionSelector> InstSelector;176std::unique_ptr<LegalizerInfo> Legalizer;177std::unique_ptr<RegisterBankInfo> RegBankInfo;178179public:180const CallLowering *getCallLowering() const override;181InstructionSelector *getInstructionSelector() const override;182const LegalizerInfo *getLegalizerInfo() const override;183const RegisterBankInfo *getRegBankInfo() const override;184};185} // namespace llvm186187#endif // LLVM_LIB_TARGET_M68K_M68KSUBTARGET_H188189190