Path: blob/main/contrib/llvm-project/llvm/lib/Target/AVR/AVRISelLowering.h
35267 views
//===-- AVRISelLowering.h - AVR 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// This file defines the interfaces that AVR uses to lower LLVM code into a9// selection DAG.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_AVR_ISEL_LOWERING_H14#define LLVM_AVR_ISEL_LOWERING_H1516#include "llvm/CodeGen/CallingConvLower.h"17#include "llvm/CodeGen/TargetLowering.h"1819namespace llvm {2021namespace AVRISD {2223/// AVR Specific DAG Nodes24enum NodeType {25/// Start the numbering where the builtin ops leave off.26FIRST_NUMBER = ISD::BUILTIN_OP_END,27/// Return from subroutine.28RET_GLUE,29/// Return from ISR.30RETI_GLUE,31/// Represents an abstract call instruction,32/// which includes a bunch of information.33CALL,34/// A wrapper node for TargetConstantPool,35/// TargetExternalSymbol, and TargetGlobalAddress.36WRAPPER,37LSL, ///< Logical shift left.38LSLBN, ///< Byte logical shift left N bits.39LSLWN, ///< Word logical shift left N bits.40LSLHI, ///< Higher 8-bit of word logical shift left.41LSLW, ///< Wide logical shift left.42LSR, ///< Logical shift right.43LSRBN, ///< Byte logical shift right N bits.44LSRWN, ///< Word logical shift right N bits.45LSRLO, ///< Lower 8-bit of word logical shift right.46LSRW, ///< Wide logical shift right.47ASR, ///< Arithmetic shift right.48ASRBN, ///< Byte arithmetic shift right N bits.49ASRWN, ///< Word arithmetic shift right N bits.50ASRLO, ///< Lower 8-bit of word arithmetic shift right.51ASRW, ///< Wide arithmetic shift right.52ROR, ///< Bit rotate right.53ROL, ///< Bit rotate left.54LSLLOOP, ///< A loop of single logical shift left instructions.55LSRLOOP, ///< A loop of single logical shift right instructions.56ROLLOOP, ///< A loop of single left bit rotate instructions.57RORLOOP, ///< A loop of single right bit rotate instructions.58ASRLOOP, ///< A loop of single arithmetic shift right instructions.59/// AVR conditional branches. Operand 0 is the chain operand, operand 160/// is the block to branch if condition is true, operand 2 is the61/// condition code, and operand 3 is the flag operand produced by a CMP62/// or TEST instruction.63BRCOND,64/// Compare instruction.65CMP,66/// Compare with carry instruction.67CMPC,68/// Test for zero or minus instruction.69TST,70/// Swap Rd[7:4] <-> Rd[3:0].71SWAP,72/// Operand 0 and operand 1 are selection variable, operand 273/// is condition code and operand 3 is flag operand.74SELECT_CC75};7677} // end of namespace AVRISD7879class AVRSubtarget;80class AVRTargetMachine;8182/// Performs target lowering for the AVR.83class AVRTargetLowering : public TargetLowering {84public:85explicit AVRTargetLowering(const AVRTargetMachine &TM,86const AVRSubtarget &STI);8788public:89MVT getScalarShiftAmountTy(const DataLayout &, EVT LHSTy) const override {90return MVT::i8;91}9293MVT::SimpleValueType getCmpLibcallReturnType() const override {94return MVT::i8;95}9697const char *getTargetNodeName(unsigned Opcode) const override;9899SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;100101void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,102SelectionDAG &DAG) const override;103104bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,105unsigned AS,106Instruction *I = nullptr) const override;107108bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, SDValue &Offset,109ISD::MemIndexedMode &AM,110SelectionDAG &DAG) const override;111112bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, SDValue &Base,113SDValue &Offset, ISD::MemIndexedMode &AM,114SelectionDAG &DAG) const override;115116bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;117118EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,119EVT VT) const override;120121MachineBasicBlock *122EmitInstrWithCustomInserter(MachineInstr &MI,123MachineBasicBlock *MBB) const override;124125ConstraintType getConstraintType(StringRef Constraint) const override;126127ConstraintWeight128getSingleConstraintMatchWeight(AsmOperandInfo &info,129const char *constraint) const override;130131std::pair<unsigned, const TargetRegisterClass *>132getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,133StringRef Constraint, MVT VT) const override;134135InlineAsm::ConstraintCode136getInlineAsmMemConstraint(StringRef ConstraintCode) const override;137138void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint,139std::vector<SDValue> &Ops,140SelectionDAG &DAG) const override;141142Register getRegisterByName(const char *RegName, LLT VT,143const MachineFunction &MF) const override;144145bool shouldSplitFunctionArgumentsAsLittleEndian(146const DataLayout &DL) const override {147return false;148}149150ShiftLegalizationStrategy151preferredShiftLegalizationStrategy(SelectionDAG &DAG, SDNode *N,152unsigned ExpansionFactor) const override {153return ShiftLegalizationStrategy::LowerToLibcall;154}155156private:157SDValue getAVRCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, SDValue &AVRcc,158SelectionDAG &DAG, SDLoc dl) const;159SDValue getAVRCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG,160SDLoc dl) const;161SDValue LowerShifts(SDValue Op, SelectionDAG &DAG) const;162SDValue LowerDivRem(SDValue Op, SelectionDAG &DAG) const;163SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;164SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;165SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;166SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;167SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;168SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;169SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;170171bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,172bool isVarArg,173const SmallVectorImpl<ISD::OutputArg> &Outs,174LLVMContext &Context) const override;175176SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,177const SmallVectorImpl<ISD::OutputArg> &Outs,178const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,179SelectionDAG &DAG) const override;180SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,181bool isVarArg,182const SmallVectorImpl<ISD::InputArg> &Ins,183const SDLoc &dl, SelectionDAG &DAG,184SmallVectorImpl<SDValue> &InVals) const override;185SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,186SmallVectorImpl<SDValue> &InVals) const override;187SDValue LowerCallResult(SDValue Chain, SDValue InGlue,188CallingConv::ID CallConv, bool isVarArg,189const SmallVectorImpl<ISD::InputArg> &Ins,190const SDLoc &dl, SelectionDAG &DAG,191SmallVectorImpl<SDValue> &InVals) const;192193protected:194const AVRSubtarget &Subtarget;195196private:197MachineBasicBlock *insertShift(MachineInstr &MI, MachineBasicBlock *BB,198bool Tiny) const;199MachineBasicBlock *insertWideShift(MachineInstr &MI,200MachineBasicBlock *BB) const;201MachineBasicBlock *insertMul(MachineInstr &MI, MachineBasicBlock *BB) const;202MachineBasicBlock *insertCopyZero(MachineInstr &MI,203MachineBasicBlock *BB) const;204MachineBasicBlock *insertAtomicArithmeticOp(MachineInstr &MI,205MachineBasicBlock *BB,206unsigned Opcode, int Width) const;207};208209} // end namespace llvm210211#endif // LLVM_AVR_ISEL_LOWERING_H212213214