Skip to content

Commit c64c74c

Browse files
author
Cameron McInally
committed
Address a handful of review comments:
1) Rename utility functions. Use camelCase, not PascalCase. 2) Change header comments to be documentation comments. 3) Update Frontend tests to account for implicit attributes. 4) Add Compilation Driver support and test case.
1 parent f4812aa commit c64c74c

File tree

7 files changed

+59
-30
lines changed

7 files changed

+59
-30
lines changed

clang/include/clang/Driver/CommonArgs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,12 @@ void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args,
273273

274274
// Parse -mprefer-vector-width=. Return the Value string if well-formed.
275275
// Otherwise, return an empty string and issue a diagnosic message if needed.
276-
StringRef ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
276+
StringRef parseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
277277
const llvm::opt::ArgList &Args);
278278

279279
// Parse -mrecip. Return the Value string if well-formed.
280280
// Otherwise, return an empty string and issue a diagnosic message if needed.
281-
StringRef ParseMRecipOption(clang::DiagnosticsEngine &Diags,
281+
StringRef parseMRecipOption(clang::DiagnosticsEngine &Diags,
282282
const llvm::opt::ArgList &Args);
283283

284284
} // end namespace tools

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,7 +3351,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
33513351
CmdArgs.push_back(Args.MakeArgString("-fbfloat16-excess-precision=" +
33523352
BFloat16ExcessPrecision));
33533353

3354-
StringRef Recip = ParseMRecipOption(D.getDiags(), Args);
3354+
StringRef Recip = parseMRecipOption(D.getDiags(), Args);
33553355
if (!Recip.empty())
33563356
CmdArgs.push_back(Args.MakeArgString("-mrecip=" + Recip));
33573357

@@ -7450,7 +7450,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
74507450
handleVectorizeLoopsArgs(Args, CmdArgs);
74517451
handleVectorizeSLPArgs(Args, CmdArgs);
74527452

7453-
StringRef VecWidth = ParseMPreferVectorWidthOption(D.getDiags(), Args);
7453+
StringRef VecWidth = parseMPreferVectorWidthOption(D.getDiags(), Args);
74547454
if (!VecWidth.empty())
74557455
CmdArgs.push_back(Args.MakeArgString("-mprefer-vector-width=" + VecWidth));
74567456

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,7 +3170,7 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args,
31703170

