Skip to content

Commit e978ccd

Browse files
committed
Remove dependency on clangDriver from flangFrontend
1 parent 9d5208a commit e978ccd

File tree

8 files changed

+174
-177
lines changed

8 files changed

+174
-177
lines changed

clang/include/clang/Driver/CommonArgs.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,6 @@ void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args,
291291
void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args,
292292
llvm::opt::ArgStringList &CmdArgs);
293293

294-
// Parse -mprefer-vector-width=. Return the Value string if well-formed.
295-
// Otherwise, return an empty string and issue a diagnosic message if needed.
296-
StringRef parseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
297-
const llvm::opt::ArgList &Args);
298-
299-
// Parse -mrecip. Return the Value string if well-formed.
300-
// Otherwise, return an empty string and issue a diagnosic message if needed.
301-
StringRef parseMRecipOption(clang::DiagnosticsEngine &Diags,
302-
const llvm::opt::ArgList &Args);
303-
304294
// Convert ComplexRangeKind to a string that can be passed as a frontend option.
305295
std::string complexRangeKindToStr(LangOptions::ComplexRangeKind Range);
306296

clang/include/clang/Options/OptionUtils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ inline uint64_t getLastArgUInt64Value(const llvm::opt::ArgList &Args,
5353
return getLastArgUInt64Value(Args, Id, Default, &Diags, Base);
5454
}
5555

56+
// Parse -mprefer-vector-width=. Return the Value string if well-formed.
57+
// Otherwise, return an empty string and issue a diagnosic message if needed.
58+
StringRef parseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
59+
const llvm::opt::ArgList &Args);
60+
61+
// Parse -mrecip. Return the Value string if well-formed.
62+
// Otherwise, return an empty string and issue a diagnosic message if needed.
63+
StringRef parseMRecipOption(clang::DiagnosticsEngine &Diags,
64+
const llvm::opt::ArgList &Args);
65+
5666
} // namespace clang
5767

5868
#endif // LLVM_CLANG_OPTIONS_OPTIONUTILS_H

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "clang/Driver/SanitizerArgs.h"
3333
#include "clang/Driver/Types.h"
3434
#include "clang/Driver/XRayArgs.h"
35+
#include "clang/Options/OptionUtils.h"
3536
#include "clang/Options/Options.h"
3637
#include "llvm/ADT/ScopeExit.h"
3738
#include "llvm/ADT/SmallSet.h"

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,169 +3379,6 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args,
33793379
CmdArgs.push_back("-floop-interchange");
33803380
}
33813381

