|
6 | 6 | #include "aot_emit_exception.h" |
7 | 7 | #include "../aot/aot_runtime.h" |
8 | 8 |
|
9 | | -static char *exce_block_names[] = { |
10 | | - "exce_unreachable", /* EXCE_UNREACHABLE */ |
11 | | - "exce_out_of_memory", /* EXCE_OUT_OF_MEMORY */ |
12 | | - "exce_out_of_bounds_mem_access",/* EXCE_OUT_OF_BOUNDS_MEMORY_ACCESS */ |
13 | | - "exce_integer_overflow", /* EXCE_INTEGER_OVERFLOW */ |
14 | | - "exce_divide_by_zero", /* EXCE_INTEGER_DIVIDE_BY_ZERO */ |
15 | | - "exce_invalid_convert_to_int", /* EXCE_INVALID_CONVERSION_TO_INTEGER */ |
16 | | - "exce_invalid_func_type_idx", /* EXCE_INVALID_FUNCTION_TYPE_INDEX */ |
17 | | - "exce_invalid_func_idx", /* EXCE_INVALID_FUNCTION_INDEX */ |
18 | | - "exce_undefined_element", /* EXCE_UNDEFINED_ELEMENT */ |
19 | | - "exce_uninit_element", /* EXCE_UNINITIALIZED_ELEMENT */ |
20 | | - "exce_call_unlinked", /* EXCE_CALL_UNLINKED_IMPORT_FUNC */ |
21 | | - "exce_native_stack_overflow", /* EXCE_NATIVE_STACK_OVERFLOW */ |
22 | | - "exce_unaligned_atomic" /* EXCE_UNALIGNED_ATOMIC */ |
23 | | -}; |
24 | | - |
25 | 9 | bool |
26 | 10 | aot_emit_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, |
27 | 11 | int32 exception_id, |
28 | 12 | bool is_cond_br, |
29 | 13 | LLVMValueRef cond_br_if, |
30 | 14 | LLVMBasicBlockRef cond_br_else_block) |
31 | 15 | { |
32 | | - LLVMBasicBlockRef exce_block; |
33 | 16 | LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder); |
34 | 17 | LLVMValueRef exce_id = I32_CONST((uint32)exception_id), func_const, func; |
35 | 18 | LLVMTypeRef param_types[2], ret_type, func_type, func_ptr_type; |
@@ -116,44 +99,20 @@ aot_emit_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, |
116 | 99 | LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr); |
117 | 100 | } |
118 | 101 |
|
119 | | - /* Create exception block if needed */ |
120 | | - if (!(exce_block = func_ctx->exception_blocks[exception_id])) { |
121 | | - if (!(func_ctx->exception_blocks[exception_id] = exce_block = |
122 | | - LLVMAppendBasicBlockInContext(comp_ctx->context, |
123 | | - func_ctx->func, |
124 | | - exce_block_names[exception_id]))) { |
125 | | - aot_set_last_error("add LLVM basic block failed."); |
126 | | - return false; |
127 | | - } |
128 | | - |
129 | | - /* Move before got_exception block */ |
130 | | - LLVMMoveBasicBlockBefore(exce_block, func_ctx->got_exception_block); |
131 | | - |
132 | | - /* Add phi incoming value to got_exception block */ |
133 | | - LLVMAddIncoming(func_ctx->exception_id_phi, &exce_id, &exce_block, 1); |
134 | | - |
135 | | - /* Jump to got exception block */ |
136 | | - LLVMPositionBuilderAtEnd(comp_ctx->builder, exce_block); |
137 | | - if (!LLVMBuildBr(comp_ctx->builder, func_ctx->got_exception_block)) { |
138 | | - aot_set_last_error("llvm build br failed."); |
139 | | - return false; |
140 | | - } |
141 | | - } |
142 | | - |
143 | | - /* Resume builder position */ |
144 | | - LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr); |
| 102 | + /* Add phi incoming value to got_exception block */ |
| 103 | + LLVMAddIncoming(func_ctx->exception_id_phi, &exce_id, &block_curr, 1); |
145 | 104 |
|
146 | 105 | if (!is_cond_br) { |
147 | 106 | /* not condition br, create br IR */ |
148 | | - if (!LLVMBuildBr(comp_ctx->builder, exce_block)) { |
| 107 | + if (!LLVMBuildBr(comp_ctx->builder, func_ctx->got_exception_block)) { |
149 | 108 | aot_set_last_error("llvm build br failed."); |
150 | 109 | return false; |
151 | 110 | } |
152 | 111 | } |
153 | 112 | else { |
154 | 113 | /* Create condition br */ |
155 | 114 | if (!LLVMBuildCondBr(comp_ctx->builder, cond_br_if, |
156 | | - exce_block, cond_br_else_block)) { |
| 115 | + func_ctx->got_exception_block, cond_br_else_block)) { |
157 | 116 | aot_set_last_error("llvm build cond br failed."); |
158 | 117 | return false; |
159 | 118 | } |
|
0 commit comments