Skip to content

Commit a182926

Browse files
authored
Refactor interpreter/AOT module instance layout (#1559)
Refactor the layout of interpreter and AOT module instance: - Unify the interp/AOT module instance, use the same WASMModuleInstance/ WASMMemoryInstance/WASMTableInstance data structures for both interpreter and AOT - Make the offset of most fields the same in module instance for both interpreter and AOT, append memory instance structure, global data and table instances to the end of module instance for interpreter mode (like AOT mode) - For extra fields in WASM module instance, use WASMModuleInstanceExtra to create a field `e` for interpreter - Change the LLVM JIT module instance creating process, LLVM JIT uses the WASM module and module instance same as interpreter/Fast-JIT mode. So that Fast JIT and LLVM JIT can access the same data structures, and make it possible to implement the Multi-tier JIT (tier-up from Fast JIT to LLVM JIT) in the future - Unify some APIs: merge some APIs for module instance and memory instance's related operations (only implement one copy) Note that the AOT ABI is same, the AOT file format, AOT relocation types, how AOT code accesses the AOT module instance and so on are kept unchanged. Refer to: #1384
1 parent dc4dcc3 commit a182926

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3790
-3274
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ tests/wamr-test-suites/workspace
2828

2929
samples/socket-api/wasm-src/inc/pthread.h
3030

31-
**/__pycache__
31+
**/__pycache__
32+
33+
# ignore benchmarks generated
34+
tests/benchmarks/coremark/coremark*

build-scripts/config_common.cmake

+26-31
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
string(TOUPPER ${WAMR_BUILD_TARGET} WAMR_BUILD_TARGET)
55

6-
76
# Add definitions for the build target
87
if (WAMR_BUILD_TARGET STREQUAL "X86_64")
98
add_definitions(-DBUILD_TARGET_X86_64)
@@ -85,33 +84,29 @@ endif ()
8584
endif ()
8685

8786
if (WAMR_BUILD_JIT EQUAL 1)
88-
if (WAMR_BUILD_AOT EQUAL 1)
89-
add_definitions("-DWASM_ENABLE_JIT=1")
90-
if (NOT WAMR_BUILD_LAZY_JIT EQUAL 0)
91-
# Enable Lazy JIT by default
92-
set (WAMR_BUILD_LAZY_JIT 1)
93-
add_definitions("-DWASM_ENABLE_LAZY_JIT=1")
87+
add_definitions("-DWASM_ENABLE_JIT=1")
88+
if (NOT WAMR_BUILD_LAZY_JIT EQUAL 0)
89+
# Enable Lazy JIT by default
90+
set (WAMR_BUILD_LAZY_JIT 1)
91+
add_definitions("-DWASM_ENABLE_LAZY_JIT=1")
92+
endif ()
93+
if (NOT DEFINED LLVM_DIR)
94+
set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
95+
set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build")
96+
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
97+
set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/win32build")
9498
endif ()
95-
if (NOT DEFINED LLVM_DIR)
96-
set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
97-
set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build")
98-
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
99-
set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/win32build")
100-
endif ()
101-
if (NOT EXISTS "${LLVM_BUILD_ROOT}")
99+
if (NOT EXISTS "${LLVM_BUILD_ROOT}")
102100
message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_BUILD_ROOT}")
103-
endif ()
104-
set (CMAKE_PREFIX_PATH "${LLVM_BUILD_ROOT};${CMAKE_PREFIX_PATH}")
105101
endif ()
106-
find_package(LLVM REQUIRED CONFIG)
107-
include_directories(${LLVM_INCLUDE_DIRS})
108-
add_definitions(${LLVM_DEFINITIONS})
109-
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
110-
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
111-
else ()
112-
set (WAMR_BUILD_JIT 0)
113-
message ("-- WAMR JIT disabled due to WAMR AOT is disabled")
114-
endif ()
102+
set (CMAKE_PREFIX_PATH "${LLVM_BUILD_ROOT};${CMAKE_PREFIX_PATH}")
103+
set (LLVM_DIR ${LLVM_BUILD_ROOT}/lib/cmake/llvm)
104+
endif ()
105+
find_package(LLVM REQUIRED CONFIG)
106+
include_directories(${LLVM_INCLUDE_DIRS})
107+
add_definitions(${LLVM_DEFINITIONS})
108+
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
109+
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
115110
else ()
116111
unset (LLVM_AVAILABLE_LIBS)
117112
endif ()
@@ -139,9 +134,6 @@ message (" Build as target ${WAMR_BUILD_TARGET}")
139134
message (" CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
140135
if (WAMR_BUILD_INTERP EQUAL 1)
141136
message (" WAMR Interpreter enabled")
142-
elseif (WAMR_BUILD_JIT EQUAL 1)
143-
set (WAMR_BUILD_INTERP 1)
144-
message (" WAMR Interpreter enabled due to WAMR JIT is enabled")
145137
else ()
146138
message (" WAMR Interpreter disabled")
147139
endif ()
@@ -150,16 +142,19 @@ if (WAMR_BUILD_AOT EQUAL 1)
150142
else ()
151143
message (" WAMR AOT disabled")
152144
endif ()
145+
if (WAMR_BUILD_FAST_JIT EQUAL 1)
146+
message (" WAMR Fast JIT enabled")
147+
else ()
148+
message (" WAMR Fast JIT disabled")
149+
endif ()
153150
if (WAMR_BUILD_JIT EQUAL 1)
154151
if (WAMR_BUILD_LAZY_JIT EQUAL 1)
155152
message (" WAMR LLVM Orc Lazy JIT enabled")
156153
else ()
157154
message (" WAMR LLVM MC JIT enabled")
158155
endif ()
159-
elseif (WAMR_BUILD_FAST_JIT EQUAL 1)
160-
message (" WAMR Fast JIT enabled")
161156
else ()
162-
message (" WAMR JIT disabled")
157+
message (" WAMR LLVM JIT disabled")
163158
endif ()
164159
if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
165160
message (" Libc builtin enabled")

build-scripts/runtime_lib.cmake

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright (C) 2019 Intel Corporation. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4-
54
if (NOT DEFINED WAMR_ROOT_DIR)
65
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../)
76
endif ()
@@ -50,25 +49,30 @@ if (NOT DEFINED WAMR_BUILD_TARGET)
5049
endif ()
5150

