Skip to content

Commit 652cffa

Browse files
committed
fixup! [AArch64] Add ability to list extensions enabled for a target
1 parent 003afb7 commit 652cffa

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5709,7 +5709,7 @@ def print_supported_extensions : Flag<["-", "--"], "print-supported-extensions">
57095709
MarshallingInfoFlag<FrontendOpts<"PrintSupportedExtensions">>;
57105710
def print_enabled_extensions : Flag<["-", "--"], "print-enabled-extensions">,
57115711
Visibility<[ClangOption, CC1Option, CLOption]>,
5712-
HelpText<"Print the -march/-mcpu extensions enabled for the given target"
5712+
HelpText<"Print the extensions enabled by the given target and -march/-mcpu options."
57135713
" (AArch64 only)">,
57145714
MarshallingInfoFlag<FrontendOpts<"PrintEnabledExtensions">>;
57155715
def : Flag<["-"], "mcpu=help">, Alias<print_supported_cpus>;

clang/lib/Driver/ToolChain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static void getAArch64MultilibFlags(const Driver &D,
195195
UnifiedFeatures.end());
196196
std::vector<std::string> MArch;
197197
for (const auto &Ext : AArch64::Extensions)
198-
if (FeatureSet.contains(Ext.TargetFeature))
198+
if (FeatureSet.contains(Ext.PosTargetFeature))
199199
MArch.push_back(Ext.UserVisibleName.str());
200200
for (const auto &Ext : AArch64::Extensions)
201201
if (FeatureSet.contains(Ext.NegTargetFeature))

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
15231523
auto isPAuthLR = [](const char *member) {
15241524
llvm::AArch64::ExtensionInfo pauthlr_extension =
15251525
llvm::AArch64::getExtensionByID(llvm::AArch64::AEK_PAUTHLR);
1526-
return pauthlr_extension.TargetFeature == member;
1526+
return pauthlr_extension.PosTargetFeature == member;
15271527
};
15281528

15291529
if (std::any_of(CmdArgs.begin(), CmdArgs.end(), isPAuthLR))

