Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TBAA for non leaftypes more precise #21308

Merged
merged 1 commit into from
Apr 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,17 @@ static bool isbits_spec(jl_value_t *jt, bool allow_singleton = true)
(allow_singleton || (jl_datatype_size(jt) > 0) || (jl_datatype_nfields(jt) > 0));
}

static MDNode *best_tbaa(jl_value_t *jt) {
jt = jl_unwrap_unionall(jt);
if (!jl_is_datatype(jt))
return tbaa_value;
if (jl_is_abstracttype(jt))
return tbaa_value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these conditions return the same thing, couldn't you just collapse them as

if (!jl_is_datatype(jt) || jl_is_abstracttype(jt))
    return tbaa_value;

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The !is_datatype branch could theoretically be made smarter, I just didn't need it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. Does it warrant a // TODO?

// If we're here, we know all subtypes are (im)mutable, even if we
// don't know what the exact type is
return jl_is_mutable(jt) ? tbaa_mutab : tbaa_immut;
}

// metadata tracking for a llvm Value* during codegen
struct jl_cgval_t {
Value *V; // may be of type T* or T, or set to NULL if ghost (or if the value has not been initialized yet, for a variable definition)
Expand Down Expand Up @@ -464,9 +475,7 @@ struct jl_cgval_t {
isboxed(isboxed),
isghost(false),
isimmutable(isboxed && jl_is_immutable_datatype(typ)),
tbaa(isboxed ? (jl_is_leaf_type(typ) ?
(jl_is_mutable(typ) ? tbaa_mutab : tbaa_immut) :
tbaa_value) : nullptr)
tbaa(isboxed ? best_tbaa(typ) : nullptr)
{
assert(!(isboxed && TIndex != NULL));
assert(TIndex == NULL || TIndex->getType() == T_int8);
Expand Down