From: Sanjay Patel Date: Tue, 4 Oct 2016 20:44:05 +0000 (+0000) Subject: [clang] make reciprocal estimate codegen a function attribute X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4da1cc6c609dfb1bd7a07773aeccc89ddeb350ff;p=clang [clang] make reciprocal estimate codegen a function attribute 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 --- diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 8fc3e59b4f..346aa0beb1 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -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(CodeGenOpts.ThreadModel) .Case("posix", llvm::ThreadModel::POSIX) diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 2c40854bbb..f441bf4eda 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -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 &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 index 0000000000..954c57ae10 --- /dev/null +++ b/test/CodeGen/attr-mrecip.c @@ -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" +