https://github.com/JuliaLang/julia
Raw File
Tip revision: aa1ad7d8ccb2b9e0e198033384c1be8524f2aaaa authored by Isaiah Norton on 30 December 2014, 03:26:19 UTC
Handle undef refs in jl_copy_ast, fixes #9475
Tip revision: aa1ad7d
win64-int128.llvm-3.3.patch
diff -rupN llvm-3.3.src/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp llvm-3.3/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
--- llvm-3.3.src/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp	2013-04-20 08:32:17.000000000 -0400
+++ llvm-3.3/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp	2013-08-20 23:12:52.847754541 -0400
@@ -1849,6 +1849,17 @@ SDValue SelectionDAGLegalize::ExpandBUIL
 // and leave the Hi part unset.
 SDValue SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, SDNode *Node,
                                             bool isSigned) {
+  Triple Trip(DAG.getTarget().getTargetTriple());
+  int Win64 = Trip.isArch64Bit() && Trip.isOSWindows();
+
+  // By default, the input chain to this libcall is the entry node of the
+  // function. If the libcall is going to be emitted as a tail call then
+  // TLI.isUsedByReturnOnly will change it to the right chain if the return
+  // node which is being folded has a non-entry input chain.
+  SDValue InChain = DAG.getEntryNode();
+  bool isTailCall = true;
+  DebugLoc dl = Node->getDebugLoc();
+
   TargetLowering::ArgListTy Args;
   TargetLowering::ArgListEntry Entry;
   for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) {
@@ -1857,31 +1868,48 @@ SDValue SelectionDAGLegalize::ExpandLibC
     Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy;
     Entry.isSExt = isSigned;
     Entry.isZExt = !isSigned;
+    if (Win64 && Entry.Node.getValueType().getSizeInBits() > 64) {
+      //printf("win64 libcall arg %d i128*\n", i);
+      SDValue StackPtr = DAG.CreateStackTemporary(Entry.Node.getValueType(), 16); 
+      int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
+      MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(SPFI);
+      // Emit a store to the stack slot.
+      InChain = DAG.getStore(InChain, dl, Entry.Node, StackPtr, PtrInfo,
+                                   false, false, 16); 
+      Entry.Node = StackPtr;
+      Entry.Ty = PointerType::get(Entry.Ty,0);
+      Entry.isSExt = false;
+      Entry.isZExt = false;
+      if (isTailCall) isTailCall = false;
+    }
     Args.push_back(Entry);
   }
   SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
                                          TLI.getPointerTy());
 
-  Type *RetTy = Node->getValueType(0).getTypeForEVT(*DAG.getContext());
-
-  // By default, the input chain to this libcall is the entry node of the
-  // function. If the libcall is going to be emitted as a tail call then
-  // TLI.isUsedByReturnOnly will change it to the right chain if the return
-  // node which is being folded has a non-entry input chain.
-  SDValue InChain = DAG.getEntryNode();
+  EVT RetVT = Node->getValueType(0);
+  Type *RetTy;
+  if (Win64 && RetVT.getSizeInBits() == 128) {
+      RetTy = static_cast<EVT>(MVT::v2i64).getTypeForEVT(*DAG.getContext());
+      isTailCall = false; // necessary because of the calling convention mismatch between LLVM and native Win64
+  } else {
+      RetTy = RetVT.getTypeForEVT(*DAG.getContext());
+  }
 
-  // isTailCall may be true since the callee does not reference caller stack
-  // frame. Check if it's in the right position.
-  SDValue TCChain = InChain;
-  bool isTailCall = TLI.isInTailCallPosition(DAG, Node, TCChain);
-  if (isTailCall)
-    InChain = TCChain;
+  if (isTailCall) {
+    // isTailCall may be true since the callee does not reference caller stack
+    // frame. Check if it's in the right position.
+    SDValue TCChain = InChain;
+    isTailCall = TLI.isInTailCallPosition(DAG, Node, TCChain);
+    if (isTailCall)
+      InChain = TCChain;
+  }
 
   TargetLowering::
   CallLoweringInfo CLI(InChain, RetTy, isSigned, !isSigned, false, false,
                     0, TLI.getLibcallCallingConv(LC), isTailCall,
                     /*doesNotReturn=*/false, /*isReturnValueUsed=*/true,
-                    Callee, Args, DAG, Node->getDebugLoc());
+                    Callee, Args, DAG, dl);
   std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
 
 
