llvm.org GIT mirror llvm / 095cc29
Define CallSDNode, an SDNode subclass for use with ISD::CALL. Currently it just holds the calling convention and flags for isVarArgs and isTailCall. And it has several utility methods, which eliminate magic 5+2*i and similar index computations in several places. CallSDNodes are not CSE'd. Teach UpdateNodeOperands to handle nodes that are not CSE'd gracefully. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56183 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
18 changed file(s) with 258 addition(s) and 199 deletion(s). Raw diff Collapse all Expand all
142142
143143 /// AnalyzeCallOperands - Analyze an ISD::CALL node, incorporating info
144144 /// about the passed values into this state.
145 void AnalyzeCallOperands(SDNode *TheCall, CCAssignFn Fn);
145 void AnalyzeCallOperands(CallSDNode *TheCall, CCAssignFn Fn);
146146
147147 /// AnalyzeCallOperands - Same as above except it takes vectors of types
148148 /// and argument flags.
152152
153153 /// AnalyzeCallResult - Analyze the return values of an ISD::CALL node,
154154 /// incorporating info about the passed values into this state.
155 void AnalyzeCallResult(SDNode *TheCall, CCAssignFn Fn);
155 void AnalyzeCallResult(CallSDNode *TheCall, CCAssignFn Fn);
156156
157157 /// AnalyzeCallResult - Same as above except it's specialized for calls which
158158 /// produce a single value.
462462 return getNode(ISD::MERGE_VALUES, VTs, Ops, NumOps);
463463 }
464464
465 /// getCall - Create a CALL node from the given information.
466 ///
467 SDValue getCall(unsigned CallingConv, bool IsVarArgs, bool IsTailCall,
468 SDVTList VTs, const SDValue *Operands, unsigned NumOperands);
469
465470 /// getLoad - Loads are not normal binary operators: their result type is not
466471 /// determined by their operands, and they produce a value AND a token chain.
467472 ///
730735 SDValue getShuffleScalarElt(const SDNode *N, unsigned Idx);
731736
732737 private:
733 void RemoveNodeFromCSEMaps(SDNode *N);
738 bool RemoveNodeFromCSEMaps(SDNode *N);
734739 SDNode *AddNonLeafNodeToCSEMaps(SDNode *N);
735740 SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos);
736741 SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
178178 ///
179179 FORMAL_ARGUMENTS,
180180
181 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
181 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CALLEE,
182182 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
183183 /// This node represents a fully general function call, before the legalizer
184184 /// runs. This has one result value for each argument / flag pair, plus
193193 /// Bit 10-26 - size of byval structures
194194 /// Bits 31:27 - argument ABI alignment in the first argument piece and
195195 /// alignment '1' in other argument pieces.
196 ///
197 /// CALL nodes use the CallSDNode subclass of SDNode, which
198 /// additionally carries information about the calling convention,
199 /// whether the call is varargs, and if it's marked as a tail call.
200 ///
196201 CALL,
197202
198203 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
21802185 }
21812186 };
21822187
2188 /// CallSDNode - Node for calls -- ISD::CALL.
2189 class CallSDNode : public SDNode {
2190 unsigned CallingConv;
2191 bool IsVarArg;
2192 bool IsTailCall;
2193 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2194 protected:
2195 friend class SelectionDAG;
2196 CallSDNode(unsigned cc, bool isvararg, bool istailcall,
2197 SDVTList VTs, const SDValue *Operands, unsigned numOperands)
2198 : SDNode(ISD::CALL, VTs, Operands, numOperands),
2199 CallingConv(cc), IsVarArg(isvararg), IsTailCall(istailcall) {}
2200 public:
2201 unsigned getCallingConv() const { return CallingConv; }
2202 unsigned isVarArg() const { return IsVarArg; }
2203 unsigned isTailCall() const { return IsTailCall; }
2204
2205 /// Set this call to not be marked as a tail call. Normally setter
2206 /// methods in SDNodes are unsafe because it breaks the CSE map,
2207 /// but we don't CSE calls so it's ok in this case.
2208 void setNotTailCall() { IsTailCall = false; }
2209
2210 SDValue getChain() const { return getOperand(0); }
2211 SDValue getCallee() const { return getOperand(1); }
2212
2213 unsigned getNumArgs() const { return (getNumOperands() - 2) / 2; }
2214 SDValue getArg(unsigned i) const { return getOperand(2+2*i); }
2215 SDValue getArgFlagsVal(unsigned i) const {
2216 return getOperand(3+2*i);
2217 }
2218 ISD::ArgFlagsTy getArgFlags(unsigned i) const {
2219 return cast(getArgFlagsVal(i).getNode())->getArgFlags();
2220 }
2221
2222 unsigned getNumRetVals() const { return getNumValues() - 1; }
2223 MVT getRetValType(unsigned i) const { return getValueType(i); }
2224
2225 static bool classof(const CallSDNode *) { return true; }
2226 static bool classof(const SDNode *N) {
2227 return N->getOpcode() == ISD::CALL;
2228 }
2229 };
2230
21832231 /// VTSDNode - This class is used to represent MVT's, which are used
21842232 /// to parameterize some operations.
21852233 class VTSDNode : public SDNode {
10741074 /// IsEligibleForTailCallOptimization - Check whether the call is eligible for
10751075 /// tail call optimization. Targets which want to do tail call optimization
10761076 /// should override this function.
1077 virtual bool IsEligibleForTailCallOptimization(SDValue Call,
1077 virtual bool IsEligibleForTailCallOptimization(CallSDNode *Call,
10781078 SDValue Ret,
10791079 SelectionDAG &DAG) const {
10801080 return false;
10841084 /// preceeds the RET node and whether the return uses the result of the node
10851085 /// or is a void return. This function can be used by the target to determine
10861086 /// eligiblity of tail call optimization.
1087 static bool CheckTailCallReturnConstraints(SDValue Call, SDValue Ret) {
1087 static bool CheckTailCallReturnConstraints(CallSDNode *TheCall, SDValue Ret) {
10881088 unsigned NumOps = Ret.getNumOperands();
10891089 if ((NumOps == 1 &&
1090 (Ret.getOperand(0) == SDValue(Call.getNode(),1) ||
1091 Ret.getOperand(0) == SDValue(Call.getNode(),0))) ||
1090 (Ret.getOperand(0) == SDValue(TheCall,1) ||
1091 Ret.getOperand(0) == SDValue(TheCall,0))) ||
10921092 (NumOps > 1 &&
1093 Ret.getOperand(0) == SDValue(Call.getNode(),
1094 Call.getNode()->getNumValues()-1) &&
1095 Ret.getOperand(1) == SDValue(Call.getNode(),0)))
1093 Ret.getOperand(0) == SDValue(TheCall,
1094 TheCall->getNumValues()-1) &&
1095 Ret.getOperand(1) == SDValue(TheCall,0)))
10961096 return true;
10971097 return false;
10981098 }
9090
9191 /// AnalyzeCallOperands - Analyze an ISD::CALL node, incorporating info
9292 /// about the passed values into this state.
93 void CCState::AnalyzeCallOperands(SDNode *TheCall, CCAssignFn Fn) {
94 unsigned NumOps = (TheCall->getNumOperands() - 5) / 2;
93 void CCState::AnalyzeCallOperands(CallSDNode *TheCall, CCAssignFn Fn) {
94 unsigned NumOps = TheCall->getNumArgs();
9595 for (unsigned i = 0; i != NumOps; ++i) {
96 MVT ArgVT = TheCall->getOperand(5+2*i).getValueType();
97 ISD::ArgFlagsTy ArgFlags =
98 cast(TheCall->getOperand(5+2*i+1))->getArgFlags();
96 MVT ArgVT = TheCall->getArg(i).getValueType();
97 ISD::ArgFlagsTy ArgFlags = TheCall->getArgFlags(i);
9998 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, *this)) {
10099 cerr << "Call operand #" << i << " has unhandled type "
101100 << ArgVT.getMVTString() << "\n";
123122
124123 /// AnalyzeCallResult - Analyze the return values of an ISD::CALL node,
125124 /// incorporating info about the passed values into this state.
126 void CCState::AnalyzeCallResult(SDNode *TheCall, CCAssignFn Fn) {
127 for (unsigned i = 0, e = TheCall->getNumValues() - 1; i != e; ++i) {
128 MVT VT = TheCall->getValueType(i);
125 void CCState::AnalyzeCallResult(CallSDNode *TheCall, CCAssignFn Fn) {
126 for (unsigned i = 0, e = TheCall->getNumRetVals(); i != e; ++i) {
127 MVT VT = TheCall->getRetValType(i);
129128 if (Fn(i, VT, VT, CCValAssign::Full, ISD::ArgFlagsTy(), *this)) {
130129 cerr << "Call result #" << i << " has unhandled type "
131130 << VT.getMVTString() << "\n";
594594 /// correspond to it. This is useful when we're about to delete or repurpose
595595 /// the node. We don't want future request for structurally identical nodes
596596 /// to return N anymore.
597 void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
597 bool SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
598598 bool Erased = false;
599599 switch (N->getOpcode()) {
600600 case ISD::EntryToken:
601601 assert(0 && "EntryToken should not be in CSEMaps!");
602 return;
603 case ISD::HANDLENODE: return; // noop.
602 return false;
603 case ISD::HANDLENODE: return false; // noop.
604604 case ISD::CONDCODE:
605605 assert(CondCodeNodes[cast(N)->get()] &&
606606 "Cond code doesn't exist!");
634634 // flag result (which cannot be CSE'd) or is one of the special cases that are
635635 // not subject to CSE.
636636 if (!Erased && N->getValueType(N->getNumValues()-1) != MVT::Flag &&
637 !N->isTargetOpcode() &&
637 !N->isMachineOpcode() &&
638 N->getOpcode() != ISD::CALL &&
638639 N->getOpcode() != ISD::DBG_LABEL &&
639640 N->getOpcode() != ISD::DBG_STOPPOINT &&
640641 N->getOpcode() != ISD::EH_LABEL &&
644645 assert(0 && "Node is not in map!");
645646 }
646647 #endif
648 return Erased;
647649 }
648650
649651 /// AddNonLeafNodeToCSEMaps - Add the specified node back to the CSE maps. It
659661
660662 switch (N->getOpcode()) {
661663 default: break;
664 case ISD::CALL:
662665 case ISD::HANDLENODE:
663666 case ISD::DBG_LABEL:
664667 case ISD::DBG_STOPPOINT:
33033306 }
33043307
33053308 SDValue
3309 SelectionDAG::getCall(unsigned CallingConv, bool IsVarArgs, bool IsTailCall,
3310 SDVTList VTs,
3311 const SDValue *Operands, unsigned NumOperands) {
3312 // Do not CSE calls. Note that in addition to being a compile-time
3313 // optimization (since attempting CSE of calls is unlikely to be
3314 // meaningful), we actually depend on this behavior. CallSDNode can
3315 // be mutated, which is only safe if calls are not CSE'd.
3316 SDNode *N = NodeAllocator.Allocate();
3317 new (N) CallSDNode(CallingConv, IsVarArgs, IsTailCall,
3318 VTs, Operands, NumOperands);
3319 AllNodes.push_back(N);
3320 return SDValue(N, 0);
3321 }
3322
3323 SDValue
33063324 SelectionDAG::getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
33073325 MVT VT, SDValue Chain,
33083326 SDValue Ptr, SDValue Offset,
37603778
37613779 // Nope it doesn't. Remove the node from its current place in the maps.
37623780 if (InsertPos)
3763 RemoveNodeFromCSEMaps(N);
3781 if (!RemoveNodeFromCSEMaps(N))
3782 InsertPos = 0;
37643783
37653784 // Now we update the operands.
37663785 N->OperandList[0].getVal()->removeUser(0, N);
37893808
37903809 // Nope it doesn't. Remove the node from its current place in the maps.
37913810 if (InsertPos)
3792 RemoveNodeFromCSEMaps(N);
3811 if (!RemoveNodeFromCSEMaps(N))
3812 InsertPos = 0;
37933813
37943814 // Now we update the operands.
37953815 if (N->OperandList[0] != Op1) {
38553875
38563876 // Nope it doesn't. Remove the node from its current place in the maps.
38573877 if (InsertPos)
3858 RemoveNodeFromCSEMaps(N);
3878 if (!RemoveNodeFromCSEMaps(N))
3879 InsertPos = 0;
38593880
38603881 // Now we update the operands.
38613882 for (unsigned i = 0; i != NumOps; ++i) {
40784099 return ON;
40794100 }
40804101
4081 RemoveNodeFromCSEMaps(N);
4102 if (!RemoveNodeFromCSEMaps(N))
4103 IP = 0;
40824104
40834105 // Start the morphing.
40844106 N->NodeType = Opc;
45814603 void LoadSDNode::ANCHOR() {}
45824604 void StoreSDNode::ANCHOR() {}
45834605 void AtomicSDNode::ANCHOR() {}
4606 void CallSDNode::ANCHOR() {}
45844607
45854608 HandleSDNode::~HandleSDNode() {
45864609 DropOperands();
53245324 ArgListTy &Args, SelectionDAG &DAG) {
53255325 SmallVector Ops;
53265326 Ops.push_back(Chain); // Op#0 - Chain
5327 Ops.push_back(DAG.getConstant(CallingConv, getPointerTy())); // Op#1 - CC
5328 Ops.push_back(DAG.getConstant(isVarArg, getPointerTy())); // Op#2 - VarArg
5329 Ops.push_back(DAG.getConstant(isTailCall, getPointerTy())); // Op#3 - Tail
53305327 Ops.push_back(Callee);
53315328
53325329 // Handle all of the outgoing arguments.
54115408 LoweredRetTys.push_back(MVT::Other); // Always has a chain.
54125409
54135410 // Create the CALL node.
5414 SDValue Res = DAG.getNode(ISD::CALL,
5415 DAG.getVTList(&LoweredRetTys[0],
5416 LoweredRetTys.size()),
5417 &Ops[0], Ops.size());
5411 SDValue Res = DAG.getCall(CallingConv, isVarArg, isTailCall,
5412 DAG.getVTList(&LoweredRetTys[0],
5413 LoweredRetTys.size()),
5414 &Ops[0], Ops.size());
54185415 Chain = Res.getValue(LoweredRetTys.size() - 1);
54195416
54205417 // Gather up the call result into a single value.
401401 for (SelectionDAG::allnodes_iterator BE = DAG.allnodes_begin(),
402402 BI = DAG.allnodes_end(); BI != BE; ) {
403403 --BI;
404 if (BI->getOpcode() == ISD::CALL) {
404 if (CallSDNode *TheCall = dyn_cast(BI)) {
405405 SDValue OpRet(Ret, 0);
406406 SDValue OpCall(BI, 0);
407 bool isMarkedTailCall =
408 cast(OpCall.getOperand(3))->getZExtValue() != 0;
407 bool isMarkedTailCall = TheCall->isTailCall();
409408 // If CALL node has tail call attribute set to true and the call is not
410409 // eligible (no RET or the target rejects) the attribute is fixed to
411410 // false. The TargetLowering::IsEligibleForTailCallOptimization function
412411 // must correctly identify tail call optimizable calls.
413412 if (!isMarkedTailCall) continue;
414413 if (Ret==NULL ||
415 !TLI.IsEligibleForTailCallOptimization(OpCall, OpRet, DAG)) {
416 // Not eligible. Mark CALL node as non tail call.
417 SmallVector Ops;
418 unsigned idx=0;
419 for(SDNode::op_iterator I =OpCall.getNode()->op_begin(),
420 E = OpCall.getNode()->op_end(); I != E; I++, idx++) {
421 if (idx!=3)
422 Ops.push_back(*I);
423 else
424 Ops.push_back(DAG.getConstant(false, TLI.getPointerTy()));
425 }
426 DAG.UpdateNodeOperands(OpCall, Ops.begin(), Ops.size());
414 !TLI.IsEligibleForTailCallOptimization(TheCall, OpRet, DAG)) {
415 // Not eligible. Mark CALL node as non tail call. Note that we
416 // can modify the call node in place since calls are not CSE'd.
417 TheCall->setNotTailCall();
427418 } else {
428419 // Look for tail call clobbered arguments. Emit a series of
429420 // copyto/copyfrom virtual register nodes to protect them.
430421 SmallVector Ops;
431 SDValue Chain = OpCall.getOperand(0), InFlag;
432 unsigned idx=0;
433 for(SDNode::op_iterator I = OpCall.getNode()->op_begin(),
434 E = OpCall.getNode()->op_end(); I != E; I++, idx++) {
435 SDValue Arg = *I;
436 if (idx > 4 && (idx % 2)) {
437 bool isByVal = cast(OpCall.getOperand(idx+1))->
438 getArgFlags().isByVal();
439 MachineFunction &MF = DAG.getMachineFunction();
440 MachineFrameInfo *MFI = MF.getFrameInfo();
441 if (!isByVal &&
442 IsPossiblyOverwrittenArgumentOfTailCall(Arg, MFI)) {
443 MVT VT = Arg.getValueType();
444 unsigned VReg = MF.getRegInfo().
445 createVirtualRegister(TLI.getRegClassFor(VT));
446 Chain = DAG.getCopyToReg(Chain, VReg, Arg, InFlag);
447 InFlag = Chain.getValue(1);
448 Arg = DAG.getCopyFromReg(Chain, VReg, VT, InFlag);
449 Chain = Arg.getValue(1);
450 InFlag = Arg.getValue(2);
451 }
422 SDValue Chain = TheCall->getChain(), InFlag;
423 Ops.push_back(Chain);
424 Ops.push_back(TheCall->getCallee());
425 for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; ++i) {
426 SDValue Arg = TheCall->getArg(i);
427 bool isByVal = TheCall->getArgFlags(i).isByVal();
428 MachineFunction &MF = DAG.getMachineFunction();
429 MachineFrameInfo *MFI = MF.getFrameInfo();
430 if (!isByVal &&
431 IsPossiblyOverwrittenArgumentOfTailCall(Arg, MFI)) {
432 MVT VT = Arg.getValueType();
433 unsigned VReg = MF.getRegInfo().
434 createVirtualRegister(TLI.getRegClassFor(VT));
435 Chain = DAG.getCopyToReg(Chain, VReg, Arg, InFlag);
436 InFlag = Chain.getValue(1);
437 Arg = DAG.getCopyFromReg(Chain, VReg, VT, InFlag);
438 Chain = Arg.getValue(1);
439 InFlag = Arg.getValue(2);
452440 }
453441 Ops.push_back(Arg);
442 Ops.push_back(TheCall->getArgFlagsVal(i));
454443 }
455444 // Link in chain of CopyTo/CopyFromReg.
456445 Ops[0] = Chain;
178178 Op += ":" + utostr(D->getColumn());
179179 } else if (const LabelSDNode *L = dyn_cast(Node)) {
180180 Op += ": LabelID=" + utostr(L->getLabelID());
181 } else if (const CallSDNode *C = dyn_cast(Node)) {
182 Op += ": CallingConv=" + utostr(C->getCallingConv());
183 if (C->isVarArg())
184 Op += ", isVarArg";
185 if (C->isTailCall())
186 Op += ", isTailCall";
181187 } else if (const ExternalSymbolSDNode *ES =
182188 dyn_cast(Node)) {
183189 Op += "'" + std::string(ES->getSymbol()) + "'";
409409 /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter
410410 /// nodes.
411411 SDValue ARMTargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) {
412 MVT RetVT= Op.getNode()->getValueType(0);
413 SDValue Chain = Op.getOperand(0);
414 unsigned CallConv = cast(Op.getOperand(1))->getZExtValue();
412 CallSDNode *TheCall = cast(Op.getNode());
413 MVT RetVT = TheCall->getRetValType(0);
414 SDValue Chain = TheCall->getChain();
415 unsigned CallConv = TheCall->getCallingConv();
415416 assert((CallConv == CallingConv::C ||
416417 CallConv == CallingConv::Fast) && "unknown calling convention");
417 SDValue Callee = Op.getOperand(4);
418 unsigned NumOps = (Op.getNumOperands() - 5) / 2;
418 SDValue Callee = TheCall->getCallee();
419 unsigned NumOps = TheCall->getNumArgs();
419420 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
420421 unsigned NumGPRs = 0; // GPRs used for parameter passing.
421422
428429 unsigned ObjGPRs;
429430 unsigned StackPad;
430431 unsigned GPRPad;
431 MVT ObjectVT = Op.getOperand(5+2*i).getValueType();
432 ISD::ArgFlagsTy Flags =
433 cast(Op.getOperand(5+2*i+1))->getArgFlags();
432 MVT ObjectVT = TheCall->getArg(i).getValueType();
433 ISD::ArgFlagsTy Flags = TheCall->getArgFlags(i);
434434 HowToPassArgument(ObjectVT, NumGPRs, NumBytes, ObjGPRs, ObjSize,
435435 GPRPad, StackPad, Flags);
436436 NumBytes += ObjSize + StackPad;
452452 std::vector > RegsToPass;
453453 std::vector MemOpChains;
454454 for (unsigned i = 0; i != NumOps; ++i) {
455 SDValue Arg = Op.getOperand(5+2*i);
456 ISD::ArgFlagsTy Flags =
457 cast(Op.getOperand(5+2*i+1))->getArgFlags();
455 SDValue Arg = TheCall->getArg(i);
456 ISD::ArgFlagsTy Flags = TheCall->getArgFlags(i);
458457 MVT ArgVT = Arg.getValueType();
459458
460459 unsigned ObjSize;
630629 case MVT::i32:
631630 Chain = DAG.getCopyFromReg(Chain, ARM::R0, MVT::i32, InFlag).getValue(1);
632631 ResultVals.push_back(Chain.getValue(0));
633 if (Op.getNode()->getValueType(1) == MVT::i32) {
632 if (TheCall->getNumRetVals() > 1 &&
633 TheCall->getRetValType(1) == MVT::i32) {
634634 // Returns a i64 value.
635635 Chain = DAG.getCopyFromReg(Chain, ARM::R1, MVT::i32,
636636 Chain.getValue(2)).getValue(1);
11001100 static
11011101 SDValue
11021102 LowerCALL(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
1103 SDValue Chain = Op.getOperand(0);
1103 CallSDNode *TheCall = cast(Op.getNode());
1104 SDValue Chain = TheCall->getChain();
11041105 #if 0
1105 bool isVarArg = cast(Op.getOperand(2))->getZExtValue() != 0;
1106 bool isTailCall = cast(Op.getOperand(3))->getZExtValue() != 0;
1106 bool isVarArg = TheCall->isVarArg();
1107 bool isTailCall = TheCall->isTailCall();
11071108 #endif
1108 SDValue Callee = Op.getOperand(4);
1109 unsigned NumOps = (Op.getNumOperands() - 5) / 2;
1109 SDValue Callee = TheCall->getCallee();
1110 unsigned NumOps = TheCall->getNumArgs();
11101111 unsigned StackSlotSize = SPUFrameInfo::stackSlotSize();
11111112 const unsigned *ArgRegs = SPURegisterInfo::getArgRegs();
11121113 const unsigned NumArgRegs = SPURegisterInfo::getNumArgRegs();
11351136 SmallVector MemOpChains;
11361137
11371138 for (unsigned i = 0; i != NumOps; ++i) {
1138 SDValue Arg = Op.getOperand(5+2*i);
1139 SDValue Arg = TheCall->getArg(i);
11391140
11401141 // PtrOff will be used to store the current argument to the stack if a
11411142 // register cannot be found for it.
12551256 DAG.getConstant(NumStackBytes, PtrVT),
12561257 DAG.getConstant(0, PtrVT),
12571258 InFlag);
1258 if (Op.getNode()->getValueType(0) != MVT::Other)
1259 if (TheCall->getValueType(0) != MVT::Other)
12591260 InFlag = Chain.getValue(1);
12601261
12611262 SDValue ResultVals[3];
12621263 unsigned NumResults = 0;
12631264
12641265 // If the call has results, copy the values out of the ret val registers.
1265 switch (Op.getNode()->getValueType(0).getSimpleVT()) {
1266 switch (TheCall->getValueType(0).getSimpleVT()) {
12661267 default: assert(0 && "Unexpected ret value!");
12671268 case MVT::Other: break;
12681269 case MVT::i32:
1269 if (Op.getNode()->getValueType(1) == MVT::i32) {
1270 if (TheCall->getValueType(1) == MVT::i32) {
12701271 Chain = DAG.getCopyFromReg(Chain, SPU::R4, MVT::i32, InFlag).getValue(1);
12711272 ResultVals[0] = Chain.getValue(0);
12721273 Chain = DAG.getCopyFromReg(Chain, SPU::R3, MVT::i32,
12861287 break;
12871288 case MVT::f32:
12881289 case MVT::f64:
1289 Chain = DAG.getCopyFromReg(Chain, SPU::R3, Op.getNode()->getValueType(0),
1290 Chain = DAG.getCopyFromReg(Chain, SPU::R3, TheCall->getValueType(0),
12901291 InFlag).getValue(1);
12911292 ResultVals[0] = Chain.getValue(0);
12921293 NumResults = 1;
12961297 case MVT::v4i32:
12971298 case MVT::v8i16:
12981299 case MVT::v16i8:
1299 Chain = DAG.getCopyFromReg(Chain, SPU::R3, Op.getNode()->getValueType(0),
1300 Chain = DAG.getCopyFromReg(Chain, SPU::R3, TheCall->getValueType(0),
13001301 InFlag).getValue(1);
13011302 ResultVals[0] = Chain.getValue(0);
13021303 NumResults = 1;
584584 {
585585 MachineFunction &MF = DAG.getMachineFunction();
586586
587 SDValue Chain = Op.getOperand(0);
588 SDValue Callee = Op.getOperand(4);
589 bool isVarArg = cast(Op.getOperand(2))->getZExtValue() != 0;
590 unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv();
587 CallSDNode *TheCall = cast(Op.getNode());
588 SDValue Chain = TheCall->getChain();
589 SDValue Callee = TheCall->getCallee();
590 bool isVarArg = TheCall->isVarArg();
591 unsigned CC = TheCall->getCallingConv();
591592
592593 MachineFrameInfo *MFI = MF.getFrameInfo();
593594
602603 MFI->CreateFixedObject(VTsize, (VTsize*3));
603604 }
604605
605 CCInfo.AnalyzeCallOperands(Op.getNode(), CC_Mips);
606 CCInfo.AnalyzeCallOperands(TheCall, CC_Mips);
606607
607608 // Get a count of how many bytes are to be pushed on the stack.
608609 unsigned NumBytes = CCInfo.getNextStackOffset();
623624 CCValAssign &VA = ArgLocs[i];
624625
625626 // Arguments start after the 5 first operands of ISD::CALL
626 SDValue Arg = Op.getOperand(5+2*VA.getValNo());
627 SDValue Arg = TheCall->getArg(i);
627628
628629 // Promote the value if needed.
629630 switch (VA.getLocInfo()) {
750751
751752 // Handle result values, copying them out of physregs into vregs that we
752753 // return.
753 return SDValue(LowerCallResult(Chain, InFlag, Op.getNode(), CC, DAG), Op.getResNo());
754 return SDValue(LowerCallResult(Chain, InFlag, TheCall, CC, DAG), Op.getResNo());
754755 }
755756
756757 /// LowerCallResult - Lower the result values of an ISD::CALL into the
759760 /// being lowered. Returns a SDNode with the same number of values as the
760761 /// ISD::CALL.
761762 SDNode *MipsTargetLowering::
762 LowerCallResult(SDValue Chain, SDValue InFlag, SDNode *TheCall,
763 LowerCallResult(SDValue Chain, SDValue InFlag, CallSDNode *TheCall,
763764 unsigned CallingConv, SelectionDAG &DAG) {
764765
765 bool isVarArg =
766 cast(TheCall->getOperand(2))->getZExtValue() != 0;
766 bool isVarArg = TheCall->isVarArg();
767767
768768 // Assign locations to each value returned by this call.
769769 SmallVector RVLocs;
8585 const MipsSubtarget *Subtarget;
8686
8787 // Lower Operand helpers
88 SDNode *LowerCallResult(SDValue Chain, SDValue InFlag, SDNode*TheCall,
88 SDNode *LowerCallResult(SDValue Chain, SDValue InFlag, CallSDNode *TheCall,
8989 unsigned CallingConv, SelectionDAG &DAG);
9090 bool IsGlobalInSmallSection(GlobalValue *GV);
9191 bool IsInSmallSection(unsigned Size);
13271327
13281328 /// CalculateStackSlotSize - Calculates the size reserved for this argument on
13291329 /// the stack.
1330 static unsigned CalculateStackSlotSize(SDValue Arg, SDValue Flag,
1330 static unsigned CalculateStackSlotSize(SDValue Arg, ISD::ArgFlagsTy Flags,
13311331 bool isVarArg, unsigned PtrByteSize) {
13321332 MVT ArgVT = Arg.getValueType();
1333 ISD::ArgFlagsTy Flags = cast(Flag)->getArgFlags();
13341333 unsigned ArgSize =ArgVT.getSizeInBits()/8;
13351334 if (Flags.isByVal())
13361335 ArgSize = Flags.getByValSize();
14741473 if (isVarArg || isPPC64) {
14751474 MinReservedArea = ((MinReservedArea+15)/16)*16;
14761475 MinReservedArea += CalculateStackSlotSize(Op.getValue(ArgNo),
1477 Op.getOperand(ArgNo+3),
1476 Flags,
14781477 isVarArg,
14791478 PtrByteSize);
14801479 } else nAltivecParamsAtEnd++;
14811480 } else
14821481 // Calculate min reserved area.
14831482 MinReservedArea += CalculateStackSlotSize(Op.getValue(ArgNo),
1484 Op.getOperand(ArgNo+3),
1483 Flags,
14851484 isVarArg,
14861485 PtrByteSize);
14871486
17931792 bool isMachoABI,
17941793 bool isVarArg,
17951794 unsigned CC,
1796 SDValue Call,
1795 CallSDNode *TheCall,
17971796 unsigned &nAltivecParamsAtEnd) {
17981797 // Count how many bytes are to be pushed on the stack, including the linkage
17991798 // area, and parameter passing area. We start with 24/48 bytes, which is
18001799 // prereserved space for [SP][CR][LR][3 x unused].
18011800 unsigned NumBytes = PPCFrameInfo::getLinkageSize(isPPC64, isMachoABI);
1802 unsigned NumOps = (Call.getNumOperands() - 5) / 2;
1801 unsigned NumOps = TheCall->getNumArgs();
18031802 unsigned PtrByteSize = isPPC64 ? 8 : 4;
18041803
18051804 // Add up all the space actually used.
18101809 // 16-byte aligned.
18111810 nAltivecParamsAtEnd = 0;
18121811 for (unsigned i = 0; i != NumOps; ++i) {
1813 SDValue Arg = Call.getOperand(5+2*i);
1814 SDValue Flag = Call.getOperand(5+2*i+1);
1812 SDValue Arg = TheCall->getArg(i);
1813 ISD::ArgFlagsTy Flags = TheCall->getArgFlags(i);
18151814 MVT ArgVT = Arg.getValueType();
18161815 // Varargs Altivec parameters are padded to a 16 byte boundary.
18171816 if (ArgVT==MVT::v4f32 || ArgVT==MVT::v4i32 ||
18251824 // Varargs and 64-bit Altivec parameters are padded to 16 byte boundary.
18261825 NumBytes = ((NumBytes+15)/16)*16;
18271826 }
1828 NumBytes += CalculateStackSlotSize(Arg, Flag, isVarArg, PtrByteSize);
1827 NumBytes += CalculateStackSlotSize(Arg, Flags, isVarArg, PtrByteSize);
18291828 }
18301829
18311830 // Allow for Altivec parameters at the end, if needed.
18751874 /// calling conventions match, currently only fastcc supports tail calls, and
18761875 /// the function CALL is immediatly followed by a RET.
18771876 bool
1878 PPCTargetLowering::IsEligibleForTailCallOptimization(SDValue Call,
1877 PPCTargetLowering::IsEligibleForTailCallOptimization(CallSDNode *TheCall,
18791878 SDValue Ret,
18801879 SelectionDAG& DAG) const {
18811880 // Variable argument functions are not supported.
1882 if (!PerformTailCallOpt ||
1883 cast(Call.getOperand(2))->getZExtValue() != 0)
1881 if (!PerformTailCallOpt || TheCall->isVarArg())
18841882 return false;
18851883
1886 if (CheckTailCallReturnConstraints(Call, Ret)) {
1884 if (CheckTailCallReturnConstraints(TheCall, Ret)) {
18871885 MachineFunction &MF = DAG.getMachineFunction();
18881886 unsigned CallerCC = MF.getFunction()->getCallingConv();
1889 unsigned CalleeCC= cast(Call.getOperand(1))->getZExtValue();
1887 unsigned CalleeCC = TheCall->getCallingConv();
18901888 if (CalleeCC == CallingConv::Fast && CallerCC == CalleeCC) {
18911889 // Functions containing by val parameters are not supported.
1892 for (unsigned i = 0; i != ((Call.getNumOperands()-5)/2); i++) {
1893 ISD::ArgFlagsTy Flags = cast(Call.getOperand(5+2*i+1))
1894 ->getArgFlags();
1890 for (unsigned i = 0; i != TheCall->getNumArgs(); i++) {
1891 ISD::ArgFlagsTy Flags = TheCall->getArgFlags(i);
18951892 if (Flags.isByVal()) return false;
18961893 }
18971894
1898 SDValue Callee = Call.getOperand(4);
1895 SDValue Callee = TheCall->getCallee();
18991896 // Non PIC/GOT tail calls are supported.
19001897 if (getTargetMachine().getRelocationModel() != Reloc::PIC_)
19011898 return true;
20692066 SDValue PPCTargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG,
20702067 const PPCSubtarget &Subtarget,
20712068 TargetMachine &TM) {
2072 SDValue Chain = Op.getOperand(0);
2073 bool isVarArg = cast(Op.getOperand(2))->getZExtValue() != 0;
2074 unsigned CC = cast(Op.getOperand(1))->getZExtValue();
2075 bool isTailCall = cast(Op.getOperand(3))->getZExtValue() != 0
2069 CallSDNode *TheCall = cast(Op.getNode());
2070 SDValue Chain = TheCall->getChain();
2071 bool isVarArg = TheCall->isVarArg();
2072 unsigned CC = TheCall->getCallingConv();
2073 bool isTailCall = TheCall->isTailCall()
20762074 && CC == CallingConv::Fast && PerformTailCallOpt;
2077 SDValue Callee = Op.getOperand(4);
2078 unsigned NumOps = (Op.getNumOperands() - 5) / 2;
2075 SDValue Callee = TheCall->getCallee();
2076 unsigned NumOps = TheCall->getNumArgs();
20792077
20802078 bool isMachoABI = Subtarget.isMachoABI();
20812079 bool isELF32_ABI = Subtarget.isELF32_ABI();
21052103 // prereserved space for [SP][CR][LR][3 x unused].
21062104 unsigned NumBytes =
21072105 CalculateParameterAndLinkageAreaSize(DAG, isPPC64, isMachoABI, isVarArg, CC,
2108 Op, nAltivecParamsAtEnd);
2106 TheCall, nAltivecParamsAtEnd);
21092107
21102108 // Calculate by how many bytes the stack has to be adjusted in case of tail
21112109 // call optimization.
21642162 SmallVector MemOpChains;
21652163 for (unsigned i = 0; i != NumOps; ++i) {
21662164 bool inMem = false;
2167 SDValue Arg = Op.getOperand(5+2*i);
2168 ISD::ArgFlagsTy Flags =
2169 cast(Op.getOperand(5+2*i+1))->getArgFlags();
2165 SDValue Arg = TheCall->getArg(i);
2166 ISD::ArgFlagsTy Flags = TheCall->getArgFlags(i);
21702167 // See if next argument requires stack alignment in ELF
21712168 bool Align = Flags.isSplit();
21722169
23902387 ArgOffset = ((ArgOffset+15)/16)*16;
23912388 ArgOffset += 12*16;
23922389 for (unsigned i = 0; i != NumOps; ++i) {
2393 SDValue Arg = Op.getOperand(5+2*i);
2390 SDValue Arg = TheCall->getArg(i);
23942391 MVT ArgType = Arg.getValueType();
23952392 if (ArgType==MVT::v4f32 || ArgType==MVT::v4i32 ||
23962393 ArgType==MVT::v8i16 || ArgType==MVT::v16i8) {
25292526 assert(InFlag.getNode() &&
25302527 "Flag must be set. Depend on flag being set in LowerRET");
25312528 Chain = DAG.getNode(PPCISD::TAILCALL,
2532 Op.getNode()->getVTList(), &Ops[0], Ops.size());
2529 TheCall->getVTList(), &Ops[0], Ops.size());
25332530 return SDValue(Chain.getNode(), Op.getResNo());
25342531 }
25352532
25402537 DAG.getConstant(NumBytes, PtrVT),
25412538 DAG.getConstant(BytesCalleePops, PtrVT),
25422539 InFlag);
2543 if (Op.getNode()->getValueType(0) != MVT::Other)
2540 if (TheCall->getValueType(0) != MVT::Other)
25442541 InFlag = Chain.getValue(1);
25452542
25462543 SmallVector ResultVals;
25472544 SmallVector RVLocs;
25482545 unsigned CallerCC = DAG.getMachineFunction().getFunction()->getCallingConv();
25492546 CCState CCInfo(CallerCC, isVarArg, TM, RVLocs);
2550 CCInfo.AnalyzeCallResult(Op.getNode(), RetCC_PPC);
2547 CCInfo.AnalyzeCallResult(TheCall, RetCC_PPC);
25512548
25522549 // Copy all of the result registers out of their specified physreg.
25532550 for (unsigned i = 0, e = RVLocs.size(); i != e; ++i) {
25652562
25662563 // Otherwise, merge everything together with a MERGE_VALUES node.
25672564 ResultVals.push_back(Chain);
2568 SDValue Res = DAG.getMergeValues(Op.getNode()->getVTList(), &ResultVals[0],
2565 SDValue Res = DAG.getMergeValues(TheCall->getVTList(), &ResultVals[0],
25692566 ResultVals.size());
25702567 return Res.getValue(Op.getResNo());
25712568 }
321321 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
322322 /// for tail call optimization. Target which want to do tail call
323323 /// optimization should implement this function.
324 virtual bool IsEligibleForTailCallOptimization(SDValue Call,
324 virtual bool IsEligibleForTailCallOptimization(CallSDNode *TheCall,
325325 SDValue Ret,
326326 SelectionDAG &DAG) const;
327327
223223 }
224224
225225 static SDValue LowerCALL(SDValue Op, SelectionDAG &DAG) {
226 unsigned CallingConv = cast(Op.getOperand(1))->getZExtValue();
227 SDValue Chain = Op.getOperand(0);
228 SDValue Callee = Op.getOperand(4);
229 bool isVarArg = cast(Op.getOperand(2))->getZExtValue() != 0;
226 CallSDNode *TheCall = cast(Op.getNode());
227 unsigned CallingConv = TheCall->getCallingConv();
228 SDValue Chain = TheCall->getChain();
229 SDValue Callee = TheCall->getCallee();
230 bool isVarArg = TheCall->isVarArg();
230231
231232 #if 0
232233 // Analyze operands of the call, assigning locations to each operand.
242243
243244 // Count the size of the outgoing arguments.
244245 unsigned ArgsSize = 0;
245 for (unsigned i = 5, e = Op.getNumOperands(); i != e; i += 2) {
246 switch (Op.getOperand(i).getValueType().getSimpleVT()) {
246 for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; ++i) {
247 switch (TheCall->getArg(i).getValueType().getSimpleVT()) {
247248 default: assert(0 && "Unknown value type!");
248249 case MVT::i1:
249250 case MVT::i8:
278279 CCValAssign &VA = ArgLocs[i];
279280
280281 // Arguments start after the 5 first operands of ISD::CALL
281 SDValue Arg = Op.getOperand(5+2*VA.getValNo());
282 SDValue Arg = TheCall->getArg(i);
282283
283284 // Promote the value if needed.
284285 switch (VA.getLocInfo()) {
318319 };
319320 unsigned ArgOffset = 68;
320321
321 for (unsigned i = 5, e = Op.getNumOperands(); i != e; i += 2) {
322 SDValue Val = Op.getOperand(i);
322 for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; ++i) {
323 SDValue Val = TheCall->getArg(i);
323324 MVT ObjectVT = Val.getValueType();
324325 SDValue ValToStore(0, 0);
325326 unsigned ObjSize;
427428 SmallVector RVLocs;
428429 CCState RVInfo(CallingConv, isVarArg, DAG.getTarget(), RVLocs);
429430
430 RVInfo.AnalyzeCallResult(Op.getNode(), RetCC_Sparc32);
431 RVInfo.AnalyzeCallResult(TheCall, RetCC_Sparc32);
431432 SmallVector ResultVals;
432433
433434 // Copy all of the result registers out of their specified physreg.
447448 ResultVals.push_back(Chain);
448449
449450 // Merge everything together with a MERGE_VALUES node.
450 return DAG.getMergeValues(Op.getNode()->getVTList(), &ResultVals[0],
451 return DAG.getMergeValues(TheCall->getVTList(), &ResultVals[0],
451452 ResultVals.size());
452453 }
453454
976976 /// being lowered. The returns a SDNode with the same number of values as the
977977 /// ISD::CALL.
978978 SDNode *X86TargetLowering::
979 LowerCallResult(SDValue Chain, SDValue InFlag, SDNode *TheCall,
979 LowerCallResult(SDValue Chain, SDValue InFlag, CallSDNode *TheCall,
980980 unsigned CallingConv, SelectionDAG &DAG) {
981981
982982 // Assign locations to each value returned by this call.
983983 SmallVector RVLocs;
984 bool isVarArg =
985 cast(TheCall->getOperand(2))->getZExtValue() != 0;
984 bool isVarArg = TheCall->isVarArg();
986985 CCState CCInfo(CallingConv, isVarArg, getTargetMachine(), RVLocs);
987986 CCInfo.AnalyzeCallResult(TheCall, RetCC_X86);
988987
10471046
10481047 /// CallIsStructReturn - Determines whether a CALL node uses struct return
10491048 /// semantics.
1050 static bool CallIsStructReturn(SDValue Op) {
1051 unsigned NumOps = (Op.getNumOperands() - 5) / 2;
1049 static bool CallIsStructReturn(CallSDNode *TheCall) {
1050 unsigned NumOps = TheCall->getNumArgs();
10521051 if (!NumOps)
10531052 return false;
10541053
1055 return cast(Op.getOperand(6))->getArgFlags().isSRet();
1054 return TheCall->getArgFlags(0).isSRet();
10561055 }
10571056
10581057 /// ArgsAreStructReturn - Determines whether a FORMAL_ARGUMENTS node uses struct
10681067 /// IsCalleePop - Determines whether a CALL or FORMAL_ARGUMENTS node requires
10691068 /// the callee to pop its own arguments. Callee pop is necessary to support tail
10701069 /// calls.
1071 bool X86TargetLowering::IsCalleePop(SDValue Op) {
1072 bool IsVarArg = cast(Op.getOperand(2))->getZExtValue() != 0;
1070 bool X86TargetLowering::IsCalleePop(bool IsVarArg, unsigned CallingConv) {
10731071 if (IsVarArg)
10741072 return false;
10751073
1076 switch (cast(Op.getOperand(1))->getZExtValue()) {
1074 switch (CallingConv) {
10771075 default:
10781076 return false;
10791077 case CallingConv::X86_StdCall:
10851083 }
10861084 }
10871085
1088 /// CCAssignFnForNode - Selects the correct CCAssignFn for a CALL or
1089 /// FORMAL_ARGUMENTS node.
1090 CCAssignFn *X86TargetLowering::CCAssignFnForNode(SDValue Op) const {
1091 unsigned CC = cast(Op.getOperand(1))->getZExtValue();
1092
1086 /// CCAssignFnForNode - Selects the correct CCAssignFn for a the
1087 /// given CallingConvention value.
1088 CCAssignFn *X86TargetLowering::CCAssignFnForNode(unsigned CC) const {
10931089 if (Subtarget->is64Bit()) {
10941090 if (Subtarget->isTargetWin64())
10951091 return CC_X86_Win64_C;
12021198 // Assign locations to all of the incoming arguments.
12031199 SmallVector ArgLocs;
12041200 CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs);
1205 CCInfo.AnalyzeFormalArguments(Op.getNode(), CCAssignFnForNode(Op));
1201 CCInfo.AnalyzeFormalArguments(Op.getNode(), CCAssignFnForNode(CC));
12061202
12071203 SmallVector ArgValues;
12081204 unsigned LastVal = ~0U;
13871383 ArgValues.push_back(Root);
13881384
13891385 // Some CCs need callee pop.
1390 if (IsCalleePop(Op)) {
1386 if (IsCalleePop(isVarArg, CC)) {
13911387 BytesToPopOnReturn = StackSize; // Callee pops everything.
13921388 BytesCallerReserves = 0;
13931389 } else {
14121408 }
14131409
14141410 SDValue
1415 X86TargetLowering::LowerMemOpCallTo(SDValue Op, SelectionDAG &DAG,
1411 X86TargetLowering::LowerMemOpCallTo(CallSDNode *TheCall, SelectionDAG &DAG,
14161412 const SDValue &StackPtr,
14171413 const CCValAssign &VA,
14181414 SDValue Chain,
1419 SDValue Arg) {
1415 SDValue Arg, ISD::ArgFlagsTy Flags) {
14201416 unsigned LocMemOffset = VA.getLocMemOffset();
14211417 SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset);
14221418 PtrOff = DAG.getNode(ISD::ADD, getPointerTy(), StackPtr, PtrOff);
1423 ISD::ArgFlagsTy Flags =
1424 cast(Op.getOperand(6+2*VA.getValNo()))->getArgFlags();
14251419 if (Flags.isByVal()) {
14261420 return CreateCopyOfByValArgument(Arg, PtrOff, Chain, Flags, DAG);
14271421 }
14691463
14701464 SDValue X86TargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) {
14711465 MachineFunction &MF = DAG.getMachineFunction();
1472 SDValue Chain = Op.getOperand(0);
1473 unsigned CC = cast(Op.getOperand(1))->getZExtValue();
1474 bool isVarArg = cast(Op.getOperand(2))->getZExtValue() != 0;
1475 bool IsTailCall = cast(Op.getOperand(3))->getZExtValue() != 0
1476 && CC == CallingConv::Fast && PerformTailCallOpt;
1477 SDValue Callee = Op.getOperand(4);
1466 CallSDNode *TheCall = cast(Op.getNode());
1467 SDValue Chain = TheCall->getChain();
1468 unsigned CC = TheCall->getCallingConv();
1469 bool isVarArg = TheCall->isVarArg();
1470 bool IsTailCall = TheCall->isTailCall() &&
1471 CC == CallingConv::Fast && PerformTailCallOpt;
1472 SDValue Callee = TheCall->getCallee();
14781473 bool Is64Bit = Subtarget->is64Bit();
1479 bool IsStructRet = CallIsStructReturn(Op);
1474 bool IsStructRet = CallIsStructReturn(TheCall);
14801475
14811476 assert(!(isVarArg && CC == CallingConv::Fast) &&
14821477 "Var args not supported with calling convention fastcc");
14841479 // Analyze operands of the call, assigning locations to each operand.
14851480 SmallVector ArgLocs;
14861481 CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs);
1487 CCInfo.AnalyzeCallOperands(Op.getNode(), CCAssignFnForNode(Op));
1482 CCInfo.AnalyzeCallOperands(TheCall, CCAssignFnForNode(CC));
14881483
14891484 // Get a count of how many bytes are to be pushed on the stack.
14901485 unsigned NumBytes = CCInfo.getNextStackOffset();
15191514 // of tail call optimization arguments are handle later.
15201515 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
15211516 CCValAssign &VA = ArgLocs[i];
1522 SDValue Arg = Op.getOperand(5+2*VA.getValNo());
1523 bool isByVal = cast(Op.getOperand(6+2*VA.getValNo()))->
1524 getArgFlags().isByVal();
1517 SDValue Arg = TheCall->getArg(i);
1518 ISD::ArgFlagsTy Flags = TheCall->getArgFlags(i);
1519 bool isByVal = Flags.isByVal();
15251520
15261521 // Promote the value if needed.
15271522 switch (VA.getLocInfo()) {
15701565 if (StackPtr.getNode() == 0)
15711566 StackPtr = DAG.getCopyFromReg(Chain, X86StackPtr, getPointerTy());
15721567
1573 MemOpChains.push_back(LowerMemOpCallTo(Op, DAG, StackPtr, VA, Chain,
1574 Arg));
1568 MemOpChains.push_back(LowerMemOpCallTo(TheCall, DAG, StackPtr, VA,
1569 Chain, Arg, Flags));
15751570 }
15761571 }
15771572 }
16501645 CCValAssign &VA = ArgLocs[i];
16511646 if (!VA.isRegLoc()) {
16521647 assert(VA.isMemLoc());
1653 SDValue Arg = Op.getOperand(5+2*VA.getValNo());
1654 SDValue FlagsOp = Op.getOperand(6+2*VA.getValNo());
1655 ISD::ArgFlagsTy Flags =
1656 cast(FlagsOp)->getArgFlags();
1648 SDValue Arg = TheCall->getArg(i);
1649 ISD::ArgFlagsTy Flags = TheCall->getArgFlags(i);
16571650 // Create frame index.
16581651 int32_t Offset = VA.getLocMemOffset()+FPDiff;
16591652 uint32_t OpSize = (VA.getLocVT().getSizeInBits()+7)/8;
17631756 assert(InFlag.getNode() &&
17641757 "Flag must be set. Depend on flag being set in LowerRET");
17651758 Chain = DAG.getNode(X86ISD::TAILCALL,
1766 Op.getNode()->getVTList(), &Ops[0], Ops.size());
1759 TheCall->getVTList(), &Ops[0], Ops.size());
17671760
17681761 return SDValue(Chain.getNode(), Op.getResNo());
17691762 }
17731766
17741767 // Create the CALLSEQ_END node.
17751768 unsigned NumBytesForCalleeToPush;
1776 if (IsCalleePop(Op))
1769 if (IsCalleePop(isVarArg, CC))
17771770 NumBytesForCalleeToPush = NumBytes; // Callee pops everything
17781771 else if (!Is64Bit && CC != CallingConv::Fast && IsStructRet)
17791772 // If this is is a call to a struct-return function, the callee
17921785
17931786 // Handle result values, copying them out of physregs into vregs that we
17941787 // return.
1795 return SDValue(LowerCallResult(Chain, InFlag, Op.getNode(), CC, DAG),
1788 return SDValue(LowerCallResult(Chain, InFlag, TheCall, CC, DAG),
17961789 Op.getResNo());
17971790 }
17981791
18541847 /// following the call is a return. A function is eligible if caller/callee
18551848 /// calling conventions match, currently only fastcc supports tail calls, and
18561849 /// the function CALL is immediatly followed by a RET.
1857 bool X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Call,
1850 bool X86TargetLowering::IsEligibleForTailCallOptimization(CallSDNode *TheCall,
18581851 SDValue Ret,
18591852 SelectionDAG& DAG) const {
18601853 if (!PerformTailCallOpt)
18611854 return false;
18621855
1863 if (CheckTailCallReturnConstraints(Call, Ret)) {
1856 if (CheckTailCallReturnConstraints(TheCall, Ret)) {
18641857 MachineFunction &MF = DAG.getMachineFunction();
18651858 unsigned CallerCC = MF.getFunction()->getCallingConv();
1866 unsigned CalleeCC= cast(Call.getOperand(1))->getZExtValue();
1859 unsigned CalleeCC= TheCall->getCallingConv();
18671860 if (CalleeCC == CallingConv::Fast && CallerCC == CalleeCC) {
1868 SDValue Callee = Call.getOperand(4);
1861 SDValue Callee = TheCall->getCallee();
18691862 // On x86/32Bit PIC/GOT tail calls are supported.
18701863 if (getTargetMachine().getRelocationModel() != Reloc::PIC_ ||
18711864 !Subtarget->isPICStyleGOT()|| !Subtarget->is64Bit())
452452 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
453453 /// for tail call optimization. Target which want to do tail call
454454 /// optimization should implement this function.
455 virtual bool IsEligibleForTailCallOptimization(SDValue Call,
455 virtual bool IsEligibleForTailCallOptimization(CallSDNode *TheCall,
456456 SDValue Ret,
457457 SelectionDAG &DAG) const;
458458
492492 bool X86ScalarSSEf32;
493493 bool X86ScalarSSEf64;
494494
495 SDNode *LowerCallResult(SDValue Chain, SDValue InFlag, SDNode*TheCall,
495 SDNode *LowerCallResult(SDValue Chain, SDValue InFlag, CallSDNode *TheCall,
496496 unsigned CallingConv, SelectionDAG &DAG);
497497
498498 SDValue LowerMemArgument(SDValue Op, SelectionDAG &DAG,
499499 const CCValAssign &VA, MachineFrameInfo *MFI,
500500 unsigned CC, SDValue Root, unsigned i);
501501
502 SDValue LowerMemOpCallTo(SDValue Op, SelectionDAG &DAG,
502 SDValue LowerMemOpCallTo(CallSDNode *TheCall, SelectionDAG &DAG,
503503 const SDValue &StackPtr,
504504 const CCValAssign &VA, SDValue Chain,
505 SDValue Arg);
505 SDValue Arg, ISD::ArgFlagsTy Flags);
506506
507507 // Call lowering helpers.
508 bool IsCalleePop(SDValue Op);
508 bool IsCalleePop(bool isVarArg, unsigned CallingConv);
509509 bool CallRequiresGOTPtrInReg(bool Is64Bit, bool IsTailCall);
510510 bool CallRequiresFnAddressInReg(bool Is64Bit, bool IsTailCall);
511511 SDValue EmitTailCallLoadRetAddr(SelectionDAG &DAG, SDValue &OutRetAddr,
512512 SDValue Chain, bool IsTailCall, bool Is64Bit,
513513 int FPDiff);
514514
515 CCAssignFn *CCAssignFnForNode(SDValue Op) const;
515 CCAssignFn *CCAssignFnForNode(unsigned CallingConv) const;
516516 NameDecorationStyle NameDecorationForFORMAL_ARGUMENTS(SDValue Op);
517517 unsigned GetAlignedArgumentStackSize(unsigned StackSize, SelectionDAG &DAG);
518518