[cfe-dev] [llvm-dev] TBAA metadata
Daniel Berlin via cfe-dev
cfe-dev at lists.llvm.org
Fri Apr 27 07:30:04 PDT 2018
On Fri, Apr 27, 2018 at 6:47 AM, Marianne Mailhot-Sarrasin via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> Hi,
>
>
>
> I am looking at the Type Based Alias Analysis and I am trying to
> understand why, from what I see, *pointsToConstantMemory()* never returns
> true.
>
>
>
> It seems that this information should come from the TBAA metadata, in
> which the Access Tag has an optional 4th field to specify this information.
>
>
>
> “Access tags are represented as MDNode s with either 3 or 4 operands. The
> first operand is an MDNode pointing to the node representing the base type.
> The second operand is an MDNode pointing to the node representing the
> access type. The third operand is a ConstantInt that states the offset of
> the access. *If a fourth field is present, it must be
> a ConstantInt valued at 0 or 1. If it is 1 then the access tag states that
> the location being accessed is “constant”
> (meaningpointsToConstantMemory should return true; see other useful
> AliasAnalysis methods
> <https://llvm.org/docs/AliasAnalysis.html#OtherItfs>). *The TBAA root of
> the access type and the base type of an access tag must be the same, and
> that is the TBAA root of the access tag.” (https://llvm.org/docs/
> LangRef.html#tbaa-metadata)
>
>
>
> But, from what I see, the CodeGenTBAA pass never sets this field.
> CodeGenTBAA::getAccessTagInfo() calls createTBAAStructTagNode() to create
> the access tag, but it does not pass the IsConstant parameter.
>
>
>
> /// \brief Return metadata for a TBAA tag node with the given
>
> /// base type, access type and offset relative to the base type.
>
> MDNode *createTBAAStructTagNode(MDNode *BaseType, MDNode *AccessType,
>
> uint64_t Offset, bool IsConstant = false
> );
>
>
>
> So my questions are:
>
>
>
> - Is there any reason *IsConstant* is never set ?
>
>
It should be set for global constants (but not global Constant objects, i
believe).
> - Would it be valid to set this information according to the
> const-qualifier of the data accessed, maybe by getting it from QualType
> ::isConstQualified()somehow ?
>
No, because even const objects are set once, and pointsToConstantMemory is
about completely unchanging memory locations. It's only true for
llvm-level gllobal constants, functions, etc.
There's a long historical discussion on the llvm mailing list about the
best way to mark that kind of thing as unchanging once it is initialized.
Various methods were proposed, i don't remember the end result.
But everyone seem to agree that at least *this* is not the way to do that.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180427/f0dc9d6e/attachment.html>
More information about the cfe-dev
mailing list