llvm/include/llvm/TargetParser/AArch64TargetParser.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,18 @@ using ExtensionBitset = Bitset<AEK_NUM_EXTENSIONS>;
114114
// SubtargetFeature which may represent either an actual extension or some
115115
// internal LLVM property.
116116
struct ExtensionInfo {
117-
StringRef UserVisibleName; // Human readable name used in -march/-cpu, e.g. "profile"
117+
StringRef UserVisibleName; // Human readable name used in -march, -cpu
118+
// and target func attribute, e.g. "profile".
118119
std::optional<StringRef> Alias; // An alias for this extension, if one exists.
119120
ArchExtKind ID; // Corresponding to the ArchExtKind, this
120121
// extensions representation in the bitfield.
121-
StringRef ArchFeatureName; // The feature name defined by the Architecture
122-
StringRef Description; // The textual description of the extension
123-
StringRef TargetFeature; // -target-feature/-mattr enable string, e.g. "+spe"
124-
StringRef NegTargetFeature; // -target-feature/-mattr disable string, e.g. "-spe"
122+
StringRef ArchFeatureName; // The feature name defined by the
123+
// Architecture, e.g. FEAT_AdvSIMD.
124+
StringRef Description; // The textual description of the extension.
125+
StringRef PosTargetFeature; // -target-feature/-mattr enable string,
126+
// e.g. "+spe".
127+
StringRef NegTargetFeature; // -target-feature/-mattr disable string,
128+
// e.g. "-spe".
125129
CPUFeatures CPUFeature; // Function Multi Versioning (FMV) bitfield value
126130
// set in __aarch64_cpu_features
127131
StringRef DependentFeatures; // FMV enabled features string,
@@ -275,10 +279,10 @@ struct ExtensionSet {
275279
Features.emplace_back(T(BaseArch->ArchFeature));
276280

277281
for (const auto &E : Extensions) {
278-
if (E.TargetFeature.empty() || !Touched.test(E.ID))
282+
if (E.PosTargetFeature.empty() || !Touched.test(E.ID))
279283
continue;
280284
if (Enabled.test(E.ID))
281-
Features.emplace_back(T(E.TargetFeature));
285+
Features.emplace_back(T(E.PosTargetFeature));
282286
else
283287
Features.emplace_back(T(E.NegTargetFeature));
284288
}

llvm/lib/TargetParser/AArch64TargetParser.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ bool AArch64::getExtensionFeatures(
5858
std::vector<StringRef> &Features) {
5959
for (const auto &E : Extensions)
6060
/* INVALID and NONE have no feature name. */
61-
if (InputExts.test(E.ID) && !E.TargetFeature.empty())
62-
Features.push_back(E.TargetFeature);
61+
if (InputExts.test(E.ID) && !E.PosTargetFeature.empty())
62+
Features.push_back(E.PosTargetFeature);
6363

6464
return true;
6565
}
@@ -77,7 +77,7 @@ StringRef AArch64::getArchExtFeature(StringRef ArchExt) {
7777

7878
if (auto AE = parseArchExtension(ArchExtBase)) {
7979
// Note: the returned string can be empty.
80-
return IsNegated ? AE->NegTargetFeature : AE->TargetFeature;
80+
return IsNegated ? AE->NegTargetFeature : AE->PosTargetFeature;
8181
}
8282

8383
return StringRef();
@@ -112,9 +112,9 @@ const AArch64::ArchInfo *AArch64::parseArch(StringRef Arch) {
112112

113113
std::optional<AArch64::ExtensionInfo>
114114
AArch64::parseArchExtension(StringRef ArchExt) {
115+
if (ArchExt.empty())
116+
return {};
115117
for (const auto &A : Extensions) {
116-
if (A.UserVisibleName.empty() && !A.Alias)
117-
continue;
118118
if (ArchExt == A.UserVisibleName || ArchExt == A.Alias)
119119
return A;
120120
}
@@ -124,7 +124,7 @@ AArch64::parseArchExtension(StringRef ArchExt) {
124124
std::optional<AArch64::ExtensionInfo>
125125
AArch64::targetFeatureToExtension(StringRef TargetFeature) {
126126
for (const auto &E : Extensions)
127-
if (TargetFeature == E.TargetFeature)
127+
if (TargetFeature == E.PosTargetFeature)
128128
return E;
129129
return {};
130130
}
@@ -148,7 +148,7 @@ void AArch64::PrintSupportedExtensions() {
148148
<< "Description\n";
149149
for (const auto &Ext : Extensions) {
150150
// Extensions without a feature cannot be used with -march.
151-
if (!Ext.UserVisibleName.empty() && !Ext.TargetFeature.empty()) {
151+
if (!Ext.UserVisibleName.empty() && !Ext.PosTargetFeature.empty()) {
152152
outs() << " "
153153
<< format(Ext.Description.empty() ? "%-20s%s\n" : "%-20s%-55s%s\n",
154154
Ext.UserVisibleName.str().c_str(),
@@ -164,7 +164,7 @@ AArch64::printEnabledExtensions(std::vector<StringRef> EnabledFeatureNames) {
164164
<< " " << left_justify("Architecture Feature(s)", 55)
165165
<< "Description\n";
166166
auto IsEnabled = [&](const ExtensionInfo &Ext) {
167-
StringRef FeatureName = Ext.TargetFeature.drop_front(); // drop '+' before comparing
167+
StringRef FeatureName = Ext.PosTargetFeature.drop_front(); // drop '+' before comparing
168168
return std::find(EnabledFeatureNames.begin(), EnabledFeatureNames.end(),
169169
FeatureName) != EnabledFeatureNames.end();
170170
};
@@ -275,7 +275,7 @@ bool AArch64::ExtensionSet::parseModifier(StringRef Modifier,
275275
StringRef ArchExt = Modifier.drop_front(NChars);
276276

277277
if (auto AE = parseArchExtension(ArchExt)) {
278-
if (AE->TargetFeature.empty() || AE->NegTargetFeature.empty())
278+
if (AE->PosTargetFeature.empty() || AE->NegTargetFeature.empty())
279279
return false;
280280
if (IsNegated)
281281
disable(AE->ID);

0 commit comments

Comments
 (0)