[PATCH] D17092: [X86] Add -mseparate-stack-seg

Michael LeMay via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 15 11:07:57 PDT 2016


mlemay-intel updated this revision to Diff 53920.
mlemay-intel added a comment.

Revise patch to fix line alignment.


http://reviews.llvm.org/D17092

Files:
  include/clang/Driver/Options.td
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/varargs.c

Index: test/CodeGen/varargs.c
===================================================================
--- test/CodeGen/varargs.c
+++ test/CodeGen/varargs.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-unknown -target-feature +separate-stack-seg -emit-llvm -o - %s | FileCheck -check-prefix=SEPARATE-SS %s
 
 // PR6433 - Don't crash on va_arg(typedef).
 typedef double gdouble;
@@ -20,4 +21,5 @@
   __builtin_va_list ap;
   void *p;
   p = __builtin_va_arg(ap, typeof (int (*)[++n])); // CHECK: add nsw i32 {{.*}}, 1
+  // SEPARATE-SS: load i32*, i32* addrspace(258)* {{.*}}
 }
Index: lib/CodeGen/TargetInfo.cpp
===================================================================
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -1690,9 +1690,26 @@
   TypeInfo.second = CharUnits::fromQuantity(
                 getTypeStackAlignInBytes(Ty, TypeInfo.second.getQuantity()));
 
-  return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect*/ false,
-                          TypeInfo, CharUnits::fromQuantity(4),
-                          /*AllowHigherAlign*/ true);
+  const Address Addr = emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect*/ false,
+                                        TypeInfo, CharUnits::fromQuantity(4),
+                                        /*AllowHigherAlign*/ true);
+
+  const std::vector<std::string> &TargetFeatures =
+    CGF.getTarget().getTargetOpts().Features;
+  if (std::find(TargetFeatures.begin(), TargetFeatures.end(),
+                "+separate-stack-seg") != TargetFeatures.end()) {
+    // Cast the pointer into the address space for the stack segment.
+    // This is to help support multi-segment memory models in which DS and SS
+    // may differ from each other.
+    llvm::Type *DirectTy = CGF.ConvertTypeForMem(Ty);
+    llvm::Value *PtrAsInt =
+      CGF.Builder.CreatePtrToInt(Addr.getPointer(), CGF.IntPtrTy);
+    llvm::Value *PtrInStackSeg =
+      CGF.Builder.CreateIntToPtr(PtrAsInt, DirectTy->getPointerTo(258));
+    return Address(PtrInStackSeg, Addr.getAlignment());
+  }
+
+  return Addr;
 }
 
 bool X86_32TargetCodeGenInfo::isStructReturnInRegABI(
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1407,6 +1407,7 @@
 def mno_xsavec : Flag<["-"], "mno-xsavec">, Group<m_x86_Features_Group>;
 def mno_xsaves : Flag<["-"], "mno-xsaves">, Group<m_x86_Features_Group>;
 def mno_pku : Flag<["-"], "mno-pku">, Group<m_x86_Features_Group>;
+def mseparate_stack_seg : Flag<["-"], "mseparate-stack-seg">, Group<m_x86_Features_Group>;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group<m_arm_Features_Group>,
   HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64 only)">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17092.53920.patch
Type: text/x-patch
Size: 2893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160415/c145df3b/attachment.bin>


More information about the cfe-commits mailing list