LLVM API Documentation

MSP430ISelLowering.h
Go to the documentation of this file.
00001 //===-- MSP430ISelLowering.h - MSP430 DAG Lowering Interface ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the interfaces that MSP430 uses to lower LLVM code into a
00011 // selection DAG.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_LIB_TARGET_MSP430_MSP430ISELLOWERING_H
00016 #define LLVM_LIB_TARGET_MSP430_MSP430ISELLOWERING_H
00017 
00018 #include "MSP430.h"
00019 #include "llvm/CodeGen/SelectionDAG.h"
00020 #include "llvm/Target/TargetLowering.h"
00021 
00022 namespace llvm {
00023   namespace MSP430ISD {
00024     enum {
00025       FIRST_NUMBER = ISD::BUILTIN_OP_END,
00026 
00027       /// Return with a flag operand. Operand 0 is the chain operand.
00028       RET_FLAG,
00029 
00030       /// Same as RET_FLAG, but used for returning from ISRs.
00031       RETI_FLAG,
00032 
00033       /// Y = R{R,L}A X, rotate right (left) arithmetically
00034       RRA, RLA,
00035 
00036       /// Y = RRC X, rotate right via carry
00037       RRC,
00038 
00039       /// CALL - These operations represent an abstract call
00040       /// instruction, which includes a bunch of information.
00041       CALL,
00042 
00043       /// Wrapper - A wrapper node for TargetConstantPool, TargetExternalSymbol,
00044       /// and TargetGlobalAddress.
00045       Wrapper,
00046 
00047       /// CMP - Compare instruction.
00048       CMP,
00049 
00050       /// SetCC - Operand 0 is condition code, and operand 1 is the flag
00051       /// operand produced by a CMP instruction.
00052       SETCC,
00053 
00054       /// MSP430 conditional branches. Operand 0 is the chain operand, operand 1
00055       /// is the block to branch if condition is true, operand 2 is the
00056       /// condition code, and operand 3 is the flag operand produced by a CMP
00057       /// instruction.
00058       BR_CC,
00059 
00060       /// SELECT_CC - Operand 0 and operand 1 are selection variable, operand 3
00061       /// is condition code and operand 4 is flag operand.
00062       SELECT_CC,
00063 
00064       /// SHL, SRA, SRL - Non-constant shifts.
00065       SHL, SRA, SRL
00066     };
00067   }
00068 
00069   class MSP430TargetLowering : public TargetLowering {
00070   public:
00071     explicit MSP430TargetLowering(const TargetMachine &TM);
00072 
00073     MVT getScalarShiftAmountTy(EVT LHSTy) const override { return MVT::i8; }
00074 
00075     /// LowerOperation - Provide custom lowering hooks for some operations.
00076     SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
00077 
00078     /// getTargetNodeName - This method returns the name of a target specific
00079     /// DAG node.
00080     const char *getTargetNodeName(unsigned Opcode) const override;
00081 
00082     SDValue LowerShifts(SDValue Op, SelectionDAG &DAG) const;
00083     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
00084     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
00085     SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
00086     SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
00087     SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
00088     SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
00089     SDValue LowerSIGN_EXTEND(SDValue Op, SelectionDAG &DAG) const;
00090     SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
00091     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
00092     SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
00093     SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
00094     SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const;
00095 
00096     TargetLowering::ConstraintType
00097     getConstraintType(const std::string &Constraint) const override;
00098     std::pair<unsigned, const TargetRegisterClass*>
00099     getRegForInlineAsmConstraint(const std::string &Constraint,
00100                                  MVT VT) const override;
00101 
00102     /// isTruncateFree - Return true if it's free to truncate a value of type
00103     /// Ty1 to type Ty2. e.g. On msp430 it's free to truncate a i16 value in
00104     /// register R15W to i8 by referencing its sub-register R15B.
00105     bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
00106     bool isTruncateFree(EVT VT1, EVT VT2) const override;
00107 
00108     /// isZExtFree - Return true if any actual instruction that defines a value
00109     /// of type Ty1 implicit zero-extends the value to Ty2 in the result
00110     /// register. This does not necessarily include registers defined in unknown
00111     /// ways, such as incoming arguments, or copies from unknown virtual
00112     /// registers. Also, if isTruncateFree(Ty2, Ty1) is true, this does not
00113     /// necessarily apply to truncate instructions. e.g. on msp430, all
00114     /// instructions that define 8-bit values implicit zero-extend the result
00115     /// out to 16 bits.
00116     bool isZExtFree(Type *Ty1, Type *Ty2) const override;
00117     bool isZExtFree(EVT VT1, EVT VT2) const override;
00118     bool isZExtFree(SDValue Val, EVT VT2) const override;
00119 
00120     MachineBasicBlock* EmitInstrWithCustomInserter(MachineInstr *MI,
00121                                                    MachineBasicBlock *BB) const override;
00122     MachineBasicBlock* EmitShiftInstr(MachineInstr *MI,
00123                                       MachineBasicBlock *BB) const;
00124 
00125   private:
00126     SDValue LowerCCCCallTo(SDValue Chain, SDValue Callee,
00127                            CallingConv::ID CallConv, bool isVarArg,
00128                            bool isTailCall,
00129                            const SmallVectorImpl<ISD::OutputArg> &Outs,
00130                            const SmallVectorImpl<SDValue> &OutVals,
00131                            const SmallVectorImpl<ISD::InputArg> &Ins,
00132                            SDLoc dl, SelectionDAG &DAG,
00133                            SmallVectorImpl<SDValue> &InVals) const;
00134 
00135     SDValue LowerCCCArguments(SDValue Chain,
00136                               CallingConv::ID CallConv,
00137                               bool isVarArg,
00138                               const SmallVectorImpl<ISD::InputArg> &Ins,
00139                               SDLoc dl,
00140                               SelectionDAG &DAG,
00141                               SmallVectorImpl<SDValue> &InVals) const;
00142 
00143     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
00144                             CallingConv::ID CallConv, bool isVarArg,
00145                             const SmallVectorImpl<ISD::InputArg> &Ins,
00146                             SDLoc dl, SelectionDAG &DAG,
00147                             SmallVectorImpl<SDValue> &InVals) const;
00148 
00149     SDValue
00150       LowerFormalArguments(SDValue Chain,
00151                            CallingConv::ID CallConv, bool isVarArg,
00152                            const SmallVectorImpl<ISD::InputArg> &Ins,
00153                            SDLoc dl, SelectionDAG &DAG,
00154                            SmallVectorImpl<SDValue> &InVals) const override;
00155     SDValue
00156       LowerCall(TargetLowering::CallLoweringInfo &CLI,
00157                 SmallVectorImpl<SDValue> &InVals) const override;
00158 
00159     SDValue LowerReturn(SDValue Chain,
00160                         CallingConv::ID CallConv, bool isVarArg,
00161                         const SmallVectorImpl<ISD::OutputArg> &Outs,
00162                         const SmallVectorImpl<SDValue> &OutVals,
00163                         SDLoc dl, SelectionDAG &DAG) const override;
00164 
00165     bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
00166                                     SDValue &Base,
00167                                     SDValue &Offset,
00168                                     ISD::MemIndexedMode &AM,
00169                                     SelectionDAG &DAG) const override;
00170   };
00171 } // namespace llvm
00172 
00173 #endif