@@ -1889,7 +1917,10 @@ SDValue SelectionDAGLegalize::ExpandLibC
     // It's a tailcall, return the chain (which is the DAG root).
     return DAG.getRoot();
 
-  return CallInfo.first;
+  SDValue ret = CallInfo.first;
+  if (isa<VectorType>(RetTy))
+      ret = DAG.getNode(ISD::BITCAST, dl, RetVT, ret);
+  return ret;
 }
 
 /// ExpandLibCall - Generate a libcall taking the given operands as arguments
@@ -1900,27 +1931,52 @@ SDValue SelectionDAGLegalize::ExpandLibC
   TargetLowering::ArgListTy Args;
   Args.reserve(NumOps);
 
+  Triple Trip(DAG.getTarget().getTargetTriple());
+  int Win64 = Trip.isArch64Bit() && Trip.isOSWindows();
+
+  SDValue InChain = DAG.getEntryNode();
   TargetLowering::ArgListEntry Entry;
   for (unsigned i = 0; i != NumOps; ++i) {
     Entry.Node = Ops[i];
     Entry.Ty = Entry.Node.getValueType().getTypeForEVT(*DAG.getContext());
     Entry.isSExt = isSigned;
     Entry.isZExt = !isSigned;
+    if (Win64 && Entry.Node.getValueType().getSizeInBits() > 64) {
+      //printf("win64 libcall arg %d i128*\n", i);
+      SDValue StackPtr = DAG.CreateStackTemporary(Entry.Node.getValueType(), 16); 
+      int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
+      MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(SPFI);
+      // Emit a store to the stack slot.
+      InChain = DAG.getStore(InChain, dl, Entry.Node, StackPtr, PtrInfo,
+                                   false, false, 16); 
+      Entry.Node = StackPtr;
+      Entry.Ty = PointerType::get(Entry.Ty,0);
+      Entry.isSExt = false;
+      Entry.isZExt = false;
+    }
     Args.push_back(Entry);
   }
   SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
                                          TLI.getPointerTy());
 
-  Type *RetTy = RetVT.getTypeForEVT(*DAG.getContext());
+  Type *RetTy;
+  if (Win64 && RetVT.getSizeInBits() == 128) {
+      RetTy = static_cast<EVT>(MVT::v2i64).getTypeForEVT(*DAG.getContext());
+  } else {
+      RetTy = RetVT.getTypeForEVT(*DAG.getContext());
+  }
   TargetLowering::
-  CallLoweringInfo CLI(DAG.getEntryNode(), RetTy, isSigned, !isSigned, false,
+  CallLoweringInfo CLI(InChain, RetTy, isSigned, !isSigned, false,
                        false, 0, TLI.getLibcallCallingConv(LC),
                        /*isTailCall=*/false,
                   /*doesNotReturn=*/false, /*isReturnValueUsed=*/true,
                   Callee, Args, DAG, dl);
   std::pair<SDValue,SDValue> CallInfo = TLI.LowerCallTo(CLI);
 
-  return CallInfo.first;
+  SDValue ret = CallInfo.first;
+  if (isa<VectorType>(RetTy))
+      ret = DAG.getNode(ISD::BITCAST, dl, RetVT, ret);
+  return ret; 
 }
 
 // ExpandChainLibCall - Expand a node into a call to a libcall. Similar to
