From 140d53c99c3a70b9d3858a3c87f8ecb098994748 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 13 Jan 2006 02:50:02 +0000 Subject: [PATCH] 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 --- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 58 +++++++++++++++++++ lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 18 ++++-- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index e62c6d32e8e..5ea8b3dd1e8 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -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 VTs; + VTs.push_back(Node->getValueType(0)); + VTs.push_back(MVT::Other); + std::vector 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)) { diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 4c594bf1faf..061a3ef8a3e 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -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 VTs; + VTs.push_back(TLI.getPointerTy()); + VTs.push_back(MVT::Other); + std::vector 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; -- 2.34.1