Add relocation types for Hexagon processor; patch by Sidney Manning <sidneym@codeauro...
[oota-llvm.git] / include / llvm / Support / MDBuilder.h
index 72b2c6746ac0d6d378fb618ba09d79c32053a9ae..855e58d699de35ec5db0251108603201ff553d2d 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
-#include "llvm/Instructions.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/Metadata.h"
 #include "llvm/ADT/APInt.h"
@@ -30,17 +29,56 @@ namespace llvm {
   public:
     MDBuilder(LLVMContext &context) : Context(context) {}
 
-    /// CreateString - Return the given string as metadata.
-    MDString *CreateString(StringRef Str) {
+    /// \brief Return the given string as metadata.
+    MDString *createString(StringRef Str) {
       return MDString::get(Context, Str);
     }
 
+    //===------------------------------------------------------------------===//
+    // FPMath metadata.
+    //===------------------------------------------------------------------===//
+
+    /// \brief Return metadata with the given settings.  The special value 0.0
+    /// for the Accuracy parameter indicates the default (maximal precision)
+    /// setting.
+    MDNode *createFPMath(float Accuracy) {
+      if (Accuracy == 0.0)
+        return 0;
+      assert(Accuracy > 0.0 && "Invalid fpmath accuracy!");
+      Value *Op = ConstantFP::get(Type::getFloatTy(Context), Accuracy);
+      return MDNode::get(Context, Op);
+    }
+
+    //===------------------------------------------------------------------===//
+    // Prof metadata.
+    //===------------------------------------------------------------------===//
+
+    /// \brief Return metadata containing two branch weights.
+    MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight) {
+      uint32_t Weights[] = { TrueWeight, FalseWeight };
+      return createBranchWeights(Weights);
+    }
+
+    /// \brief Return metadata containing a number of branch weights.
+    MDNode *createBranchWeights(ArrayRef<uint32_t> Weights) {
+      assert(Weights.size() >= 2 && "Need at least two branch weights!");
+
+      SmallVector<Value *, 4> Vals(Weights.size()+1);
+      Vals[0] = createString("branch_weights");
+
+      Type *Int32Ty = Type::getInt32Ty(Context);
+      for (unsigned i = 0, e = Weights.size(); i != e; ++i)
+        Vals[i+1] = ConstantInt::get(Int32Ty, Weights[i]);
+
+      return MDNode::get(Context, Vals);
+    }
+
     //===------------------------------------------------------------------===//
     // Range metadata.
     //===------------------------------------------------------------------===//
 
-    /// CreateRange - Return metadata describing the range [Lo, Hi).
-    MDNode *CreateRange(const APInt &Lo, const APInt &Hi) {
+    /// \brief Return metadata describing the range [Lo, Hi).
+    MDNode *createRange(const APInt &Lo, const APInt &Hi) {
       assert(Lo.getBitWidth() == Hi.getBitWidth() && "Mismatched bitwidths!");
       // If the range is everything then it is useless.
       if (Hi == Lo)
@@ -52,25 +90,15 @@ namespace llvm {
       return MDNode::get(Context, Range);
     }
 
-    /// GetRangeMetadata - Get range metadata attached to an instruction.
-    MDNode *GetRangeMetadata(Instruction *I) const {
-      return I->getMetadata(LLVMContext::MD_range);
-    }
-
-    /// SetRangeMetadata - Attach range metadata to an instruction.
-    void SetRangeMetadata(Instruction *I, MDNode *RangeTag) {
-      I->setMetadata(LLVMContext::MD_range, RangeTag);
-    }
-
 
     //===------------------------------------------------------------------===//
     // TBAA metadata.
     //===------------------------------------------------------------------===//
 
-    /// CreateAnonymousTBAARoot - Return metadata appropriate for a TBAA root
-    /// node.  Each returned node is distinct from all other metadata and will
-    /// never be identified (uniqued) with anything else.
-    MDNode *CreateAnonymousTBAARoot() {
+    /// \brief Return metadata appropriate for a TBAA root node.  Each returned
+    /// node is distinct from all other metadata and will never be identified
+    /// (uniqued) with anything else.
+    MDNode *createAnonymousTBAARoot() {
       // To ensure uniqueness the root node is self-referential.
       MDNode *Dummy = MDNode::getTemporary(Context, ArrayRef<Value*>());
       MDNode *Root = MDNode::get(Context, Dummy);
@@ -85,37 +113,27 @@ namespace llvm {
       return Root;
     }
 
-    /// CreateTBAARoot - Return metadata appropriate for a TBAA root node with
-    /// the given name.  This may be identified (uniqued) with other roots with
-    /// the same name.
-    MDNode *CreateTBAARoot(StringRef Name) {
-      return MDNode::get(Context, CreateString(Name));
+    /// \brief Return metadata appropriate for a TBAA root node with the given
+    /// name.  This may be identified (uniqued) with other roots with the same
+    /// name.
+    MDNode *createTBAARoot(StringRef Name) {
+      return MDNode::get(Context, createString(Name));
     }
 
-    /// CreateTBAANode - Return metadata for a non-root TBAA node with the given
-    /// name, parent in the TBAA tree, and value for 'pointsToConstantMemory'.
-    MDNode *CreateTBAANode(StringRef Name, MDNode *Parent,
+    /// \brief Return metadata for a non-root TBAA node with the given name,
+    /// parent in the TBAA tree, and value for 'pointsToConstantMemory'.
+    MDNode *createTBAANode(StringRef Name, MDNode *Parent,
                            bool isConstant = false) {
       if (isConstant) {
         Constant *Flags = ConstantInt::get(Type::getInt64Ty(Context), 1);
-        Value *Ops[3] = { CreateString(Name), Parent, Flags };
+        Value *Ops[3] = { createString(Name), Parent, Flags };
         return MDNode::get(Context, Ops);
       } else {
-        Value *Ops[2] = { CreateString(Name), Parent };
+        Value *Ops[2] = { createString(Name), Parent };
         return MDNode::get(Context, Ops);
       }
     }
 
-    /// GetTBAAMetadata - Get tbaa metadata attached to an instruction.
-    MDNode *GetTBAAMetadata(Instruction *I) const {
-      return I->getMetadata(LLVMContext::MD_tbaa);
-    }
-
-    /// SetTBAAMetadata - Attach tbaa metadata to an instruction.
-    void SetTBAAMetadata(Instruction *I, MDNode *TBAATag) {
-      I->setMetadata(LLVMContext::MD_tbaa, TBAATag);
-    }
-
   };
 
 } // end namespace llvm