Skip to content

Commit d13a52f

Browse files
committed
Fixes from first review
1 parent 9ea7ff6 commit d13a52f

14 files changed

Lines changed: 65 additions & 85 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ if (NOT DEFINED WAMR_BUILD_REF_TYPES)
119119
set (WAMR_BUILD_REF_TYPES 1)
120120
endif ()
121121

122-
if (NOT DEFINED WAMR_BUILD_BRANCH_HINTS)
123-
# Enable branch hints by default
124-
set (WAMR_BUILD_BRANCH_HINTS 1)
125-
endif ()
126-
127122
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
128123

129124
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)

build-scripts/SConscript_config

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ if GetDepend(['WAMR_BUILD_REF_TYPES']):
128128
CPPDEFINES += ['WASM_ENABLE_REF_TYPES=1']
129129
print('[WAMR] enable ref types')
130130

131-
if GetDepend(['WAMR_BUILD_BRANCH_HINTS']):
132-
CPPDEFINES += ['WASM_ENABLE_BRANCH_HINTS=1']
133-
print('[WAMR] enable branch hints')
134-
135131
CPPDEFINES += ['BH_MALLOC=wasm_runtime_malloc']
136132
CPPDEFINES += ['BH_FREE=wasm_runtime_free']
137133

build-scripts/config_common.cmake

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,6 @@ if (NOT DEFINED WAMR_BUILD_EXTENDED_CONST_EXPR)
215215
set (WAMR_BUILD_EXTENDED_CONST_EXPR 0)
216216
endif ()
217217

