[Hexagon] Adding basic ELF relocation generation and testing advanced relaxation...
[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 Constant;
28 class ConstantAsMetadata;
29 class MDNode;
30 class MDString;
31
32 class MDBuilder {
33   LLVMContext &Context;
34
35 public:
36   MDBuilder(LLVMContext &context) : Context(context) {}
37
38   /// \brief Return the given string as metadata.
39   MDString *createString(StringRef Str);
40
41   /// \brief Return the given constant as metadata.
42   ConstantAsMetadata *createConstant(Constant *C);
43
44   //===------------------------------------------------------------------===//
45   // FPMath metadata.
46   //===------------------------------------------------------------------===//
47
48   /// \brief Return metadata with the given settings.  The special value 0.0
49   /// for the Accuracy parameter indicates the default (maximal precision)
50   /// setting.
51   MDNode *createFPMath(float Accuracy);
52
53   //===------------------------------------------------------------------===//
54   // Prof metadata.
55   //===------------------------------------------------------------------===//
56
57   /// \brief Return metadata containing two branch weights.
58   MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight);
59
60   /// \brief Return metadata containing a number of branch weights.
61   MDNode *createBranchWeights(ArrayRef<uint32_t> Weights);
62
63   /// Return metadata containing the entry count for a function.
64   MDNode *createFunctionEntryCount(uint64_t Count);
65
66   //===------------------------------------------------------------------===//
67   // Range metadata.
68   //===------------------------------------------------------------------===//
69
70   /// \brief Return metadata describing the range [Lo, Hi).
71   MDNode *createRange(const APInt &Lo, const APInt &Hi);
72
73   /// \brief Return metadata describing the range [Lo, Hi).
74   MDNode *createRange(Constant *Lo, Constant *Hi);
75
76   //===------------------------------------------------------------------===//
77   // AA metadata.
78   //===------------------------------------------------------------------===//
79
80 protected:
81   /// \brief Return metadata appropriate for a AA root node (scope or TBAA).
82   /// Each returned node is distinct from all other metadata and will never
83   /// be identified (uniqued) with anything else.
84   MDNode *createAnonymousAARoot(StringRef Name = StringRef(),
85                                 MDNode *Extra = nullptr);
86
87 public:
88   /// \brief Return metadata appropriate for a TBAA root node. Each returned
89   /// node is distinct from all other metadata and will never be identified
90   /// (uniqued) with anything else.
91   MDNode *createAnonymousTBAARoot() {
92     return createAnonymousAARoot();
93   }
94
95   /// \brief Return metadata appropriate for an alias scope domain node.
96   /// Each returned node is distinct from all other metadata and will never
97   /// be identified (uniqued) with anything else.
98   MDNode *createAnonymousAliasScopeDomain(StringRef Name = StringRef()) {
99     return createAnonymousAARoot(Name);
100   }
101
102   /// \brief Return metadata appropriate for an alias scope root node.
103   /// Each returned node is distinct from all other metadata and will never
104   /// be identified (uniqued) with anything else.
105   MDNode *createAnonymousAliasScope(MDNode *Domain,
106                                     StringRef Name = StringRef()) {
107     return createAnonymousAARoot(Name, Domain);
108   }
109
110   /// \brief Return metadata appropriate for a TBAA root node with the given
111   /// name.  This may be identified (uniqued) with other roots with the same
112   /// name.
113   MDNode *createTBAARoot(StringRef Name);
114
115   /// \brief Return metadata appropriate for an alias scope domain node with
116   /// the given name. This may be identified (uniqued) with other roots with
117   /// the same name.
118   MDNode *createAliasScopeDomain(StringRef Name);
119
120   /// \brief Return metadata appropriate for an alias scope node with
121   /// the given name. This may be identified (uniqued) with other scopes with
122   /// the same name and domain.
123   MDNode *createAliasScope(StringRef Name, MDNode *Domain);
124
125   /// \brief Return metadata for a non-root TBAA node with the given name,
126   /// parent in the TBAA tree, and value for 'pointsToConstantMemory'.
127   MDNode *createTBAANode(StringRef Name, MDNode *Parent,
128                          bool isConstant = false);
129
130   struct TBAAStructField {
131     uint64_t Offset;
132     uint64_t Size;
133     MDNode *TBAA;
134     TBAAStructField(uint64_t Offset, uint64_t Size, MDNode *TBAA) :
135       Offset(Offset), Size(Size), TBAA(TBAA) {}
136   };
137
138   /// \brief Return metadata for a tbaa.struct node with the given
139   /// struct field descriptions.
140   MDNode *createTBAAStructNode(ArrayRef<TBAAStructField> Fields);
141
142   /// \brief Return metadata for a TBAA struct node in the type DAG
143   /// with the given name, a list of pairs (offset, field type in the type DAG).
144   MDNode *
145   createTBAAStructTypeNode(StringRef Name,
146                            ArrayRef<std::pair<MDNode *, uint64_t>> Fields);
147
148   /// \brief Return metadata for a TBAA scalar type node with the
149   /// given name, an offset and a parent in the TBAA type DAG.
150   MDNode *createTBAAScalarTypeNode(StringRef Name, MDNode *Parent,
151                                    uint64_t Offset = 0);
152
153   /// \brief Return metadata for a TBAA tag node with the given
154   /// base type, access type and offset relative to the base type.
155   MDNode *createTBAAStructTagNode(MDNode *BaseType, MDNode *AccessType,
156                                   uint64_t Offset);
157 };
158
159 } // end namespace llvm
160
161 #endif