Author: spatel Date: Tue Oct 4 15:44:05 2016 New Revision: 283251 URL: http://llvm.org/viewvc/llvm-project?rev=283251&view=rev Log: [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 Added: cfe/trunk/test/CodeGen/attr-mrecip.c Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/CodeGen/CGCall.cpp Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=283251&r1=283250&r2=283251&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Oct 4 15:44:05 2016 @@ -533,9 +533,6 @@ void EmitAssemblyHelper::CreateTargetMac 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) Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=283251&r1=283250&r2=283251&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Oct 4 15:44:05 2016 @@ -1730,6 +1730,9 @@ void CodeGenModule::ConstructAttributeLi 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::ConstructAttributeLi "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) Added: cfe/trunk/test/CodeGen/attr-mrecip.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-mrecip.c?rev=283251&view=auto ============================================================================== --- cfe/trunk/test/CodeGen/attr-mrecip.c (added) +++ cfe/trunk/test/CodeGen/attr-mrecip.c Tue Oct 4 15:44:05 2016 @@ -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" + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits