Skip to content

Commit

Permalink
codegen: improve our argument annotations (#35463)
Browse files Browse the repository at this point in the history
Reflect that immutable struct parameters are readonly by the time LLVM
can see them, even passed inside boxes.

LLVM seems to require an explicit additional LICM call, to avoid
regressions from this (observing the scheduling of fewer LICM calls).
  • Loading branch information
vtjnash authored Apr 18, 2020
1 parent ac09f10 commit c3fc367
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
PM->add(createLowerSimdLoopPass()); // Annotate loop marked with "loopinfo" as LLVM parallel loop
PM->add(createLICMPass());
PM->add(createLoopUnswitchPass());
PM->add(createLICMPass());
// Subsequent passes not stripping metadata from terminator
PM->add(createInstSimplifyLegacyPass());
PM->add(createIndVarSimplifyPass());
Expand Down
8 changes: 7 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4997,7 +4997,8 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, String
jl_value_t *jt = jl_tparam(sig, i);
if (is_uniquerep_Type(jt))
continue;
Type *ty = deserves_argbox(jt) ? T_prjlvalue : julia_type_to_llvm(ctx, jt);
bool isboxed = deserves_argbox(jt);
Type *ty = isboxed ? T_prjlvalue : julia_type_to_llvm(ctx, jt);
if (type_is_ghost(ty))
continue;
unsigned argno = fsig.size();
Expand All @@ -5006,6 +5007,9 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, String
attributes = attributes.addParamAttribute(jl_LLVMContext, argno, Attribute::ReadOnly);
ty = PointerType::get(ty, AddressSpace::Derived);
}
else if (isboxed && jl_is_immutable_datatype(jt)) {
attributes = attributes.addParamAttribute(jl_LLVMContext, argno, Attribute::ReadOnly);
}
fsig.push_back(ty);
}

Expand Down Expand Up @@ -5581,6 +5585,8 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
if (isboxed) // e.g. is-pointer
maybe_mark_argument_dereferenceable(Arg, argType);
theArg = mark_julia_type(ctx, Arg, isboxed, argType);
if (theArg.tbaa == tbaa_immut)
theArg.tbaa = tbaa_const;
}
return theArg;
};
Expand Down

0 comments on commit c3fc367

Please sign in to comment.