Skip to content

Commit a258f60

Browse files
committed
Implement ppc/ppc64 preserves_flags option for inline asm
Treat cr (cr0-cr7) and xer as preserved flags if the inline_asm option is specified. fpscr and vscr are not tracked as they contain sticky bits which are generally assumed to be volatile, but do not contains flags used to control branches.
1 parent 2c37607 commit a258f60

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,19 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
251251
constraints.push("~{sreg}".to_string());
252252
}
253253
InlineAsmArch::Nvptx64 => {}
254-
InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => {}
254+
InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => {
255+
constraints.extend_from_slice(&[
256+
"~{cr0}".to_string(),
257+
"~{cr1}".to_string(),
258+
"~{cr2}".to_string(),
259+
"~{cr3}".to_string(),
260+
"~{cr4}".to_string(),
261+
"~{cr5}".to_string(),
262+
"~{cr6}".to_string(),
263+
"~{cr7}".to_string(),
264+
"~{xer}".to_string(),
265+
]);
266+
}
255267
InlineAsmArch::Hexagon => {}
256268
InlineAsmArch::LoongArch32 | InlineAsmArch::LoongArch64 => {
257269
constraints.extend_from_slice(&[

src/doc/unstable-book/src/language-features/asm-experimental-arch.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ These flags registers must be restored upon exiting the asm block if the `preser
201201
- The status register `r2`.
202202
- M68k
203203
- The condition code register `ccr`.
204+
- PowerPC
205+
- The condition registers `cr[0-7]`
206+
- The fixed-point exception register `xer`
204207
- SPARC
205208
- Integer condition codes (`icc` and `xcc`)
206209
- Floating-point condition codes (`fcc[0-3]`)

tests/codegen-llvm/asm/powerpc-clobbers.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,28 @@ pub unsafe fn vs32_clobber() {
7777
pub unsafe fn clobber_abi() {
7878
asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags));
7979
}
80+
81+
// CHECK-LABEL: @clobber_no_preserves_flags
82+
// CHECK: call void asm sideeffect "", "~{cr0},~{cr1},~{cr2},~{cr3},~{cr4},~{cr5},~{cr6},~{cr7},~{xer}"()
83+
#[no_mangle]
84+
pub unsafe fn clobber_no_preserves_flags() {
85+
asm!("", options(nostack, nomem));
86+
}
87+
88+
// CHECK-LABEL: @clobber_preservesflags
89+
// CHECK: call void asm sideeffect "", "~{memory}"()
90+
#[no_mangle]
91+
pub unsafe fn clobber_preservesflags() {
92+
asm!("", options(nostack, preserves_flags));
93+
}
94+
95+
// Output format depends on the availability of altivec and vsx
96+
// CHECK-LABEL: @clobber_abi_no_preserves_flags
97+
#[no_mangle]
98+
// powerpc: asm sideeffect "", "={r0},={r3},={r4},={r5},={r6},={r7},={r8},={r9},={r10},={r11},={r12},={f0},={f1},={f2},={f3},={f4},={f5},={f6},={f7},={f8},={f9},={f10},={f11},={f12},={f13},~{vs0},~{vs1},~{vs2},~{vs3},~{vs4},~{vs5},~{vs6},~{vs7},~{vs8},~{vs9},~{vs10},~{vs11},~{vs12},~{vs13},~{vs14},~{vs15},~{vs16},~{vs17},~{vs18},~{vs19},~{vs20},~{vs21},~{vs22},~{vs23},~{vs24},~{vs25},~{vs26},~{vs27},~{vs28},~{vs29},~{vs30},~{vs31},~{v0},~{v1},~{v2},~{v3},~{v4},~{v5},~{v6},~{v7},~{v8},~{v9},~{v10},~{v11},~{v12},~{v13},~{v14},~{v15},~{v16},~{v17},~{v18},~{v19},~{cr0},~{cr1},~{cr5},~{cr6},~{cr7},~{ctr},~{lr},~{xer},~{cr0},~{cr1},~{cr2},~{cr3},~{cr4},~{cr5},~{cr6},~{cr7},~{xer}"()
99+
// powerpc64: asm sideeffect "", "={r0},={r3},={r4},={r5},={r6},={r7},={r8},={r9},={r10},={r11},={r12},={f0},={f1},={f2},={f3},={f4},={f5},={f6},={f7},={f8},={f9},={f10},={f11},={f12},={f13},={v0},={v1},={v2},={v3},={v4},={v5},={v6},={v7},={v8},={v9},={v10},={v11},={v12},={v13},={v14},={v15},={v16},={v17},={v18},={v19},~{vs0},~{vs1},~{vs2},~{vs3},~{vs4},~{vs5},~{vs6},~{vs7},~{vs8},~{vs9},~{vs10},~{vs11},~{vs12},~{vs13},~{vs14},~{vs15},~{vs16},~{vs17},~{vs18},~{vs19},~{vs20},~{vs21},~{vs22},~{vs23},~{vs24},~{vs25},~{vs26},~{vs27},~{vs28},~{vs29},~{vs30},~{vs31},~{cr0},~{cr1},~{cr5},~{cr6},~{cr7},~{ctr},~{lr},~{xer},~{cr0},~{cr1},~{cr2},~{cr3},~{cr4},~{cr5},~{cr6},~{cr7},~{xer}"()
100+
// powerpc64le: asm sideeffect "", "={r0},={r3},={r4},={r5},={r6},={r7},={r8},={r9},={r10},={r11},={r12},={f0},={f1},={f2},={f3},={f4},={f5},={f6},={f7},={f8},={f9},={f10},={f11},={f12},={f13},={vs0},={vs1},={vs2},={vs3},={vs4},={vs5},={vs6},={vs7},={vs8},={vs9},={vs10},={vs11},={vs12},={vs13},={vs14},={vs15},={vs16},={vs17},={vs18},={vs19},={vs20},={vs21},={vs22},={vs23},={vs24},={vs25},={vs26},={vs27},={vs28},={vs29},={vs30},={vs31},={v0},={v1},={v2},={v3},={v4},={v5},={v6},={v7},={v8},={v9},={v10},={v11},={v12},={v13},={v14},={v15},={v16},={v17},={v18},={v19},~{cr0},~{cr1},~{cr5},~{cr6},~{cr7},~{ctr},~{lr},~{xer},~{cr0},~{cr1},~{cr2},~{cr3},~{cr4},~{cr5},~{cr6},~{cr7},~{xer}"()
101+
// aix64: asm sideeffect "", "={r0},={r3},={r4},={r5},={r6},={r7},={r8},={r9},={r10},={r11},={r12},={f0},={f1},={f2},={f3},={f4},={f5},={f6},={f7},={f8},={f9},={f10},={f11},={f12},={f13},={vs0},={vs1},={vs2},={vs3},={vs4},={vs5},={vs6},={vs7},={vs8},={vs9},={vs10},={vs11},={vs12},={vs13},={vs14},={vs15},={vs16},={vs17},={vs18},={vs19},={vs20},={vs21},={vs22},={vs23},={vs24},={vs25},={vs26},={vs27},={vs28},={vs29},={vs30},={vs31},={v0},={v1},={v2},={v3},={v4},={v5},={v6},={v7},={v8},={v9},={v10},={v11},={v12},={v13},={v14},={v15},={v16},={v17},={v18},={v19},~{cr0},~{cr1},~{cr5},~{cr6},~{cr7},~{ctr},~{lr},~{xer},~{cr0},~{cr1},~{cr2},~{cr3},~{cr4},~{cr5},~{cr6},~{cr7},~{xer}"()
102+
pub unsafe fn clobber_abi_no_preserves_flags() {
103+
asm!("", clobber_abi("C"), options(nostack, nomem));
104+
}

0 commit comments

Comments
 (0)