LLVM API Documentation
00001 //===-- PPCISelLowering.h - PPC32 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 PPC uses to lower LLVM code into a 00011 // selection DAG. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_TARGET_POWERPC_PPC32ISELLOWERING_H 00016 #define LLVM_TARGET_POWERPC_PPC32ISELLOWERING_H 00017 00018 #include "llvm/Target/TargetLowering.h" 00019 #include "llvm/CodeGen/SelectionDAG.h" 00020 #include "PPC.h" 00021 #include "PPCSubtarget.h" 00022 00023 namespace llvm { 00024 namespace PPCISD { 00025 enum NodeType { 00026 // Start the numbering where the builtin ops and target ops leave off. 00027 FIRST_NUMBER = ISD::BUILTIN_OP_END, 00028 00029 /// FSEL - Traditional three-operand fsel node. 00030 /// 00031 FSEL, 00032 00033 /// FCFID - The FCFID instruction, taking an f64 operand and producing 00034 /// and f64 value containing the FP representation of the integer that 00035 /// was temporarily in the f64 operand. 00036 FCFID, 00037 00038 /// FCTI[D,W]Z - The FCTIDZ and FCTIWZ instructions, taking an f32 or f64 00039 /// operand, producing an f64 value containing the integer representation 00040 /// of that FP value. 00041 FCTIDZ, FCTIWZ, 00042 00043 /// STFIWX - The STFIWX instruction. The first operand is an input token 00044 /// chain, then an f64 value to store, then an address to store it to, 00045 /// then a SRCVALUE for the address. 00046 STFIWX, 00047 00048 // VMADDFP, VNMSUBFP - The VMADDFP and VNMSUBFP instructions, taking 00049 // three v4f32 operands and producing a v4f32 result. 00050 VMADDFP, VNMSUBFP, 00051 00052 /// VPERM - The PPC VPERM Instruction. 00053 /// 00054 VPERM, 00055 00056 /// Hi/Lo - These represent the high and low 16-bit parts of a global 00057 /// address respectively. These nodes have two operands, the first of 00058 /// which must be a TargetGlobalAddress, and the second of which must be a 00059 /// Constant. Selected naively, these turn into 'lis G+C' and 'li G+C', 00060 /// though these are usually folded into other nodes. 00061 Hi, Lo, 00062 00063 /// OPRC, CHAIN = DYNALLOC(CHAIN, NEGSIZE, FRAME_INDEX) 00064 /// This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to 00065 /// compute an allocation on the stack. 00066 DYNALLOC, 00067 00068 /// GlobalBaseReg - On Darwin, this node represents the result of the mflr 00069 /// at function entry, used for PIC code. 00070 GlobalBaseReg, 00071 00072 /// These nodes represent the 32-bit PPC shifts that operate on 6-bit 00073 /// shift amounts. These nodes are generated by the multi-precision shift 00074 /// code. 00075 SRL, SRA, SHL, 00076 00077 /// EXTSW_32 - This is the EXTSW instruction for use with "32-bit" 00078 /// registers. 00079 EXTSW_32, 00080 00081 /// STD_32 - This is the STD instruction for use with "32-bit" registers. 00082 STD_32, 00083 00084 /// CALL - A direct function call. 00085 CALL_Macho, CALL_ELF, 00086 00087 /// CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a 00088 /// MTCTR instruction. 00089 MTCTR, 00090 00091 /// CHAIN,FLAG = BCTRL(CHAIN, INFLAG) - Directly corresponds to a 00092 /// BCTRL instruction. 00093 BCTRL_Macho, BCTRL_ELF, 00094 00095 /// Return with a flag operand, matched by 'blr' 00096 RET_FLAG, 00097 00098 /// R32 = MFCR(CRREG, INFLAG) - Represents the MFCR/MFOCRF instructions. 00099 /// This copies the bits corresponding to the specified CRREG into the 00100 /// resultant GPR. Bits corresponding to other CR regs are undefined. 00101 MFCR, 00102 00103 /// RESVEC = VCMP(LHS, RHS, OPC) - Represents one of the altivec VCMP* 00104 /// instructions. For lack of better number, we use the opcode number 00105 /// encoding for the OPC field to identify the compare. For example, 838 00106 /// is VCMPGTSH. 00107 VCMP, 00108 00109 /// RESVEC, OUTFLAG = VCMPo(LHS, RHS, OPC) - Represents one of the 00110 /// altivec VCMP*o instructions. For lack of better number, we use the 00111 /// opcode number encoding for the OPC field to identify the compare. For 00112 /// example, 838 is VCMPGTSH. 00113 VCMPo, 00114 00115 /// CHAIN = COND_BRANCH CHAIN, CRRC, OPC, DESTBB [, INFLAG] - This 00116 /// corresponds to the COND_BRANCH pseudo instruction. CRRC is the 00117 /// condition register to branch on, OPC is the branch opcode to use (e.g. 00118 /// PPC::BLE), DESTBB is the destination block to branch to, and INFLAG is 00119 /// an optional input flag argument. 00120 COND_BRANCH, 00121 00122 /// CHAIN = STBRX CHAIN, GPRC, Ptr, SRCVALUE, Type - This is a 00123 /// byte-swapping store instruction. It byte-swaps the low "Type" bits of 00124 /// the GPRC input, then stores it through Ptr. Type can be either i16 or 00125 /// i32. 00126 STBRX, 00127 00128 /// GPRC, CHAIN = LBRX CHAIN, Ptr, SRCVALUE, Type - This is a 00129 /// byte-swapping load instruction. It loads "Type" bits, byte swaps it, 00130 /// then puts it in the bottom bits of the GPRC. TYPE can be either i16 00131 /// or i32. 00132 LBRX, 00133 00134 // The following 5 instructions are used only as part of the 00135 // long double-to-int conversion sequence. 00136 00137 /// OUTFLAG = MFFS F8RC - This moves the FPSCR (not modelled) into the 00138 /// register. 00139 MFFS, 00140 00141 /// OUTFLAG = MTFSB0 INFLAG - This clears a bit in the FPSCR. 00142 MTFSB0, 00143 00144 /// OUTFLAG = MTFSB1 INFLAG - This sets a bit in the FPSCR. 00145 MTFSB1, 00146 00147 /// F8RC, OUTFLAG = FADDRTZ F8RC, F8RC, INFLAG - This is an FADD done with 00148 /// rounding towards zero. It has flags added so it won't move past the 00149 /// FPSCR-setting instructions. 00150 FADDRTZ, 00151 00152 /// MTFSF = F8RC, INFLAG - This moves the register into the FPSCR. 00153 MTFSF, 00154 00155 /// LARX = This corresponds to PPC l{w|d}arx instrcution: load and 00156 /// reserve indexed. This is used to implement atomic operations. 00157 LARX, 00158 00159 /// STCX = This corresponds to PPC stcx. instrcution: store conditional 00160 /// indexed. This is used to implement atomic operations. 00161 STCX, 00162 00163 /// TAILCALL - Indicates a tail call should be taken. 00164 TAILCALL, 00165 /// TC_RETURN - A tail call return. 00166 /// operand #0 chain 00167 /// operand #1 callee (register or absolute) 00168 /// operand #2 stack adjustment 00169 /// operand #3 optional in flag 00170 TC_RETURN 00171 }; 00172 } 00173 00174 /// Define some predicates that are used for node matching. 00175 namespace PPC { 00176 /// isVPKUHUMShuffleMask - Return true if this is the shuffle mask for a 00177 /// VPKUHUM instruction. 00178 bool isVPKUHUMShuffleMask(SDNode *N, bool isUnary); 00179 00180 /// isVPKUWUMShuffleMask - Return true if this is the shuffle mask for a 00181 /// VPKUWUM instruction. 00182 bool isVPKUWUMShuffleMask(SDNode *N, bool isUnary); 00183 00184 /// isVMRGLShuffleMask - Return true if this is a shuffle mask suitable for 00185 /// a VRGL* instruction with the specified unit size (1,2 or 4 bytes). 00186 bool isVMRGLShuffleMask(SDNode *N, unsigned UnitSize, bool isUnary); 00187 00188 /// isVMRGHShuffleMask - Return true if this is a shuffle mask suitable for 00189 /// a VRGH* instruction with the specified unit size (1,2 or 4 bytes). 00190 bool isVMRGHShuffleMask(SDNode *N, unsigned UnitSize, bool isUnary); 00191 00192 /// isVSLDOIShuffleMask - If this is a vsldoi shuffle mask, return the shift 00193 /// amount, otherwise return -1. 00194 int isVSLDOIShuffleMask(SDNode *N, bool isUnary); 00195 00196 /// isSplatShuffleMask - Return true if the specified VECTOR_SHUFFLE operand 00197 /// specifies a splat of a single element that is suitable for input to 00198 /// VSPLTB/VSPLTH/VSPLTW. 00199 bool isSplatShuffleMask(SDNode *N, unsigned EltSize); 00200 00201 /// isAllNegativeZeroVector - Returns true if all elements of build_vector 00202 /// are -0.0. 00203 bool isAllNegativeZeroVector(SDNode *N); 00204 00205 /// getVSPLTImmediate - Return the appropriate VSPLT* immediate to splat the 00206 /// specified isSplatShuffleMask VECTOR_SHUFFLE mask. 00207 unsigned getVSPLTImmediate(SDNode *N, unsigned EltSize); 00208 00209 /// get_VSPLTI_elt - If this is a build_vector of constants which can be 00210 /// formed by using a vspltis[bhw] instruction of the specified element 00211 /// size, return the constant being splatted. The ByteSize field indicates 00212 /// the number of bytes of each element [124] -> [bhw]. 00213 SDValue get_VSPLTI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG); 00214 } 00215 00216 class PPCTargetLowering : public TargetLowering { 00217 int VarArgsFrameIndex; // FrameIndex for start of varargs area. 00218 int VarArgsStackOffset; // StackOffset for start of stack 00219 // arguments. 00220 unsigned VarArgsNumGPR; // Index of the first unused integer 00221 // register for parameter passing. 00222 unsigned VarArgsNumFPR; // Index of the first unused double 00223 // register for parameter passing. 00224 int ReturnAddrIndex; // FrameIndex for return slot. 00225 const PPCSubtarget &PPCSubTarget; 00226 public: 00227 explicit PPCTargetLowering(PPCTargetMachine &TM); 00228 00229 /// getTargetNodeName() - This method returns the name of a target specific 00230 /// DAG node. 00231 virtual const char *getTargetNodeName(unsigned Opcode) const; 00232 00233 /// getSetCCResultType - Return the ISD::SETCC ValueType 00234 virtual MVT getSetCCResultType(MVT VT) const; 00235 00236 /// getPreIndexedAddressParts - returns true by value, base pointer and 00237 /// offset pointer and addressing mode by reference if the node's address 00238 /// can be legally represented as pre-indexed load / store address. 00239 virtual bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, 00240 SDValue &Offset, 00241 ISD::MemIndexedMode &AM, 00242 SelectionDAG &DAG) const; 00243 00244 /// SelectAddressRegReg - Given the specified addressed, check to see if it 00245 /// can be represented as an indexed [r+r] operation. Returns false if it 00246 /// can be more efficiently represented with [r+imm]. 00247 bool SelectAddressRegReg(SDValue N, SDValue &Base, SDValue &Index, 00248 SelectionDAG &DAG) const; 00249 00250 /// SelectAddressRegImm - Returns true if the address N can be represented 00251 /// by a base register plus a signed 16-bit displacement [r+imm], and if it 00252 /// is not better represented as reg+reg. 00253 bool SelectAddressRegImm(SDValue N, SDValue &Disp, SDValue &Base, 00254 SelectionDAG &DAG) const; 00255 00256 /// SelectAddressRegRegOnly - Given the specified addressed, force it to be 00257 /// represented as an indexed [r+r] operation. 00258 bool SelectAddressRegRegOnly(SDValue N, SDValue &Base, SDValue &Index, 00259 SelectionDAG &DAG) const; 00260 00261 /// SelectAddressRegImmShift - Returns true if the address N can be 00262 /// represented by a base register plus a signed 14-bit displacement 00263 /// [r+imm*4]. Suitable for use by STD and friends. 00264 bool SelectAddressRegImmShift(SDValue N, SDValue &Disp, SDValue &Base, 00265 SelectionDAG &DAG) const; 00266 00267 00268 /// LowerOperation - Provide custom lowering hooks for some operations. 00269 /// 00270 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG); 00271 00272 /// ReplaceNodeResults - Replace the results of node with an illegal result 00273 /// type with new values built out of custom code. 00274 /// 00275 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results, 00276 SelectionDAG &DAG); 00277 00278 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; 00279 00280 virtual void computeMaskedBitsForTargetNode(const SDValue Op, 00281 const APInt &Mask, 00282 APInt &KnownZero, 00283 APInt &KnownOne, 00284 const SelectionDAG &DAG, 00285 unsigned Depth = 0) const; 00286 00287 virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI, 00288 MachineBasicBlock *MBB); 00289 MachineBasicBlock *EmitAtomicBinary(MachineInstr *MI, 00290 MachineBasicBlock *MBB, bool is64Bit, 00291 unsigned BinOpcode); 00292 MachineBasicBlock *EmitPartwordAtomicBinary(MachineInstr *MI, 00293 MachineBasicBlock *MBB, 00294 bool is8bit, unsigned Opcode); 00295 00296 ConstraintType getConstraintType(const std::string &Constraint) const; 00297 std::pair<unsigned, const TargetRegisterClass*> 00298 getRegForInlineAsmConstraint(const std::string &Constraint, 00299 MVT VT) const; 00300 00301 /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate 00302 /// function arguments in the caller parameter area. This is the actual 00303 /// alignment, not its logarithm. 00304 unsigned getByValTypeAlignment(const Type *Ty) const; 00305 00306 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops 00307 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is 00308 /// true it means one of the asm constraint of the inline asm instruction 00309 /// being processed is 'm'. 00310 virtual void LowerAsmOperandForConstraint(SDValue Op, 00311 char ConstraintLetter, 00312 bool hasMemory, 00313 std::vector<SDValue> &Ops, 00314 SelectionDAG &DAG) const; 00315 00316 /// isLegalAddressingMode - Return true if the addressing mode represented 00317 /// by AM is legal for this target, for a load/store of the specified type. 00318 virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty)const; 00319 00320 /// isLegalAddressImmediate - Return true if the integer value can be used 00321 /// as the offset of the target addressing mode for load / store of the 00322 /// given type. 00323 virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const; 00324 00325 /// isLegalAddressImmediate - Return true if the GlobalValue can be used as 00326 /// the offset of the target addressing mode. 00327 virtual bool isLegalAddressImmediate(GlobalValue *GV) const; 00328 00329 /// IsEligibleForTailCallOptimization - Check whether the call is eligible 00330 /// for tail call optimization. Target which want to do tail call 00331 /// optimization should implement this function. 00332 virtual bool IsEligibleForTailCallOptimization(CallSDNode *TheCall, 00333 SDValue Ret, 00334 SelectionDAG &DAG) const; 00335 00336 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const; 00337 00338 private: 00339 SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const; 00340 SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const; 00341 00342 SDValue EmitTailCallLoadFPAndRetAddr(SelectionDAG & DAG, 00343 int SPDiff, 00344 SDValue Chain, 00345 SDValue &LROpOut, 00346 SDValue &FPOpOut); 00347 00348 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG); 00349 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG); 00350 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG); 00351 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG); 00352 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG); 00353 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG); 00354 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG); 00355 SDValue LowerTRAMPOLINE(SDValue Op, SelectionDAG &DAG); 00356 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG, 00357 int VarArgsFrameIndex, int VarArgsStackOffset, 00358 unsigned VarArgsNumGPR, unsigned VarArgsNumFPR, 00359 const PPCSubtarget &Subtarget); 00360 SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG, int VarArgsFrameIndex, 00361 int VarArgsStackOffset, unsigned VarArgsNumGPR, 00362 unsigned VarArgsNumFPR, const PPCSubtarget &Subtarget); 00363 SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG, 00364 int &VarArgsFrameIndex, 00365 int &VarArgsStackOffset, 00366 unsigned &VarArgsNumGPR, 00367 unsigned &VarArgsNumFPR, 00368 const PPCSubtarget &Subtarget); 00369 SDValue LowerCALL(SDValue Op, SelectionDAG &DAG, 00370 const PPCSubtarget &Subtarget, TargetMachine &TM); 00371 SDValue LowerRET(SDValue Op, SelectionDAG &DAG, TargetMachine &TM); 00372 SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG, 00373 const PPCSubtarget &Subtarget); 00374 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG, 00375 const PPCSubtarget &Subtarget); 00376 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG); 00377 SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG); 00378 SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG); 00379 SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG); 00380 SDValue LowerSHL_PARTS(SDValue Op, SelectionDAG &DAG); 00381 SDValue LowerSRL_PARTS(SDValue Op, SelectionDAG &DAG); 00382 SDValue LowerSRA_PARTS(SDValue Op, SelectionDAG &DAG); 00383 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG); 00384 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG); 00385 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG); 00386 SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG); 00387 SDValue LowerMUL(SDValue Op, SelectionDAG &DAG); 00388 }; 00389 } 00390 00391 #endif // LLVM_TARGET_POWERPC_PPC32ISELLOWERING_H