[llvm] AMDGPU: Respect target assembler directives over command line (PR #207812)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 7 00:17:48 PDT 2026
================
@@ -5989,14 +6001,48 @@ bool AMDGPUAsmParser::ParseDirectiveAMDGCNTarget() {
const std::optional<AMDGPU::TargetID> &CurrentTargetID =
getTargetStreamer().getTargetID();
- if (*CurrentTargetID != ParsedTargetID) {
+ Triple DirectiveTriple(ParsedTargetID.getTargetTripleString());
+ const Triple &STITriple = getSTI().getTargetTriple();
+ if (!DirectiveTriple.isCompatibleWith(STITriple)) {
return getParser().Error(
- TargetStart, Twine(".amdgcn_target directive's target id ") +
- Twine(ParsedTargetID.toString()) +
- Twine(" does not match the specified target id ") +
+ TargetStart, ".amdgcn_target " + Twine(ParsedTargetID.toString()) +
+ " is incompatible with " +
Twine(CurrentTargetID->toString()));
}
+ // Error if the ISA version doesn't match
+ AMDGPU::IsaVersion DirectiveISA = AMDGPU::getIsaVersion(
+ AMDGPU::getArchNameAMDGCN(ParsedTargetID.getGPUKind()));
+ AMDGPU::IsaVersion CurrentISA = AMDGPU::getIsaVersion(getSTI().getCPU());
+ if (DirectiveISA != CurrentISA) {
+ return getParser().Error(
+ TargetStart, ".amdgcn_target " + Twine(ParsedTargetID.toString()) +
+ " does not match the specified target id " +
+ Twine(CurrentTargetID->toString()));
+ }
+
+ // Warn if sramecc or xnack mismatch. These do not change the encoding.
+ if (AMDGPU::IsaInfo::targetIDSettingsConflict(
+ ParsedTargetID.getXnackSetting(),
+ CurrentTargetID->getXnackSetting())) {
+ Warning(TargetStart,
+ ".amdgcn_target directive has conflicting xnack settings");
+ }
+ if (AMDGPU::IsaInfo::targetIDSettingsConflict(
+ ParsedTargetID.getSramEccSetting(),
+ CurrentTargetID->getSramEccSetting())) {
+ Warning(TargetStart,
+ ".amdgcn_target directive has conflicting sramecc settings");
+ }
+
+ // Update the target streamer's TargetID with settings from the directive.
+ // We don't update the MCSubtargetInfo because we've already validated
+ // that the directive matches the command-line CPU.
----------------
arsenm wrote:
I changed my mind on this several times. My original goal was to eliminate dependency on the xnack/sramecc features, so this PR ended up on only weakening mismatch on xnack/sramecc. This is worth revisiting after the sub arch patches have landed for a while
https://github.com/llvm/llvm-project/pull/207812
More information about the llvm-commits
mailing list