Skip to content

Commit

Permalink
[clang] make reciprocal estimate codegen a function attribute
Browse files Browse the repository at this point in the history
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

llvm-svn: 283251
  • Loading branch information
rotateright committed Oct 4, 2016
1 parent f993d6e commit 0bb72c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 0 additions & 3 deletions clang/lib/CodeGen/BackendUtil.cpp
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/CodeGen/CGCall.cpp
Expand Up @@ -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",
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions clang/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"

0 comments on commit 0bb72c1

Please sign in to comment.