31713171
// Parse -mprefer-vector-width=. Return the Value string if well-formed.
31723172
// Otherwise, return an empty string and issue a diagnosic message if needed.
3173-
StringRef tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
3173+
StringRef tools::parseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
31743174
const llvm::opt::ArgList &Args) {
31753175
Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ);
31763176
if (!A)
@@ -3223,7 +3223,7 @@ static bool getRefinementStep(StringRef In, clang::DiagnosticsEngine &Diags,
32233223

32243224
// Parse -mrecip. Return the Value string if well-formed.
32253225
// Otherwise, return an empty string and issue a diagnosic message if needed.
3226-
StringRef tools::ParseMRecipOption(clang::DiagnosticsEngine &Diags,
3226+
StringRef tools::parseMRecipOption(clang::DiagnosticsEngine &Diags,
32273227
const ArgList &Args) {
32283228
StringRef DisabledPrefixIn = "!";
32293229
StringRef DisabledPrefixOut = "!";

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,10 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
695695
A->claim();
696696
}
697697

698+
StringRef Recip = parseMRecipOption(D.getDiags(), Args);
699+
if (!Recip.empty())
700+
CmdArgs.push_back(Args.MakeArgString("-mrecip=" + Recip));
701+
698702
if (!HonorINFs && !HonorNaNs && AssociativeMath && ReciprocalMath &&
699703
ApproxFunc && !SignedZeros &&
700704
(FPContract == "fast" || FPContract.empty())) {

flang/include/flang/Frontend/CodeGenOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
5353
/// The paths to the pass plugins that were registered using -fpass-plugin.
5454
std::vector<std::string> LLVMPassPlugins;
5555

56-
// The prefered vector width, if requested by -mprefer-vector-width.
56+
/// The prefered vector width, if requested by -mprefer-vector-width.
5757
std::string PreferVectorWidth;
5858

59-
// List of reciprocal estimate sub-options.
59+
/// List of reciprocal estimate sub-options.
6060
std::string Reciprocals;
6161

6262
/// List of filenames passed in using the -fembed-offload-object option. These

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
310310
for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
311311
opts.LLVMPassPlugins.push_back(a->getValue());
312312

313-
opts.Reciprocals = clang::driver::tools::ParseMRecipOption(diags, args);
313+
opts.Reciprocals = clang::driver::tools::parseMRecipOption(diags, args);
314314

315315
opts.PreferVectorWidth =
316-
clang::driver::tools::ParseMPreferVectorWidthOption(diags, args);
316+
clang::driver::tools::parseMPreferVectorWidthOption(diags, args);
317317

318318
// -fembed-offload-object option
319319
for (auto *a :

flang/test/Driver/mrecip.f90

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
11
! Test that -mrecip[=<list>] works as expected.
22

3-
! RUN: %flang_fc1 -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-OMIT
4-
! RUN: %flang_fc1 -mrecip -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-NOARG
5-
! RUN: %flang_fc1 -mrecip=all -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-ALL
6-
! RUN: %flang_fc1 -mrecip=none -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-NONE
7-
! RUN: %flang_fc1 -mrecip=default -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-DEF
8-
! RUN: %flang_fc1 -mrecip=divd,divf,divh,vec-divd,vec-divf,vec-divh,sqrtd,sqrtf,sqrth,vec-sqrtd,vec-sqrtf,vec-sqrth -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-POS
3+
! RUN: %flang -### -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FLANG,CHECK-FLANG-OMIT
4+
! RUN: %flang -mrecip -### -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FLANG,CHECK-FLANG-NOARG
5+
! RUN: %flang -mrecip=all -### -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FLANG,CHECK-FLANG-ALL
6+
! RUN: %flang -mrecip=none -### -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FLANG,CHECK-FLANG-NONE
7+
! RUN: %flang -mrecip=default -### -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FLANG,CHECK-FLANG-DEF
8+
! RUN: %flang -mrecip=divd,divf,divh,vec-divd,vec-divf,vec-divh,sqrtd,sqrtf,sqrth,vec-sqrtd,vec-sqrtf,vec-sqrth -### -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FLANG,CHECK-FLANG-POS
9+
! RUN: %flang -mrecip=!divd,!divf,!divh,!vec-divd,!vec-divf,!vec-divh,!sqrtd,!sqrtf,!sqrth,!vec-sqrtd,!vec-sqrtf,!vec-sqrth -### -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FLANG,CHECK-FLANG-NEG
10+
! RUN: %flang -mrecip=!divd,divf,!divh,sqrtd,!sqrtf,sqrth -### -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FLANG,CHECK-FLANG-MIX
11+
! RUN: not %flang -mrecip=xxx -### -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FLANG-INV
12+
! RUN: not %flang -mrecip=divd,divd -### -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FLANG-DUP
13+
14+
! RUN: %flang_fc1 -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-FC1-OMIT
15+
! RUN: %flang_fc1 -mrecip -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FC1,CHECK-FC1-NOARG
16+
! RUN: %flang_fc1 -mrecip=all -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FC1,CHECK-FC1-ALL
17+
! RUN: %flang_fc1 -mrecip=none -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FC1,CHECK-FC1-NONE
18+
! RUN: %flang_fc1 -mrecip=default -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FC1,CHECK-FC1-DEF
19+
! RUN: %flang_fc1 -mrecip=divd,divf,divh,vec-divd,vec-divf,vec-divh,sqrtd,sqrtf,sqrth,vec-sqrtd,vec-sqrtf,vec-sqrth -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FC1,CHECK-FC1-POS
920
! RUN: %flang_fc1 -mrecip=!divd,!divf,!divh,!vec-divd,!vec-divf,!vec-divh,!sqrtd,!sqrtf,!sqrth,!vec-sqrtd,!vec-sqrtf,!vec-sqrth
10-
! -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-NEG
11-
! RUN: %flang_fc1 -mrecip=!divd,divf,!divh,sqrtd,!sqrtf,sqrth -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-MIX
12-
! RUN: not %flang_fc1 -mrecip=xxx -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-INV
13-
! RUN: not %flang_fc1 -mrecip=divd,divd -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-DUP
21+
! -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FC1,CHECK-FC1-NEG
22+
! RUN: %flang_fc1 -mrecip=!divd,divf,!divh,sqrtd,!sqrtf,sqrth -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FC1,CHECK-FC1-MIX
23+
! RUN: not %flang_fc1 -mrecip=xxx -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FC1-INV
24+
! RUN: not %flang_fc1 -mrecip=divd,divd -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefixes=CHECK-FC1-DUP
1425

1526
subroutine func
1627
end subroutine func
1728

18-
! CHECK-OMIT-NOT: attributes #0 = { "reciprocal-estimates"={{.*}} }
19-
! CHECK-NOARG: attributes #0 = { "reciprocal-estimates"="all" }
20-
! CHECK-ALL: attributes #0 = { "reciprocal-estimates"="all" }
21-
! CHECK-NONE: attributes #0 = { "reciprocal-estimates"="none" }
22-
! CHECK-DEF: attributes #0 = { "reciprocal-estimates"="default" }
23-
! CHECK-POS: attributes #0 = { "reciprocal-estimates"="divd,divf,divh,vec-divd,vec-divf,vec-divh,sqrtd,sqrtf,sqrth,vec-sqrtd,vec-sqrtf,vec-sqrth" }
24-
! CHECK-NEG: attributes #0 = { "reciprocal-estimates"="!divd,!divf,!divh,!vec-divd,!vec-divf,!vec-divh,!sqrtd,!sqrtf,!sqrth,!vec-sqrtd,!vec-sqrtf,!vec-sqrth" }
25-
! CHECK-MIX: attributes #0 = { "reciprocal-estimates"="!divd,divf,!divh,sqrtd,!sqrtf,sqrth" }
26-
! CHECK-INV: error: unknown argument: 'xxx'
27-
! CHECK-DUP: error: invalid value 'divd' in 'mrecip='
29+
! CHECK-FLANG: "-fc1"
30+
! CHECK-FLANG-OMIT-NOT: "-mrecip="
31+
! CHECK-FLANG-NOARG-SAME: "-mrecip=all"
32+
! CHECK-FLANG-ALL-SAME: "-mrecip=all"
33+
! CHECK-FLANG-NONE-SAME: "-mrecip=none"
34+
! CHECK-FLANG-DEF-SAME: "-mrecip=default"
35+
! CHECK-FLANG-POS-SAME: "-mrecip=divd,divf,divh,vec-divd,vec-divf,vec-divh,sqrtd,sqrtf,sqrth,vec-sqrtd,vec-sqrtf,vec-sqrth"
36+
! CHECK-FLANG-NEG-SAME: "-mrecip=!divd,!divf,!divh,!vec-divd,!vec-divf,!vec-divh,!sqrtd,!sqrtf,!sqrth,!vec-sqrtd,!vec-sqrtf,!vec-sqrth"
37+
! CHECK-FLANG-MIX-SAME: "-mrecip=!divd,divf,!divh,sqrtd,!sqrtf,sqrth"
38+
! CHECK-FLANG-INV: error: unknown argument: 'xxx'
39+
! CHECK-FLANG-DUP: error: invalid value 'divd' in 'mrecip='
40+
41+
! CHECK-FC1: define {{.+}} @func{{.*}} #[[ATTRS:[0-9]+]]
42+
! CHECK-FC1: attributes #[[ATTRS]] =
43+
! CHECK-FC1-OMIT-NOT: "reciprocal-estimates"
44+
! CHECK-FC1-NOARG-SAME: "reciprocal-estimates"="all"
45+
! CHECK-FC1-ALL-SAME: "reciprocal-estimates"="all"
46+
! CHECK-FC1-NONE-SAME: "reciprocal-estimates"="none"
47+
! CHECK-FC1-DEF-SAME: "reciprocal-estimates"="default"
48+
! CHECK-FC1-POS-SAME: "reciprocal-estimates"="divd,divf,divh,vec-divd,vec-divf,vec-divh,sqrtd,sqrtf,sqrth,vec-sqrtd,vec-sqrtf,vec-sqrth"
49+
! CHECK-FC1-NEG-SAME: "reciprocal-estimates"="!divd,!divf,!divh,!vec-divd,!vec-divf,!vec-divh,!sqrtd,!sqrtf,!sqrth,!vec-sqrtd,!vec-sqrtf,!vec-sqrth"
50+
! CHECK-FC1-MIX-SAME: "reciprocal-estimates"="!divd,divf,!divh,sqrtd,!sqrtf,sqrth"
51+
! CHECK-FC1-INV: error: unknown argument: 'xxx'
52+
! CHECK-FC1-DUP: error: invalid value 'divd' in 'mrecip='

0 commit comments

Comments
 (0)