cranelift: Resolve alias lookups in interpreter
This commit is contained in:
committed by
Andrew Brown
parent
4deed8fe50
commit
6be4441bbf
30
cranelift/filetests/filetests/runtests/alias.clif
Normal file
30
cranelift/filetests/filetests/runtests/alias.clif
Normal file
@@ -0,0 +1,30 @@
|
||||
test interpret
|
||||
test run
|
||||
target aarch64
|
||||
target s390x
|
||||
target x86_64 machinst
|
||||
|
||||
function %alias(i8) -> i8 {
|
||||
block0(v0: i8):
|
||||
v1 -> v0
|
||||
return v1
|
||||
}
|
||||
; run: %alias(0) == 0
|
||||
; run: %alias(-1) == -1
|
||||
|
||||
function %double_alias(i8) -> i8 {
|
||||
block0(v0: i8):
|
||||
v1 -> v0
|
||||
v2 -> v1
|
||||
return v2
|
||||
}
|
||||
; run: %double_alias(0) == 0
|
||||
; run: %double_alias(-1) == -1
|
||||
|
||||
function %alias_inst() -> i8 {
|
||||
block0:
|
||||
v0 = iconst.i8 10
|
||||
v1 -> v0
|
||||
return v1
|
||||
}
|
||||
; run: %alias_inst() == 10
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Implements a call frame (activation record) for the Cranelift interpreter.
|
||||
|
||||
use cranelift_codegen::data_value::DataValue;
|
||||
use cranelift_codegen::ir::{Function, Value as ValueRef};
|
||||
use cranelift_codegen::ir::{types, Function, Value as ValueRef};
|
||||
use cranelift_entity::EntityRef;
|
||||
use log::trace;
|
||||
|
||||
@@ -40,6 +40,22 @@ impl<'a> Frame<'a> {
|
||||
.get(name.index())
|
||||
.unwrap_or_else(|| panic!("unknown value: {}", name))
|
||||
.as_ref()
|
||||
.or_else(|| {
|
||||
// We couldn't find the `name` value directly in `registers`, but it is still
|
||||
// possible that it is aliased to another value.
|
||||
|
||||
// If we are looking up an undefined value it will have an invalid type, return
|
||||
// before trying to resolve it.
|
||||
if self.function.dfg.value_type(name) == types::INVALID {
|
||||
return None;
|
||||
}
|
||||
|
||||
let alias = self.function.dfg.resolve_aliases(name);
|
||||
self.registers
|
||||
.get(alias.index())
|
||||
.unwrap_or_else(|| panic!("unknown value: {}", alias))
|
||||
.as_ref()
|
||||
})
|
||||
.unwrap_or_else(|| panic!("empty slot: {}", name))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user