Commit Graph

55 Commits

Author SHA1 Message Date
Dan Gohman
ff18772d0e Avoid a heap allocation. 2017-09-21 14:21:30 -07:00
Dan Gohman
22b769b716 Convert use_var and predecessors_lookup into a state machine to avoid recursion. 2017-09-21 14:21:30 -07:00
Dan Gohman
9cda4eacde Minor refactor. 2017-09-21 14:21:30 -07:00
Dan Gohman
df5ba8bbba Correct a comment. 2017-09-21 14:21:30 -07:00
Dan Gohman
f524977920 Factor some logic out of seal_ebb_header_block into parts.
This allows append_jump_argument to call just the part that it needs
instead of the whole of seal_ebb_header_block, which is a nice cleanup
on its own, and it also eliminates a cycle from the static call graph.
2017-09-21 14:21:30 -07:00
Jakob Stoklund Olesen
1cd91b6f30 Eliminate layout::Cursor from cton_frontend.
Replace all uses with a FuncCursor.

Avoid the anti-pattern of passing parts of a function around as
independent references.
2017-09-21 12:24:27 -07:00
Dan Gohman
74845fed6c Use more helper functions on CursorBase to reduce cursor repositioning. 2017-09-20 11:19:35 -07:00
Dan Gohman
b888894fbb Use CursorBase utility functions to reduce repositioning clutter. 2017-09-20 09:06:17 -07:00
Dan Gohman
144d39a53d Minor code simplification. 2017-09-20 08:17:40 -07:00
Jakob Stoklund Olesen
da4cde8117 Always insert the entry EBB before translating any WASM.
The FuncEnvironment callbacks (make_global in particular) may need to
insert code in the entry EBB. We need to make sure the entry EBB has
been inserted in the layout before making those callbacks.
2017-09-18 11:53:32 -07:00
Jakob Stoklund Olesen
1349a6bdbc Always require a Flags reference for verifying functions.
Add a settings::FlagsOrIsa struct which represents a flags reference and
optionally the ISA it belongs to. Use this for passing flags/isa
information to the verifier.

The verify_function() and verify_context() functions are now generic so
they accept either a &Flags or a &TargetISa argument.

Fix the return_at_end verifier tests which no longer require an ISA
specified. The signle "set return_at_end" flag setting now makes it to
the verifier even when no ISA is present to carry it.
2017-09-14 17:51:15 -07:00
Dan Gohman
2e046d68ce Remove obsolete derivations of Hash. 2017-09-12 12:28:25 -07:00
Dan Gohman
620f1f49e2 Move several functions from FunctionBuilder to Function.
With FuncEnvironment using FuncCursors in place of full
FunctionBuilders, it's useful to move several of these convenience
functions from FunctionBuilder to Function.
2017-09-11 08:40:50 -07:00
Jakob Stoklund Olesen
26048c2ecc Move WasmRuntime::translate_call_indirect() into FuncEnvironment.
Add two new arguments:

- table_index is the WebAssembly table referenced in the indirect call.
- sig_index is the WebAssembly signature index. We still have the SigRef
  that was created by make_indirect_sig(), but the WebAssembly signature
  index may be needed for detecting type mismatches at runtime.

Change the insertion location to a plain FuncCursor rather than a
FunctionBuilder<Local>. The fact that cretonne-wasm uses FunctionBuilder
should be an implementation detail, and the callbacks don't need to
access WebAssembly locals, so they don't need the extended interface.

Add a FunctionBuilder::cursor() method which creates a FuncCursor for
inserting instructions in the current EBB.

Also add a FuncEnvironment::translate_call() method which allows the
environment to override direct calls the same way as indirect calls.
2017-09-06 15:18:55 -07:00
Dan Gohman
d3712575b5 Use mem::replace instead of mem::swap when it's cleaner. 2017-09-05 16:30:44 -07:00
Jakob Stoklund Olesen
0ac1d0dd94 Add FuncEnvironment trait.
This trait is used to provide the environment necessary to translate a
single WebAssembly function without having other global data structures
for the WebAssembly module.

The WasmRuntime trait extends the FuncEnvironment trait for those uses
that want to parse a whole WebAssembly module.

- Change the handling of WebAssembly globals to use the FuncEnvironment
  trait as well as the new GlobalVar infrastructure in Cretonne. The
  runtime is not consulted on the translation of each
  get_global/get_global instruction. Instead it gets to create the
  GlobalVar declaration in the function preamble the first time the
  global is used.

- Change the handling of heap load/store instructions to use the new
  Heap infrastructure in Cretonne. The runtime is called to create the
  Heap declaration in the preamble. It is not involved in individual
  load/store instructions.
2017-09-05 16:17:52 -07:00
Dan Gohman
9ea40ad44a Replace SSABuilder's variables HashMaps with EntityMaps. (#150)
* Replace SSABuilder's variables HashMaps with EntityMaps.

Current measurements show that memory usage is approximately the same,
and it's about 20% faster.

* Add EntityMap::with_default and use it.

* rustfmt

* Use var_defs[block].expand().
2017-09-02 04:11:51 -07:00
Dan Gohman
8237893113 Eliminate a temporary heap allocation when splitting a critical edge. 2017-09-01 12:50:51 -07:00
Dan Gohman
d4c53935b4 Introduce EntitySet, and use it to replace the HashSet in the frontend. 2017-09-01 12:23:53 -07:00
Dan Gohman
fe12fe0e63 Avoid unneeded calls to .as_slice(). 2017-09-01 12:15:14 -07:00
Dan Gohman
28779dc7e4 Avoid allocating jump arguments on the heap.
Instead of allocating a vector to store jump arguments for processing
later, just have the later code rescan through the predecessors to
obtain the values, which are memoized.

