Skip to content

Commit 50d44b2

Browse files
committed
Merge pull request #1903 from pguyot/w42/armv6m-use-literal-pool-to-reduce-binary-size
JIT (armv6m): use literal pool to reduce binary size Continuation of: - #1901 These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 2925c21 + 5f2b6ce commit 50d44b2

File tree

10 files changed

+850
-358
lines changed

10 files changed

+850
-358
lines changed

libs/estdlib/src/code_server.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ load(Module) ->
164164
code_server:literal_resolver(Module, Index)
165165
end,
166166
TypeResolver = fun(Index) -> code_server:type_resolver(Module, Index) end,
167-
Stream0 = jit:stream(jit_mmap_size(byte_size(Code))),
168-
{BackendModule, BackendState0} = jit:backend(Stream0),
167+
{StreamModule, Stream0} = jit:stream(jit_mmap_size(byte_size(Code))),
168+
{BackendModule, BackendState0} = jit:backend(StreamModule, Stream0),
169169
{LabelsCount, BackendState1} = jit:compile(
170170
Code,
171171
AtomResolver,
@@ -175,7 +175,8 @@ load(Module) ->
175175
BackendState0
176176
),
177177
Stream1 = BackendModule:stream(BackendState1),
178-
code_server:set_native_code(Module, LabelsCount, Stream1),
178+
Stream2 = StreamModule:flush(Stream1),
179+
code_server:set_native_code(Module, LabelsCount, Stream2),
179180
End = erlang:system_time(millisecond),
180181
io:format("~B ms (bytecode: ~B bytes, native code: ~B bytes)\n", [
181182
End - Start, byte_size(Code), BackendModule:offset(BackendState1)

libs/jit/src/jit.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
-export([
2424
stream/1,
25-
backend/1,
25+
backend/2,
2626
beam_chunk_header/3,
2727
compile/6
2828
]).
@@ -148,7 +148,8 @@ compile(
148148
},
149149
{State1, MSt2} = first_pass(Opcodes, MMod, MSt1, State0),
150150
MSt3 = second_pass(MMod, MSt2, State1),
151-
{LabelsCount, MSt3};
151+
MSt4 = MMod:flush(MSt3),
152+
{LabelsCount, MSt4};
152153
compile(
153154
<<16:32, 0:32, OpcodeMax:32, _LabelsCount:32, _FunctionsCount:32, _Opcodes/binary>>,
154155
_AtomResolver,
@@ -3852,7 +3853,7 @@ variant() ->
38523853

38533854
%% @doc Instantiate backend for this platform
38543855
%% @return A tuple with the backend module and the backend state for this platform
3855-
backend({StreamModule, Stream}) ->
3856+
backend(StreamModule, Stream) ->
38563857
BackendModule = ?MODULE:backend_module(),
38573858
Variant = ?MODULE:variant(),
38583859
BackendState = BackendModule:new(Variant, StreamModule, Stream),

libs/jit/src/jit_aarch64.erl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
new/3,
2626
stream/1,
2727
offset/1,
28+
flush/1,
2829
debugger/1,
2930
used_regs/1,
3031
available_regs/1,
@@ -259,6 +260,16 @@ stream(#state{stream = Stream}) ->
259260
offset(#state{stream_module = StreamModule, stream = Stream}) ->
260261
StreamModule:offset(Stream).
261262

263+
%%-----------------------------------------------------------------------------
264+
%% @doc Flush the current state (unused on aarch64)
265+
%% @end
266+
%% @param State current backend state
267+
%% @return The flushed state
268+
%%-----------------------------------------------------------------------------
269+
-spec flush(state()) -> state().
270+
flush(#state{} = State) ->
271+
State.
272+
262273
%%-----------------------------------------------------------------------------
263274
%% @doc Emit a debugger of breakpoint instruction. This is used for debugging
264275
%% and not in production.

0 commit comments

Comments
 (0)