Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cranelift: Add instructions for getting the current stack/frame/return pointers #4573

Merged
15 changes: 1 addition & 14 deletions cranelift/codegen/src/isa/x64/encoding/rex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,20 +298,7 @@ pub(crate) fn emit_std_enc_mem(

prefixes.emit(sink);

let mem_e = match mem_e.clone() {
Amode::RbpOffset { simm32, flags } => {
let base = regs::rbp();
Amode::ImmReg {
simm32,
base,
flags,
}
}
other => other,
};

match mem_e {
Amode::RbpOffset { .. } => unreachable!(),
match *mem_e {
Amode::ImmReg { simm32, base, .. } => {
// If this is an access based off of RSP, it may trap with a stack overflow if it's the
// first touch of a new stack page.
Expand Down
6 changes: 1 addition & 5 deletions cranelift/codegen/src/isa/x64/inst.isle
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,7 @@
;; pointer). The appropriate relocation is emitted so
;; that the resulting immediate makes this Amode refer to
;; the given MachLabel.
(RipRelative (target MachLabel))

;; Load `rbp + sign_extend(simm32)`.
(RbpOffset (simm32 u32)
(flags MemFlags))))
(RipRelative (target MachLabel))))

;; Some Amode constructor helpers.

Expand Down
23 changes: 8 additions & 15 deletions cranelift/codegen/src/isa/x64/inst/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,16 @@ impl Amode {
) {
match self {
Amode::ImmReg { base, .. } => {
collector.reg_use(*base);
if *base != regs::rbp() && *base != regs::rsp() {
fitzgen marked this conversation as resolved.
Show resolved Hide resolved
collector.reg_use(*base);
}
}
Amode::ImmRegRegShift { base, index, .. } => {
fitzgen marked this conversation as resolved.
Show resolved Hide resolved
collector.reg_use(base.to_reg());
collector.reg_use(index.to_reg());
}
Amode::RipRelative { .. } | Amode::RbpOffset { .. } => {
// RIP and RBP aren't involved in regalloc.
Amode::RipRelative { .. } => {
// RIP isn't involved in regalloc.
}
}
}
Expand All @@ -338,17 +340,15 @@ impl Amode {
collector.reg_late_use(base.to_reg());
collector.reg_late_use(index.to_reg());
}
Amode::RipRelative { .. } | Amode::RbpOffset { .. } => {
// RIP and RBP aren't involved in regalloc.
Amode::RipRelative { .. } => {
// RIP isn't involved in regalloc.
}
}
}

pub(crate) fn get_flags(&self) -> MemFlags {
match self {
Amode::RbpOffset { flags, .. }
| Amode::ImmReg { flags, .. }
| Amode::ImmRegRegShift { flags, .. } => *flags,
Amode::ImmReg { flags, .. } | Amode::ImmRegRegShift { flags, .. } => *flags,
Amode::RipRelative { .. } => MemFlags::trusted(),
}
}
Expand Down Expand Up @@ -384,7 +384,6 @@ impl Amode {
index: Gpr::new(allocs.next(*index)).unwrap(),
},
&Amode::RipRelative { target } => Amode::RipRelative { target },
&Amode::RbpOffset { simm32, flags } => Amode::RbpOffset { simm32, flags },
}
}

Expand All @@ -403,12 +402,6 @@ impl Amode {
impl PrettyPrint for Amode {
fn pretty_print(&self, _size: u8, allocs: &mut AllocationConsumer<'_>) -> String {
match self {
Amode::RbpOffset { simm32, flags } => Amode::ImmReg {
simm32: *simm32,
base: regs::rbp(),
flags: *flags,
}
.pretty_print(8, allocs),
Amode::ImmReg { simm32, base, .. } => {
// Note: size is always 8; the address is 64 bits,
// even if the addressed operand is smaller.
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/x64/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -2853,5 +2853,5 @@

(rule (lower (get_return_address))
(x64_load $I64
(Amode.RbpOffset 8 (mem_flags_trusted))
(Amode.ImmReg 8 (preg_rbp) (mem_flags_trusted))
(ExtKind.None)))