This also eliminates a linear search through the predecessor list when
splitting a critical edge.
2017-09-01 12:15:14 -07:00
Dan Gohman
7049cc78ae Refactor out an append helper function for SideEffects. 2017-08-31 17:49:39 -07:00
Dan Gohman
ec3972f515 Avoid allocating a vector for predecessor variables in the single-value case. 2017-08-31 17:42:19 -07:00
Dan Gohman
52335c9e0f Delete an obsolete TODO comment. 2017-08-31 17:06:14 -07:00
Dan Gohman
566c772e20 Eliminate more unnecessary calls to .iter(). 2017-08-31 17:03:12 -07:00
Dan Gohman
de02976162 Minor comment cleanups. 2017-08-31 17:02:26 -07:00
Dan Gohman
1d03244e90 Use debug_assert instead of assert in code where performance is important. 2017-08-31 16:36:18 -07:00
Dan Gohman
583487bfac Refactor the non-local case of use_var into a separate function. 2017-08-31 16:32:48 -07:00
Dan Gohman
e3227e38ce Avoid cloning precessor lists to the heap. 2017-08-31 16:09:26 -07:00
Dan Gohman
539a5b3378 Avoid a heap allocation for a block's undef_variables. 2017-08-31 15:42:37 -07:00
Dan Gohman
79f257060f Inline resolve_undef_vars, and collapse the resulting redundancy. 2017-08-31 14:49:53 -07:00
Dan Gohman
dc79d155ff Comment wording cleanups. 2017-08-31 12:47:05 -07:00
Dan Gohman
ebbb836bb9 Use debug_assert_eq rather than debug_assert with an ==. 2017-08-31 12:47:05 -07:00
Dan Gohman
a7d629c368 Use the Self keyword where applicable.
https://github.com/rust-lang-nursery/rust-clippy/wiki#use_self
2017-08-31 12:47:05 -07:00
Dan Gohman
9726bb7367 Avoid matching with reference patterns.
https://github.com/rust-lang-nursery/rust-clippy/wiki#match_ref_pats
2017-08-31 12:47:05 -07:00
Dan Gohman
5a8d1a9fda Use if let instead of match.
https://github.com/rust-lang-nursery/rust-clippy/wiki#single_match
2017-08-31 12:47:05 -07:00
Dan Gohman
b6641ff443 Avoid clone() on a Copy type.
https://github.com/rust-lang-nursery/rust-clippy/wiki#clone_on_copy
2017-08-31 12:47:05 -07:00
Dan Gohman
abbc6ddf24 Use is_empty() instead of comparing len() with 0.
https://github.com/rust-lang-nursery/rust-clippy/wiki#len_zero
2017-08-31 12:47:05 -07:00
Dan Gohman
2efdc0ed37 Update rustfmt to 0.9.0. 2017-08-31 10:44:59 -07:00
Dan Gohman
46fb64cbb4 Add SideEffects::new(). 2017-08-31 10:28:56 -07:00
Dan Gohman
52186b8390 Refactor code for obtaining the header block. 2017-08-31 10:28:56 -07:00
Dan Gohman
6702221e94 Change EbbHeaderBlockData's predecessors list from a HashMap to a Vec. (#148)
In addition to efficiency, this change also eliminates some nondeterminsm
resulting from HashMap key ordering.
2017-08-31 08:54:34 -07:00
Dan Gohman
4ccd21ba94 Simplify iteration. 2017-08-30 15:04:53 -07:00
Dan Gohman
110697cfdd Replace match blocks with .expect calls. 2017-08-30 14:53:49 -07:00
Dan Gohman
5e99a4fb6a Simplify a pattern-match. 2017-08-30 14:53:39 -07:00
Dan Gohman
0cc8bd06cd Remove unnecessary () values. 2017-08-30 14:53:34 -07:00
Dan Gohman
8647b10135 Loop over references to containers instead of using explicit iteration methods.
https://github.com/rust-lang-nursery/rust-clippy/wiki#explicit_iter_loop
2017-08-30 14:52:17 -07:00
Dan Gohman
03698f6bc8 Use slices rather than Vec borrows.
https://github.com/rust-lang-nursery/rust-clippy/wiki#ptr_arg
2017-08-30 14:48:17 -07:00
Dan Gohman
01744d6f65 Avoid unneeded return keywords. 2017-08-30 14:46:48 -07:00
Jakob Stoklund Olesen
7e08b14cf6 Split EntityMap into entity::PrimaryMap and entity::EntityMap.
The new PrimaryMap replaces the primary EntityMap and the PrimaryEntityData
marker trait which was causing some confusion. We now have a clear
division between the two types of maps:

- PrimaryMap is used to assign entity numbers to the primary data for an
  entity.
- EntityMap is a secondary mapping adding additional info.

The split also means that the secondary EntityMap can now behave as if
all keys have a default value. This means that we can get rid of the
annoying ensure() and get_or_default() methods ther were used everywhere
instead of indexing. Just use normal indexing now; non-existent keys
will return the default value.
2017-08-18 16:04:43 -07:00