3382-
// Parse -mprefer-vector-width=. Return the Value string if well-formed.
3383-
// Otherwise, return an empty string and issue a diagnosic message if needed.
3384-
StringRef tools::parseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
3385-
const llvm::opt::ArgList &Args) {
3386-
Arg *A = Args.getLastArg(options::OPT_mprefer_vector_width_EQ);
3387-
if (!A)
3388-
return "";
3389-
3390-
StringRef Value = A->getValue();
3391-
unsigned Width LLVM_ATTRIBUTE_UNINITIALIZED;
3392-
3393-
// Only "none" and Integer values are accepted by
3394-
// -mprefer-vector-width=<value>.
3395-
if (Value != "none" && Value.getAsInteger(10, Width)) {
3396-
Diags.Report(clang::diag::err_drv_invalid_value)
3397-
<< A->getOption().getName() << Value;
3398-
return "";
3399-
}
3400-
3401-
return Value;
3402-
}
3403-
3404-
// This is a helper function for validating the optional refinement step
3405-
// parameter in reciprocal argument strings. Return false if there is an error
3406-
// parsing the refinement step. Otherwise, return true and set the Position
3407-
// of the refinement step in the input string.
3408-
static bool getRefinementStep(StringRef In, clang::DiagnosticsEngine &Diags,
3409-
const Arg &A, size_t &Position) {
3410-
const char RefinementStepToken = ':';
3411-
Position = In.find(RefinementStepToken);
3412-
if (Position != StringRef::npos) {
3413-
StringRef Option = A.getOption().getName();
3414-
StringRef RefStep = In.substr(Position + 1);
3415-
// Allow exactly one numeric character for the additional refinement
3416-
// step parameter. This is reasonable for all currently-supported
3417-
// operations and architectures because we would expect that a larger value
3418-
// of refinement steps would cause the estimate "optimization" to
3419-
// under-perform the native operation. Also, if the estimate does not
3420-
// converge quickly, it probably will not ever converge, so further
3421-
// refinement steps will not produce a better answer.
3422-
if (RefStep.size() != 1) {
3423-
Diags.Report(diag::err_drv_invalid_value) << Option << RefStep;
3424-
return false;
3425-
}
3426-
char RefStepChar = RefStep[0];
3427-
if (RefStepChar < '0' || RefStepChar > '9') {
3428-
Diags.Report(diag::err_drv_invalid_value) << Option << RefStep;
3429-
return false;
3430-
}
3431-
}
3432-
return true;
3433-
}
3434-
3435-
// Parse -mrecip. Return the Value string if well-formed.
3436-
// Otherwise, return an empty string and issue a diagnosic message if needed.
3437-
StringRef tools::parseMRecipOption(clang::DiagnosticsEngine &Diags,
3438-
const ArgList &Args) {
3439-
StringRef DisabledPrefixIn = "!";
3440-
StringRef DisabledPrefixOut = "!";
3441-
StringRef EnabledPrefixOut = "";
3442-
StringRef Out = "";
3443-
3444-
Arg *A = Args.getLastArg(options::OPT_mrecip, options::OPT_mrecip_EQ);
3445-
if (!A)
3446-
return "";
3447-
3448-
unsigned NumOptions = A->getNumValues();
3449-
if (NumOptions == 0) {
3450-
// No option is the same as "all".
3451-
return "all";
3452-
}
3453-
3454-
// Pass through "all", "none", or "default" with an optional refinement step.
3455-
if (NumOptions == 1) {
3456-
StringRef Val = A->getValue(0);
3457-
size_t RefStepLoc;
3458-
if (!getRefinementStep(Val, Diags, *A, RefStepLoc))
3459-
return "";
3460-
StringRef ValBase = Val.slice(0, RefStepLoc);
3461-
if (ValBase == "all" || ValBase == "none" || ValBase == "default") {
3462-
return Val;
3463-
}
3464-
}
3465-
3466-
// Each reciprocal type may be enabled or disabled individually.
3467-
// Check each input value for validity, concatenate them all back together,
3468-
// and pass through.
3469-
3470-
llvm::StringMap<bool> OptionStrings;
3471-
OptionStrings.insert(std::make_pair("divd", false));
3472-
OptionStrings.insert(std::make_pair("divf", false));
3473-
OptionStrings.insert(std::make_pair("divh", false));
3474-
OptionStrings.insert(std::make_pair("vec-divd", false));
3475-
OptionStrings.insert(std::make_pair("vec-divf", false));
3476-
OptionStrings.insert(std::make_pair("vec-divh", false));
3477-
OptionStrings.insert(std::make_pair("sqrtd", false));
3478-
OptionStrings.insert(std::make_pair("sqrtf", false));
3479-
OptionStrings.insert(std::make_pair("sqrth", false));
3480-
OptionStrings.insert(std::make_pair("vec-sqrtd", false));
3481-
OptionStrings.insert(std::make_pair("vec-sqrtf", false));
3482-
OptionStrings.insert(std::make_pair("vec-sqrth", false));
3483-
3484-
for (unsigned i = 0; i != NumOptions; ++i) {
3485-
StringRef Val = A->getValue(i);
3486-
3487-
bool IsDisabled = Val.starts_with(DisabledPrefixIn);
3488-
// Ignore the disablement token for string matching.
3489-
if (IsDisabled)
3490-
Val = Val.substr(1);
3491-
3492-
size_t RefStep;
3493-
if (!getRefinementStep(Val, Diags, *A, RefStep))
3494-
return "";
3495-
3496-
StringRef ValBase = Val.slice(0, RefStep);
3497-
llvm::StringMap<bool>::iterator OptionIter = OptionStrings.find(ValBase);
3498-
if (OptionIter == OptionStrings.end()) {
3499-
// Try again specifying float suffix.
3500-
OptionIter = OptionStrings.find(ValBase.str() + 'f');
3501-
if (OptionIter == OptionStrings.end()) {
3502-
// The input name did not match any known option string.
3503-
Diags.Report(diag::err_drv_unknown_argument) << Val;
3504-
return "";
3505-
}
3506-
// The option was specified without a half or float or double suffix.
3507-
// Make sure that the double or half entry was not already specified.
3508-
// The float entry will be checked below.
3509-
if (OptionStrings[ValBase.str() + 'd'] ||
3510-
OptionStrings[ValBase.str() + 'h']) {
3511-
Diags.Report(diag::err_drv_invalid_value)
3512-
<< A->getOption().getName() << Val;
3513-
return "";
3514-
}
3515-
}
3516-
3517-
if (OptionIter->second == true) {
3518-
// Duplicate option specified.
3519-
Diags.Report(diag::err_drv_invalid_value)
3520-
<< A->getOption().getName() << Val;
3521-
return "";
3522-
}
3523-
3524-
// Mark the matched option as found. Do not allow duplicate specifiers.
3525-
OptionIter->second = true;
3526-
3527-
// If the precision was not specified, also mark the double and half entry
3528-
// as found.
3529-
if (ValBase.back() != 'f' && ValBase.back() != 'd' &&
3530-
ValBase.back() != 'h') {
3531-
OptionStrings[ValBase.str() + 'd'] = true;
3532-
OptionStrings[ValBase.str() + 'h'] = true;
3533-
}
3534-
3535-
// Build the output string.
3536-
StringRef Prefix = IsDisabled ? DisabledPrefixOut : EnabledPrefixOut;
3537-
Out = Args.MakeArgString(Out + Prefix + Val);
3538-
if (i != NumOptions - 1)
3539-
Out = Args.MakeArgString(Out + ",");
3540-
}
3541-
3542-
return Out;
3543-
}
3544-
35453382
std::string tools::complexRangeKindToStr(LangOptions::ComplexRangeKind Range) {
35463383
switch (Range) {
35473384
case LangOptions::ComplexRangeKind::CX_Full:

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "clang/Basic/CodeGenOptions.h"
1313
#include "clang/Driver/CommonArgs.h"
14+
#include "clang/Options/OptionUtils.h"
1415
#include "clang/Options/Options.h"
1516
#include "llvm/Frontend/Debug/Options.h"
1617
#include "llvm/Support/Path.h"

clang/lib/Options/OptionUtils.cpp

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "clang/Options/OptionUtils.h"
1010
#include "clang/Basic/Diagnostic.h"
1111
#include "clang/Basic/DiagnosticDriver.h"
12+
#include "clang/Options/Options.h"
1213
#include "llvm/Option/ArgList.h"
1314

1415
using namespace clang;
@@ -44,4 +45,163 @@ uint64_t getLastArgUInt64Value(const ArgList &Args, OptSpecifier Id,
4445
return getLastArgIntValueImpl<uint64_t>(Args, Id, Default, Diags, Base);
4546
}
4647

48+
StringRef parseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
49+
const llvm::opt::ArgList &Args) {
50+
const Arg *A = Args.getLastArg(options::OPT_mprefer_vector_width_EQ);
51+
if (!A)
52+
return "";
53+
54+
StringRef Value = A->getValue();
55+
unsigned Width LLVM_ATTRIBUTE_UNINITIALIZED;
56+
57+
// Only "none" and Integer values are accepted by
58+
// -mprefer-vector-width=<value>.
59+
if (Value != "none" && Value.getAsInteger(10, Width)) {
60+
Diags.Report(clang::diag::err_drv_invalid_value)
61+
<< A->getOption().getName() << Value;
62+
return "";
63+
}
64+
65+
return Value;
66+
}
67+
68+
// This is a helper function for validating the optional refinement step
69+
// parameter in reciprocal argument strings. Return false if there is an error
70+
// parsing the refinement step. Otherwise, return true and set the Position
71+
// of the refinement step in the input string.
72+
static bool getRefinementStep(StringRef In, clang::DiagnosticsEngine &Diags,
73+
const Arg &A, size_t &Position) {
74+
const char RefinementStepToken = ':';
75+
Position = In.find(RefinementStepToken);
76+
if (Position != StringRef::npos) {
77+
StringRef Option = A.getOption().getName();
78+
StringRef RefStep = In.substr(Position + 1);
79+
// Allow exactly one numeric character for the additional refinement
80+
// step parameter. This is reasonable for all currently-supported
81+
// operations and architectures because we would expect that a larger value
82+
// of refinement steps would cause the estimate "optimization" to
83+
// under-perform the native operation. Also, if the estimate does not
84+
// converge quickly, it probably will not ever converge, so further
85+
// refinement steps will not produce a better answer.
86+
if (RefStep.size() != 1) {
87+
Diags.Report(diag::err_drv_invalid_value) << Option << RefStep;
88+
return false;
89+
}
90+
char RefStepChar = RefStep[0];
91+
if (RefStepChar < '0' || RefStepChar > '9') {
92+
Diags.Report(diag::err_drv_invalid_value) << Option << RefStep;
93+
return false;
94+
}
95+
}
96+
return true;
97+
}
98+
99+
StringRef parseMRecipOption(clang::DiagnosticsEngine &Diags,
100+
const ArgList &Args) {
101+
StringRef DisabledPrefixIn = "!";
102+
StringRef DisabledPrefixOut = "!";
103+
StringRef EnabledPrefixOut = "";
104+
StringRef Out = "";
105+
106+
const Arg *A = Args.getLastArg(options::OPT_mrecip, options::OPT_mrecip_EQ);
107+
if (!A)
108+
return "";
109+
110+
const unsigned NumOptions = A->getNumValues();
111+
if (NumOptions == 0) {
112+
// No option is the same as "all".
113+
return "all";
114+
}
115+
116+
// Pass through "all", "none", or "default" with an optional refinement step.
117+
if (NumOptions == 1) {
118+
StringRef Val = A->getValue(0);
119+
size_t RefStepLoc;
120+
if (!getRefinementStep(Val, Diags, *A, RefStepLoc))
121+
return "";
122+
StringRef ValBase = Val.slice(0, RefStepLoc);
123+
if (ValBase == "all" || ValBase == "none" || ValBase == "default") {
124+
return Val;
125+
}
126+
}
127+
128+
// Each reciprocal type may be enabled or disabled individually.
129+
// Check each input value for validity, concatenate them all back together,
130+
// and pass through.
131+
132+
llvm::StringMap<bool> OptionStrings;
133+
OptionStrings.insert(std::make_pair("divd", false));
134+
OptionStrings.insert(std::make_pair("divf", false));
135+
OptionStrings.insert(std::make_pair("divh", false));
136+
OptionStrings.insert(std::make_pair("vec-divd", false));
137+
OptionStrings.insert(std::make_pair("vec-divf", false));
138+
OptionStrings.insert(std::make_pair("vec-divh", false));
139+
OptionStrings.insert(std::make_pair("sqrtd", false));
140+
OptionStrings.insert(std::make_pair("sqrtf", false));
141+
OptionStrings.insert(std::make_pair("sqrth", false));
142+
OptionStrings.insert(std::make_pair("vec-sqrtd", false));
143+
OptionStrings.insert(std::make_pair("vec-sqrtf", false));
144+
OptionStrings.insert(std::make_pair("vec-sqrth", false));
145+
146+
for (unsigned i = 0; i != NumOptions; ++i) {
147+
StringRef Val = A->getValue(i);
148+
149+
bool IsDisabled = Val.starts_with(DisabledPrefixIn);
150+
// Ignore the disablement token for string matching.
151+
if (IsDisabled)
152+
Val = Val.substr(1);
153+
154+
size_t RefStep;
155+
if (!getRefinementStep(Val, Diags, *A, RefStep))
156+
return "";
157+
158+
StringRef ValBase = Val.slice(0, RefStep);
159+
llvm::StringMap<bool>::iterator OptionIter = OptionStrings.find(ValBase);
160+
if (OptionIter == OptionStrings.end()) {
161+
// Try again specifying float suffix.
162+
OptionIter = OptionStrings.find(ValBase.str() + 'f');
163+
if (OptionIter == OptionStrings.end()) {
164+
// The input name did not match any known option string.
165+
Diags.Report(diag::err_drv_unknown_argument) << Val;
166+
return "";
167+
}
168+
// The option was specified without a half or float or double suffix.
169+
// Make sure that the double or half entry was not already specified.
170+
// The float entry will be checked below.
171+
if (OptionStrings[ValBase.str() + 'd'] ||
172+
OptionStrings[ValBase.str() + 'h']) {
173+
Diags.Report(diag::err_drv_invalid_value)
174+
<< A->getOption().getName() << Val;
175+
return "";
176+
}
177+
}
178+
179+
if (OptionIter->second == true) {
180+
// Duplicate option specified.
181+
Diags.Report(diag::err_drv_invalid_value)
182+
<< A->getOption().getName() << Val;
183+
return "";
184+
}
185+
186+
// Mark the matched option as found. Do not allow duplicate specifiers.
187+
OptionIter->second = true;
188+
189+
// If the precision was not specified, also mark the double and half entry
190+
// as found.
191+
if (ValBase.back() != 'f' && ValBase.back() != 'd' &&
192+
ValBase.back() != 'h') {
193+
OptionStrings[ValBase.str() + 'd'] = true;
194+
OptionStrings[ValBase.str() + 'h'] = true;
195+
}
196+
197+
// Build the output string.
198+
StringRef Prefix = IsDisabled ? DisabledPrefixOut : EnabledPrefixOut;
199+
Out = Args.MakeArgString(Out + Prefix + Val);
200+
if (i != NumOptions - 1)
201+
Out = Args.MakeArgString(Out + ",");
202+
}
203+
204+
return Out;
205+
}
206+
47207
} // namespace clang

flang/lib/Frontend/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ add_flang_library(flangFrontend
7575

7676
CLANG_LIBS
7777
clangBasic
78-
clangDriver
7978
clangOptions
8079
)
8180

0 commit comments

Comments
 (0)