218-
if (NOT DEFINED WAMR_BUILD_BRANCH_HINTS)
219-
set (WAMR_BUILD_BRANCH_HINTS 1)
220-
endif ()
221-
222218
########################################
223219
# Compilation options to marco
224220
########################################
@@ -423,12 +419,6 @@ endif ()
423419
if (WAMR_BUILD_REF_TYPES EQUAL 1)
424420
add_definitions (-DWASM_ENABLE_REF_TYPES=1)
425421
endif ()
426-
if (WAMR_BUILD_BRANCH_HINTS EQUAL 1)
427-
add_definitions (-DWASM_ENABLE_BRANCH_HINTS=1)
428-
message (" branch hints enabled")
429-
else ()
430-
message (" branch hints disabled")
431-
endif ()
432422
if (WAMR_BUILD_GC EQUAL 1)
433423
if (WAMR_TEST_GC EQUAL 1)
434424
message(" GC testing enabled")
@@ -718,7 +708,6 @@ message (
718708
" \"Tail call\" via WAMR_BUILD_TAIL_CALL: ${WAMR_BUILD_TAIL_CALL}\n"
719709
" \"Threads\" via WAMR_BUILD_SHARED_MEMORY: ${WAMR_BUILD_SHARED_MEMORY}\n"
720710
" \"Typed Function References\" via WAMR_BUILD_GC: ${WAMR_BUILD_GC}\n"
721-
" \"Branch Hinting\" via WAMR_BUILD_BRANCH_HINTS: ${WAMR_BUILD_BRANCH_HINTS}\n"
722711
" Unsupported (>= Phase4):\n"
723712
" \"Custom Annotation Syntax in the Text Format\"\n"
724713
" \"Exception handling\"\n"

core/iwasm/aot/aot_loader.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,6 @@ check_feature_flags(char *error_buf, uint32 error_buf_size,
505505
}
506506
#endif
507507

508-
#if WASM_ENABLE_BRANCH_HINTS == 0
509-
if (feature_flags & WASM_ENABLE_BRANCH_HINTS) {
510-
LOG_WARNING(
511-
"branch hints not enabled, but wasm file contains branch hints");
512-
}
513-
#endif
514-
515508
#if WASM_ENABLE_GC == 0
516509
if (feature_flags & WASM_FEATURE_GARBAGE_COLLECTION) {
517510
set_error_buf(error_buf, error_buf_size,

core/iwasm/aot/aot_runtime.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ typedef enum AOTCustomSectionType {
5858
AOT_CUSTOM_SECTION_ACCESS_CONTROL = 2,
5959
AOT_CUSTOM_SECTION_NAME = 3,
6060
AOT_CUSTOM_SECTION_STRING_LITERAL = 4,
61-
AOT_CUSTOM_SECTION_CODE_METADATA = 5,
6261
} AOTCustomSectionType;
6362

6463
typedef struct AOTObjectDataSection {

core/iwasm/compilation/aot.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ aot_create_funcs(const WASMModule *module, uint32 pointer_size)
392392
memset(aot_func, 0, sizeof(AOTFunc));
393393

394394
func_type = aot_func->func_type = func->func_type;
395-
aot_func->func_index = i + module->import_function_count;
396395

397396
/* Resolve function type index */
398397
for (j = 0; j < module->type_count; j++) {

core/iwasm/compilation/aot.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ typedef struct AOTImportFunc {
207207
typedef struct AOTFunc {
208208
AOTFuncType *func_type;
209209
uint32 func_type_index;
210-
uint32 func_index;
211210
uint32 local_count;
212211
uint8 *local_types_wp;
213212
uint16 param_cell_num;

core/iwasm/compilation/aot_compiler.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,16 +1158,7 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index)
11581158

11591159
case WASM_OP_BR_IF:
11601160
{
1161-
// ip is advanced by one byte for the opcode
1162-
#if WASM_ENABLE_BRANCH_HINTS != 0
1163-
uint32 instr_offset =
1164-
(frame_ip - 0x1) - (func_ctx->aot_func->code_body_begin);
1165-
#else
1166-
uint32 instr_offset = 0;
1167-
#endif
1168-
read_leb_uint32(frame_ip, frame_ip_end, br_depth);
1169-
if (!aot_compile_op_br_if(comp_ctx, func_ctx, br_depth,
1170-
&frame_ip, instr_offset))
1161+
if (!aot_compile_op_br_if(comp_ctx, func_ctx, &frame_ip))
11711162
return false;
11721163
break;
11731164
}

core/iwasm/compilation/aot_emit_aot_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,7 @@ aot_emit_init_expr(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
19051905
{
19061906
WASMArrayType *array_type = NULL;
19071907

1908-
bh_assert(expr->u.array_new_default.type_index
1908+
bh_assert(expr->u.unary.v.array_new_default.type_index
19091909
< module->type_count);
19101910
array_type =
19111911
(WASMArrayType *)

core/iwasm/compilation/aot_emit_control.c

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#endif
1313
#include "../aot/aot_runtime.h"
1414
#include "../interpreter/wasm_loader.h"
15+
#include "../common/wasm_loader_common.h"
1516

1617
#if WASM_ENABLE_DEBUG_AOT != 0
1718
#include "debug/dwarf_extractor.h"
@@ -87,11 +88,10 @@ format_block_name(char *name, uint32 name_size, uint32 block_index,
8788
} \
8889
} while (0)
8990

90-
#define BUILD_COND_BR_V(value_if, block_then, block_else, instr) \
91-
do { \
92-
if (instr = LLVMBuildCondBr(comp_ctx->builder, value_if, block_then, \
93-
block_else), \
94-
!instr) { \
91+
#define BUILD_COND_BR_V(value_if, block_then, block_else, instr) \
92+
do { \
93+
if (!(instr = LLVMBuildCondBr(comp_ctx->builder, value_if, block_then, \
94+
block_else))) { \
9595
aot_set_last_error("llvm build cond br failed."); \
9696
goto fail; \
9797
} \
@@ -267,34 +267,30 @@ restore_frame_sp_for_op_end(AOTBlock *block, AOTCompFrame *aot_frame)
267267

268268
#if WASM_ENABLE_BRANCH_HINTS != 0
269269
static void
270-
aot_emit_branch_hint(LLVMContextRef ctxt, AOTFuncContext *func_ctx,
270+
aot_emit_branch_hint(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
271271
uint32 offset, LLVMValueRef br_if_instr)
272272
{
273-
struct WASMCompilationHintBranchHint *hint =
274-
(struct WASMCompilationHintBranchHint *)func_ctx->function_hints;
273+
struct WASMCompilationHint *hint = func_ctx->function_hints;
275274
while (hint != NULL) {
276275
if (hint->type == WASM_COMPILATION_BRANCH_HINT
277-
&& hint->offset == offset) {
276+
&& ((struct WASMCompilationHintBranchHint *)hint)->offset
277+
== offset) {
278278
break;
279279
}
280280
hint = hint->next;
281281
}
282282
if (hint != NULL) {
283-
LLVMMetadataRef header = LLVMMDStringInContext2(
284-
ctxt, "branch_weights", 14 /* strlen("branch_hint") */);
285283
// same weight llvm MDBuilder::createLikelyBranchWeights assigns
286284
const uint32_t likely_weight = (1U << 20) - 1;
287285
const uint32_t unlikely_weight = 1;
288-
LLVMMetadataRef true_w = LLVMValueAsMetadata(LLVMConstInt(
289-
LLVMInt32TypeInContext(ctxt),
290-
hint->is_likely ? likely_weight : unlikely_weight, false));
291-
LLVMMetadataRef false_w = LLVMValueAsMetadata(LLVMConstInt(
292-
LLVMInt32TypeInContext(ctxt),
293-
hint->is_likely ? unlikely_weight : likely_weight, false));
294-
LLVMMetadataRef mds[] = { header, true_w, false_w };
295-
LLVMMetadataRef md = LLVMMDNodeInContext2(ctxt, mds, 3);
296-
LLVMValueRef md_val = LLVMMetadataAsValue(ctxt, md);
297-
LLVMSetMetadata(br_if_instr, LLVMGetMDKindID("prof", 4), md_val);
286+
aot_set_cond_br_weights(
287+
comp_ctx, br_if_instr,
288+
((struct WASMCompilationHintBranchHint *)hint)->is_likely
289+
? likely_weight
290+
: unlikely_weight,
291+
((struct WASMCompilationHintBranchHint *)hint)->is_likely
292+
? unlikely_weight
293+
: likely_weight);
298294
}
299295
}
300296
#endif
@@ -723,8 +719,7 @@ aot_compile_op_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
723719
block->llvm_else_block, br_if_val);
724720
const uint32 off =
725721
*p_frame_ip - func_ctx->aot_func->code_body_begin;
726-
aot_emit_branch_hint(comp_ctx->context, func_ctx, off,
727-
br_if_val);
722+
aot_emit_branch_hint(comp_ctx, func_ctx, off, br_if_val);
728723
#else
729724
BUILD_COND_BR(value, block->llvm_entry_block,
730725
block->llvm_else_block);
@@ -738,8 +733,7 @@ aot_compile_op_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
738733
block->llvm_end_block, br_if_val);
739734
const uint32 off =
740735
*p_frame_ip - func_ctx->aot_func->code_body_begin;
741-
aot_emit_branch_hint(comp_ctx->context, func_ctx, off,
742-
br_if_val);
736+
aot_emit_branch_hint(comp_ctx, func_ctx, off, br_if_val);
743737
#else
744738
BUILD_COND_BR(value, block->llvm_entry_block,
745739
block->llvm_end_block);
@@ -1090,8 +1084,7 @@ aot_compile_op_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
10901084

10911085
static bool
10921086
aot_compile_conditional_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
1093-
uint32 br_depth, LLVMValueRef value_cmp,
1094-
uint8 **p_frame_ip, uint32 off)
1087+
LLVMValueRef value_cmp, uint8 **p_frame_ip)
10951088
{
10961089
AOTBlock *block_dst;
10971090
LLVMValueRef value, *values = NULL;
@@ -1100,6 +1093,17 @@ aot_compile_conditional_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
11001093
uint32 i, param_index, result_index;
11011094
uint64 size;
11021095

1096+
// ip is advanced by one byte for the opcode
1097+
#if WASM_ENABLE_BRANCH_HINTS != 0
1098+
uint32 instr_offset =
1099+
(*p_frame_ip - 0x1) - (func_ctx->aot_func->code_body_begin);
1100+
#else
1101+
uint32 instr_offset = 0;
1102+
#endif
1103+
uint64 br_depth;
1104+
if (!read_leb(p_frame_ip, *p_frame_ip + 5, 32, false, &br_depth, NULL, 0))
1105+
return false;
1106+
11031107
if (!(block_dst = get_target_block(func_ctx, br_depth))) {
11041108
return false;
11051109
}
@@ -1176,7 +1180,7 @@ aot_compile_conditional_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
11761180
LLVMValueRef br_if_val = NULL;
11771181
BUILD_COND_BR_V(value_cmp, block_dst->llvm_entry_block,
11781182
llvm_else_block, br_if_val);
1179-
aot_emit_branch_hint(comp_ctx->context, func_ctx, off, br_if_val);
1183+
aot_emit_branch_hint(comp_ctx, func_ctx, instr_offset, br_if_val);
11801184
#else
11811185
BUILD_COND_BR(value_cmp, block_dst->llvm_entry_block,
11821186
llvm_else_block);
@@ -1227,7 +1231,7 @@ aot_compile_conditional_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
12271231
LLVMValueRef br_if_val = NULL;
12281232
BUILD_COND_BR_V(value_cmp, block_dst->llvm_end_block,
12291233
llvm_else_block, br_if_val);
1230-
aot_emit_branch_hint(comp_ctx->context, func_ctx, off, br_if_val);
1234+
aot_emit_branch_hint(comp_ctx, func_ctx, instr_offset, br_if_val);
12311235
#else
12321236
BUILD_COND_BR(value_cmp, block_dst->llvm_end_block,
12331237
llvm_else_block);
@@ -1255,14 +1259,14 @@ aot_compile_conditional_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
12551259

12561260
bool
12571261
aot_compile_op_br_if(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
1258-
uint32 br_depth, uint8 **p_frame_ip, uint32 off)
1262+
uint8 **p_frame_ip)
12591263
{
12601264
LLVMValueRef value_cmp;
12611265

12621266
POP_COND(value_cmp);
12631267

1264-
return aot_compile_conditional_br(comp_ctx, func_ctx, br_depth, value_cmp,
1265-
p_frame_ip, off);
1268+
return aot_compile_conditional_br(comp_ctx, func_ctx, value_cmp,
1269+
p_frame_ip);
12661270
fail:
12671271
return false;
12681272
}

0 commit comments

Comments
 (0)