Commit Graph

69 Commits

Author SHA1 Message Date
Dan Gohman
dbd75483e8 Rename arg_value to param_value for consistency.
Also rename FunctionBuilder's `pristine` to `params_values_initialized`
to avoid confusion with the unrelated `is_pristine` accessor function.
2017-10-25 10:14:10 -07:00
Dan Gohman
fc0671a0cf Avoid dangling references to block params when sealing an unreachable block. 2017-10-25 10:04:18 -07:00
Dan Gohman
fdf2486c0a Handle uninitialized values of type b1 and vector. 2017-10-23 15:23:57 -07:00
Dan Gohman
c93959de7e Fix a bug handling a use_var of a value not defined in the entry block. 2017-10-20 15:55:04 -07:00
Dan Gohman
f4b25ff058 Have FunctionBuilder clear the ILBuilder's state in its drop(). 2017-10-20 11:37:25 -07:00
Jakob Stoklund Olesen
b3fb41087e Use the term "Function parameter" instead of "argument".
Rename the ArgumentType type to AbiParam since it describes the ABI
characteristics of a parameter or return value, not just the value type.

In Signature, rename members argument_types and return_types to "params"
and "returns". Again, they are not just types.

Fix a couple lingering references to "EBB arguments".
2017-10-19 17:39:23 -07:00
Jakob Stoklund Olesen
921bcc6c25 Use the term "EBB parameter" everywhere.
Add EBB parameter and EBB argument to the langref glossary to clarify
the distinction between formal EBB parameter values and arguments passed
to branches.

- Replace "ebb_arg" with "ebb_param" in function names that deal with
  EBB parameters.
- Rename the ValueDef variants to Result and Param.
- A bunch of other small langref fixes.

No functional changes intended.
2017-10-19 16:17:09 -07:00
Dan Gohman
1a1774af15 Fix a typo in a comment. 2017-10-19 12:59:10 -07:00
Dan Gohman
36585ddc4f Wasm control stack entries only need the number of return types.
This eliminates heap-allocated vectors which stored the actual types.
2017-09-25 13:05:29 -07:00
Jakob Stoklund Olesen
85e4e9f511 Assign source locations when translating WebAssembly to Cretonne.
The source locations are byte code offsets relative to the beginning of
the function.
2017-09-21 14:37:54 -07:00
Dan Gohman
16eb689dd1 Use Self instead of repeating the type name. 2017-09-21 14:21:30 -07:00
Dan Gohman
e5e4b59683 Tidy up some asserts. 2017-09-21 14:21:30 -07:00
Dan Gohman
e75558b800 Fix spelling of "adjustment". 2017-09-21 14:21:30 -07:00
Dan Gohman
dda8293668 Restructure code to avoid a heap allocation. 2017-09-21 14:21:30 -07:00
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