Skip to content

Commit c6042c4

Browse files
authored
Sync with internal feature (#204)
1 parent 6523868 commit c6042c4

File tree

8 files changed

+65
-21
lines changed

8 files changed

+65
-21
lines changed

core/config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ enum {
109109
#define WASM_ENABLE_ABS_LABEL_ADDR 0
110110
#endif
111111

112+
/* Enable opcode counter or not */
113+
#ifndef WASM_ENABLE_OPCODE_COUNTER
114+
#define WASM_ENABLE_OPCODE_COUNTER 0
115+
#endif
116+
112117
/* Heap and stack profiling */
113118
#define BEIHAI_ENABLE_MEMORY_PROFILING 0
114119

core/iwasm/aot/arch/aot_reloc_x86_64.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,22 @@ apply_relocation(AOTModule *module,
149149
}
150150
case R_X86_64_PLT32:
151151
{
152-
uint8 *plt = (uint8*)module->code + module->code_size - get_plt_table_size()
153-
+ get_plt_item_size() * symbol_index;
154-
intptr_t target_addr = (intptr_t) /* L + A - P */
155-
(plt + reloc_addend
156-
- (target_section_addr + reloc_offset));
152+
uint8 *plt;
153+
intptr_t target_addr = 0;
157154

158155
CHECK_RELOC_OFFSET(sizeof(int32));
159156

160-
if (symbol_index < 0) {
161-
set_error_buf(error_buf, error_buf_size,
162-
"AOT module load failed: "
163-
"invalid symbol index for relocation");
164-
return false;
157+
if (symbol_index >= 0) {
158+
plt = (uint8*)module->code + module->code_size - get_plt_table_size()
159+
+ get_plt_item_size() * symbol_index;
160+
target_addr = (intptr_t) /* L + A - P */
161+
(plt + reloc_addend
162+
- (target_section_addr + reloc_offset));
163+
}
164+
else {
165+
target_addr = (intptr_t) /* L + A - P */
166+
((uint8*)symbol_addr + reloc_addend
167+
- (target_section_addr + reloc_offset));
165168
}
166169

167170
if ((int32)target_addr != target_addr) {

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
818818

819819
#if WASM_ENABLE_LABELS_AS_VALUES != 0
820820
#define HANDLE_OPCODE(op) &&HANDLE_##op
821-
DEFINE_GOTO_TABLE (handle_table);
821+
DEFINE_GOTO_TABLE (const void *, handle_table);
822822
#undef HANDLE_OPCODE
823823
#endif
824824

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,42 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
697697
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
698698
}
699699

700+
#if WASM_ENABLE_OPCODE_COUNTER != 0
701+
typedef struct OpcodeInfo {
702+
char *name;
703+
uint64 count;
704+
} OpcodeInfo;
705+
706+
#define HANDLE_OPCODE(op) { #op, 0 }
707+
DEFINE_GOTO_TABLE (OpcodeInfo, opcode_table);
708+
#undef HANDLE_OPCODE
709+
710+
static void
711+
wasm_interp_dump_op_count()
712+
{
713+
uint32 i;
714+
uint64 total_count = 0;
715+
for (i = 0; i < WASM_OP_IMPDEP; i++)
716+
total_count += opcode_table[i].count;
717+
718+
printf("total opcode count: %ld\n", total_count);
719+
for (i = 0; i < WASM_OP_IMPDEP; i++)
720+
if (opcode_table[i].count > 0)
721+
printf("\t\t%s count:\t\t%ld,\t\t%.2f%%\n",
722+
opcode_table[i].name, opcode_table[i].count,
723+
opcode_table[i].count * 100.0f / total_count);
724+
}
725+
#endif
726+
727+
700728
#if WASM_ENABLE_LABELS_AS_VALUES != 0
701729

702730
//#define HANDLE_OP(opcode) HANDLE_##opcode:printf(#opcode"\n");h_##opcode
731+
#if WASM_ENABLE_OPCODE_COUNTER != 0
732+
#define HANDLE_OP(opcode) HANDLE_##opcode:opcode_table[opcode].count++;h_##opcode
733+
#else
703734
#define HANDLE_OP(opcode) HANDLE_##opcode
735+
#endif
704736
#if WASM_ENABLE_FAST_INTERP == 0
705737
#define FETCH_OPCODE_AND_DISPATCH() goto *handle_table[*frame_ip++]
706738
#else
@@ -765,7 +797,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
765797

766798
#if WASM_ENABLE_LABELS_AS_VALUES != 0
767799
#define HANDLE_OPCODE(op) &&HANDLE_##op
768-
DEFINE_GOTO_TABLE (handle_table);
800+
DEFINE_GOTO_TABLE (const void*, handle_table);
769801
#undef HANDLE_OPCODE
770802
#if WASM_ENABLE_FAST_INTERP != 0
771803
if (exec_env == NULL) {
@@ -2287,4 +2319,7 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst,
22872319

22882320
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
22892321
FREE_FRAME(exec_env, frame);
2322+
#if WASM_ENABLE_OPCODE_COUNTER != 0
2323+
wasm_interp_dump_op_count();
2324+
#endif
22902325
}

core/iwasm/interpreter/wasm_opcode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ typedef enum WASMOpcode {
262262
*/
263263
#define WASM_INSTRUCTION_NUM 256
264264

265-
#define DEFINE_GOTO_TABLE(_name) \
266-
static const void *_name[WASM_INSTRUCTION_NUM] = { \
265+
#define DEFINE_GOTO_TABLE(type, _name) \
266+
static type _name[WASM_INSTRUCTION_NUM] = { \
267267
HANDLE_OPCODE (WASM_OP_UNREACHABLE), /* 0x00 */ \
268268
HANDLE_OPCODE (WASM_OP_NOP), /* 0x01 */ \
269269
HANDLE_OPCODE (WASM_OP_BLOCK), /* 0x02 */ \

core/shared/platform/linux-sgx/sgx_platform.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void* os_mmap(void *hint, unsigned int size, int prot, int flags)
9292

9393
ret = sgx_alloc_rsrv_mem(alignedSize);
9494
if (ret == NULL) {
95-
os_printf_sgx("os_mmap(size=%d, alignedSize=%d, prot=0x%x) failed.",size, alignedSize, prot);
95+
os_printf("os_mmap(size=%d, alignedSize=%d, prot=0x%x) failed.",size, alignedSize, prot);
9696
return NULL;
9797
}
9898
if (prot & MMAP_PROT_READ)
@@ -103,7 +103,7 @@ void* os_mmap(void *hint, unsigned int size, int prot, int flags)
103103
mprot |= SGX_PROT_EXEC;
104104
st = sgx_tprotect_rsrv_mem(ret, alignedSize, mprot);
105105
if (st != SGX_SUCCESS){
106-
os_printf_sgx("os_mmap(size=%d,prot=0x%x) failed to set protect.",size, prot);
106+
os_printf("os_mmap(size=%d,prot=0x%x) failed to set protect.",size, prot);
107107
sgx_free_rsrv_mem(ret, alignedSize);
108108
return NULL;
109109
}
@@ -134,7 +134,8 @@ int os_mprotect(void *addr, uint32 size, int prot)
134134
if (prot & MMAP_PROT_EXEC)
135135
mprot |= SGX_PROT_EXEC;
136136
st = sgx_tprotect_rsrv_mem(addr, size, mprot);
137-
if (st != SGX_SUCCESS) os_printf_sgx("os_mprotect(addr=0x%lx,size=%d,prot=0x%x) failed.", addr, size, prot);
137+
if (st != SGX_SUCCESS)
138+
os_printf("os_mprotect(addr=0x%lx,size=%d,prot=0x%x) failed.", addr, size, prot);
138139

139140
return (st == SGX_SUCCESS? 0:-1);
140141
#else

product-mini/platforms/linux/build_llvm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ DEPS_DIR=${PWD}/../../../core/deps
88
cd ${DEPS_DIR}
99
if [ ! -d "llvm" ]; then
1010
echo "Clone llvm to core/deps/ .."
11-
git clone --depth 1 https://github.com/llvm-mirror/llvm.git
11+
git clone --depth 1 https://github.com/llvm/llvm-project.git llvm
1212
fi
1313

1414
cd llvm
@@ -24,7 +24,7 @@ if [ ! -f bin/llvm-lto ]; then
2424

2525
echo "Build llvm with" ${CORE_NUM} "cores"
2626

27-
cmake .. \
27+
cmake ../llvm \
2828
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
2929
-DCMAKE_BUILD_TYPE:STRING="Release" \
3030
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \

wamr-compiler/build_llvm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ DEPS_DIR=${PWD}/../core/deps
88
cd ${DEPS_DIR}
99
if [ ! -d "llvm" ]; then
1010
echo "Clone llvm to core/deps/ .."
11-
git clone --depth 1 https://github.com/llvm-mirror/llvm.git
11+
git clone --depth 1 https://github.com/llvm/llvm-project.git llvm
1212
fi
1313

1414
cd llvm
@@ -24,7 +24,7 @@ if [ ! -f bin/llvm-lto ]; then
2424

2525
echo "Build llvm with" ${CORE_NUM} "cores"
2626

27-
cmake .. \
27+
cmake ../llvm \
2828
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
2929
-DCMAKE_BUILD_TYPE:STRING="Release" \
3030
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \

0 commit comments

Comments
 (0)