diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 | 
| commit | 044eb2f6afba375a914ac9d8024f8f5142bb912e (patch) | |
| tree | 1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /lib/IR/MDBuilder.cpp | |
| parent | eb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff) | |
Notes
Diffstat (limited to 'lib/IR/MDBuilder.cpp')
| -rw-r--r-- | lib/IR/MDBuilder.cpp | 56 | 
1 files changed, 53 insertions, 3 deletions
diff --git a/lib/IR/MDBuilder.cpp b/lib/IR/MDBuilder.cpp index b9c4f482adf5..6d77a8f2d601 100644 --- a/lib/IR/MDBuilder.cpp +++ b/lib/IR/MDBuilder.cpp @@ -14,6 +14,7 @@  #include "llvm/IR/MDBuilder.h"  #include "llvm/IR/Constants.h" +#include "llvm/IR/Function.h"  #include "llvm/IR/Metadata.h"  using namespace llvm; @@ -62,9 +63,14 @@ MDNode *MDBuilder::createFunctionEntryCount(    SmallVector<Metadata *, 8> Ops;    Ops.push_back(createString("function_entry_count"));    Ops.push_back(createConstant(ConstantInt::get(Int64Ty, Count))); -  if (Imports) -    for (auto ID : *Imports) +  if (Imports) { +    SmallVector<GlobalValue::GUID, 2> OrderID(Imports->begin(), Imports->end()); +    std::stable_sort(OrderID.begin(), OrderID.end(), +      [] (GlobalValue::GUID A, GlobalValue::GUID B) { +        return A < B;}); +    for (auto ID : OrderID)        Ops.push_back(createConstant(ConstantInt::get(Int64Ty, ID))); +  }    return MDNode::get(Context, Ops);  } @@ -90,6 +96,13 @@ MDNode *MDBuilder::createRange(Constant *Lo, Constant *Hi) {    return MDNode::get(Context, {createConstant(Lo), createConstant(Hi)});  } +MDNode *MDBuilder::createCallees(ArrayRef<Function *> Callees) { +  SmallVector<Metadata *, 4> Ops; +  for (Function *F : Callees) +    Ops.push_back(createConstant(F)); +  return MDNode::get(Context, Ops); +} +  MDNode *MDBuilder::createAnonymousAARoot(StringRef Name, MDNode *Extra) {    // To ensure uniqueness the root node is self-referential.    auto Dummy = MDNode::getTemporary(Context, None); @@ -144,7 +157,7 @@ MDNode *MDBuilder::createTBAAStructNode(ArrayRef<TBAAStructField> Fields) {    for (unsigned i = 0, e = Fields.size(); i != e; ++i) {      Vals[i * 3 + 0] = createConstant(ConstantInt::get(Int64, Fields[i].Offset));      Vals[i * 3 + 1] = createConstant(ConstantInt::get(Int64, Fields[i].Size)); -    Vals[i * 3 + 2] = Fields[i].TBAA; +    Vals[i * 3 + 2] = Fields[i].Type;    }    return MDNode::get(Context, Vals);  } @@ -184,3 +197,40 @@ MDNode *MDBuilder::createTBAAStructTagNode(MDNode *BaseType, MDNode *AccessType,    }    return MDNode::get(Context, {BaseType, AccessType, createConstant(Off)});  } + +MDNode *MDBuilder::createTBAATypeNode(MDNode *Parent, uint64_t Size, +                                      Metadata *Id, +                                      ArrayRef<TBAAStructField> Fields) { +  SmallVector<Metadata *, 4> Ops(3 + Fields.size() * 3); +  Type *Int64 = Type::getInt64Ty(Context); +  Ops[0] = Parent; +  Ops[1] = createConstant(ConstantInt::get(Int64, Size)); +  Ops[2] = Id; +  for (unsigned I = 0, E = Fields.size(); I != E; ++I) { +    Ops[I * 3 + 3] = Fields[I].Type; +    Ops[I * 3 + 4] = createConstant(ConstantInt::get(Int64, Fields[I].Offset)); +    Ops[I * 3 + 5] = createConstant(ConstantInt::get(Int64, Fields[I].Size)); +  } +  return MDNode::get(Context, Ops); +} + +MDNode *MDBuilder::createTBAAAccessTag(MDNode *BaseType, MDNode *AccessType, +                                       uint64_t Offset, uint64_t Size, +                                       bool IsImmutable) { +  IntegerType *Int64 = Type::getInt64Ty(Context); +  auto *OffsetNode = createConstant(ConstantInt::get(Int64, Offset)); +  auto *SizeNode = createConstant(ConstantInt::get(Int64, Size)); +  if (IsImmutable) { +    auto *ImmutabilityFlagNode = createConstant(ConstantInt::get(Int64, 1)); +    return MDNode::get(Context, {BaseType, AccessType, OffsetNode, SizeNode, +                                 ImmutabilityFlagNode}); +  } +  return MDNode::get(Context, {BaseType, AccessType, OffsetNode, SizeNode}); +} + +MDNode *MDBuilder::createIrrLoopHeaderWeight(uint64_t Weight) { +  SmallVector<Metadata *, 2> Vals(2); +  Vals[0] = createString("loop_header_weight"); +  Vals[1] = createConstant(ConstantInt::get(Type::getInt64Ty(Context), Weight)); +  return MDNode::get(Context, Vals); +}  | 
