Compile llvm.stacksave/restore into STACKSAVE/STACKRESTORE nodes, and allow

targets to custom expand them as they desire.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25273 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-01-13 02:50:02 +00:00
parent b99329e8a0
commit 140d53c99c
2 changed files with 72 additions and 4 deletions

View File

@ -1425,6 +1425,64 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
if (Tmp1 != Node->getOperand(0))
Result = DAG.getNode(ISD::PCMARKER, MVT::Other, Tmp1,Node->getOperand(1));
break;
case ISD::STACKSAVE:
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
if (Tmp1 != Node->getOperand(0)) {
std::vector<MVT::ValueType> VTs;
VTs.push_back(Node->getValueType(0));
VTs.push_back(MVT::Other);
std::vector<SDOperand> Ops;
Ops.push_back(Tmp1);
Result = DAG.getNode(ISD::STACKSAVE, VTs, Ops);
}
switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) {
default: assert(0 && "This action is not supported yet!");
case TargetLowering::Custom: {
SDOperand Tmp = TLI.LowerOperation(Result, DAG);
if (Tmp.Val) {
Result = LegalizeOp(Tmp);
break;
}
// FALLTHROUGH if the target thinks it is legal.
}
case TargetLowering::Legal:
// Since stacksave produce two values, make sure to remember that we
// legalized both of them.
AddLegalizedOperand(SDOperand(Node, 0), Result);
AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1));
return Result.getValue(Op.ResNo);
case TargetLowering::Expand:
Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0));
AddLegalizedOperand(SDOperand(Node, 0), Tmp1);
AddLegalizedOperand(SDOperand(Node, 1), Node->getOperand(0));
return Op.ResNo ? Node->getOperand(0) : Tmp1;
}
case ISD::STACKRESTORE:
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer.
if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1))
Result = DAG.getNode(ISD::STACKRESTORE, MVT::Other, Tmp1, Tmp2);
switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) {
default: assert(0 && "This action is not supported yet!");
case TargetLowering::Custom: {
SDOperand Tmp = TLI.LowerOperation(Result, DAG);
if (Tmp.Val) {
Result = LegalizeOp(Tmp);
break;
}
// FALLTHROUGH if the target thinks it is legal.
}
case TargetLowering::Legal:
break;
case TargetLowering::Expand:
Result = Tmp1;
break;
}
break;
case ISD::READCYCLECOUNTER:
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain
if (Tmp1 != Node->getOperand(0)) {

View File

@ -1004,11 +1004,21 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1))));
return 0;
case Intrinsic::stacksave:
setValue(&I, DAG.getNode(ISD::UNDEF, TLI.getValueType(I.getType())));
return 0; // FIXME: discard stacksave/restore
case Intrinsic::stacksave: {
std::vector<MVT::ValueType> VTs;
VTs.push_back(TLI.getPointerTy());
VTs.push_back(MVT::Other);
std::vector<SDOperand> Ops;
Ops.push_back(getRoot());
SDOperand Tmp = DAG.getNode(ISD::STACKSAVE, VTs, Ops);
setValue(&I, Tmp);
DAG.setRoot(Tmp.getValue(1));
return 0;
}
case Intrinsic::stackrestore:
return 0; // FIXME: discard stacksave/restore
DAG.setRoot(DAG.getNode(ISD::STACKRESTORE, MVT::Other, DAG.getRoot(),
getValue(I.getOperand(1))));
return 0;
case Intrinsic::prefetch:
// FIXME: Currently discarding prefetches.
return 0;