LLVM API Documentation
00001 //===-- ARMISelLowering.h - ARM 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 ARM uses to lower LLVM code into a 00011 // selection DAG. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef ARMISELLOWERING_H 00016 #define ARMISELLOWERING_H 00017 00018 #include "ARMSubtarget.h" 00019 #include "llvm/Target/TargetLowering.h" 00020 #include "llvm/CodeGen/SelectionDAG.h" 00021 #include "llvm/CodeGen/CallingConvLower.h" 00022 #include <vector> 00023 00024 namespace llvm { 00025 class ARMConstantPoolValue; 00026 00027 namespace ARMISD { 00028 // ARM Specific DAG Nodes 00029 enum NodeType { 00030 // Start the numbering where the builtin ops and target ops leave off. 00031 FIRST_NUMBER = ISD::BUILTIN_OP_END, 00032 00033 Wrapper, // Wrapper - A wrapper node for TargetConstantPool, 00034 // TargetExternalSymbol, and TargetGlobalAddress. 00035 WrapperJT, // WrapperJT - A wrapper node for TargetJumpTable 00036 00037 CALL, // Function call. 00038 CALL_PRED, // Function call that's predicable. 00039 CALL_NOLINK, // Function call with branch not branch-and-link. 00040 tCALL, // Thumb function call. 00041 BRCOND, // Conditional branch. 00042 BR_JT, // Jumptable branch. 00043 BR2_JT, // Jumptable branch (2 level - jumptable entry is a jump). 00044 RET_FLAG, // Return with a flag operand. 00045 00046 PIC_ADD, // Add with a PC operand and a PIC label. 00047 00048 CMP, // ARM compare instructions. 00049 CMPZ, // ARM compare that sets only Z flag. 00050 CMPFP, // ARM VFP compare instruction, sets FPSCR. 00051 CMPFPw0, // ARM VFP compare against zero instruction, sets FPSCR. 00052 FMSTAT, // ARM fmstat instruction. 00053 CMOV, // ARM conditional move instructions. 00054 CNEG, // ARM conditional negate instructions. 00055 00056 FTOSI, // FP to sint within a FP register. 00057 FTOUI, // FP to uint within a FP register. 00058 SITOF, // sint to FP within a FP register. 00059 UITOF, // uint to FP within a FP register. 00060 00061 SRL_FLAG, // V,Flag = srl_flag X -> srl X, 1 + save carry out. 00062 SRA_FLAG, // V,Flag = sra_flag X -> sra X, 1 + save carry out. 00063 RRX, // V = RRX X, Flag -> srl X, 1 + shift in carry flag. 00064 00065 FMRRD, // double to two gprs. 00066 FMDRR, // Two gprs to double. 00067 00068 EH_SJLJ_SETJMP, // SjLj exception handling setjmp. 00069 EH_SJLJ_LONGJMP, // SjLj exception handling longjmp. 00070 00071 THREAD_POINTER, 00072 00073 DYN_ALLOC, // Dynamic allocation on the stack. 00074 00075 VCEQ, // Vector compare equal. 00076 VCGE, // Vector compare greater than or equal. 00077 VCGEU, // Vector compare unsigned greater than or equal. 00078 VCGT, // Vector compare greater than. 00079 VCGTU, // Vector compare unsigned greater than. 00080 VTST, // Vector test bits. 00081 00082 // Vector shift by immediate: 00083 VSHL, // ...left 00084 VSHRs, // ...right (signed) 00085 VSHRu, // ...right (unsigned) 00086 VSHLLs, // ...left long (signed) 00087 VSHLLu, // ...left long (unsigned) 00088 VSHLLi, // ...left long (with maximum shift count) 00089 VSHRN, // ...right narrow 00090 00091 // Vector rounding shift by immediate: 00092 VRSHRs, // ...right (signed) 00093 VRSHRu, // ...right (unsigned) 00094 VRSHRN, // ...right narrow 00095 00096 // Vector saturating shift by immediate: 00097 VQSHLs, // ...left (signed) 00098 VQSHLu, // ...left (unsigned) 00099 VQSHLsu, // ...left (signed to unsigned) 00100 VQSHRNs, // ...right narrow (signed) 00101 VQSHRNu, // ...right narrow (unsigned) 00102 VQSHRNsu, // ...right narrow (signed to unsigned) 00103 00104 // Vector saturating rounding shift by immediate: 00105 VQRSHRNs, // ...right narrow (signed) 00106 VQRSHRNu, // ...right narrow (unsigned) 00107 VQRSHRNsu, // ...right narrow (signed to unsigned) 00108 00109 // Vector shift and insert: 00110 VSLI, // ...left 00111 VSRI, // ...right 00112 00113 // Vector get lane (VMOV scalar to ARM core register) 00114 // (These are used for 8- and 16-bit element types only.) 00115 VGETLANEu, // zero-extend vector extract element 00116 VGETLANEs, // sign-extend vector extract element 00117 00118 // Vector duplicate: 00119 VDUP, 00120 VDUPLANE, 00121 00122 // Vector load/store with (de)interleaving 00123 VLD2D, 00124 VLD3D, 00125 VLD4D, 00126 VST2D, 00127 VST3D, 00128 VST4D, 00129 00130 // Vector shuffles: 00131 VEXT, // extract 00132 VREV64, // reverse elements within 64-bit doublewords 00133 VREV32, // reverse elements within 32-bit words 00134 VREV16, // reverse elements within 16-bit halfwords 00135 VZIP, // zip (interleave) 00136 VUZP, // unzip (deinterleave) 00137 VTRN // transpose 00138 }; 00139 } 00140 00141 /// Define some predicates that are used for node matching. 00142 namespace ARM { 00143 /// getVMOVImm - If this is a build_vector of constants which can be 00144 /// formed by using a VMOV instruction of the specified element size, 00145 /// return the constant being splatted. The ByteSize field indicates the 00146 /// number of bytes of each element [1248]. 00147 SDValue getVMOVImm(SDNode *N, unsigned ByteSize, SelectionDAG &DAG); 00148 } 00149 00150 //===--------------------------------------------------------------------===// 00151 // ARMTargetLowering - ARM Implementation of the TargetLowering interface 00152 00153 class ARMTargetLowering : public TargetLowering { 00154 int VarArgsFrameIndex; // FrameIndex for start of varargs area. 00155 public: 00156 explicit ARMTargetLowering(TargetMachine &TM); 00157 00158 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG); 00159 00160 /// ReplaceNodeResults - Replace the results of node with an illegal result 00161 /// type with new values built out of custom code. 00162 /// 00163 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results, 00164 SelectionDAG &DAG); 00165 00166 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; 00167 00168 virtual const char *getTargetNodeName(unsigned Opcode) const; 00169 00170 virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI, 00171 MachineBasicBlock *MBB) const; 00172 00173 /// allowsUnalignedMemoryAccesses - Returns true if the target allows 00174 /// unaligned memory accesses. of the specified type. 00175 /// FIXME: Add getOptimalMemOpType to implement memcpy with NEON? 00176 virtual bool allowsUnalignedMemoryAccesses(EVT VT) const; 00177 00178 /// isLegalAddressingMode - Return true if the addressing mode represented 00179 /// by AM is legal for this target, for a load/store of the specified type. 00180 virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty)const; 00181 bool isLegalT2ScaledAddressingMode(const AddrMode &AM, EVT VT) const; 00182 00183 /// getPreIndexedAddressParts - returns true by value, base pointer and 00184 /// offset pointer and addressing mode by reference if the node's address 00185 /// can be legally represented as pre-indexed load / store address. 00186 virtual bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, 00187 SDValue &Offset, 00188 ISD::MemIndexedMode &AM, 00189 SelectionDAG &DAG) const; 00190 00191 /// getPostIndexedAddressParts - returns true by value, base pointer and 00192 /// offset pointer and addressing mode by reference if this node can be 00193 /// combined with a load / store to form a post-indexed load / store. 00194 virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, 00195 SDValue &Base, SDValue &Offset, 00196 ISD::MemIndexedMode &AM, 00197 SelectionDAG &DAG) const; 00198 00199 virtual void computeMaskedBitsForTargetNode(const SDValue Op, 00200 const APInt &Mask, 00201 APInt &KnownZero, 00202 APInt &KnownOne, 00203 const SelectionDAG &DAG, 00204 unsigned Depth) const; 00205 00206 00207 ConstraintType getConstraintType(const std::string &Constraint) const; 00208 std::pair<unsigned, const TargetRegisterClass*> 00209 getRegForInlineAsmConstraint(const std::string &Constraint, 00210 EVT VT) const; 00211 std::vector<unsigned> 00212 getRegClassForInlineAsmConstraint(const std::string &Constraint, 00213 EVT VT) const; 00214 00215 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops 00216 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is 00217 /// true it means one of the asm constraint of the inline asm instruction 00218 /// being processed is 'm'. 00219 virtual void LowerAsmOperandForConstraint(SDValue Op, 00220 char ConstraintLetter, 00221 bool hasMemory, 00222 std::vector<SDValue> &Ops, 00223 SelectionDAG &DAG) const; 00224 00225 virtual const ARMSubtarget* getSubtarget() { 00226 return Subtarget; 00227 } 00228 00229 /// getFunctionAlignment - Return the Log2 alignment of this function. 00230 virtual unsigned getFunctionAlignment(const Function *F) const; 00231 00232 bool isShuffleMaskLegal(const SmallVectorImpl<int> &M, EVT VT) const; 00233 private: 00234 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can 00235 /// make the right decision when generating code for different targets. 00236 const ARMSubtarget *Subtarget; 00237 00238 /// ARMPCLabelIndex - Keep track of the number of ARM PC labels created. 00239 /// 00240 unsigned ARMPCLabelIndex; 00241 00242 void addTypeForNEON(EVT VT, EVT PromotedLdStVT, EVT PromotedBitwiseVT); 00243 void addDRTypeForNEON(EVT VT); 00244 void addQRTypeForNEON(EVT VT); 00245 00246 typedef SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPassVector; 00247 void PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, 00248 SDValue Chain, SDValue &Arg, 00249 RegsToPassVector &RegsToPass, 00250 CCValAssign &VA, CCValAssign &NextVA, 00251 SDValue &StackPtr, 00252 SmallVector<SDValue, 8> &MemOpChains, 00253 ISD::ArgFlagsTy Flags); 00254 SDValue GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, 00255 SDValue &Root, SelectionDAG &DAG, DebugLoc dl); 00256 00257 CCAssignFn *CCAssignFnForNode(unsigned CC, bool Return, bool isVarArg) const; 00258 SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg, 00259 DebugLoc dl, SelectionDAG &DAG, 00260 const CCValAssign &VA, 00261 ISD::ArgFlagsTy Flags); 00262 SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG); 00263 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG); 00264 SDValue LowerGlobalAddressDarwin(SDValue Op, SelectionDAG &DAG); 00265 SDValue LowerGlobalAddressELF(SDValue Op, SelectionDAG &DAG); 00266 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG); 00267 SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, 00268 SelectionDAG &DAG); 00269 SDValue LowerToTLSExecModels(GlobalAddressSDNode *GA, 00270 SelectionDAG &DAG); 00271 SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG); 00272 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG); 00273 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG); 00274 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG); 00275 00276 SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl, 00277 SDValue Chain, 00278 SDValue Dst, SDValue Src, 00279 SDValue Size, unsigned Align, 00280 bool AlwaysInline, 00281 const Value *DstSV, uint64_t DstSVOff, 00282 const Value *SrcSV, uint64_t SrcSVOff); 00283 SDValue LowerCallResult(SDValue Chain, SDValue InFlag, 00284 unsigned CallConv, bool isVarArg, 00285 const SmallVectorImpl<ISD::InputArg> &Ins, 00286 DebugLoc dl, SelectionDAG &DAG, 00287 SmallVectorImpl<SDValue> &InVals); 00288 00289 virtual SDValue 00290 LowerFormalArguments(SDValue Chain, 00291 unsigned CallConv, bool isVarArg, 00292 const SmallVectorImpl<ISD::InputArg> &Ins, 00293 DebugLoc dl, SelectionDAG &DAG, 00294 SmallVectorImpl<SDValue> &InVals); 00295 00296 virtual SDValue 00297 LowerCall(SDValue Chain, SDValue Callee, 00298 unsigned CallConv, bool isVarArg, 00299 bool isTailCall, 00300 const SmallVectorImpl<ISD::OutputArg> &Outs, 00301 const SmallVectorImpl<ISD::InputArg> &Ins, 00302 DebugLoc dl, SelectionDAG &DAG, 00303 SmallVectorImpl<SDValue> &InVals); 00304 00305 virtual SDValue 00306 LowerReturn(SDValue Chain, 00307 unsigned CallConv, bool isVarArg, 00308 const SmallVectorImpl<ISD::OutputArg> &Outs, 00309 DebugLoc dl, SelectionDAG &DAG); 00310 }; 00311 } 00312 00313 #endif // ARMISELLOWERING_H