Skip to content

Commit

Permalink
Tag runnables with compile-fixed-point
Browse files Browse the repository at this point in the history
  • Loading branch information
yhdengh committed Jul 11, 2024
1 parent df1a8bc commit acb2075
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
26 changes: 7 additions & 19 deletions src/fix-driver/compile.wat
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,13 @@
(local $system_deps externref)
(local $clang_deps externref)
(local $map externref)
(local $compile externref)
(local $compiletag externref)

(call $attach_tree_ro_table_0 (local.get $inner))

;; inner[1] ought to be the fixed point, i.e., a tag authored by
;; compile.elf claiming that compile.elf itself is runnable
(call $attach_tree_ro_table_1 (table.get $ro_table_0 (i32.const 1)))
;; inner[1][0] is compile.elf
(local.set $compile (table.get $ro_table_1 (i32.const 0)))
(local.set $compiletag (table.get $ro_table_0 (i32.const 1)))

;; inner[2] is the "bootstrap tag"; this is a special tag, authored
;; by compile.elf, marking a tree of resources as the string
Expand All @@ -111,7 +109,7 @@
(call $attach_tree_ro_table_0 (table.get $ro_table_0 (i32.const 2)))

;; check if the tag was authored by us
(call $is_equal (local.get $compile) (table.get $ro_table_0 (i32.const 0)))
(call $is_equal (local.get $compiletag) (table.get $ro_table_0 (i32.const 0)))

(if (result externref)
(then
Expand All @@ -128,14 +126,14 @@
(local.set $clang_deps (table.get $ro_table_0 (i32.const 4)))
(local.set $map (table.get $ro_table_0 (i32.const 5)))

(call $make_compilation_thunk (local.get $resource_limits) (local.get $compile) (local.get $input) (local.get $wasm2c) (local.get $cc) (local.get $ld) (local.get $system_deps) (local.get $clang_deps) (local.get $map)))
(call $make_compilation_thunk (local.get $resource_limits) (local.get $compiletag) (local.get $input) (local.get $wasm2c) (local.get $cc) (local.get $ld) (local.get $system_deps) (local.get $clang_deps) (local.get $map)))
(else
;; invalid tag, return an error
(call $error_invalid_boot_tree))))

(func $make_compilation_thunk
(param $resource_limits externref)
(param $compile externref)
(param $compiletag externref)
(param $input externref)
(param $wasm2c externref)
(param $cc externref)
Expand Down Expand Up @@ -223,11 +221,6 @@
(local.set $elf_file)

;; result = compile(tag(elf_file, "Continuation"))
;;
;; We cheat a bit here by creating a new tag that says the compile ELF is
;; runnable, instead of extracting it from the compile encode. Luckily,
;; since we're in Compile right now, Fixpoint will accept this as a valid
;; Runnable tag.
(table.set $rw_table_4 (i32.const 0)
(call $create_resource_limits
;; memory usage 1024 * 1024 * 1024
Expand All @@ -238,7 +231,7 @@
(i32.const 1))
;; estimated output_fan_out
(i32.const 1)))
(table.set $rw_table_4 (i32.const 1) (call $tag_runnable (local.get $compile)))
(table.set $rw_table_4 (i32.const 1) (local.get $compiletag))
(table.set $rw_table_4 (i32.const 2) (call $tag_continuation (local.get $elf_file)))
(call $create_tree_rw_table_4 (i32.const 3))
(call $create_application_thunk))
Expand Down Expand Up @@ -306,13 +299,8 @@
)))

(func $do_validate (param $inner externref) (param $input externref) (result externref)
(local $compile externref)
(local $result externref)

;; get the name of this ELF file
(call $attach_tree_ro_table_0 (local.get $inner))
(local.set $compile (table.get $ro_table_0 (i32.const 1)))

(call $is_tag (local.get $input))
(i32.eq (i32.const 1))
(if
Expand All @@ -327,7 +315,7 @@
;; Attach the Tag
(call $attach_tree_ro_table_0 (local.get $input))
;; check if the tag was authored by us
(call $is_equal (local.get $compile) (table.get $ro_table_0 (i32.const 0)))
(call $is_equal (local.get $inner) (table.get $ro_table_0 (i32.const 0)))
(if
(then
;; Created by compile
Expand Down
12 changes: 7 additions & 5 deletions src/serialize/serialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,13 @@ int main( int argc, char* argv[] )
}

vector<Handle<Fix>> runnable_tags;
auto compile_fixedpoint = create_tag( elf_names[4], elf_names[4], Handle<Literal>( "Runnable" ) );
auto compile_runnable_tag = create_tag( compile_fixedpoint, elf_names[4], Handle<Literal>( "Runnable" ) );

for ( size_t i = 0; i < 4; i++ ) {
runnable_tags.push_back( create_tag( elf_names[4], elf_names[i], Handle<Literal>( "Runnable" ) ) );
runnable_tags.push_back( create_tag( compile_fixedpoint, elf_names[i], Handle<Literal>( "Runnable" ) ) );
}

auto compile_runnable_tag = create_tag( elf_names[4], elf_names[4], Handle<Literal>( "Runnable" ) );

// {runnable-wasm2c.elf, runnable-clang.elf, runnable-lld.elf, system_dep_tree, clang_dep_tree, runnable-map.elf }
auto compile_tool_tree_name = create_tree( create_tree_ref( runnable_tags[0] ),
create_tree_ref( runnable_tags[1] ),
Expand All @@ -140,11 +141,11 @@ int main( int argc, char* argv[] )

// Tag compile_tool_tree bootstrap
auto tagged_compile_tool_tree
= create_tag( elf_names[4], compile_tool_tree_name, Handle<Literal>( "Bootstrap" ) );
= create_tag( compile_fixedpoint, compile_tool_tree_name, Handle<Literal>( "Bootstrap" ) );

// Encode: {r, runnable-compile.elf, tagged-compile-tool-tree}
auto compile_encode_name
= create_tree( Handle<Literal>( "compile" ), compile_runnable_tag, tagged_compile_tool_tree );
= create_tree( Handle<Literal>( "compile" ), compile_fixedpoint, tagged_compile_tool_tree );

rp.label( "compile-encode", compile_encode_name );

Expand All @@ -158,6 +159,7 @@ int main( int argc, char* argv[] )
rp.label( files[i] + "-runnable-tag", runnable_tags[i] );
}

rp.label( "compile-fixed-point", compile_fixedpoint );
rp.label( "compile-runnable-tag", compile_runnable_tag );
rp.label( "compile-elf", elf_names[4] );
rp.label( "system-dep-tree", system_dep_tree_name );
Expand Down

0 comments on commit acb2075

Please sign in to comment.