Skip to content

Commit

Permalink
Delete boundscheck handling from codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Aug 28, 2016
1 parent c4b07b9 commit a7b5176
Showing 1 changed file with 6 additions and 53 deletions.
59 changes: 6 additions & 53 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4498,18 +4498,13 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
DebugLoc loc;
StringRef file;
ssize_t line;
bool enabled;
bool is_inbounds;
bool loc_changed;
bool is_poploc;
};
std::vector<StmtProp> stmtprops(stmtslen);
std::vector<DbgState> DI_stack;
std::vector<bool> boundsCheck_stack{false};
std::vector<bool> inbounds_stack{false};
auto is_bounds_check_block = [&] () {
return !boundsCheck_stack.empty() && boundsCheck_stack.back();
};
auto is_inbounds = [&] () {
// inbounds rule is either of top two values on inbounds stack are true
size_t sz = inbounds_stack.size();
Expand All @@ -4518,7 +4513,7 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
inbounds |= inbounds_stack[sz - 2];
return inbounds;
};
StmtProp cur_prop{topdebugloc, filename, toplineno, true, false, true, false};
StmtProp cur_prop{topdebugloc, filename, toplineno, false, true, false};
for (i = 0; i < stmtslen; i++) {
cur_prop.loc_changed = false;
cur_prop.is_poploc = false;
Expand Down Expand Up @@ -4628,64 +4623,26 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
}
if (expr) {
jl_value_t **args = (jl_value_t**)jl_array_data(expr->args);
if (expr->head == boundscheck_sym) {
if (jl_array_len(expr->args) > 0) {
jl_value_t *arg = args[0];
if (arg == jl_true) {
boundsCheck_stack.push_back(true);
}
else if (arg == jl_false) {
boundsCheck_stack.push_back(false);
}
else {
if (!boundsCheck_stack.empty()) {
boundsCheck_stack.pop_back();
}
}
}
}
else if (cur_prop.enabled && expr->head == inbounds_sym) {
if (expr->head == inbounds_sym) {
// manipulate inbounds stack
// note that when entering an inbounds context, we must also update
// the boundsCheck context to be false
if (jl_array_len(expr->args) > 0) {
jl_value_t *arg = args[0];
if (arg == jl_true) {
inbounds_stack.push_back(true);
boundsCheck_stack.push_back(false);
}
else if (arg == jl_false) {
inbounds_stack.push_back(false);
boundsCheck_stack.push_back(false);
}
else {
if (!inbounds_stack.empty())
inbounds_stack.pop_back();
if (!boundsCheck_stack.empty())
boundsCheck_stack.pop_back();
else if (!inbounds_stack.empty()) {
inbounds_stack.pop_back();
}
}
}
}
bool is_ib = is_inbounds();
if (is_ib && is_bounds_check_block() &&
jl_options.check_bounds != JL_OPTIONS_CHECK_BOUNDS_ON) {
// elide bounds check blocks in inbounds context
cur_prop.enabled = false;
}
else if (is_bounds_check_block() &&
jl_options.check_bounds == JL_OPTIONS_CHECK_BOUNDS_OFF) {
// elide bounds check blocks when turned off by options
cur_prop.enabled = false;
}
else {
cur_prop.enabled = true;
}
cur_prop.is_inbounds = is_ib;
cur_prop.is_inbounds = is_inbounds();
stmtprops[i] = cur_prop;
}
DI_stack.clear();
boundsCheck_stack.clear();
inbounds_stack.clear();

// step 12. Do codegen in control flow order
Expand Down Expand Up @@ -4772,7 +4729,7 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
if (ctx.debug_enabled)
builder.SetCurrentDebugLocation(props.loc);
// Disable coverage for pop_loc, it doesn't start a new expression
if (do_coverage && props.enabled && !props.is_poploc) {
if (do_coverage && !props.is_poploc) {
coverageVisitLine(props.file, props.line);
}
}
Expand All @@ -4785,10 +4742,6 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
handle_label(lname, true);
continue;
}
if (!props.enabled) {
find_next_stmt(cursor + 1);
continue;
}
if (expr && expr->head == return_sym) {
bool retboxed = false;
Type *retty;
Expand Down

0 comments on commit a7b5176

Please sign in to comment.