Add scoped-noalias metadata
[oota-llvm.git] / include / llvm / IR / MDBuilder.h
1 //===---- llvm/MDBuilder.h - Builder for LLVM metadata ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the MDBuilder class, which is used as a convenient way to
11 // create LLVM metadata with a consistent and simplified interface.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_IR_MDBUILDER_H
16 #define LLVM_IR_MDBUILDER_H
17
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/DataTypes.h"
20 #include <utility>
21
22 namespace llvm {
23
24 class APInt;
25 template <typename T> class ArrayRef;
26 class LLVMContext;
27 class MDNode;
28 class MDString;
29
30 class MDBuilder {
31   LLVMContext &Context;
32
33 public:
34   MDBuilder(LLVMContext &context) : Context(context) {}
35
36   /// \brief Return the given string as metadata.
37   MDString *createString(StringRef Str);
38
39   //===------------------------------------------------------------------===//
40   // FPMath metadata.
41   //===------------------------------------------------------------------===//
42
43   /// \brief Return metadata with the given settings.  The special value 0.0
44   /// for the Accuracy parameter indicates the default (maximal precision)
45   /// setting.
46   MDNode *createFPMath(float Accuracy);
47
48   //===------------------------------------------------------------------===//
49   // Prof metadata.
50   //===------------------------------------------------------------------===//
51
52   /// \brief Return metadata containing two branch weights.
53   MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight);
54
55   /// \brief Return metadata containing a number of branch weights.
56   MDNode *createBranchWeights(ArrayRef<uint32_t> Weights);
57
58   //===------------------------------------------------------------------===//
59   // Range metadata.
60   //===------------------------------------------------------------------===//
61
62   /// \brief Return metadata describing the range [Lo, Hi).
63   MDNode *createRange(const APInt &Lo, const APInt &Hi);
64
65   //===------------------------------------------------------------------===//
66   // AA metadata.
67   //===------------------------------------------------------------------===//
68
69 protected:
70   /// \brief Return metadata appropriate for a AA root node (scope or TBAA).
71   /// Each returned node is distinct from all other metadata and will never
72   /// be identified (uniqued) with anything else.
73   MDNode *createAnonymousAARoot(StringRef Name = StringRef());
74
75 public:
76   /// \brief Return metadata appropriate for a TBAA root node. Each returned
77   /// node is distinct from all other metadata and will never be identified
78   /// (uniqued) with anything else.
79   MDNode *createAnonymousTBAARoot() {
80     return createAnonymousAARoot();
81   }
82
83   /// \brief Return metadata appropriate for an alias scope root node.
84   /// Each returned node is distinct from all other metadata and will never
85   /// be identified (uniqued) with anything else.
86   MDNode *createAnonymousAliasScopeRoot(StringRef Name = StringRef()) {
87     return createAnonymousAARoot(Name);
88   }
89
90   /// \brief Return metadata appropriate for a TBAA root node with the given
91   /// name.  This may be identified (uniqued) with other roots with the same
92   /// name.
93   MDNode *createTBAARoot(StringRef Name);
94
95   /// \brief Return metadata appropriate for an alias scope root node with
96   /// the given name. This may be identified (uniqued) with other roots with
97   /// the same name.
98   MDNode *createAliasScopeRoot(StringRef Name);
99
100   /// \brief Return metadata for a non-root TBAA node with the given name,
101   /// parent in the TBAA tree, and value for 'pointsToConstantMemory'.
102   MDNode *createTBAANode(StringRef Name, MDNode *Parent,
103                          bool isConstant = false);
104
105   /// \brief Return metadata for a non-root alias scope node with the given
106   /// name and parent in the scope tree.
107   MDNode *createAliasScopeNode(StringRef Name, MDNode *Parent);
108
109   struct TBAAStructField {
110     uint64_t Offset;
111     uint64_t Size;
112     MDNode *TBAA;
113     TBAAStructField(uint64_t Offset, uint64_t Size, MDNode *TBAA) :
114       Offset(Offset), Size(Size), TBAA(TBAA) {}
115   };
116
117   /// \brief Return metadata for a tbaa.struct node with the given
118   /// struct field descriptions.
119   MDNode *createTBAAStructNode(ArrayRef<TBAAStructField> Fields);
120
121   /// \brief Return metadata for a TBAA struct node in the type DAG
122   /// with the given name, a list of pairs (offset, field type in the type DAG).
123   MDNode *
124   createTBAAStructTypeNode(StringRef Name,
125                            ArrayRef<std::pair<MDNode *, uint64_t>> Fields);
126
127   /// \brief Return metadata for a TBAA scalar type node with the
128   /// given name, an offset and a parent in the TBAA type DAG.
129   MDNode *createTBAAScalarTypeNode(StringRef Name, MDNode *Parent,
130                                    uint64_t Offset = 0);
131
132   /// \brief Return metadata for a TBAA tag node with the given
133   /// base type, access type and offset relative to the base type.
134   MDNode *createTBAAStructTagNode(MDNode *BaseType, MDNode *AccessType,
135                                   uint64_t Offset);
136 };
137
138 } // end namespace llvm
139
140 #endif