Commit 15066724 authored by Yi Lin's avatar Yi Lin

Merge branch 'extra-validation' into 'develop'

Extra validation

See merge request !33
parents 50f25766 9086ee79
......@@ -159,5 +159,5 @@ mubench:
rustfmt:
stage: rustfmt
script:
- cargo-fmt -- --write-mode=diff --verbose -- src/ast/src/lib.rs src/gc/src/lib.rs src/utils/src/lib.rs
- cargo-fmt -- --write-mode=diff --verbose -- src/lib.rs src/ast/src/lib.rs src/gc/src/lib.rs src/utils/src/lib.rs
......@@ -60,7 +60,7 @@ pub fn link_primordial(funcs: Vec<MuName>, out: &str, vm: &VM) -> PathBuf {
ret.push(dest);
// include mu static lib
if vm.vm_options.flag_link_statically {
if vm.vm_options.flag_aot_link_static {
ret.push(get_path_under_zebu(if cfg!(debug_assertions) {
"target/debug/libmu.a"
} else {
......@@ -75,7 +75,7 @@ pub fn link_primordial(funcs: Vec<MuName>, out: &str, vm: &VM) -> PathBuf {
out_path.push(out);
link_executable_internal(
!vm.vm_options.flag_link_statically,
!vm.vm_options.flag_aot_link_static,
files,
&vm.vm_options.flag_bootimage_external_lib,
&vm.vm_options.flag_bootimage_external_libpath,
......@@ -120,7 +120,7 @@ pub fn link_test_primordial(funcs: Vec<MuName>, out: &str, vm: &VM) -> PathBuf {
ret.push(dest);
// include mu static lib
if vm.vm_options.flag_link_statically {
if vm.vm_options.flag_aot_link_static {
ret.push(get_path_under_zebu(if cfg!(debug_assertions) {
"target/debug/libmu.a"
} else {
......@@ -135,7 +135,7 @@ pub fn link_test_primordial(funcs: Vec<MuName>, out: &str, vm: &VM) -> PathBuf {
out_path.push(out);
link_executable_internal(
!vm.vm_options.flag_link_statically,
!vm.vm_options.flag_aot_link_static,
files,
&vm.vm_options.flag_bootimage_external_lib,
&vm.vm_options.flag_bootimage_external_libpath,
......
......@@ -21,9 +21,11 @@ use utils::math::align_up;
use utils::bit_utils::bits_ones;
use std;
pub static mut VALIDATE_IR: bool = true;
macro_rules! assert_ir {
($ cond : expr ) => { debug_assert!($cond) };
($ cond : expr , $ ( $ arg : tt ) + ) => { debug_assert!($cond, $($arg)+)};
($ cond : expr ) => [{if unsafe{VALIDATE_IR} {assert!($cond)} }];
($ cond : expr , $ ( $ arg : tt ) + ) => [{if unsafe{VALIDATE_IR} {assert!($cond, $($arg)+)} }];
}
pub struct MuIRBuilder {
......@@ -1283,7 +1285,8 @@ struct BundleLoader<'lb, 'lvm> {
built_uptr_of: IdPMap<MuType>,
built_constint_of: HashMap<u64, P<Value>>,
current_sig: Option<P<MuFuncSig>>
current_sig: Option<P<MuFuncSig>>,
current_entry: MuID
}
fn load_bundle(b: &mut MuIRBuilder) {
......@@ -1322,7 +1325,8 @@ fn load_bundle(b: &mut MuIRBuilder) {
built_iref_of: Default::default(),
built_uptr_of: Default::default(),
built_constint_of: Default::default(),
current_sig: Default::default()
current_sig: Default::default(),
current_entry: Default::default()
};
bl.load_bundle();
......@@ -2258,6 +2262,7 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
let mut fcb: FuncCtxBuilder = Default::default();
let entry_id = *fv.bbs.first().unwrap();
self.current_entry = entry_id;
let mut blocks = fv.bbs
.iter()
.map(|bbid| {
......@@ -3581,12 +3586,10 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
inst_result_ids: &[MuID],
blocks: &LinkedHashMap<MuID, Block>
) -> Destination {
// Note: according to the mu spec you can't branch to the entry block
// but we allow that here anyway
let dest_clause = self.b.bundle.dest_clauses.get(&id).unwrap();
let target = dest_clause.dest;
assert_ir!(target != self.current_entry);
let target_block = blocks[&target].content.as_ref().unwrap();
assert_ir!(target_block.args.len() == dest_clause.vars.len());
......
......@@ -53,3 +53,5 @@ mod deps {
pub use vm::handle::APIHandle;
extern crate mu_ast as ast;
}
pub use self::api_impl::VALIDATE_IR;
\ No newline at end of file
......@@ -27,23 +27,30 @@ Usage:
init_mu [options]
VM:
--log-level=<level> logging level: none, error, warn, info, debug, trace, env [default: env]
--log-level=<level> logging level: none, error, warn, info, debug, trace, env
[default: env]
Compiler:
--disable-inline disable compiler function inlining
--disable-regalloc-validate disable register allocation validation
--disable-ir-validate disable IR validation
--emit-debug-info emit debugging information
AOT Compiler:
--aot-emit-dir=<dir> the emit directory for ahead-of-time compiling [default: emit]
--link-statically link boot image to libmu statically (defaults to dynamic)
--bootimage-external-lib=<lib> ... library that will be linked against when making bootimage [default: ]
--bootimage-external-libpath=<path> ... path for the libraries during bootimage generation [default: ]
--aot-emit-dir=<dir> the emit directory for ahead-of-time compiling
[default: emit]
--aot-link-static link boot image to libmu statically (defaults to dynamic)
--bootimage-external-lib=<lib> ... library that will be linked against when making bootimage
[default: ]
--bootimage-external-libpath=<path> ... path for the libraries during bootimage generation
[default: ]
Garbage Collection:
--gc-disable-collection disable collection
--gc-immixspace-size=<kb> immix space size (default 65536kb = 64mb) [default: 67108864]
--gc-lospace-size=<kb> large object space size (default 65536kb = 64mb) [default: 67108864]
--gc-immixspace-size=<kb> immix space size (default 65536kb = 64mb)
[default: 67108864]
--gc-lospace-size=<kb> large object space size (default 65536kb = 64mb)
[default: 67108864]
--gc-nthreads=<n> number of threads for parallel gc [default: 8]
";
......@@ -51,24 +58,25 @@ Garbage Collection:
pub struct VMOptions {
// The comments here indicate the offset into the struct
// VM
pub flag_log_level: MuLogLevel, // +96
pub flag_log_level: MuLogLevel,
// Compiler
pub flag_disable_inline: bool, // +97
pub flag_disable_regalloc_validate: bool, // +98
pub flag_emit_debug_info: bool, // +99
pub flag_disable_inline: bool,
pub flag_disable_regalloc_validate: bool,
pub flag_disable_ir_validate: bool,
pub flag_emit_debug_info: bool,
// AOT compiler
pub flag_aot_emit_dir: String, // +0
pub flag_link_statically: bool, // +100
pub flag_bootimage_external_lib: Vec<String>, // +24
pub flag_bootimage_external_libpath: Vec<String>, // +48
pub flag_aot_emit_dir: String,
pub flag_aot_link_static: bool,
pub flag_bootimage_external_lib: Vec<String>,
pub flag_bootimage_external_libpath: Vec<String>,
// GC
pub flag_gc_disable_collection: bool, // +101
pub flag_gc_immixspace_size: usize, // +72
pub flag_gc_lospace_size: usize, // +80
pub flag_gc_nthreads: usize, // +88
pub flag_gc_disable_collection: bool,
pub flag_gc_immixspace_size: usize,
pub flag_gc_lospace_size: usize,
pub flag_gc_nthreads: usize
}
// The fields need to be listed here in the order rust stores them in
......@@ -82,8 +90,9 @@ rodal_struct!(VMOptions {
flag_log_level,
flag_disable_inline,
flag_disable_regalloc_validate,
flag_disable_ir_validate,
flag_emit_debug_info,
flag_link_statically,
flag_aot_link_static,
flag_gc_disable_collection
});
......@@ -95,7 +104,7 @@ pub enum MuLogLevel {
Info,
Debug,
Trace,
Env,
Env
}
rodal_value!(MuLogLevel); // This enum has no fields with pointers, so just dump a strait value
......@@ -129,15 +138,32 @@ impl VMOptions {
// at the moment disable collection for debugging
// also because currently GC is buggy, and we are going to rewrite the GC
// See Issue #12
ret.flag_gc_disable_collection = true;
if !ret.flag_gc_disable_collection {
warn!("gc-disabled-collection is forced to true (opposite to user setting)");
ret.flag_gc_disable_collection = true;
}
// at the moment always emit debug info
ret.flag_emit_debug_info = true;
if !ret.flag_emit_debug_info {
warn!("emit-debug-info is forced to true (opposite to user setting)");
ret.flag_emit_debug_info = true;
}
// always disable register validation
// register validation is buggy. See Issue #19
ret.flag_disable_regalloc_validate = true;
if !ret.flag_disable_regalloc_validate {
warn!("disable-regalloc-validate is forced to true (opposite to user setting)");
ret.flag_disable_regalloc_validate = true;
}
if cfg!(target_os = "macos") {
if !ret.flag_aot_link_static {
warn!("link-statically is forced to true (opposite to user setting)");
ret.flag_aot_link_static = true;
}
}
unsafe { super::api::VALIDATE_IR = !ret.flag_disable_ir_validate };
ret
}
}
......
......@@ -342,7 +342,7 @@ fn test_function_loading() {
let id_y = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.y"));
((*b).new_binop)(b, id_add, id_y, CMU_BINOP_ADD, id_i32, id_x, id_const1, 0);
let id_e = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.x"));
let id_e = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.e"));
((*b).new_cmp)(b, id_eq, id_e, CMU_CMP_EQ, id_i32, id_x, id_const99);
let id_dest_t = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.dest_t"));
......
......@@ -87,7 +87,7 @@ def test_except_stack_args():
.funcdef test_except_stack_args <main_sig>
{
entry(<int<32>>argc <uptr<uptr<char>>>argv):
CALL <stack_sig> stack_args(<int<32>>0 <int<32>>1 <int<32>>2 <int<32>>3 <int<32>>4 <int<32>>5 <int<32>>6 <int<32>>7 <int<32>>8)
CALL <stack_sig> stack_args(<int<64>>0 <int<64>>1 <int<64>>2 <int<64>>3 <int<64>>4 <int<64>>5 <int<64>>6 <int<64>>7 <int<64>>8)
EXC (exit(<int<32>> 0) exit(<int<32>> 1))
exit(<int<32>> status):
......
......@@ -320,7 +320,6 @@ def test_newthread_threadlocal():
.funcdef test_newthread_threadlocal <main_sig>
{
entry(<int<32>>argc <uptr<uptr<char>>>argv):
cs = COMMINST uvm.current_stack()
s = COMMINST uvm.new_stack<[()->()]>(test_newthread_threadlocal_thread)
tr = NEW <int<32>>
......@@ -362,4 +361,35 @@ def test_newthread_stack_args():
COMMINST uvm.thread_exit()
}
""", "test_newthread_stack_args");
assert(execute("test_newthread_stack_args", []) == 45);
\ No newline at end of file
assert(execute("test_newthread_stack_args", []) == 45);
def test_swapstack_threadlocal():
compile_bundle(
"""
.funcdef test_swapstack_threadlocal_stack <(stackref)->()>
{
entry(<stackref>s):
tr = NEW <int<32>>
tri = GETIREF <int<32>> tr
STORE <int<32>> tri <int<32>> 3
tl = REFCAST <ref<int<32>> ref<void>> tr
t = NEWTHREAD s THREADLOCAL (tl) PASS_VALUES<>()
COMMINST uvm.thread_exit()
}
.funcdef test_swapstack_threadlocal <main_sig>
{
entry(<int<32>>argc <uptr<uptr<char>>>argv):
cs = COMMINST uvm.current_stack()
s = COMMINST uvm.new_stack<[(stackref)->()]>(test_swapstack_threadlocal_stack)
SWAPSTACK s RET_WITH<> PASS_VALUES<stackref>(cs)
tv = COMMINST uvm.get_threadlocal()
tr = REFCAST <ref<void> ref<int<32>>> tv
tvi = GETIREF <int<32>> tr
tv = LOAD <int<32>> tvi
RET (tv)
}
""", "test_swapstack_threadlocal");
assert(execute("test_swapstack_threadlocal", []) == 3);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment