This repository has been archived by the owner on May 4, 2018. It is now read-only.
forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin64-int128.llvm-3.3.patch
397 lines (369 loc) · 16.7 KB
/
win64-int128.llvm-3.3.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
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;
}