Path: blob/main/contrib/llvm-project/llvm/lib/Target/M68k/M68kISelLowering.h
35269 views
//===-- M68kISelLowering.h - M68k DAG Lowering Interface --------*- 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 defines the interfaces that M68k uses to lower LLVM code into a10/// selection DAG.11///12//===----------------------------------------------------------------------===//1314#ifndef LLVM_LIB_TARGET_M68K_M68KISELLOWERING_H15#define LLVM_LIB_TARGET_M68K_M68KISELLOWERING_H1617#include "M68k.h"1819#include "llvm/CodeGen/CallingConvLower.h"20#include "llvm/CodeGen/SelectionDAG.h"21#include "llvm/CodeGen/TargetLowering.h"22#include "llvm/IR/Function.h"2324#include <deque>2526namespace llvm {27namespace M68kISD {2829/// M68k Specific DAG nodes30enum NodeType {31/// Start the numbering from where ISD NodeType finishes.32FIRST_NUMBER = ISD::BUILTIN_OP_END,3334CALL,35RET,36TAIL_CALL,37TC_RETURN,3839/// M68k compare and logical compare instructions. Subtracts the source40/// operand from the destination data register and sets the condition41/// codes according to the result. Immediate always goes first.42CMP,4344/// M68k bit-test instructions.45BTST,4647/// M68k Select48SELECT,4950/// M68k SetCC. Operand 0 is condition code, and operand 1 is the CCR51/// operand, usually produced by a CMP instruction.52SETCC,5354// Same as SETCC except it's materialized with a subx and the value is all55// one's or all zero's.56SETCC_CARRY, // R = carry_bit ? ~0 : 05758/// M68k conditional moves. Operand 0 and operand 1 are the two values59/// to select from. Operand 2 is the condition code, and operand 3 is the60/// flag operand produced by a CMP or TEST instruction. It also writes a61/// flag result.62CMOV,6364/// M68k conditional branches. Operand 0 is the chain operand, operand 165/// is the block to branch if condition is true, operand 2 is the66/// condition code, and operand 3 is the flag operand produced by a CMP67/// or TEST instruction.68BRCOND,6970// Arithmetic operations with CCR results.71ADD,72SUB,73ADDX,74SUBX,75SMUL,76UMUL,77OR,78XOR,79AND,8081// GlobalBaseReg,82GLOBAL_BASE_REG,8384/// A wrapper node for TargetConstantPool,85/// TargetExternalSymbol, and TargetGlobalAddress.86Wrapper,8788/// Special wrapper used under M68k PIC mode for PC89/// relative displacements.90WrapperPC,9192// For allocating variable amounts of stack space when using93// segmented stacks. Check if the current stacklet has enough space, and94// falls back to heap allocation if not.95SEG_ALLOCA,96};97} // namespace M68kISD9899/// Define some predicates that are used for node matching.100namespace M68k {101102/// Determines whether the callee is required to pop its103/// own arguments. Callee pop is necessary to support tail calls.104bool isCalleePop(CallingConv::ID CallingConv, bool IsVarArg, bool GuaranteeTCO);105106} // end namespace M68k107108//===--------------------------------------------------------------------===//109// TargetLowering Implementation110//===--------------------------------------------------------------------===//111112class M68kMachineFunctionInfo;113class M68kSubtarget;114115class M68kTargetLowering : public TargetLowering {116const M68kSubtarget &Subtarget;117const M68kTargetMachine &TM;118119public:120explicit M68kTargetLowering(const M68kTargetMachine &TM,121const M68kSubtarget &STI);122123static const M68kTargetLowering *create(const M68kTargetMachine &TM,124const M68kSubtarget &STI);125126const char *getTargetNodeName(unsigned Opcode) const override;127128/// Return the value type to use for ISD::SETCC.129EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,130EVT VT) const override;131132/// EVT is not used in-tree, but is used by out-of-tree target.133virtual MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override;134135/// Provide custom lowering hooks for some operations.136SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;137138/// Return the entry encoding for a jump table in the current function.139/// The returned value is a member of the MachineJumpTableInfo::JTEntryKind140/// enum.141unsigned getJumpTableEncoding() const override;142143const MCExpr *LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI,144const MachineBasicBlock *MBB,145unsigned uid,146MCContext &Ctx) const override;147148/// Returns relocation base for the given PIC jumptable.149SDValue getPICJumpTableRelocBase(SDValue Table,150SelectionDAG &DAG) const override;151152/// This returns the relocation base for the given PIC jumptable,153/// the same as getPICJumpTableRelocBase, but as an MCExpr.154const MCExpr *getPICJumpTableRelocBaseExpr(const MachineFunction *MF,155unsigned JTI,156MCContext &Ctx) const override;157158ConstraintType getConstraintType(StringRef ConstraintStr) const override;159160std::pair<unsigned, const TargetRegisterClass *>161getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,162StringRef Constraint, MVT VT) const override;163164// Lower operand with C_Immediate and C_Other constraint type165void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint,166std::vector<SDValue> &Ops,167SelectionDAG &DAG) const override;168169MachineBasicBlock *170EmitInstrWithCustomInserter(MachineInstr &MI,171MachineBasicBlock *MBB) const override;172173CCAssignFn *getCCAssignFn(CallingConv::ID CC, bool Return,174bool IsVarArg) const;175176AtomicExpansionKind177shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const override;178179/// If a physical register, this returns the register that receives the180/// exception address on entry to an EH pad.181Register182getExceptionPointerRegister(const Constant *PersonalityFn) const override;183184/// If a physical register, this returns the register that receives the185/// exception typeid on entry to a landing pad.186Register187getExceptionSelectorRegister(const Constant *PersonalityFn) const override;188189InlineAsm::ConstraintCode190getInlineAsmMemConstraint(StringRef ConstraintCode) const override;191192private:193unsigned GetAlignedArgumentStackSize(unsigned StackSize,194SelectionDAG &DAG) const;195196bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override {197// In many cases, `GA` doesn't give the correct offset to fold. It's198// hard to know if the real offset actually fits into the displacement199// of the perspective addressing mode.200// Thus, we disable offset folding altogether and leave that to ISel201// patterns.202return false;203}204205SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const;206207/// Emit a load of return address if tail call208/// optimization is performed and it is required.209SDValue EmitTailCallLoadRetAddr(SelectionDAG &DAG, SDValue &OutRetAddr,210SDValue Chain, bool IsTailCall, int FPDiff,211const SDLoc &DL) const;212213/// Emit a store of the return address if tail call214/// optimization is performed and it is required (FPDiff!=0).215SDValue EmitTailCallStoreRetAddr(SelectionDAG &DAG, MachineFunction &MF,216SDValue Chain, SDValue RetAddrFrIdx,217EVT PtrVT, unsigned SlotSize, int FPDiff,218const SDLoc &DL) const;219220SDValue LowerMemArgument(SDValue Chain, CallingConv::ID CallConv,221const SmallVectorImpl<ISD::InputArg> &ArgInfo,222const SDLoc &DL, SelectionDAG &DAG,223const CCValAssign &VA, MachineFrameInfo &MFI,224unsigned ArgIdx) const;225226SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg,227const SDLoc &DL, SelectionDAG &DAG,228const CCValAssign &VA, ISD::ArgFlagsTy Flags) const;229230SDValue LowerXALUO(SDValue Op, SelectionDAG &DAG) const;231SDValue LowerToBTST(SDValue And, ISD::CondCode CC, const SDLoc &DL,232SelectionDAG &DAG) const;233SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;234SDValue LowerSETCCCARRY(SDValue Op, SelectionDAG &DAG) const;235SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;236SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;237SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) const;238SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;239SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;240SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;241SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;242SDValue LowerGlobalAddress(const GlobalValue *GV, const SDLoc &DL,243int64_t Offset, SelectionDAG &DAG) const;244SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;245SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;246SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;247SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;248SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG, bool IsSRA) const;249250SDValue LowerATOMICFENCE(SDValue Op, SelectionDAG &DAG) const;251252SDValue LowerCallResult(SDValue Chain, SDValue InGlue,253CallingConv::ID CallConv, bool IsVarArg,254const SmallVectorImpl<ISD::InputArg> &Ins,255const SDLoc &DL, SelectionDAG &DAG,256SmallVectorImpl<SDValue> &InVals) const;257SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;258259/// LowerFormalArguments - transform physical registers into virtual260/// registers and generate load operations for arguments places on the stack.261SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CCID,262bool IsVarArg,263const SmallVectorImpl<ISD::InputArg> &Ins,264const SDLoc &DL, SelectionDAG &DAG,265SmallVectorImpl<SDValue> &InVals) const override;266267SDValue LowerCall(CallLoweringInfo &CLI,268SmallVectorImpl<SDValue> &InVals) const override;269270bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,271bool isVarArg,272const SmallVectorImpl<ISD::OutputArg> &Outs,273LLVMContext &Context) const override;274275/// Lower the result values of a call into the276/// appropriate copies out of appropriate physical registers.277SDValue LowerReturn(SDValue Chain, CallingConv::ID CCID, bool IsVarArg,278const SmallVectorImpl<ISD::OutputArg> &Outs,279const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,280SelectionDAG &DAG) const override;281282SDValue LowerExternalSymbolCall(SelectionDAG &DAG, SDLoc loc,283llvm::StringRef SymbolName,284ArgListTy &&ArgList) const;285SDValue getTLSGetAddr(GlobalAddressSDNode *GA, SelectionDAG &DAG,286unsigned TargetFlags) const;287SDValue getM68kReadTp(SDLoc Loc, SelectionDAG &DAG) const;288289SDValue LowerTLSGeneralDynamic(GlobalAddressSDNode *GA,290SelectionDAG &DAG) const;291SDValue LowerTLSLocalDynamic(GlobalAddressSDNode *GA,292SelectionDAG &DAG) const;293SDValue LowerTLSInitialExec(GlobalAddressSDNode *GA, SelectionDAG &DAG) const;294SDValue LowerTLSLocalExec(GlobalAddressSDNode *GA, SelectionDAG &DAG) const;295296bool decomposeMulByConstant(LLVMContext &Context, EVT VT,297SDValue C) const override;298299MachineBasicBlock *EmitLoweredSelect(MachineInstr &I,300MachineBasicBlock *MBB) const;301MachineBasicBlock *EmitLoweredSegAlloca(MachineInstr &MI,302MachineBasicBlock *BB) const;303304/// Emit nodes that will be selected as "test Op0,Op0", or something305/// equivalent, for use with the given M68k condition code.306SDValue EmitTest(SDValue Op0, unsigned M68kCC, const SDLoc &dl,307SelectionDAG &DAG) const;308309/// Emit nodes that will be selected as "cmp Op0,Op1", or something310/// equivalent, for use with the given M68k condition code.311SDValue EmitCmp(SDValue Op0, SDValue Op1, unsigned M68kCC, const SDLoc &dl,312SelectionDAG &DAG) const;313314/// Check whether the call is eligible for tail call optimization. Targets315/// that want to do tail call optimization should implement this function.316bool IsEligibleForTailCallOptimization(317SDValue Callee, CallingConv::ID CalleeCC, bool IsVarArg,318bool IsCalleeStructRet, bool IsCallerStructRet, Type *RetTy,319const SmallVectorImpl<ISD::OutputArg> &Outs,320const SmallVectorImpl<SDValue> &OutVals,321const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const;322323SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;324};325} // namespace llvm326327#endif // LLVM_LIB_TARGET_M68K_M68KISELLOWERING_H328329330