Fix #7539: llvm-mca falls back to autodetected arch if fails to use compilation switches

This commit is contained in:
Ofek
2025-07-21 20:35:35 +03:00
committed by GitHub
parent 58f8d74a51
commit 556fa1e29c

View File

@@ -107,6 +107,25 @@ export class LLVMMcaTool extends BaseTool {
const rewrittenOutputFilename = compilationInfo.outputFilename + '.mca';
await this.writeAsmFile(utils.normalizeAsmToString(compilationInfo.asm), rewrittenOutputFilename);
return super.runTool(compilationInfo, rewrittenOutputFilename, newArgs);
let res = await super.runTool(compilationInfo, rewrittenOutputFilename, newArgs);
if (res.code !== 0) {
if (res.stderr[0]?.text.includes('unable to get target')) {
// The compiler's set of `--target` values is strictly larger than llvm-mca's -mtriple values.
// Fallback: let llvm-mca use the autodetected architecture, with generic cpu.
const newArgs2 = newArgs.filter(arg => !arg.startsWith('-mtriple='));
res = await super.runTool(compilationInfo, rewrittenOutputFilename, newArgs2);
res.stdout = [
{
text:
`Warning: llvm-mca was unable to use the target '${target}' specified by the compiler. ` +
'Falling back to using the autodetected architecture with -mcpu=generic.\n\n',
},
...res.stdout,
];
}
}
return res;
}
}