LLVM API Documentation
00001 //===- BlackfinISelLowering.cpp - Blackfin DAG Lowering Implementation ----===// 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 implements the interfaces that Blackfin uses to lower LLVM code 00011 // into a selection DAG. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "BlackfinISelLowering.h" 00016 #include "BlackfinTargetMachine.h" 00017 #include "llvm/Function.h" 00018 #include "llvm/CodeGen/CallingConvLower.h" 00019 #include "llvm/CodeGen/MachineFrameInfo.h" 00020 #include "llvm/CodeGen/MachineFunction.h" 00021 #include "llvm/CodeGen/MachineInstrBuilder.h" 00022 #include "llvm/CodeGen/MachineRegisterInfo.h" 00023 #include "llvm/CodeGen/PseudoSourceValue.h" 00024 #include "llvm/CodeGen/SelectionDAG.h" 00025 #include "llvm/Target/TargetLoweringObjectFile.h" 00026 #include "llvm/ADT/VectorExtras.h" 00027 #include "llvm/Support/Debug.h" 00028 00029 using namespace llvm; 00030 00031 //===----------------------------------------------------------------------===// 00032 // Calling Convention Implementation 00033 //===----------------------------------------------------------------------===// 00034 00035 #include "BlackfinGenCallingConv.inc" 00036 00037 //===----------------------------------------------------------------------===// 00038 // TargetLowering Implementation 00039 //===----------------------------------------------------------------------===// 00040 00041 BlackfinTargetLowering::BlackfinTargetLowering(TargetMachine &TM) 00042 : TargetLowering(TM, new TargetLoweringObjectFileELF()) { 00043 setShiftAmountType(MVT::i16); 00044 setBooleanContents(ZeroOrOneBooleanContent); 00045 setStackPointerRegisterToSaveRestore(BF::SP); 00046 setIntDivIsCheap(false); 00047 00048 // Set up the legal register classes. 00049 addRegisterClass(MVT::i32, BF::DRegisterClass); 00050 addRegisterClass(MVT::i16, BF::D16RegisterClass); 00051 00052 computeRegisterProperties(); 00053 00054 // Blackfin doesn't have i1 loads or stores 00055 setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote); 00056 setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote); 00057 setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); 00058 00059 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); 00060 setOperationAction(ISD::JumpTable, MVT::i32, Custom); 00061 00062 setOperationAction(ISD::SELECT_CC, MVT::Other, Expand); 00063 setOperationAction(ISD::BR_JT, MVT::Other, Expand); 00064 setOperationAction(ISD::BR_CC, MVT::Other, Expand); 00065 00066 // i16 registers don't do much 00067 setOperationAction(ISD::AND, MVT::i16, Promote); 00068 setOperationAction(ISD::OR, MVT::i16, Promote); 00069 setOperationAction(ISD::XOR, MVT::i16, Promote); 00070 setOperationAction(ISD::CTPOP, MVT::i16, Promote); 00071 // The expansion of CTLZ/CTTZ uses AND/OR, so we might as well promote 00072 // immediately. 00073 setOperationAction(ISD::CTLZ, MVT::i16, Promote); 00074 setOperationAction(ISD::CTTZ, MVT::i16, Promote); 00075 setOperationAction(ISD::SETCC, MVT::i16, Promote); 00076 00077 // Blackfin has no division 00078 setOperationAction(ISD::SDIV, MVT::i16, Expand); 00079 setOperationAction(ISD::SDIV, MVT::i32, Expand); 00080 setOperationAction(ISD::SDIVREM, MVT::i16, Expand); 00081 setOperationAction(ISD::SDIVREM, MVT::i32, Expand); 00082 setOperationAction(ISD::SREM, MVT::i16, Expand); 00083 setOperationAction(ISD::SREM, MVT::i32, Expand); 00084 setOperationAction(ISD::UDIV, MVT::i16, Expand); 00085 setOperationAction(ISD::UDIV, MVT::i32, Expand); 00086 setOperationAction(ISD::UDIVREM, MVT::i16, Expand); 00087 setOperationAction(ISD::UDIVREM, MVT::i32, Expand); 00088 setOperationAction(ISD::UREM, MVT::i16, Expand); 00089 setOperationAction(ISD::UREM, MVT::i32, Expand); 00090 00091 setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); 00092 setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); 00093 setOperationAction(ISD::MULHU, MVT::i32, Expand); 00094 setOperationAction(ISD::MULHS, MVT::i32, Expand); 00095 00096 // No carry-in operations. 00097 setOperationAction(ISD::ADDE, MVT::i32, Custom); 00098 setOperationAction(ISD::SUBE, MVT::i32, Custom); 00099 00100 // Blackfin has no intrinsics for these particular operations. 00101 setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); 00102 setOperationAction(ISD::BSWAP, MVT::i32, Expand); 00103 00104 setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand); 00105 setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand); 00106 setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand); 00107 00108 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); 00109 00110 // i32 has native CTPOP, but not CTLZ/CTTZ 00111 setOperationAction(ISD::CTLZ, MVT::i32, Expand); 00112 setOperationAction(ISD::CTTZ, MVT::i32, Expand); 00113 00114 // READCYCLECOUNTER needs special type legalization. 00115 setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Custom); 00116 00117 // We don't have line number support yet. 00118 setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand); 00119 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); 00120 setOperationAction(ISD::DBG_LABEL, MVT::Other, Expand); 00121 setOperationAction(ISD::EH_LABEL, MVT::Other, Expand); 00122 setOperationAction(ISD::DECLARE, MVT::Other, Expand); 00123 00124 // Use the default implementation. 00125 setOperationAction(ISD::VACOPY, MVT::Other, Expand); 00126 setOperationAction(ISD::VAEND, MVT::Other, Expand); 00127 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); 00128 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); 00129 } 00130 00131 const char *BlackfinTargetLowering::getTargetNodeName(unsigned Opcode) const { 00132 switch (Opcode) { 00133 default: return 0; 00134 case BFISD::CALL: return "BFISD::CALL"; 00135 case BFISD::RET_FLAG: return "BFISD::RET_FLAG"; 00136 case BFISD::Wrapper: return "BFISD::Wrapper"; 00137 } 00138 } 00139 00140 MVT::SimpleValueType BlackfinTargetLowering::getSetCCResultType(EVT VT) const { 00141 // SETCC always sets the CC register. Technically that is an i1 register, but 00142 // that type is not legal, so we treat it as an i32 register. 00143 return MVT::i32; 00144 } 00145 00146 SDValue BlackfinTargetLowering::LowerGlobalAddress(SDValue Op, 00147 SelectionDAG &DAG) { 00148 DebugLoc DL = Op.getDebugLoc(); 00149 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); 00150 00151 Op = DAG.getTargetGlobalAddress(GV, MVT::i32); 00152 return DAG.getNode(BFISD::Wrapper, DL, MVT::i32, Op); 00153 } 00154 00155 SDValue BlackfinTargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) { 00156 DebugLoc DL = Op.getDebugLoc(); 00157 int JTI = cast<JumpTableSDNode>(Op)->getIndex(); 00158 00159 Op = DAG.getTargetJumpTable(JTI, MVT::i32); 00160 return DAG.getNode(BFISD::Wrapper, DL, MVT::i32, Op); 00161 } 00162 00163 SDValue 00164 BlackfinTargetLowering::LowerFormalArguments(SDValue Chain, 00165 unsigned CallConv, bool isVarArg, 00166 const SmallVectorImpl<ISD::InputArg> 00167 &Ins, 00168 DebugLoc dl, SelectionDAG &DAG, 00169 SmallVectorImpl<SDValue> &InVals) { 00170 00171 MachineFunction &MF = DAG.getMachineFunction(); 00172 MachineFrameInfo *MFI = MF.getFrameInfo(); 00173 00174 SmallVector<CCValAssign, 16> ArgLocs; 00175 CCState CCInfo(CallConv, isVarArg, getTargetMachine(), 00176 ArgLocs, *DAG.getContext()); 00177 CCInfo.AllocateStack(12, 4); // ABI requires 12 bytes stack space 00178 CCInfo.AnalyzeFormalArguments(Ins, CC_Blackfin); 00179 00180 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { 00181 CCValAssign &VA = ArgLocs[i]; 00182 00183 if (VA.isRegLoc()) { 00184 EVT RegVT = VA.getLocVT(); 00185 TargetRegisterClass *RC = VA.getLocReg() == BF::P0 ? 00186 BF::PRegisterClass : BF::DRegisterClass; 00187 assert(RC->contains(VA.getLocReg()) && "Unexpected regclass in CCState"); 00188 assert(RC->hasType(RegVT) && "Unexpected regclass in CCState"); 00189 00190 unsigned Reg = MF.getRegInfo().createVirtualRegister(RC); 00191 MF.getRegInfo().addLiveIn(VA.getLocReg(), Reg); 00192 SDValue ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); 00193 00194 // If this is an 8 or 16-bit value, it is really passed promoted to 32 00195 // bits. Insert an assert[sz]ext to capture this, then truncate to the 00196 // right size. 00197 if (VA.getLocInfo() == CCValAssign::SExt) 00198 ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, 00199 DAG.getValueType(VA.getValVT())); 00200 else if (VA.getLocInfo() == CCValAssign::ZExt) 00201 ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, 00202 DAG.getValueType(VA.getValVT())); 00203 00204 if (VA.getLocInfo() != CCValAssign::Full) 00205 ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); 00206 00207 InVals.push_back(ArgValue); 00208 } else { 00209 assert(VA.isMemLoc() && "CCValAssign must be RegLoc or MemLoc"); 00210 unsigned ObjSize = VA.getLocVT().getStoreSizeInBits()/8; 00211 int FI = MFI->CreateFixedObject(ObjSize, VA.getLocMemOffset()); 00212 SDValue FIN = DAG.getFrameIndex(FI, MVT::i32); 00213 InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, NULL, 0)); 00214 } 00215 } 00216 00217 return Chain; 00218 } 00219 00220 SDValue 00221 BlackfinTargetLowering::LowerReturn(SDValue Chain, 00222 unsigned CallConv, bool isVarArg, 00223 const SmallVectorImpl<ISD::OutputArg> &Outs, 00224 DebugLoc dl, SelectionDAG &DAG) { 00225 00226 // CCValAssign - represent the assignment of the return value to locations. 00227 SmallVector<CCValAssign, 16> RVLocs; 00228 00229 // CCState - Info about the registers and stack slot. 00230 CCState CCInfo(CallConv, isVarArg, DAG.getTarget(), 00231 RVLocs, *DAG.getContext()); 00232 00233 // Analize return values. 00234 CCInfo.AnalyzeReturn(Outs, RetCC_Blackfin); 00235 00236 // If this is the first return lowered for this function, add the regs to the 00237 // liveout set for the function. 00238 if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { 00239 for (unsigned i = 0; i != RVLocs.size(); ++i) 00240 DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); 00241 } 00242 00243 SDValue Flag; 00244 00245 // Copy the result values into the output registers. 00246 for (unsigned i = 0; i != RVLocs.size(); ++i) { 00247 CCValAssign &VA = RVLocs[i]; 00248 assert(VA.isRegLoc() && "Can only return in registers!"); 00249 SDValue Opi = Outs[i].Val; 00250 00251 // Expand to i32 if necessary 00252 switch (VA.getLocInfo()) { 00253 default: llvm_unreachable("Unknown loc info!"); 00254 case CCValAssign::Full: break; 00255 case CCValAssign::SExt: 00256 Opi = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Opi); 00257 break; 00258 case CCValAssign::ZExt: 00259 Opi = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Opi); 00260 break; 00261 case CCValAssign::AExt: 00262 Opi = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Opi); 00263 break; 00264 } 00265 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Opi, SDValue()); 00266 // Guarantee that all emitted copies are stuck together with flags. 00267 Flag = Chain.getValue(1); 00268 } 00269 00270 if (Flag.getNode()) { 00271 return DAG.getNode(BFISD::RET_FLAG, dl, MVT::Other, Chain, Flag); 00272 } else { 00273 return DAG.getNode(BFISD::RET_FLAG, dl, MVT::Other, Chain); 00274 } 00275 } 00276 00277 SDValue 00278 BlackfinTargetLowering::LowerCall(SDValue Chain, SDValue Callee, 00279 unsigned CallConv, bool isVarArg, 00280 bool isTailCall, 00281 const SmallVectorImpl<ISD::OutputArg> &Outs, 00282 const SmallVectorImpl<ISD::InputArg> &Ins, 00283 DebugLoc dl, SelectionDAG &DAG, 00284 SmallVectorImpl<SDValue> &InVals) { 00285 00286 // Analyze operands of the call, assigning locations to each operand. 00287 SmallVector<CCValAssign, 16> ArgLocs; 00288 CCState CCInfo(CallConv, isVarArg, DAG.getTarget(), ArgLocs, 00289 *DAG.getContext()); 00290 CCInfo.AllocateStack(12, 4); // ABI requires 12 bytes stack space 00291 CCInfo.AnalyzeCallOperands(Outs, CC_Blackfin); 00292 00293 // Get the size of the outgoing arguments stack space requirement. 00294 unsigned ArgsSize = CCInfo.getNextStackOffset(); 00295 00296 Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(ArgsSize, true)); 00297 SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPass; 00298 SmallVector<SDValue, 8> MemOpChains; 00299 00300 // Walk the register/memloc assignments, inserting copies/loads. 00301 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { 00302 CCValAssign &VA = ArgLocs[i]; 00303 SDValue Arg = Outs[i].Val; 00304 00305 // Promote the value if needed. 00306 switch (VA.getLocInfo()) { 00307 default: llvm_unreachable("Unknown loc info!"); 00308 case CCValAssign::Full: break; 00309 case CCValAssign::SExt: 00310 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); 00311 break; 00312 case CCValAssign::ZExt: 00313 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); 00314 break; 00315 case CCValAssign::AExt: 00316 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); 00317 break; 00318 } 00319 00320 // Arguments that can be passed on register must be kept at 00321 // RegsToPass vector 00322 if (VA.isRegLoc()) { 00323 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); 00324 } else { 00325 assert(VA.isMemLoc() && "CCValAssign must be RegLoc or MemLoc"); 00326 int Offset = VA.getLocMemOffset(); 00327 assert(Offset%4 == 0 && "Unaligned LocMemOffset"); 00328 assert(VA.getLocVT()==MVT::i32 && "Illegal CCValAssign type"); 00329 SDValue SPN = DAG.getCopyFromReg(Chain, dl, BF::SP, MVT::i32); 00330 SDValue OffsetN = DAG.getIntPtrConstant(Offset); 00331 OffsetN = DAG.getNode(ISD::ADD, dl, MVT::i32, SPN, OffsetN); 00332 MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, OffsetN, 00333 PseudoSourceValue::getStack(), 00334 Offset)); 00335 } 00336 } 00337 00338 // Transform all store nodes into one single node because 00339 // all store nodes are independent of each other. 00340 if (!MemOpChains.empty()) 00341 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, 00342 &MemOpChains[0], MemOpChains.size()); 00343 00344 // Build a sequence of copy-to-reg nodes chained together with token 00345 // chain and flag operands which copy the outgoing args into registers. 00346 // The InFlag in necessary since all emited instructions must be 00347 // stuck together. 00348 SDValue InFlag; 00349 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { 00350 Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, 00351 RegsToPass[i].second, InFlag); 00352 InFlag = Chain.getValue(1); 00353 } 00354 00355 // If the callee is a GlobalAddress node (quite common, every direct call is) 00356 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. 00357 // Likewise ExternalSymbol -> TargetExternalSymbol. 00358 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) 00359 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), MVT::i32); 00360 else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee)) 00361 Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32); 00362 00363 std::vector<EVT> NodeTys; 00364 NodeTys.push_back(MVT::Other); // Returns a chain 00365 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use. 00366 SDValue Ops[] = { Chain, Callee, InFlag }; 00367 Chain = DAG.getNode(BFISD::CALL, dl, NodeTys, Ops, 00368 InFlag.getNode() ? 3 : 2); 00369 InFlag = Chain.getValue(1); 00370 00371 Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(ArgsSize, true), 00372 DAG.getIntPtrConstant(0, true), InFlag); 00373 InFlag = Chain.getValue(1); 00374 00375 // Assign locations to each value returned by this call. 00376 SmallVector<CCValAssign, 16> RVLocs; 00377 CCState RVInfo(CallConv, isVarArg, DAG.getTarget(), RVLocs, 00378 *DAG.getContext()); 00379 00380 RVInfo.AnalyzeCallResult(Ins, RetCC_Blackfin); 00381 00382 // Copy all of the result registers out of their specified physreg. 00383 for (unsigned i = 0; i != RVLocs.size(); ++i) { 00384 CCValAssign &RV = RVLocs[i]; 00385 unsigned Reg = RV.getLocReg(); 00386 00387 Chain = DAG.getCopyFromReg(Chain, dl, Reg, 00388 RVLocs[i].getLocVT(), InFlag); 00389 SDValue Val = Chain.getValue(0); 00390 InFlag = Chain.getValue(2); 00391 Chain = Chain.getValue(1); 00392 00393 // Callee is responsible for extending any i16 return values. 00394 switch (RV.getLocInfo()) { 00395 case CCValAssign::SExt: 00396 Val = DAG.getNode(ISD::AssertSext, dl, RV.getLocVT(), Val, 00397 DAG.getValueType(RV.getValVT())); 00398 break; 00399 case CCValAssign::ZExt: 00400 Val = DAG.getNode(ISD::AssertZext, dl, RV.getLocVT(), Val, 00401 DAG.getValueType(RV.getValVT())); 00402 break; 00403 default: 00404 break; 00405 } 00406 00407 // Truncate to valtype 00408 if (RV.getLocInfo() != CCValAssign::Full) 00409 Val = DAG.getNode(ISD::TRUNCATE, dl, RV.getValVT(), Val); 00410 InVals.push_back(Val); 00411 } 00412 00413 return Chain; 00414 } 00415 00416 // Expansion of ADDE / SUBE. This is a bit involved since blackfin doesn't have 00417 // add-with-carry instructions. 00418 SDValue BlackfinTargetLowering::LowerADDE(SDValue Op, SelectionDAG &DAG) { 00419 // Operands: lhs, rhs, carry-in (AC0 flag) 00420 // Results: sum, carry-out (AC0 flag) 00421 DebugLoc dl = Op.getDebugLoc(); 00422 00423 unsigned Opcode = Op.getOpcode()==ISD::ADDE ? BF::ADD : BF::SUB; 00424 00425 // zext incoming carry flag in AC0 to 32 bits 00426 SDNode* CarryIn = DAG.getTargetNode(BF::MOVE_cc_ac0, dl, MVT::i32, 00427 /* flag= */ Op.getOperand(2)); 00428 CarryIn = DAG.getTargetNode(BF::MOVECC_zext, dl, MVT::i32, 00429 SDValue(CarryIn, 0)); 00430 00431 // Add operands, produce sum and carry flag 00432 SDNode *Sum = DAG.getTargetNode(Opcode, dl, MVT::i32, MVT::Flag, 00433 Op.getOperand(0), Op.getOperand(1)); 00434 00435 // Store intermediate carry from Sum 00436 SDNode* Carry1 = DAG.getTargetNode(BF::MOVE_cc_ac0, dl, MVT::i32, 00437 /* flag= */ SDValue(Sum, 1)); 00438 00439 // Add incoming carry, again producing an output flag 00440 Sum = DAG.getTargetNode(Opcode, dl, MVT::i32, MVT::Flag, 00441 SDValue(Sum, 0), SDValue(CarryIn, 0)); 00442 00443 // Update AC0 with the intermediate carry, producing a flag. 00444 SDNode *CarryOut = DAG.getTargetNode(BF::OR_ac0_cc, dl, MVT::Flag, 00445 SDValue(Carry1, 0)); 00446 00447 // Compose (i32, flag) pair 00448 SDValue ops[2] = { SDValue(Sum, 0), SDValue(CarryOut, 0) }; 00449 return DAG.getMergeValues(ops, 2, dl); 00450 } 00451 00452 SDValue BlackfinTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) { 00453 switch (Op.getOpcode()) { 00454 default: 00455 Op.getNode()->dump(); 00456 llvm_unreachable("Should not custom lower this!"); 00457 case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG); 00458 case ISD::GlobalTLSAddress: 00459 llvm_unreachable("TLS not implemented for Blackfin."); 00460 case ISD::JumpTable: return LowerJumpTable(Op, DAG); 00461 // Frame & Return address. Currently unimplemented 00462 case ISD::FRAMEADDR: return SDValue(); 00463 case ISD::RETURNADDR: return SDValue(); 00464 case ISD::ADDE: 00465 case ISD::SUBE: return LowerADDE(Op, DAG); 00466 } 00467 } 00468 00469 void 00470 BlackfinTargetLowering::ReplaceNodeResults(SDNode *N, 00471 SmallVectorImpl<SDValue> &Results, 00472 SelectionDAG &DAG) { 00473 DebugLoc dl = N->getDebugLoc(); 00474 switch (N->getOpcode()) { 00475 default: 00476 llvm_unreachable("Do not know how to custom type legalize this operation!"); 00477 return; 00478 case ISD::READCYCLECOUNTER: { 00479 // The low part of the cycle counter is in CYCLES, the high part in 00480 // CYCLES2. Reading CYCLES will latch the value of CYCLES2, so we must read 00481 // CYCLES2 last. 00482 SDValue TheChain = N->getOperand(0); 00483 SDValue lo = DAG.getCopyFromReg(TheChain, dl, BF::CYCLES, MVT::i32); 00484 SDValue hi = DAG.getCopyFromReg(lo.getValue(1), dl, BF::CYCLES2, MVT::i32); 00485 // Use a buildpair to merge the two 32-bit values into a 64-bit one. 00486 Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, lo, hi)); 00487 // Outgoing chain. If we were to use the chain from lo instead, it would be 00488 // possible to entirely eliminate the CYCLES2 read in (i32 (trunc 00489 // readcyclecounter)). Unfortunately this could possibly delay the CYCLES2 00490 // read beyond the next CYCLES read, leading to invalid results. 00491 Results.push_back(hi.getValue(1)); 00492 return; 00493 } 00494 } 00495 } 00496 00497 /// getFunctionAlignment - Return the Log2 alignment of this function. 00498 unsigned BlackfinTargetLowering::getFunctionAlignment(const Function *F) const { 00499 return 2; 00500 } 00501 00502 //===----------------------------------------------------------------------===// 00503 // Blackfin Inline Assembly Support 00504 //===----------------------------------------------------------------------===// 00505 00506 /// getConstraintType - Given a constraint letter, return the type of 00507 /// constraint it is for this target. 00508 BlackfinTargetLowering::ConstraintType 00509 BlackfinTargetLowering::getConstraintType(const std::string &Constraint) const { 00510 if (Constraint.size() != 1) 00511 return TargetLowering::getConstraintType(Constraint); 00512 00513 switch (Constraint[0]) { 00514 // Standard constraints 00515 case 'r': 00516 return C_RegisterClass; 00517 00518 // Blackfin-specific constraints 00519 case 'a': 00520 case 'd': 00521 case 'z': 00522 case 'D': 00523 case 'W': 00524 case 'e': 00525 case 'b': 00526 case 'v': 00527 case 'f': 00528 case 'c': 00529 case 't': 00530 case 'u': 00531 case 'k': 00532 case 'x': 00533 case 'y': 00534 case 'w': 00535 return C_RegisterClass; 00536 case 'A': 00537 case 'B': 00538 case 'C': 00539 case 'Z': 00540 case 'Y': 00541 return C_Register; 00542 } 00543 00544 // Not implemented: q0-q7, qA. Use {R2} etc instead 00545 00546 return TargetLowering::getConstraintType(Constraint); 00547 } 00548 00549 /// getRegForInlineAsmConstraint - Return register no and class for a C_Register 00550 /// constraint. 00551 std::pair<unsigned, const TargetRegisterClass*> BlackfinTargetLowering:: 00552 getRegForInlineAsmConstraint(const std::string &Constraint, EVT VT) const { 00553 typedef std::pair<unsigned, const TargetRegisterClass*> Pair; 00554 using namespace BF; 00555 00556 if (Constraint.size() != 1) 00557 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); 00558 00559 switch (Constraint[0]) { 00560 // Standard constraints 00561 case 'r': 00562 return Pair(0U, VT == MVT::i16 ? D16RegisterClass : DPRegisterClass); 00563 00564 // Blackfin-specific constraints 00565 case 'a': return Pair(0U, PRegisterClass); 00566 case 'd': return Pair(0U, DRegisterClass); 00567 case 'e': return Pair(0U, AccuRegisterClass); 00568 case 'A': return Pair(A0, AccuRegisterClass); 00569 case 'B': return Pair(A1, AccuRegisterClass); 00570 case 'b': return Pair(0U, IRegisterClass); 00571 case 'v': return Pair(0U, BRegisterClass); 00572 case 'f': return Pair(0U, MRegisterClass); 00573 case 'C': return Pair(CC, JustCCRegisterClass); 00574 case 'x': return Pair(0U, GRRegisterClass); 00575 case 'w': return Pair(0U, ALLRegisterClass); 00576 case 'Z': return Pair(P3, PRegisterClass); 00577 case 'Y': return Pair(P1, PRegisterClass); 00578 } 00579 00580 // Not implemented: q0-q7, qA. Use {R2} etc instead. 00581 // Constraints z, D, W, c, t, u, k, and y use non-existing classes, defer to 00582 // getRegClassForInlineAsmConstraint() 00583 00584 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); 00585 } 00586 00587 std::vector<unsigned> BlackfinTargetLowering:: 00588 getRegClassForInlineAsmConstraint(const std::string &Constraint, EVT VT) const { 00589 using namespace BF; 00590 00591 if (Constraint.size() != 1) 00592 return std::vector<unsigned>(); 00593 00594 switch (Constraint[0]) { 00595 case 'z': return make_vector<unsigned>(P0, P1, P2, 0); 00596 case 'D': return make_vector<unsigned>(R0, R2, R4, R6, 0); 00597 case 'W': return make_vector<unsigned>(R1, R3, R5, R7, 0); 00598 case 'c': return make_vector<unsigned>(I0, I1, I2, I3, 00599 B0, B1, B2, B3, 00600 L0, L1, L2, L3, 0); 00601 case 't': return make_vector<unsigned>(LT0, LT1, 0); 00602 case 'u': return make_vector<unsigned>(LB0, LB1, 0); 00603 case 'k': return make_vector<unsigned>(LC0, LC1, 0); 00604 case 'y': return make_vector<unsigned>(RETS, RETN, RETI, RETX, RETE, 00605 ASTAT, SEQSTAT, USP, 0); 00606 } 00607 00608 return std::vector<unsigned>(); 00609 } 00610 00611 bool BlackfinTargetLowering:: 00612 isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { 00613 // The Blackfin target isn't yet aware of offsets. 00614 return false; 00615 }