Skip to content

Commit

Permalink
Revert "add stack-probes to make stack-overflow detection more reliab…
Browse files Browse the repository at this point in the history
…le (JuliaLang#40068)"

This reverts commit c0f8aef.
  • Loading branch information
staticfloat authored and LilithHafner committed Feb 22, 2022
1 parent 03eb434 commit f0fb798
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
35 changes: 20 additions & 15 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1777,14 +1777,6 @@ static void jl_init_function(Function *F)
#ifdef JL_DISABLE_FPO
F->addFnAttr("frame-pointer", "all");
#endif
#if !defined(_COMPILER_ASAN_ENABLED_) && !defined(_OS_WINDOWS_)
// ASAN won't like us accessing undefined memory causing spurious issues,
// and Windows has platform-specific handling which causes it to mishandle
// this annotation. Other platforms should just ignore this if they don't
// implement it.
F->addFnAttr("probe-stack", "inline-asm");
//F->addFnAttr("stack-probe-size", 4096); // can use this to change the default
#endif
}

static std::pair<bool, bool> uses_specsig(jl_method_instance_t *lam, jl_value_t *rettype, bool prefer_specsig)
Expand Down Expand Up @@ -6496,15 +6488,28 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
}
}

// step 6. set up GC frame
/*
// step 6. (optional) check for stack overflow (the slower way)
Value *cur_sp =
ctx.builder.CreateCall(Intrinsic::getDeclaration(M,
Intrinsic::frameaddress),
ConstantInt::get(T_int32, 0));
Value *sp_ok =
ctx.builder.CreateICmpUGT(cur_sp,
ConstantInt::get(T_size,
(uptrint_t)jl_stack_lo));
error_unless(ctx, sp_ok, "stack overflow");
*/

// step 7. set up GC frame
allocate_gc_frame(ctx, b0);
Value *last_age = NULL;
emit_last_age_field(ctx);
if (toplevel || ctx.is_opaque_closure) {
last_age = tbaa_decorate(tbaa_gcframe, ctx.builder.CreateAlignedLoad(ctx.world_age_field, Align(sizeof(size_t))));
}

// step 7. allocate local variables slots
// step 8. allocate local variables slots
// must be in the first basic block for the llvm mem2reg pass to work
auto allocate_local = [&](jl_varinfo_t &varinfo, jl_sym_t *s) {
jl_value_t *jt = varinfo.value.typ;
Expand Down Expand Up @@ -6622,7 +6627,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
}
}

// step 8. move args into local variables
// step 9. move args into local variables
Function::arg_iterator AI = f->arg_begin();

auto get_specsig_arg = [&](jl_value_t *argType, Type *llvmArgType, bool isboxed) {
Expand Down Expand Up @@ -6752,7 +6757,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
}
}

// step 9. allocate rest argument
// step 10. allocate rest argument
CallInst *restTuple = NULL;
if (va && ctx.vaSlot != -1) {
jl_varinfo_t &vi = ctx.slots[ctx.vaSlot];
Expand Down Expand Up @@ -6794,7 +6799,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
}
}

// step 10. Compute properties for each statements
// step 11. Compute properties for each statements
// This needs to be computed by iterating in the IR order
// instead of control flow order.
auto in_user_mod = [] (jl_module_t *mod) {
Expand Down Expand Up @@ -6916,7 +6921,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
Instruction &prologue_end = ctx.builder.GetInsertBlock()->back();


// step 11. Do codegen in control flow order
// step 12. Do codegen in control flow order
std::vector<int> workstack;
std::map<int, BasicBlock*> BB;
std::map<size_t, BasicBlock*> come_from_bb;
Expand Down Expand Up @@ -7463,7 +7468,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
PN->eraseFromParent();
}

// step 12. Perform any delayed instantiations
// step 13. Perform any delayed instantiations
if (ctx.debug_enabled) {
bool in_prologue = true;
for (auto &BB : *ctx.f) {
Expand Down
2 changes: 1 addition & 1 deletion test/llvmpasses/noinline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ include(joinpath("..", "testhelpers", "llvmpasses.jl"))
return A + B
end

# CHECK: attributes #{{[0-9]+}} = {{{[^}]*}} noinline {{[^}]*}}}
# CHECK: attributes #{{[0-9]+}} = {{{([a-z]+ )*}} noinline {{([a-z]+ )*}}}
emit(simple_noinline, Float64, Float64)

0 comments on commit f0fb798

Please sign in to comment.