Compile llvm.stacksave/restore into STACKSAVE/STACKRESTORE nodes, and allow
authorChris Lattner <sabre@nondot.org>
Fri, 13 Jan 2006 02:50:02 +0000 (02:50 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 13 Jan 2006 02:50:02 +0000 (02:50 +0000)
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
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index e62c6d32e8edd155b29513e0b5f68fb1dd5cb96e..5ea8b3dd1e834721df68421a91bd60a3fda94605 100644 (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)) {
index 4c594bf1faffb03d2f5cc72e60f2a64a89ae1dcb..061a3ef8a3e41f8c5076a59e007335e852f62fdb 100644 (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;