104eeddc0SDimitry Andric //===-- M68kISelLowering.h - M68k DAG Lowering Interface --------*- C++ -*-===// 2fe6060f1SDimitry Andric // 3fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6fe6060f1SDimitry Andric // 7fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 8fe6060f1SDimitry Andric /// 9fe6060f1SDimitry Andric /// \file 10fe6060f1SDimitry Andric /// This file defines the interfaces that M68k uses to lower LLVM code into a 11fe6060f1SDimitry Andric /// selection DAG. 12fe6060f1SDimitry Andric /// 13fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 14fe6060f1SDimitry Andric 15fe6060f1SDimitry Andric #ifndef LLVM_LIB_TARGET_M68K_M68KISELLOWERING_H 16fe6060f1SDimitry Andric #define LLVM_LIB_TARGET_M68K_M68KISELLOWERING_H 17fe6060f1SDimitry Andric 18fe6060f1SDimitry Andric #include "M68k.h" 19fe6060f1SDimitry Andric 20fe6060f1SDimitry Andric #include "llvm/CodeGen/CallingConvLower.h" 21fe6060f1SDimitry Andric #include "llvm/CodeGen/SelectionDAG.h" 22fe6060f1SDimitry Andric #include "llvm/CodeGen/TargetLowering.h" 23fe6060f1SDimitry Andric #include "llvm/IR/Function.h" 24fe6060f1SDimitry Andric 25fe6060f1SDimitry Andric #include <deque> 26fe6060f1SDimitry Andric 27fe6060f1SDimitry Andric namespace llvm { 28fe6060f1SDimitry Andric namespace M68kISD { 29fe6060f1SDimitry Andric 30fe6060f1SDimitry Andric /// M68k Specific DAG nodes 31fe6060f1SDimitry Andric enum NodeType { 32fe6060f1SDimitry Andric /// Start the numbering from where ISD NodeType finishes. 33fe6060f1SDimitry Andric FIRST_NUMBER = ISD::BUILTIN_OP_END, 34fe6060f1SDimitry Andric 35fe6060f1SDimitry Andric CALL, 36fe6060f1SDimitry Andric RET, 37fe6060f1SDimitry Andric TAIL_CALL, 38fe6060f1SDimitry Andric TC_RETURN, 39fe6060f1SDimitry Andric 40fe6060f1SDimitry Andric /// M68k compare and logical compare instructions. Subtracts the source 41fe6060f1SDimitry Andric /// operand from the destination data register and sets the condition 42fe6060f1SDimitry Andric /// codes according to the result. Immediate always goes first. 43fe6060f1SDimitry Andric CMP, 44fe6060f1SDimitry Andric 45fe6060f1SDimitry Andric /// M68k bit-test instructions. 4604eeddc0SDimitry Andric BTST, 47fe6060f1SDimitry Andric 48fe6060f1SDimitry Andric /// M68k Select 49fe6060f1SDimitry Andric SELECT, 50fe6060f1SDimitry Andric 51fe6060f1SDimitry Andric /// M68k SetCC. Operand 0 is condition code, and operand 1 is the CCR 52fe6060f1SDimitry Andric /// operand, usually produced by a CMP instruction. 53fe6060f1SDimitry Andric SETCC, 54fe6060f1SDimitry Andric 55fe6060f1SDimitry Andric // Same as SETCC except it's materialized with a subx and the value is all 56fe6060f1SDimitry Andric // one's or all zero's. 57fe6060f1SDimitry Andric SETCC_CARRY, // R = carry_bit ? ~0 : 0 58fe6060f1SDimitry Andric 59fe6060f1SDimitry Andric /// M68k conditional moves. Operand 0 and operand 1 are the two values 60fe6060f1SDimitry Andric /// to select from. Operand 2 is the condition code, and operand 3 is the 61fe6060f1SDimitry Andric /// flag operand produced by a CMP or TEST instruction. It also writes a 62fe6060f1SDimitry Andric /// flag result. 63fe6060f1SDimitry Andric CMOV, 64fe6060f1SDimitry Andric 65fe6060f1SDimitry Andric /// M68k conditional branches. Operand 0 is the chain operand, operand 1 66fe6060f1SDimitry Andric /// is the block to branch if condition is true, operand 2 is the 67fe6060f1SDimitry Andric /// condition code, and operand 3 is the flag operand produced by a CMP 68fe6060f1SDimitry Andric /// or TEST instruction. 69fe6060f1SDimitry Andric BRCOND, 70fe6060f1SDimitry Andric 71fe6060f1SDimitry Andric // Arithmetic operations with CCR results. 72fe6060f1SDimitry Andric ADD, 73fe6060f1SDimitry Andric SUB, 74fe6060f1SDimitry Andric ADDX, 75fe6060f1SDimitry Andric SUBX, 76fe6060f1SDimitry Andric SMUL, 77fe6060f1SDimitry Andric UMUL, 78fe6060f1SDimitry Andric OR, 79fe6060f1SDimitry Andric XOR, 80fe6060f1SDimitry Andric AND, 81fe6060f1SDimitry Andric 82fe6060f1SDimitry Andric // GlobalBaseReg, 83fe6060f1SDimitry Andric GLOBAL_BASE_REG, 84fe6060f1SDimitry Andric 85fe6060f1SDimitry Andric /// A wrapper node for TargetConstantPool, 86fe6060f1SDimitry Andric /// TargetExternalSymbol, and TargetGlobalAddress. 87fe6060f1SDimitry Andric Wrapper, 88fe6060f1SDimitry Andric 89fe6060f1SDimitry Andric /// Special wrapper used under M68k PIC mode for PC 90fe6060f1SDimitry Andric /// relative displacements. 91fe6060f1SDimitry Andric WrapperPC, 92fe6060f1SDimitry Andric 93fe6060f1SDimitry Andric // For allocating variable amounts of stack space when using 94fe6060f1SDimitry Andric // segmented stacks. Check if the current stacklet has enough space, and 95fe6060f1SDimitry Andric // falls back to heap allocation if not. 96fe6060f1SDimitry Andric SEG_ALLOCA, 97fe6060f1SDimitry Andric }; 98fe6060f1SDimitry Andric } // namespace M68kISD 99fe6060f1SDimitry Andric 100fe6060f1SDimitry Andric /// Define some predicates that are used for node matching. 101fe6060f1SDimitry Andric namespace M68k { 102fe6060f1SDimitry Andric 103fe6060f1SDimitry Andric /// Determines whether the callee is required to pop its 104fe6060f1SDimitry Andric /// own arguments. Callee pop is necessary to support tail calls. 105fe6060f1SDimitry Andric bool isCalleePop(CallingConv::ID CallingConv, bool IsVarArg, bool GuaranteeTCO); 106fe6060f1SDimitry Andric 107fe6060f1SDimitry Andric } // end namespace M68k 108fe6060f1SDimitry Andric 109fe6060f1SDimitry Andric //===--------------------------------------------------------------------===// 110fe6060f1SDimitry Andric // TargetLowering Implementation 111fe6060f1SDimitry Andric //===--------------------------------------------------------------------===// 112fe6060f1SDimitry Andric 113fe6060f1SDimitry Andric class M68kMachineFunctionInfo; 114fe6060f1SDimitry Andric class M68kSubtarget; 115fe6060f1SDimitry Andric 116fe6060f1SDimitry Andric class M68kTargetLowering : public TargetLowering { 117fe6060f1SDimitry Andric const M68kSubtarget &Subtarget; 118fe6060f1SDimitry Andric const M68kTargetMachine &TM; 119fe6060f1SDimitry Andric 120fe6060f1SDimitry Andric public: 121fe6060f1SDimitry Andric explicit M68kTargetLowering(const M68kTargetMachine &TM, 122fe6060f1SDimitry Andric const M68kSubtarget &STI); 123fe6060f1SDimitry Andric 124fe6060f1SDimitry Andric static const M68kTargetLowering *create(const M68kTargetMachine &TM, 125fe6060f1SDimitry Andric const M68kSubtarget &STI); 126fe6060f1SDimitry Andric 127fe6060f1SDimitry Andric const char *getTargetNodeName(unsigned Opcode) const override; 128fe6060f1SDimitry Andric 129fe6060f1SDimitry Andric /// Return the value type to use for ISD::SETCC. 130fe6060f1SDimitry Andric EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, 131fe6060f1SDimitry Andric EVT VT) const override; 132fe6060f1SDimitry Andric 133fe6060f1SDimitry Andric /// EVT is not used in-tree, but is used by out-of-tree target. 134fe6060f1SDimitry Andric virtual MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override; 135fe6060f1SDimitry Andric 136fe6060f1SDimitry Andric /// Provide custom lowering hooks for some operations. 137fe6060f1SDimitry Andric SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; 138fe6060f1SDimitry Andric 139fe6060f1SDimitry Andric /// Return the entry encoding for a jump table in the current function. 140fe6060f1SDimitry Andric /// The returned value is a member of the MachineJumpTableInfo::JTEntryKind 141fe6060f1SDimitry Andric /// enum. 142fe6060f1SDimitry Andric unsigned getJumpTableEncoding() const override; 143fe6060f1SDimitry Andric 144fe6060f1SDimitry Andric const MCExpr *LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI, 145fe6060f1SDimitry Andric const MachineBasicBlock *MBB, 146fe6060f1SDimitry Andric unsigned uid, 147fe6060f1SDimitry Andric MCContext &Ctx) const override; 148fe6060f1SDimitry Andric 149fe6060f1SDimitry Andric /// Returns relocation base for the given PIC jumptable. 150fe6060f1SDimitry Andric SDValue getPICJumpTableRelocBase(SDValue Table, 151fe6060f1SDimitry Andric SelectionDAG &DAG) const override; 152fe6060f1SDimitry Andric 153fe6060f1SDimitry Andric /// This returns the relocation base for the given PIC jumptable, 154fe6060f1SDimitry Andric /// the same as getPICJumpTableRelocBase, but as an MCExpr. 155fe6060f1SDimitry Andric const MCExpr *getPICJumpTableRelocBaseExpr(const MachineFunction *MF, 156fe6060f1SDimitry Andric unsigned JTI, 157fe6060f1SDimitry Andric MCContext &Ctx) const override; 158fe6060f1SDimitry Andric 159fe6060f1SDimitry Andric ConstraintType getConstraintType(StringRef ConstraintStr) const override; 160fe6060f1SDimitry Andric 161fe6060f1SDimitry Andric std::pair<unsigned, const TargetRegisterClass *> 162fe6060f1SDimitry Andric getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, 163fe6060f1SDimitry Andric StringRef Constraint, MVT VT) const override; 164fe6060f1SDimitry Andric 165fe6060f1SDimitry Andric // Lower operand with C_Immediate and C_Other constraint type 166fe6060f1SDimitry Andric void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint, 167fe6060f1SDimitry Andric std::vector<SDValue> &Ops, 168fe6060f1SDimitry Andric SelectionDAG &DAG) const override; 169fe6060f1SDimitry Andric 170fe6060f1SDimitry Andric MachineBasicBlock * 171fe6060f1SDimitry Andric EmitInstrWithCustomInserter(MachineInstr &MI, 172fe6060f1SDimitry Andric MachineBasicBlock *MBB) const override; 173fe6060f1SDimitry Andric 174fe6060f1SDimitry Andric CCAssignFn *getCCAssignFn(CallingConv::ID CC, bool Return, 175fe6060f1SDimitry Andric bool IsVarArg) const; 176fe6060f1SDimitry Andric 177*bdd1243dSDimitry Andric AtomicExpansionKind 178*bdd1243dSDimitry Andric shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const override; 179*bdd1243dSDimitry Andric 180fe6060f1SDimitry Andric private: 181fe6060f1SDimitry Andric unsigned GetAlignedArgumentStackSize(unsigned StackSize, 182fe6060f1SDimitry Andric SelectionDAG &DAG) const; 183fe6060f1SDimitry Andric 184fe6060f1SDimitry Andric SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const; 185fe6060f1SDimitry Andric 186fe6060f1SDimitry Andric /// Emit a load of return address if tail call 187fe6060f1SDimitry Andric /// optimization is performed and it is required. 188fe6060f1SDimitry Andric SDValue EmitTailCallLoadRetAddr(SelectionDAG &DAG, SDValue &OutRetAddr, 189fe6060f1SDimitry Andric SDValue Chain, bool IsTailCall, int FPDiff, 190fe6060f1SDimitry Andric const SDLoc &DL) const; 191fe6060f1SDimitry Andric 192fe6060f1SDimitry Andric /// Emit a store of the return address if tail call 193fe6060f1SDimitry Andric /// optimization is performed and it is required (FPDiff!=0). 194fe6060f1SDimitry Andric SDValue EmitTailCallStoreRetAddr(SelectionDAG &DAG, MachineFunction &MF, 195fe6060f1SDimitry Andric SDValue Chain, SDValue RetAddrFrIdx, 196fe6060f1SDimitry Andric EVT PtrVT, unsigned SlotSize, int FPDiff, 197fe6060f1SDimitry Andric const SDLoc &DL) const; 198fe6060f1SDimitry Andric 199fe6060f1SDimitry Andric SDValue LowerMemArgument(SDValue Chain, CallingConv::ID CallConv, 200fe6060f1SDimitry Andric const SmallVectorImpl<ISD::InputArg> &ArgInfo, 201fe6060f1SDimitry Andric const SDLoc &DL, SelectionDAG &DAG, 202fe6060f1SDimitry Andric const CCValAssign &VA, MachineFrameInfo &MFI, 203fe6060f1SDimitry Andric unsigned ArgIdx) const; 204fe6060f1SDimitry Andric 205fe6060f1SDimitry Andric SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg, 206fe6060f1SDimitry Andric const SDLoc &DL, SelectionDAG &DAG, 207fe6060f1SDimitry Andric const CCValAssign &VA, ISD::ArgFlagsTy Flags) const; 208fe6060f1SDimitry Andric 209fe6060f1SDimitry Andric SDValue LowerXALUO(SDValue Op, SelectionDAG &DAG) const; 21004eeddc0SDimitry Andric SDValue LowerToBTST(SDValue And, ISD::CondCode CC, const SDLoc &DL, 211fe6060f1SDimitry Andric SelectionDAG &DAG) const; 212fe6060f1SDimitry Andric SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const; 213fe6060f1SDimitry Andric SDValue LowerSETCCCARRY(SDValue Op, SelectionDAG &DAG) const; 214fe6060f1SDimitry Andric SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const; 215fe6060f1SDimitry Andric SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const; 216fe6060f1SDimitry Andric SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) const; 217fe6060f1SDimitry Andric SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const; 218fe6060f1SDimitry Andric SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const; 219fe6060f1SDimitry Andric SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const; 220fe6060f1SDimitry Andric SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const; 221fe6060f1SDimitry Andric SDValue LowerGlobalAddress(const GlobalValue *GV, const SDLoc &DL, 222fe6060f1SDimitry Andric int64_t Offset, SelectionDAG &DAG) const; 223fe6060f1SDimitry Andric SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; 224fe6060f1SDimitry Andric SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const; 225fe6060f1SDimitry Andric SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const; 22681ad6265SDimitry Andric SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const; 22781ad6265SDimitry Andric SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG, bool IsSRA) const; 228fe6060f1SDimitry Andric 229fe6060f1SDimitry Andric SDValue LowerCallResult(SDValue Chain, SDValue InFlag, 230fe6060f1SDimitry Andric CallingConv::ID CallConv, bool IsVarArg, 231fe6060f1SDimitry Andric const SmallVectorImpl<ISD::InputArg> &Ins, 232fe6060f1SDimitry Andric const SDLoc &DL, SelectionDAG &DAG, 233fe6060f1SDimitry Andric SmallVectorImpl<SDValue> &InVals) const; 234fe6060f1SDimitry Andric 235fe6060f1SDimitry Andric /// LowerFormalArguments - transform physical registers into virtual 236fe6060f1SDimitry Andric /// registers and generate load operations for arguments places on the stack. 237fe6060f1SDimitry Andric SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CCID, 238fe6060f1SDimitry Andric bool IsVarArg, 239fe6060f1SDimitry Andric const SmallVectorImpl<ISD::InputArg> &Ins, 240fe6060f1SDimitry Andric const SDLoc &DL, SelectionDAG &DAG, 241fe6060f1SDimitry Andric SmallVectorImpl<SDValue> &InVals) const override; 242fe6060f1SDimitry Andric 243fe6060f1SDimitry Andric SDValue LowerCall(CallLoweringInfo &CLI, 244fe6060f1SDimitry Andric SmallVectorImpl<SDValue> &InVals) const override; 245fe6060f1SDimitry Andric 246fe6060f1SDimitry Andric /// Lower the result values of a call into the 247fe6060f1SDimitry Andric /// appropriate copies out of appropriate physical registers. 248fe6060f1SDimitry Andric SDValue LowerReturn(SDValue Chain, CallingConv::ID CCID, bool IsVarArg, 249fe6060f1SDimitry Andric const SmallVectorImpl<ISD::OutputArg> &Outs, 250fe6060f1SDimitry Andric const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL, 251fe6060f1SDimitry Andric SelectionDAG &DAG) const override; 252fe6060f1SDimitry Andric 253fe6060f1SDimitry Andric bool decomposeMulByConstant(LLVMContext &Context, EVT VT, 254fe6060f1SDimitry Andric SDValue C) const override; 255fe6060f1SDimitry Andric 256fe6060f1SDimitry Andric MachineBasicBlock *EmitLoweredSelect(MachineInstr &I, 257fe6060f1SDimitry Andric MachineBasicBlock *MBB) const; 258fe6060f1SDimitry Andric MachineBasicBlock *EmitLoweredSegAlloca(MachineInstr &MI, 259fe6060f1SDimitry Andric MachineBasicBlock *BB) const; 260fe6060f1SDimitry Andric 261fe6060f1SDimitry Andric /// Emit nodes that will be selected as "test Op0,Op0", or something 262fe6060f1SDimitry Andric /// equivalent, for use with the given M68k condition code. 263fe6060f1SDimitry Andric SDValue EmitTest(SDValue Op0, unsigned M68kCC, const SDLoc &dl, 264fe6060f1SDimitry Andric SelectionDAG &DAG) const; 265fe6060f1SDimitry Andric 266fe6060f1SDimitry Andric /// Emit nodes that will be selected as "cmp Op0,Op1", or something 267fe6060f1SDimitry Andric /// equivalent, for use with the given M68k condition code. 268fe6060f1SDimitry Andric SDValue EmitCmp(SDValue Op0, SDValue Op1, unsigned M68kCC, const SDLoc &dl, 269fe6060f1SDimitry Andric SelectionDAG &DAG) const; 270fe6060f1SDimitry Andric 271fe6060f1SDimitry Andric /// Check whether the call is eligible for tail call optimization. Targets 272fe6060f1SDimitry Andric /// that want to do tail call optimization should implement this function. 273fe6060f1SDimitry Andric bool IsEligibleForTailCallOptimization( 274fe6060f1SDimitry Andric SDValue Callee, CallingConv::ID CalleeCC, bool IsVarArg, 275fe6060f1SDimitry Andric bool IsCalleeStructRet, bool IsCallerStructRet, Type *RetTy, 276fe6060f1SDimitry Andric const SmallVectorImpl<ISD::OutputArg> &Outs, 277fe6060f1SDimitry Andric const SmallVectorImpl<SDValue> &OutVals, 278fe6060f1SDimitry Andric const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const; 279fe6060f1SDimitry Andric 280fe6060f1SDimitry Andric SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override; 281fe6060f1SDimitry Andric }; 282fe6060f1SDimitry Andric } // namespace llvm 283fe6060f1SDimitry Andric 28404eeddc0SDimitry Andric #endif // LLVM_LIB_TARGET_M68K_M68KISELLOWERING_H 285