fix(ptoas): clamp host -target-cpu for bisheng host stub compile#959
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a workaround in tools/ptoas/ObjectEmission.cpp to resolve host CPU names, clamping znver4 and znver5 to znver3 to accommodate bisheng's Clang 15, and allowing overrides via the PTOAS_HOST_CPU environment variable. The review feedback suggests two minor improvements: utilizing a C++17 init-statement in the environment variable check, and performing comparisons directly on llvm::StringRef to avoid premature std::string allocations.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if (const char *env = std::getenv("PTOAS_HOST_CPU")) | ||
| if (*env) | ||
| return std::string(env); |
There was a problem hiding this comment.
Since you are using C++17, you can combine the check for the environment variable into a single if statement with an initializer. This can improve readability slightly.
| if (const char *env = std::getenv("PTOAS_HOST_CPU")) | |
| if (*env) | |
| return std::string(env); | |
| if (const char *env = std::getenv("PTOAS_HOST_CPU"); env && *env) { | |
| return std::string(env); | |
| } |
| std::string cpu = llvm::sys::getHostCPUName().str(); | ||
| if (cpu == "znver4" || cpu == "znver5") | ||
| return "znver3"; | ||
| return cpu; |
There was a problem hiding this comment.
For a minor performance improvement, you can avoid creating a std::string from the result of llvm::sys::getHostCPUName() until it's actually needed. llvm::sys::getHostCPUName() returns a StringRef, which is a non-owning view of a string. You can perform the comparisons on the StringRef directly and only convert to std::string when returning the original CPU name.
| std::string cpu = llvm::sys::getHostCPUName().str(); | |
| if (cpu == "znver4" || cpu == "znver5") | |
| return "znver3"; | |
| return cpu; | |
| llvm::StringRef cpu = llvm::sys::getHostCPUName(); | |
| if (cpu == "znver4" || cpu == "znver5") | |
| return "znver3"; | |
| return std::string(cpu); |
ptoas passes llvm::sys::getHostCPUName() from the (newer) LLVM it is built against straight to 'bisheng -cc1 -target-cpu', but bisheng's Clang 15 only recognizes up to znver3, so every target="pto" compile fails on Zen 4/Zen 5 hosts with 'unknown target CPU'. Add resolveHostTargetCPU(): clamp znver4/znver5 to znver3 and cortex-x925 to tsv200m, and allow PTOAS_HOST_TARGET_CPU to override detection. Implementation matches mly/feature-vmi to avoid a textual conflict when that branch lands. Fixes hw-native-sys#958
f8f748e to
0e3113f
Compare
A5 板测成功
|
A3 板测失败
失败用例
|
A3 板测失败详情:PR #959comm_p2p_binding_variants
comm_p2p
|
ptoas passes llvm::sys::getHostCPUName() from the (newer) LLVM it is built against straight to 'bisheng -cc1 -target-cpu', but bisheng's Clang 15 only recognizes up to znver3, so every target="pto" compile fails on Zen 4/Zen 5 hosts with 'unknown target CPU'.
Add resolveHostCPUName(): clamp znver4/znver5 to znver3 and allow PTOAS_HOST_CPU to override detection. Marked as WORKAROUND to drop once bisheng upgrades to LLVM 21.
Fixes #958