Skip to content

Commit

Permalink
[AArch64][Driver] Better handling of target feature dependencies (#78270
Browse files Browse the repository at this point in the history
)

Currently there are several bits of code in the AArch64 driver which
attempt to enforce dependencies between optional features in the -march=
and -mcpu= options. However, these are based on the list of feature
names being enabled/disabled, so they have a lot of logic to consider
the order in which features were turned on and off, which doesn't scale
well as dependency chains get longer.

This patch moves the code handling these dependencies to TargetParser,
and changes them to use a Bitset of enabled features. This makes it easy
to check which features are enabled, and is converted back to a list of
LLVM feature names once all of the command-line options are parsed.

The motivating example for this was the -mcpu=cortex-r82+nofp option.
Previously, the code handling the dependency between the fp16 and
fp16fml extensions did not consider the nofp modifier, so it added
+fullfp16 to the feature list. This should have been disabled by the
+nofp modifier, and also the backend did follow the dependency between
fullfp16 and fp, resulting in fp being turned back on in the backend.

Most of the dependencies added to AArch64TargetParser.h weren't known
about by clang before, I built that list by checking what the backend
thinks the dependencies between SubtargetFeatures are.
  • Loading branch information
ostannard committed Jan 17, 2024
1 parent b7c81c1 commit 13e977d
Show file tree
Hide file tree
Showing 46 changed files with 833 additions and 437 deletions.
3 changes: 1 addition & 2 deletions clang/lib/Basic/Targets/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,7 @@ ParsedTargetAttr AArch64TargetInfo::parseTargetAttr(StringRef Features) const {
FoundArch = true;
std::pair<StringRef, StringRef> Split =
Feature.split("=").second.trim().split("+");
const std::optional<llvm::AArch64::ArchInfo> AI =
llvm::AArch64::parseArch(Split.first);
const llvm::AArch64::ArchInfo *AI = llvm::AArch64::parseArch(Split.first);

// Parse the architecture version, adding the required features to
// Ret.Features.
Expand Down

0 comments on commit 13e977d

Please sign in to comment.