]> granicus.if.org Git - clang/commitdiff
[clang] make reciprocal estimate codegen a function attribute
authorSanjay Patel <spatel@rotateright.com>
Tue, 4 Oct 2016 20:44:05 +0000 (20:44 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 4 Oct 2016 20:44:05 +0000 (20:44 +0000)
The motivation for the change is that we can't have pseudo-global settings
for codegen living in TargetOptions because that doesn't work with LTO.

Ideally, these reciprocal attributes will be moved to the instruction-level
via FMF, metadata, or something else. But making them function attributes is
at least an improvement over the current state.

I'm committing this patch ahead of the related LLVM patch to avoid bot failures,
but if that patch needs to be reverted, then this should be reverted too.

Differential Revision: https://reviews.llvm.org/D24815

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283251 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/BackendUtil.cpp
lib/CodeGen/CGCall.cpp
test/CodeGen/attr-mrecip.c [new file with mode: 0644]

index 8fc3e59b4fd079df6cd6a3a1b4e039e8b032ae35..346aa0beb160f3b64b87d7b553844f75bfce3c34 100644 (file)
@@ -533,9 +533,6 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
 
   llvm::TargetOptions Options;
 
-  if (!TargetOpts.Reciprocals.empty())
-    Options.Reciprocals = TargetRecip(TargetOpts.Reciprocals);
-
   Options.ThreadModel =
     llvm::StringSwitch<llvm::ThreadModel::Model>(CodeGenOpts.ThreadModel)
       .Case("posix", llvm::ThreadModel::POSIX)
index 2c40854bbb6bdfc6463192626cd87c4386cdf61c..f441bf4eda1b5d10cc1e381777ac05c4f2676e96 100644 (file)
@@ -1730,6 +1730,9 @@ void CodeGenModule::ConstructAttributeList(
 
     FuncAttrs.addAttribute("no-trapping-math",
                            llvm::toStringRef(CodeGenOpts.NoTrappingMath));
+
+    // TODO: Are these all needed?
+    // unsafe/inf/nan/nsz are handled by instruction-level FastMathFlags.
     FuncAttrs.addAttribute("no-infs-fp-math",
                            llvm::toStringRef(CodeGenOpts.NoInfsFPMath));
     FuncAttrs.addAttribute("no-nans-fp-math",
@@ -1746,6 +1749,12 @@ void CodeGenModule::ConstructAttributeList(
         "correctly-rounded-divide-sqrt-fp-math",
         llvm::toStringRef(CodeGenOpts.CorrectlyRoundedDivSqrt));
 
+    // TODO: Reciprocal estimate codegen options should apply to instructions?
+    std::vector<std::string> &Recips = getTarget().getTargetOpts().Reciprocals;
+    if (!Recips.empty())
+      FuncAttrs.addAttribute("reciprocal-estimates",
+                             llvm::join(Recips.begin(), Recips.end(), ","));
+
     if (CodeGenOpts.StackRealignment)
       FuncAttrs.addAttribute("stackrealign");
     if (CodeGenOpts.Backchain)
diff --git a/test/CodeGen/attr-mrecip.c b/test/CodeGen/attr-mrecip.c
new file mode 100644 (file)
index 0000000..954c57a
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -mrecip=!sqrtf,vec-divf:3 -emit-llvm %s -o - | FileCheck %s
+
+int baz(int a) { return 4; }
+
+// CHECK: baz{{.*}} #0
+// CHECK: #0 = {{.*}}"reciprocal-estimates"="!sqrtf,vec-divf:3"
+