aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
AgeCommit message (Collapse)Author
2019-02-20beam_validator: Refactor stack trimmingJohn Högberg
2019-02-20beam_validator: Track definitions of all termsJohn Högberg
2019-02-20beam_validator: Remove special handling of map_get/is_map_keyJohn Högberg
Neither can be used for type subtraction, so the default BIF handler suits them just fine.
2019-02-20beam_validator: Refactor select_tuple_arityJohn Högberg
2019-02-20beam_validator: Treat select_val as a series of '=:='John Högberg
2019-02-20beam_validator: Treat all bs_get instructions as extractionsJohn Högberg
While this is strictly only relevant for bs_get_binary2, we should never build anything while matching a message, so it ought to be safe to remove this last raw use of propagate_fragility.
2019-02-20beam_validator: Separate BIF/call types more clearlyJohn Högberg
2019-02-20beam_validator: Assert that no tuple elements are out of boundsJohn Högberg
2019-02-20beam_validator: Get rid of the last uses of set_aliased_typeJohn Högberg
Granted, it's replaced with a thin wrapper, but it'll simplify migration to the new type format.
2019-02-20beam_validator: Minor cosmetic refactoringJohn Högberg
2019-02-20erl_bifs: Add a note to the comment for is_pure/3Björn Gustavsson
2019-02-20Correct confusing comment in beam_ssa_typeBjörn Gustavsson
2019-02-20Improve optimization of switchesBjörn Gustavsson
Part of the switch optimization done by `ssa_opt_sw` can be better done in `beam_ssa_type`.
2019-02-20Evaluate pure BIFs with literal argumentsBjörn Gustavsson
2019-02-20Refactor optimization of Bool =:= trueBjörn Gustavsson
Refactor optimization of `Bool =:= true` to make the code somewhat simpler, as well as potentially apply the optimization in more cases.
2019-02-20Always make andalso/orelse right-associativeBjörn Gustavsson
Always rewriting left-associative andalso/orelse to right-associative will not change the code (except in very rare cases), but it will make sure that the transformation is tested.
2019-02-19Do the destructive setelement optimization in SSABjörn Gustavsson
The expansion of record field updates, when more than one field is updated, but not a majority of the fields, will create a sequence of calls to `erlang:setelement(Index, Value, Tuple)` where Tuple in the first call is the original record tuple, and in the subsequent calls Tuple is the result of the previous call. Furthermore, all Index values are constant positive integers, and the first call to `setelement` will have the greatest index. Thus all the following calls do not actually need to test at run-time whether Tuple has type tuple, nor that the index is within the tuple bounds. Since OTP R7, the `sys_core_dsetel` pass, run as the very last Core Erlang pass, has optimized this sequence of `setelement` calls to use a special destructive version of `setelement` (called `set_tuple_element`) for all but the very first `setelement` in the sequence. It turns out that the presence of the `set_tuple_element` in SSA code is awkward and can prevent or complicate type analysis and aggressive optimizations. Therefore, this commit removes the `sys_core_dsetel` pass and reimplements it for SSA code. The optimization will be done in the `beam_ssa_pre_codegen` pass (that is, just before code generation and after running all other SSA code optimization passes). In most cases, the resulting BEAM code is identical to previous code. For a few modules, the BEAM code is actually slightly better, with smaller stack frames.
2019-02-19Merge branch 'john/compiler/cuddle-validator'John Högberg
* john/compiler/cuddle-validator: compiler: Allow disabling SSA passes in -compile() directives beam_validator: Infer types from result of all type test BIFs beam_validator: Infer BIF argument types beam_validator: type_test in BIFs that only fail on invalid types beam_validator: Simplify complex branches beam_validator: Explain why verify_get_map wipes dst registers beam_validator: fconv means we have a number beam_validator: Simplify update_ne/eq_types beam_validator: Remove pointless fragility propagation beam_validator: Misc cosmetic refactoring
2019-02-18compiler: Allow disabling SSA passes in -compile() directivesJohn Högberg
This fixes compiling against older OTP versions with the +r?VSN options, which often expand to disabling certain SSA passes to avoid new instructions.
2019-02-18beam_validator: Infer types from result of all type test BIFsJohn Högberg
The compiler will usually optimize these into test instructions, but they'll nevertheless pop up in some cases.
2019-02-18beam_validator: Infer BIF argument typesJohn Högberg
If we know that a BIF will badarg unless its arguments have certain types, we can infer that we have at least those types on success. Note that we can't do this in the general case as the BIF could fail for reasons other than bad arguments.
2019-02-15inline_SUITE: Make coverage/1 test cheaperBjörn Gustavsson
The sole purpose of inline_SUITE:coverage/1 is to ensure that all lines are covered in sys_core_inline. Do that in a cheaper way.
2019-02-15Remove compile_SUITE:big_file/1Björn Gustavsson
This test case does not test anything unique that is not tested by other test cases.
2019-02-15Add test modules that disable all SSA optimizationsBjörn Gustavsson
This makes sure that the SSA optimizations are not essential and may help to cover more code in beam_ssa_pre_codegen and beam_ssa_codegen.
2019-02-15Cover erl_bifs.erlBjörn Gustavsson
2019-02-15Remove attempt to handle all bs_match_string instructionsBjörn Gustavsson
eb0b8da6e816 started to use a binary instead of a string in bs_match_string instructions. Remove a clause that attempts to handle the old form of bs_match_string from old .S files. This is pointless, because an old .S file is likely to contain a bs_context_to_binary instruction as well. The bs_context_to_binary is no longer recognized by `beam_validator`, so those old .S files will not work anyway.
2019-02-15Cover exception throwing code in beam_ssa_optBjörn Gustavsson
2019-02-15Parallelize test of listing filesBjörn Gustavsson
2019-02-15Don't limit the number of processes when running coverBjörn Gustavsson
With the recent update to cover to use the `counters` modules, there is no longer any reason to limit the number of parallel processes when running `cover`.
2019-02-15Merge branch 'bjorn/compiler/beam_ssa_opt'Björn Gustavsson
* bjorn/compiler/beam_ssa_opt: Make sure that beam_ssa_opt optimizes all functions
2019-02-15Merge branch 'maint'Björn Gustavsson
* maint: Add persistent_term:get(Key, DefaultValue) Make dialyzer faster for left-associative andalso/orelse expressions
2019-02-15Make sure that beam_ssa_opt optimizes all functionsBjörn Gustavsson
The function `get_call_order_po/2` did not always include all functions in a module. The method it used was to first find all leave functions (functions not calling any other function), and then find all others functions that called any of the leave functions either directly or indirectly. Functions that did not call a leave function (directly or indirectly) would not be included in the list of functions to optimize. Reimplement `get_call_order_po/2` to use the standard algorithm for constructing a list of nodes in reverse postorder and then reverse that list.
2019-02-14Merge branch 'bjorn/compiler/improve-move-elimination'Björn Gustavsson
* bjorn/compiler/improve-move-elimination: beam_jump: Improve elimination of redundant moves
2019-02-13Make dialyzer faster for left-associative andalso/orelse expressionsBjörn Gustavsson
https://bugs.erlang.org/browse/ERL-851
2019-02-11beam_jump: Improve elimination of redundant movesBjörn Gustavsson
2019-02-11compiler tests: Restrict cover to run on the local nodeBjörn Gustavsson
This change saves about about a minute when running the cover-compiled compiler tests.
2019-02-11Merge pull request #2134 from bjorng/bjorn/compiler/propagate-noneBjörn Gustavsson
beam_ssa_type: Propagate the 'none' type from calls
2019-02-11beam_ssa_type: Propagate the 'none' type from callsBjörn Gustavsson
Consider this pseudo code: f(...) -> Val = case Expr of ... -> ... ; ... -> ... ; ... -> my_abort(something_went_wrong) end, %% Here follows code that uses Val. . . . my_abort(Reason) -> throw({error,Reason}). The first two clauses in the case will probably provide some information about the type of the variable `Var`, information that would be useful for optimizing the code that follows the case. However, the third clause would ruin everything. The call to `my_abort/1` could return anything, and thus `Val` could also have any type. 294d66a295f6 introduced module-level type analysis, which will in general keep track of the return type of a local function call. However, it does not improve the optimization for this specific function. When a function never returns, that is, when its type is `none`, it does not propagate the `none` type, but instead pretends that the return type is `any`. This commit extends the handling of functions that don't return to properly handle the `none` type. Any instructions that directly follows the function that does not return will be discarded, and the call will be rewritten to a tail-recursive call. For this specific example, it means that the type for `Val` deduced from the first two clauses will be retained and can be used for optimizing the code after the case.
2019-02-08beam_validator: type_test in BIFs that only fail on invalid typesJohn Högberg
2019-02-08beam_validator: Simplify complex branchesJohn Högberg
Branches where the state is altered on both success and failure are hard to follow and require juggling the current state, so this commit adds a helper function to make it easier.
2019-02-08beam_validator: Explain why verify_get_map wipes dst registersJohn Högberg
2019-02-08beam_validator: fconv means we have a numberJohn Högberg
2019-02-08beam_validator: Simplify update_ne/eq_typesJohn Högberg
2019-02-08beam_validator: Remove pointless fragility propagationJohn Högberg
set_aliased_type already preserves fragility when updating the type of a fragile register.
2019-02-08beam_validator: Misc cosmetic refactoringJohn Högberg
2019-02-07Merge pull request #2135 from bjorng/bjorn/compiler/optimize-dominatorsBjörn Gustavsson
Optimize ssa_opt_sink for huge functions
2019-02-06Optimize ssa_opt_sink for huge functionsBjörn Gustavsson
The ssa_opt_sink optimization of beam_ssa_opt could get very slow for certain huge functions. 9a190cae9bd7 partly addressed this issue by terminating the optimization early if there happened to be no get_tuple_element instructions at all in the function. This commit addresses the issue more directly by making the dominator calculation in beam_ssa:dominators/1 more efficient. The same algorithm as before is used, but it is implemented in a more efficient way based on the ideas in "A Simple, Fast Dominance Algorithm" (http://www.hipersoft.rice.edu/grads/publications/dom14.pdf). As well as being more efficient, the new implementation also gives an explicit representation of the dominator tree, which makes it possible to simplify and optimize the ssa_opt_sink optimization.
2019-02-05beam_ssa_type: Track the types of tuple elementsJohn Högberg
Prior to 294d66a295f6c2101fe3c2da630979ad4e736c08 there wasn't much point to keeping track of tuple element types; they were only known when we had inserted or extracted values from a tuple, and in neither case was it likely that we'd extract the same values again. It makes a lot more sense to do so now that type optimizations are applied across functions; if we return a tuple it's very likely that its elements will be extracted soon after, and knowing their types lets us eliminate more type checks. Co-authored-by: Björn Gustavsson <[email protected]>
2019-02-04beam_ssa_type: Infer types based on the result of #b_switch{}John Högberg
2019-02-04beam_ssa_opt: Fix function name printing in sub-pass crash dumpJohn Högberg