Infer #clobber memory and #clobber cc from the mnemonics directly

This commit is contained in:
gingerBill
2026-08-12 12:45:48 +01:00
parent b9a7ed9942
commit 2300a48782
5 changed files with 60 additions and 8 deletions

View File

@@ -403,6 +403,7 @@ struct lbAsmGenerate_amd64 : lbAsmGenerate {
}
}
bool memory_clobbered_already = false;
// Pass 3: clobbers
// Only the Scratch group. Unpinned register scratch was already emitted as an
// output in Pass 1, so it is skipped here.
@@ -427,12 +428,27 @@ struct lbAsmGenerate_amd64 : lbAsmGenerate {
break;
case AsmTemplateEntityDecl_Memory: // general memory clobber
raw("~{memory}");
memory_clobbered_already = true;
break;
default:
GB_PANIC("asm: invalid scratch operand kind");
}
}
// Template-level clobbers derived from #clobber cc / #clobber memory.
if (tmpl_entity->AsmTemplate.clobber_cc) {
sep();
if (build_context.metrics.arch == TargetArch_amd64) {
raw("~{flags}"); // x86 EFLAGS condition codes
} else {
raw("~{cc}"); // AArch64 uses ~{cc}
}
}
if (tmpl_entity->AsmTemplate.clobber_memory && memory_clobbered_already) {
sep();
raw("~{memory}");
}
// Build the callee type
// NOTE(bill): Even though the user has given a signature, this might not actually match what
// LLVM requires it to be due to the scratch parameters and more, so many of the results might