From 249d953ed7b850446fdfc600992ffb221da2f9d3 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 27 Oct 2011 19:19:07 +0000 Subject: [PATCH] Document tbaa metadata in LangRef (documentation largely based on comments at top of TypeBasedAliasAnalysis.cpp). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143134 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/GetElementPtr.html | 8 +++---- docs/LangRef.html | 53 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/docs/GetElementPtr.html b/docs/GetElementPtr.html index 2c32a9ea7cc..6297aa7de71 100644 --- a/docs/GetElementPtr.html +++ b/docs/GetElementPtr.html @@ -594,10 +594,10 @@ idx3 = (char*) &MyVar + 8 because LLVM has no restrictions on mixing types in addressing, loads or stores.

-

It would be possible to add special annotations to the IR, probably using - metadata, to describe a different type system (such as the C type system), - and do type-based aliasing on top of that. This is a much bigger - undertaking though.

+

LLVM's type-based alias analysis pass uses metadata to describe a different + type system (such as the C type system), and performs type-based aliasing + on top of that. Further details are in the + language reference.

diff --git a/docs/LangRef.html b/docs/LangRef.html index f937ae6ef9d..8dca4151720 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -100,7 +100,11 @@
  • Other Values
    1. Inline Assembler Expressions
    2. -
    3. Metadata Nodes and Metadata Strings
    4. +
    5. Metadata Nodes and Metadata Strings +
        +
      1. 'tbaa' Metadata
      2. +
      +
  • Intrinsic Global Variables @@ -2915,6 +2919,53 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25) +

    More information about specific metadata nodes recognized by the optimizers + and code generator is found below.

    + +

    + 'tbaa' Metadata +

    + +
    + +

    In LLVM IR, memory does not have types, so LLVM's own type system is not + suitable for doing TBAA. Instead, metadata is added to the IR to describe + a type system of a higher level language. This can be used to implement + typical C/C++ TBAA, but it can also be used to implement custom alias + analysis behavior for other languages.

    + +

    The current metadata format is very simple. TBAA metadata nodes have up to + three fields, e.g.:

    + +
    +
    +!0 = metadata !{ metadata !"an example type tree" }
    +!1 = metadata !{ metadata !"int", metadata !0 }
    +!2 = metadata !{ metadata !"float", metadata !0 }
    +!3 = metadata !{ metadata !"const float", metadata !2, i64 1 }
    +
    +
    + +

    The first field is an identity field. It can be any value, usually + a metadata string, which uniquely identifies the type. The most important + name in the tree is the name of the root node. Two trees with + different root node names are entirely disjoint, even if they + have leaves with common names.

    + +

    The second field identifies the type's parent node in the tree, or + is null or omitted for a root node. A type is considered to alias + all of its descendants and all of its ancestors in the tree. Also, + a type is considered to alias all types in other trees, so that + bitcode produced from multiple front-ends is handled conservatively.

    + +

    If the third field is present, it's an integer which if equal to 1 + indicates that the type is "constant" (meaning + pointsToConstantMemory should return true; see + other useful + AliasAnalysis methods).

    + +
    + -- 2.34.1