Welcome to mirror list, hosted at ThFree Co, Russian Federation.

llvm-alloca-fix.diff « patches « build_environment « build_files - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5394a472167c418a745b36decbdb207ab9bfc86f (plain)
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
Index: lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- lib/Target/X86/X86ISelLowering.cpp	2014-04-11 23:04:44.000000000 +0200
+++ lib/Target/X86/X86ISelLowering.cpp (working copy)
@@ -15493,12 +15493,36 @@
   // non-trivial part is impdef of ESP.
 
   if (Subtarget->isTargetWin64()) {
+    const char *StackProbeSymbol = 
+      Subtarget->isTargetCygMing() ? "___chkstk" : "__chkstk";
+      
+    MachineInstrBuilder MIB;
+    
+    if (getTargetMachine().getCodeModel() == CodeModel::Large) {
+      // For large code model we need to do indirect call to __chkstk.
+    
+      // R11 will be used to contain the address of __chkstk.
+      // R11 is a volotiale register and assumed to be destoyed by the callee, 
+      // so there is no need to save and restore it.
+      BuildMI(*BB, MI, DL, TII->get(X86::MOV64ri), X86::R11)
+        .addExternalSymbol(StackProbeSymbol);
+      // Create a call to __chkstk function which address contained in R11.
+      MIB = BuildMI(*BB, MI, DL, TII->get(X86::CALL64r))
+                    .addReg(X86::R11, RegState::Kill);
+                  
+    } else {
+      
+      // For non-large code model we can do direct call to __chkstk.
+      
+      MIB = BuildMI(*BB, MI, DL, TII->get(X86::W64ALLOCA))
+              .addExternalSymbol(StackProbeSymbol);
+    }
+  
     if (Subtarget->isTargetCygMing()) {
       // ___chkstk(Mingw64):
       // Clobbers R10, R11, RAX and EFLAGS.
       // Updates RSP.
-      BuildMI(*BB, MI, DL, TII->get(X86::W64ALLOCA))
-        .addExternalSymbol("___chkstk")
+      MIB
         .addReg(X86::RAX, RegState::Implicit)
         .addReg(X86::RSP, RegState::Implicit)
         .addReg(X86::RAX, RegState::Define | RegState::Implicit)
@@ -15507,8 +15531,7 @@
     } else {
       // __chkstk(MSVCRT): does not update stack pointer.
       // Clobbers R10, R11 and EFLAGS.
-      BuildMI(*BB, MI, DL, TII->get(X86::W64ALLOCA))
-        .addExternalSymbol("__chkstk")
+      MIB
         .addReg(X86::RAX, RegState::Implicit)
         .addReg(X86::EFLAGS, RegState::Define | RegState::Implicit);
       // RAX has the offset to be subtracted from RSP.
Index: lib/Target/X86/X86FrameLowering.cpp
===================================================================
--- lib/Target/X86/X86FrameLowering.cpp	2013-10-24 01:37:01.000000000 +0200
+++ lib/Target/X86/X86FrameLowering.cpp (working copy)
@@ -635,25 +635,49 @@
         .addReg(X86::EAX, RegState::Kill)
         .setMIFlag(MachineInstr::FrameSetup);
     }
+    
+    MachineInstrBuilder MIB;
 
     if (Is64Bit) {
+           
       // Handle the 64-bit Windows ABI case where we need to call __chkstk.
       // Function prologue is responsible for adjusting the stack pointer.
       BuildMI(MBB, MBBI, DL, TII.get(X86::MOV64ri), X86::RAX)
         .addImm(NumBytes)
         .setMIFlag(MachineInstr::FrameSetup);
+        
+      if (TM.getCodeModel() == CodeModel::Large) {
+        // For large code model we need to do indirect call to __chkstk.
+      
+          
+        // R11 will be used to contain the address of __chkstk.
+        // R11 is a volotiale register and assumed to be destoyed by the callee, 
+        // so there is no need to save and restore it.
+        BuildMI(MBB, MBBI, DL, TII.get(X86::MOV64ri), X86::R11)
+          .addExternalSymbol(StackProbeSymbol);
+        // Create a call to __chkstk function which address contained in R11.
+        MIB = BuildMI(MBB, MBBI, DL, TII.get(X86::CALL64r))
+                .addReg(X86::R11, RegState::Kill);
+      } else {
+      
+        // For non-large code model we can do direct call to __chkstk.
+              
+        MIB = BuildMI(MBB, MBBI, DL, TII.get(X86::W64ALLOCA))
+                .addExternalSymbol(StackProbeSymbol);
+      }
     } else {
       // Allocate NumBytes-4 bytes on stack in case of isEAXAlive.
       // We'll also use 4 already allocated bytes for EAX.
       BuildMI(MBB, MBBI, DL, TII.get(X86::MOV32ri), X86::EAX)
         .addImm(isEAXAlive ? NumBytes - 4 : NumBytes)
         .setMIFlag(MachineInstr::FrameSetup);
+        
+      MIB = BuildMI(MBB, MBBI, DL, TII.get(X86::CALLpcrel32))
+              .addExternalSymbol(StackProbeSymbol);
     }
 
-    BuildMI(MBB, MBBI, DL,
-            TII.get(Is64Bit ? X86::W64ALLOCA : X86::CALLpcrel32))
-      .addExternalSymbol(StackProbeSymbol)
-      .addReg(StackPtr,    RegState::Define | RegState::Implicit)
+    
+    MIB.addReg(StackPtr,    RegState::Define | RegState::Implicit)
       .addReg(X86::EFLAGS, RegState::Define | RegState::Implicit)
       .setMIFlag(MachineInstr::FrameSetup);