@@ -1931,6 +1987,10 @@ SelectionDAGLegalize::ExpandChainLibCall
                                          bool isSigned) {
   SDValue InChain = Node->getOperand(0);
 
+  Triple Trip(DAG.getTarget().getTargetTriple());
+  int Win64 = Trip.isArch64Bit() && Trip.isOSWindows();
+  DebugLoc dl = Node->getDebugLoc();
+
   TargetLowering::ArgListTy Args;
   TargetLowering::ArgListEntry Entry;
   for (unsigned i = 1, e = Node->getNumOperands(); i != e; ++i) {
@@ -1940,19 +2000,39 @@ SelectionDAGLegalize::ExpandChainLibCall
     Entry.Ty = ArgTy;
     Entry.isSExt = isSigned;
     Entry.isZExt = !isSigned;
+    if (Win64 && Entry.Node.getValueType().getSizeInBits() > 64) {
+      //printf("win64 libcall arg %d i128*\n", i);
+      SDValue StackPtr = DAG.CreateStackTemporary(Entry.Node.getValueType(), 16);
+      int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
+      MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(SPFI);
+      // Emit a store to the stack slot.
+      InChain = DAG.getStore(InChain, dl, Entry.Node, StackPtr, PtrInfo,
+                                   false, false, 16);
+      Entry.Node = StackPtr;
+      Entry.Ty = PointerType::get(Entry.Ty,0);
+      Entry.isSExt = false;
+      Entry.isZExt = false;
+    }
     Args.push_back(Entry);
   }
   SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
                                          TLI.getPointerTy());
-
-  Type *RetTy = Node->getValueType(0).getTypeForEVT(*DAG.getContext());
+  EVT RetVT = Node->getValueType(0);
+  Type *RetTy;
+  if (Win64 && RetVT.getSizeInBits() == 128) {
+      RetTy = static_cast<EVT>(MVT::v2i64).getTypeForEVT(*DAG.getContext());
+  } else {
+      RetTy = RetVT.getTypeForEVT(*DAG.getContext());
+  }
   TargetLowering::
   CallLoweringInfo CLI(InChain, RetTy, isSigned, !isSigned, false, false,
                     0, TLI.getLibcallCallingConv(LC), /*isTailCall=*/false,
                     /*doesNotReturn=*/false, /*isReturnValueUsed=*/true,
-                    Callee, Args, DAG, Node->getDebugLoc());
+                    Callee, Args, DAG, dl);
   std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
-
+  
+  if (isa<VectorType>(RetTy))
+            CallInfo.first = DAG.getNode(ISD::BITCAST, dl, RetVT, CallInfo.first);
   return CallInfo;
 }
 
@@ -2056,10 +2136,14 @@ SelectionDAGLegalize::ExpandDivRemLibCal
   // Legalizing the call will automatically add the previous call to the
   // dependence.
   SDValue InChain = DAG.getEntryNode();
+  DebugLoc dl = Node->getDebugLoc();
 
   EVT RetVT = Node->getValueType(0);
   Type *RetTy = RetVT.getTypeForEVT(*DAG.getContext());
 
+  Triple Trip(DAG.getTarget().getTargetTriple());
+  int Win64 = Trip.isArch64Bit() && Trip.isOSWindows();
+
   TargetLowering::ArgListTy Args;
   TargetLowering::ArgListEntry Entry;
   for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) {
@@ -2068,6 +2152,19 @@ SelectionDAGLegalize::ExpandDivRemLibCal
     Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy;
     Entry.isSExt = isSigned;
     Entry.isZExt = !isSigned;
+    if (Win64 && Entry.Node.getValueType().getSizeInBits() > 64) {
+      //printf("win64 libcall arg %d i128*\n", i);
+      SDValue StackPtr = DAG.CreateStackTemporary(Entry.Node.getValueType(), 16);
+      int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
+      MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(SPFI);
+      // Emit a store to the stack slot.
+      InChain = DAG.getStore(InChain, dl, Entry.Node, StackPtr, PtrInfo,
+                                   false, false, 16);
+      Entry.Node = StackPtr;
+      Entry.Ty = PointerType::get(Entry.Ty,0);
+      Entry.isSExt = false;
+      Entry.isZExt = false;
+    }
     Args.push_back(Entry);
   }
 
