Skip to content

Commit 2477e17

Browse files
authored
[OffloadBundler] Rework the ctor of OffloadTargetInfo to support AMDGPU's generic target (#122629)
The current parsing logic for the target string assumes it follows the format `<kind>-<triple>-<target id>:<feature>`, such as `hipv4-amdgcn-amd-amdhsa-gfx1030:+xnack`. Specifically, it assumes that `<target id>` does not contain any `-`, relying on `rsplit` for parsing. However, this assumption breaks for AMDGPU's generic targets, which may contain one or more `-`, such as `gfx10-3-generic` or `gfx12-generic`. As a result, the existing approach using `rstrip` is no longer reliable. This patch reworks the parsing logic to handle target strings more robustly, including support for generic targets. The bundler now strictly requires a 4-field target triple. Additionally, a new Python helper function has been added to `config.py` to normalize the target triple into the 4-field format when it is not, ensuring tests pass reliably.
1 parent e37db4a commit 2477e17

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lit/llvm/config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ def get_clang_has_lsan(self, clang, triple):
355355

356356
return False
357357

358+
# Normalize 3-field target triple to 4-field triple with "unknown" as environment
359+
def normalize_triple(self, triple):
360+
compoments = triple.split("-", maxsplit=3)
361+
if len(compoments) == 4:
362+
return triple
363+
assert len(compoments) == 3
364+
return triple + "-unknown"
365+
358366
def make_itanium_abi_triple(self, triple):
359367
m = re.match(r"(\w+)-(\w+)-(\w+)", triple)
360368
if not m:
@@ -665,7 +673,9 @@ def use_clang(
665673
self.config.substitutions.append(
666674
(
667675
"%itanium_abi_triple",
668-
self.make_itanium_abi_triple(self.config.target_triple),
676+
self.normalize_triple(
677+
self.make_itanium_abi_triple(self.config.target_triple)
678+
),
669679
)
670680
)
671681
self.config.substitutions.append(

0 commit comments

Comments
 (0)