Skip to content

Commit 505aa24

Browse files
committed
[Attr] Move ParsedTargetAttr out of the TargetAttr class
Need to forward declare it in ASTContext.h for D68627, so it can't be a nested struct. Differential Revision: https://reviews.llvm.org/D71159
1 parent 56bba01 commit 505aa24

File tree

8 files changed

+26
-26
lines changed

8 files changed

+26
-26
lines changed

clang/include/clang/AST/Attr.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,18 @@ class ParamIdx {
329329
static_assert(sizeof(ParamIdx) == sizeof(ParamIdx::SerialType),
330330
"ParamIdx does not fit its serialization type");
331331

332+
/// Contains information gathered from parsing the contents of TargetAttr.
333+
struct ParsedTargetAttr {
334+
std::vector<std::string> Features;
335+
StringRef Architecture;
336+
StringRef BranchProtection;
337+
bool DuplicateArchitecture = false;
338+
bool operator ==(const ParsedTargetAttr &Other) const {
339+
return DuplicateArchitecture == Other.DuplicateArchitecture &&
340+
Architecture == Other.Architecture && Features == Other.Features;
341+
}
342+
};
343+
332344
#include "clang/AST/Attrs.inc"
333345

334346
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,16 +2162,6 @@ def Target : InheritableAttr {
21622162
let Subjects = SubjectList<[Function], ErrorDiag>;
21632163
let Documentation = [TargetDocs];
21642164
let AdditionalMembers = [{
2165-
struct ParsedTargetAttr {
2166-
std::vector<std::string> Features;
2167-
StringRef Architecture;
2168-
StringRef BranchProtection;
2169-
bool DuplicateArchitecture = false;
2170-
bool operator ==(const ParsedTargetAttr &Other) const {
2171-
return DuplicateArchitecture == Other.DuplicateArchitecture &&
2172-
Architecture == Other.Architecture && Features == Other.Features;
2173-
}
2174-
};
21752165
ParsedTargetAttr parse() const {
21762166
return parse(getFeaturesStr());
21772167
}

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2286,7 +2286,7 @@ void CodeGenFunction::checkTargetFeatures(SourceLocation Loc,
22862286
// Get the required features for the callee.
22872287

22882288
const TargetAttr *TD = TargetDecl->getAttr<TargetAttr>();
2289-
TargetAttr::ParsedTargetAttr ParsedAttr = CGM.filterFunctionTargetAttrs(TD);
2289+
ParsedTargetAttr ParsedAttr = CGM.filterFunctionTargetAttrs(TD);
22902290

22912291
SmallVector<StringRef, 1> ReqFeatures;
22922292
llvm::StringMap<bool> CalleeFeatureMap;

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ static void AppendTargetMangling(const CodeGenModule &CGM,
957957

958958
Out << '.';
959959
const TargetInfo &Target = CGM.getTarget();
960-
TargetAttr::ParsedTargetAttr Info =
960+
ParsedTargetAttr Info =
961961
Attr->parse([&Target](StringRef LHS, StringRef RHS) {
962962
// Multiversioning doesn't allow "no-${feature}", so we can
963963
// only have "+" prefixes here.
@@ -1678,7 +1678,7 @@ bool CodeGenModule::GetCPUAndFeaturesAttributes(GlobalDecl GD,
16781678
// get and parse the target attribute so we can get the cpu for
16791679
// the function.
16801680
if (TD) {
1681-
TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
1681+
ParsedTargetAttr ParsedAttr = TD->parse();
16821682
if (ParsedAttr.Architecture != "" &&
16831683
getTarget().isValidCPUName(ParsedAttr.Architecture))
16841684
TargetCPU = ParsedAttr.Architecture;
@@ -5858,9 +5858,9 @@ void CodeGenModule::AddVTableTypeMetadata(llvm::GlobalVariable *VTable,
58585858
}
58595859
}
58605860

5861-
TargetAttr::ParsedTargetAttr CodeGenModule::filterFunctionTargetAttrs(const TargetAttr *TD) {
5861+
ParsedTargetAttr CodeGenModule::filterFunctionTargetAttrs(const TargetAttr *TD) {
58625862
assert(TD != nullptr);
5863-
TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
5863+
ParsedTargetAttr ParsedAttr = TD->parse();
58645864

58655865
ParsedAttr.Features.erase(
58665866
llvm::remove_if(ParsedAttr.Features,
@@ -5880,7 +5880,7 @@ void CodeGenModule::getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
58805880
StringRef TargetCPU = Target.getTargetOpts().CPU;
58815881
const FunctionDecl *FD = GD.getDecl()->getAsFunction();
58825882
if (const auto *TD = FD->getAttr<TargetAttr>()) {
5883-
TargetAttr::ParsedTargetAttr ParsedAttr = filterFunctionTargetAttrs(TD);
5883+
ParsedTargetAttr ParsedAttr = filterFunctionTargetAttrs(TD);
58845884

58855885
// Make a copy of the features as passed on the command line into the
58865886
// beginning of the additional features from the function to override.

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ class CodeGenModule : public CodeGenTypeCache {
11521152

11531153
/// Parses the target attributes passed in, and returns only the ones that are
11541154
/// valid feature names.
1155-
TargetAttr::ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD);
1155+
ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD);
11561156

11571157
// Fills in the supplied string map with the set of target features for the
11581158
// passed in function.

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5061,7 +5061,7 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
50615061
CodeGenOptions::SignReturnAddressKeyValue Key = CGM.getCodeGenOpts().getSignReturnAddressKey();
50625062
bool BranchTargetEnforcement = CGM.getCodeGenOpts().BranchTargetEnforcement;
50635063
if (const auto *TA = FD->getAttr<TargetAttr>()) {
5064-
TargetAttr::ParsedTargetAttr Attr = TA->parse();
5064+
ParsedTargetAttr Attr = TA->parse();
50655065
if (!Attr.BranchProtection.empty()) {
50665066
TargetInfo::BranchProtectionInfo BPI;
50675067
StringRef Error;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9741,7 +9741,7 @@ bool Sema::shouldLinkDependentDeclWithPrevious(Decl *D, Decl *PrevDecl) {
97419741
static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD) {
97429742
const auto *TA = FD->getAttr<TargetAttr>();
97439743
assert(TA && "MultiVersion Candidate requires a target attribute");
9744-
TargetAttr::ParsedTargetAttr ParseInfo = TA->parse();
9744+
ParsedTargetAttr ParseInfo = TA->parse();
97459745
const TargetInfo &TargetInfo = S.Context.getTargetInfo();
97469746
enum ErrType { Feature = 0, Architecture = 1 };
97479747

@@ -9992,7 +9992,7 @@ static bool CheckTargetCausesMultiVersioning(
99929992
bool &Redeclaration, NamedDecl *&OldDecl, bool &MergeTypeWithPrevious,
99939993
LookupResult &Previous) {
99949994
const auto *OldTA = OldFD->getAttr<TargetAttr>();
9995-
TargetAttr::ParsedTargetAttr NewParsed = NewTA->parse();
9995+
ParsedTargetAttr NewParsed = NewTA->parse();
99969996
// Sort order doesn't matter, it just needs to be consistent.
99979997
llvm::sort(NewParsed.Features);
99989998

@@ -10036,8 +10036,7 @@ static bool CheckTargetCausesMultiVersioning(
1003610036
return true;
1003710037
}
1003810038

10039-
TargetAttr::ParsedTargetAttr OldParsed =
10040-
OldTA->parse(std::less<std::string>());
10039+
ParsedTargetAttr OldParsed = OldTA->parse(std::less<std::string>());
1004110040

1004210041
if (OldParsed == NewParsed) {
1004310042
S.Diag(NewFD->getLocation(), diag::err_multiversion_duplicate);
@@ -10090,7 +10089,7 @@ static bool CheckMultiVersionAdditionalDecl(
1009010089
return true;
1009110090
}
1009210091

10093-
TargetAttr::ParsedTargetAttr NewParsed;
10092+
ParsedTargetAttr NewParsed;
1009410093
if (NewTA) {
1009510094
NewParsed = NewTA->parse();
1009610095
llvm::sort(NewParsed.Features);
@@ -10117,8 +10116,7 @@ static bool CheckMultiVersionAdditionalDecl(
1011710116
return false;
1011810117
}
1011910118

10120-
TargetAttr::ParsedTargetAttr CurParsed =
10121-
CurTA->parse(std::less<std::string>());
10119+
ParsedTargetAttr CurParsed = CurTA->parse(std::less<std::string>());
1012210120
if (CurParsed == NewParsed) {
1012310121
S.Diag(NewFD->getLocation(), diag::err_multiversion_duplicate);
1012410122
S.Diag(CurFD->getLocation(), diag::note_previous_declaration);

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3046,7 +3046,7 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
30463046
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
30473047
<< Unsupported << None << Str;
30483048

3049-
TargetAttr::ParsedTargetAttr ParsedAttrs = TargetAttr::parse(AttrStr);
3049+
ParsedTargetAttr ParsedAttrs = TargetAttr::parse(AttrStr);
30503050

30513051
if (!ParsedAttrs.Architecture.empty() &&
30523052
!Context.getTargetInfo().isValidCPUName(ParsedAttrs.Architecture))

0 commit comments

Comments
 (0)