5251
################ optional according to settings ################
53-
if (WAMR_BUILD_INTERP EQUAL 1 OR WAMR_BUILD_JIT EQUAL 1
54-
OR WAMR_BUILD_FAST_JIT EQUAL 1)
55-
if (WAMR_BUILD_FAST_JIT EQUAL 1 OR WAMR_BUILD_JIT EQUAL 1)
56-
set (WAMR_BUILD_FAST_INTERP 0)
57-
endif ()
58-
include (${IWASM_DIR}/interpreter/iwasm_interp.cmake)
52+
if (WAMR_BUILD_FAST_JIT EQUAL 1 OR WAMR_BUILD_JIT EQUAL 1)
53+
# Enable classic interpreter if Fast JIT or LLVM JIT is enabled
54+
set (WAMR_BUILD_INTERP 1)
55+
set (WAMR_BUILD_FAST_INTERP 0)
5956
endif ()
6057

61-
if (WAMR_BUILD_AOT EQUAL 1)
62-
include (${IWASM_DIR}/aot/iwasm_aot.cmake)
63-
if (WAMR_BUILD_JIT EQUAL 1)
64-
include (${IWASM_DIR}/compilation/iwasm_compl.cmake)
65-
endif ()
58+
if (WAMR_BUILD_INTERP EQUAL 1)
59+
include (${IWASM_DIR}/interpreter/iwasm_interp.cmake)
6660
endif ()
6761

68-
if (NOT WAMR_BUILD_JIT EQUAL 1 AND WAMR_BUILD_FAST_JIT EQUAL 1)
62+
if (WAMR_BUILD_FAST_JIT EQUAL 1)
6963
include (${IWASM_DIR}/fast-jit/iwasm_fast_jit.cmake)
7064
endif ()
7165

66+
if (WAMR_BUILD_JIT EQUAL 1)
67+
# Enable AOT if LLVM JIT is enabled
68+
set (WAMR_BUILD_AOT 1)
69+
include (${IWASM_DIR}/compilation/iwasm_compl.cmake)
70+
endif ()
71+
72+
if (WAMR_BUILD_AOT EQUAL 1)
73+
include (${IWASM_DIR}/aot/iwasm_aot.cmake)
74+
endif ()
75+
7276
if (WAMR_BUILD_APP_FRAMEWORK EQUAL 1)
7377
include (${APP_FRAMEWORK_DIR}/app_framework.cmake)
7478
include (${SHARED_DIR}/coap/lib_coap.cmake)

core/iwasm/aot/aot_intrinsic.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define _AOT_INTRINSIC_H
88

99
#include "aot_runtime.h"
10-
#if WASM_ENABLE_WAMR_COMPILER != 0
10+
#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
1111
#include "aot_llvm.h"
1212
#endif
1313

0 commit comments

Comments
 (0)