@@ -2081,8 +2178,10 @@ SelectionDAGLegalize::ExpandDivRemLibCal
 
   SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
                                          TLI.getPointerTy());
-
-  DebugLoc dl = Node->getDebugLoc();
+  
+  if (Win64 && RetVT.getSizeInBits() == 128) {
+      RetTy = static_cast<EVT>(MVT::v2i64).getTypeForEVT(*DAG.getContext());
+  }
   TargetLowering::
   CallLoweringInfo CLI(InChain, RetTy, isSigned, !isSigned, false, false,
                     0, TLI.getLibcallCallingConv(LC), /*isTailCall=*/false,
@@ -2093,7 +2192,10 @@ SelectionDAGLegalize::ExpandDivRemLibCal
   // Remainder is loaded back from the stack frame.
   SDValue Rem = DAG.getLoad(RetVT, dl, CallInfo.second, FIPtr,
                             MachinePointerInfo(), false, false, false, 0);
-  Results.push_back(CallInfo.first);
+  if (isa<VectorType>(RetTy))
+      Results.push_back(DAG.getNode(ISD::BITCAST, dl, RetVT, CallInfo.first));
+  else
+      Results.push_back(CallInfo.first);
   Results.push_back(Rem);
 }
 
diff -rupN llvm-3.3.src/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp llvm-3.3/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
--- llvm-3.3.src/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp	2013-03-20 10:51:01.000000000 -0400
+++ llvm-3.3/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp	2013-08-20 23:00:29.455790788 -0400
@@ -15,6 +15,7 @@
 
 #include "LegalizeTypes.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/IR/CallingConv.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/Support/CommandLine.h"
@@ -1069,6 +1070,10 @@ std::pair<SDValue, SDValue>
 DAGTypeLegalizer::ExpandChainLibCall(RTLIB::Libcall LC,
                                          SDNode *Node,
                                          bool isSigned) {
+  Triple Trip(DAG.getTarget().getTargetTriple());
+  int Win64 = Trip.isArch64Bit() && Trip.isOSWindows();
+  DebugLoc dl = Node->getDebugLoc();
+
   SDValue InChain = Node->getOperand(0);
 
   TargetLowering::ArgListTy Args;
@@ -1080,12 +1085,32 @@ DAGTypeLegalizer::ExpandChainLibCall(RTL
     Entry.Ty = ArgTy;
     Entry.isSExt = isSigned;
     Entry.isZExt = !isSigned;
+    if (Win64 && Entry.Node.getValueType().getSizeInBits() > 64) {
+      //printf("win64 libcall arg %d i128*\n", i);
+      SDValue StackPtr = DAG.CreateStackTemporary(Entry.Node.getValueType(), 16);
+      int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
+      MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(SPFI);
+      // Emit a store to the stack slot.
+      InChain = DAG.getStore(InChain, dl, Entry.Node, StackPtr, PtrInfo,
+                                   false, false, 16);
+      Entry.Node = StackPtr;
+      Entry.Ty = PointerType::get(Entry.Ty,0);
+      Entry.isSExt = false;
+      Entry.isZExt = false;
+    }
     Args.push_back(Entry);
   }
   SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
                                          TLI.getPointerTy());
 
