[PATCH] D27051: Propagate NumRegisterParameters to Backend

Nirav Dave via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 10:35:34 PST 2016


niravd updated this revision to Diff 79946.
niravd added a comment.

Change propagate to use subtarget features


https://reviews.llvm.org/D27051

Files:
  lib/Basic/Targets.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGen/pr3997.c


Index: test/CodeGen/pr3997.c
===================================================================
--- /dev/null
+++ test/CodeGen/pr3997.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -triple i386-unknown-linux-gnu -mregparm 3 -emit-llvm -o - | FileCheck %s
+
+void *memcpy(void *dest, const void *src, unsigned int n);
+
+void use_builtin_memcpy(void *dest, const void *src, unsigned int n) {
+  __builtin_memcpy(dest, src, n);
+}
+
+void use_memcpy(void *dest, const void *src, unsigned int n) {
+  memcpy(dest, src, n);
+}
+
+//CHECK: define void @use_builtin_memcpy(i8* inreg %dest, i8* inreg %src, i32 inreg %n) #0
+//CHECK: define void @use_memcpy(i8* inreg %dest, i8* inreg %src, i32 inreg %n) #0
+//CHECK: #0 = {{.*}} "target-features"="{{[^"]*}}+regparm3,{{[^"]*}}"
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===================================================================
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -729,7 +729,7 @@
         CGM.CreateRuntimeFunction(FTy, "_CxxThrowException"));
     // _CxxThrowException is stdcall on 32-bit x86 platforms.
     if (CGM.getTarget().getTriple().getArch() == llvm::Triple::x86)
-      Fn->setCallingConv(llvm::CallingConv::X86_StdCall);
+      Fn->setCallingConv(llvm::CallingConv::X86_LibStdCall);
     return Fn;
   }
 
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2802,6 +2802,28 @@
   initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
                  StringRef CPU,
                  const std::vector<std::string> &FeaturesVec) const override;
+
+  void adjustTargetOptions(const CodeGenOptions &CGOpts,
+                           TargetOptions &TargetOpts) const override {
+    StringRef Feature;
+    switch (CGOpts.NumRegisterParameters) {
+    case 1:
+      Feature = "+regparm1";
+      break;
+    case 2:
+      Feature = "+regparm2";
+      break;
+    case 3:
+      Feature = "+regparm3";
+      break;
+    }
+    if (!Feature.empty())
+      TargetOpts.Features.push_back(Feature);
+
+    // Run Generic.
+    TargetInfo::adjustTargetOptions(CGOpts, TargetOpts);
+  }
+
   bool hasFeature(StringRef Feature) const override;
   bool handleTargetFeatures(std::vector<std::string> &Features,
                             DiagnosticsEngine &Diags) override;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27051.79946.patch
Type: text/x-patch
Size: 2393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161201/ceda8880/attachment.bin>


More information about the llvm-commits mailing list