-  Type *RetTy = Node->getValueType(0).getTypeForEVT(*DAG.getContext());
+  EVT RetVT = Node->getValueType(0);
+  Type *RetTy;
+  if (Win64 && RetVT.getSizeInBits() == 128) {
+      RetTy = static_cast<EVT>(MVT::v2i64).getTypeForEVT(*DAG.getContext());
+  } else {
+      RetTy = RetVT.getTypeForEVT(*DAG.getContext());
+  }
+
   TargetLowering::
   CallLoweringInfo CLI(InChain, RetTy, isSigned, !isSigned, false, false,
                     0, TLI.getLibcallCallingConv(LC), /*isTailCall=*/false,
@@ -1093,6 +1118,8 @@ DAGTypeLegalizer::ExpandChainLibCall(RTL
                     Callee, Args, DAG, Node->getDebugLoc());
   std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
 
+  if (isa<VectorType>(RetTy))
+      CallInfo.first = DAG.getNode(ISD::BITCAST, dl, RetVT, CallInfo.first);
   return CallInfo;
 }
 
diff -rupN llvm-3.3.src/lib/CodeGen/SelectionDAG/TargetLowering.cpp llvm-3.3/lib/CodeGen/SelectionDAG/TargetLowering.cpp
--- llvm-3.3.src/lib/CodeGen/SelectionDAG/TargetLowering.cpp	2013-02-12 16:21:59.000000000 -0500
+++ llvm-3.3/lib/CodeGen/SelectionDAG/TargetLowering.cpp	2013-08-20 22:33:34.663869523 -0400
@@ -14,6 +14,7 @@
 #include "llvm/Target/TargetLowering.h"
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/CodeGen/Analysis.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineFunction.h"
@@ -74,26 +75,50 @@ SDValue TargetLowering::makeLibCall(Sele
   TargetLowering::ArgListTy Args;
   Args.reserve(NumOps);
 
+  Triple Trip(DAG.getTarget().getTargetTriple());
+  int Win64 = Trip.isArch64Bit() && Trip.isOSWindows();
+  SDValue InChain = DAG.getEntryNode();
   TargetLowering::ArgListEntry Entry;
   for (unsigned i = 0; i != NumOps; ++i) {
     Entry.Node = Ops[i];
     Entry.Ty = Entry.Node.getValueType().getTypeForEVT(*DAG.getContext());
     Entry.isSExt = isSigned;
     Entry.isZExt = !isSigned;
+    if (Win64 && Entry.Node.getValueType().getSizeInBits() > 64) {
+      //printf("win64 libcall arg %d i128*\n", i);
+      SDValue StackPtr = DAG.CreateStackTemporary(Entry.Node.getValueType(), 16); 
+      int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
+      MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(SPFI);
+      // Emit a store to the stack slot.
+      InChain = DAG.getStore(InChain, dl, Entry.Node, StackPtr, PtrInfo,
+                                   false, false, 16); 
+      Entry.Node = StackPtr;
+      Entry.Ty = PointerType::get(Entry.Ty,0);
+      Entry.isSExt = false;
+      Entry.isZExt = false;
+    }
     Args.push_back(Entry);
   }
   SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC), getPointerTy());
 
-  Type *RetTy = RetVT.getTypeForEVT(*DAG.getContext());
+  Type *RetTy;
+  if (Win64 && RetVT.getSizeInBits() == 128) {
+      RetTy = static_cast<EVT>(MVT::v2i64).getTypeForEVT(*DAG.getContext());
+  } else {
+      RetTy = RetVT.getTypeForEVT(*DAG.getContext());
+  }
   TargetLowering::
-  CallLoweringInfo CLI(DAG.getEntryNode(), RetTy, isSigned, !isSigned, false,
+  CallLoweringInfo CLI(InChain, RetTy, isSigned, !isSigned, false,
                     false, 0, getLibcallCallingConv(LC),
                     /*isTailCall=*/false,
                     /*doesNotReturn=*/false, /*isReturnValueUsed=*/true,
                     Callee, Args, DAG, dl);
   std::pair<SDValue,SDValue> CallInfo = LowerCallTo(CLI);
 
-  return CallInfo.first;
+  SDValue ret = CallInfo.first;
+  if (isa<VectorType>(RetTy))
+      ret = DAG.getNode(ISD::BITCAST, dl, RetVT, ret);
+  return ret;
 }
 
 
back to top