mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Fix indent and remove unneeded #includes in MDBuilder.h.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172115 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -15,148 +15,149 @@
|
|||||||
#ifndef LLVM_IR_MDBUILDER_H
|
#ifndef LLVM_IR_MDBUILDER_H
|
||||||
#define LLVM_IR_MDBUILDER_H
|
#define LLVM_IR_MDBUILDER_H
|
||||||
|
|
||||||
#include "llvm/ADT/APInt.h"
|
|
||||||
#include "llvm/IR/Constants.h"
|
#include "llvm/IR/Constants.h"
|
||||||
#include "llvm/IR/DerivedTypes.h"
|
#include "llvm/IR/DerivedTypes.h"
|
||||||
#include "llvm/IR/LLVMContext.h"
|
|
||||||
#include "llvm/IR/Metadata.h"
|
#include "llvm/IR/Metadata.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class MDBuilder {
|
class APInt;
|
||||||
LLVMContext &Context;
|
class LLVMContext;
|
||||||
|
|
||||||
public:
|
class MDBuilder {
|
||||||
MDBuilder(LLVMContext &context) : Context(context) {}
|
LLVMContext &Context;
|
||||||
|
|
||||||
/// \brief Return the given string as metadata.
|
public:
|
||||||
MDString *createString(StringRef Str) {
|
MDBuilder(LLVMContext &context) : Context(context) {}
|
||||||
return MDString::get(Context, 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
|
// FPMath metadata.
|
||||||
/// for the Accuracy parameter indicates the default (maximal precision)
|
//===------------------------------------------------------------------===//
|
||||||
/// setting.
|
|
||||||
MDNode *createFPMath(float Accuracy) {
|
/// \brief Return metadata with the given settings. The special value 0.0
|
||||||
if (Accuracy == 0.0)
|
/// for the Accuracy parameter indicates the default (maximal precision)
|
||||||
return 0;
|
/// setting.
|
||||||
assert(Accuracy > 0.0 && "Invalid fpmath accuracy!");
|
MDNode *createFPMath(float Accuracy) {
|
||||||
Value *Op = ConstantFP::get(Type::getFloatTy(Context), Accuracy);
|
if (Accuracy == 0.0)
|
||||||
return MDNode::get(Context, Op);
|
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.
|
// Prof metadata.
|
||||||
MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight) {
|
//===------------------------------------------------------------------===//
|
||||||
uint32_t Weights[] = { TrueWeight, FalseWeight };
|
|
||||||
return createBranchWeights(Weights);
|
/// \brief Return metadata containing two branch weights.
|
||||||
}
|
MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight) {
|
||||||
|
uint32_t Weights[] = { TrueWeight, FalseWeight };
|
||||||
/// \brief Return metadata containing a number of branch weights.
|
return createBranchWeights(Weights);
|
||||||
MDNode *createBranchWeights(ArrayRef<uint32_t> Weights) {
|
}
|
||||||
assert(Weights.size() >= 2 && "Need at least two branch weights!");
|
|
||||||
|
/// \brief Return metadata containing a number of branch weights.
|
||||||
SmallVector<Value *, 4> Vals(Weights.size()+1);
|
MDNode *createBranchWeights(ArrayRef<uint32_t> Weights) {
|
||||||
Vals[0] = createString("branch_weights");
|
assert(Weights.size() >= 2 && "Need at least two branch weights!");
|
||||||
|
|
||||||
Type *Int32Ty = Type::getInt32Ty(Context);
|
SmallVector<Value *, 4> Vals(Weights.size()+1);
|
||||||
for (unsigned i = 0, e = Weights.size(); i != e; ++i)
|
Vals[0] = createString("branch_weights");
|
||||||
Vals[i+1] = ConstantInt::get(Int32Ty, Weights[i]);
|
|
||||||
|
Type *Int32Ty = Type::getInt32Ty(Context);
|
||||||
return MDNode::get(Context, Vals);
|
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.
|
}
|
||||||
//===------------------------------------------------------------------===//
|
|
||||||
|
//===------------------------------------------------------------------===//
|
||||||
/// \brief Return metadata describing the range [Lo, Hi).
|
// Range metadata.
|
||||||
MDNode *createRange(const APInt &Lo, const APInt &Hi) {
|
//===------------------------------------------------------------------===//
|
||||||
assert(Lo.getBitWidth() == Hi.getBitWidth() && "Mismatched bitwidths!");
|
|
||||||
// If the range is everything then it is useless.
|
/// \brief Return metadata describing the range [Lo, Hi).
|
||||||
if (Hi == Lo)
|
MDNode *createRange(const APInt &Lo, const APInt &Hi) {
|
||||||
return 0;
|
assert(Lo.getBitWidth() == Hi.getBitWidth() && "Mismatched bitwidths!");
|
||||||
|
// If the range is everything then it is useless.
|
||||||
// Return the range [Lo, Hi).
|
if (Hi == Lo)
|
||||||
Type *Ty = IntegerType::get(Context, Lo.getBitWidth());
|
return 0;
|
||||||
Value *Range[2] = { ConstantInt::get(Ty, Lo), ConstantInt::get(Ty, Hi) };
|
|
||||||
return MDNode::get(Context, Range);
|
// Return the range [Lo, Hi).
|
||||||
}
|
Type *Ty = IntegerType::get(Context, Lo.getBitWidth());
|
||||||
|
Value *Range[2] = { ConstantInt::get(Ty, Lo), ConstantInt::get(Ty, Hi) };
|
||||||
|
return MDNode::get(Context, Range);
|
||||||
//===------------------------------------------------------------------===//
|
}
|
||||||
// TBAA metadata.
|
|
||||||
//===------------------------------------------------------------------===//
|
|
||||||
|
//===------------------------------------------------------------------===//
|
||||||
/// \brief Return metadata appropriate for a TBAA root node. Each returned
|
// TBAA metadata.
|
||||||
/// 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
|
||||||
// To ensure uniqueness the root node is self-referential.
|
/// node is distinct from all other metadata and will never be identified
|
||||||
MDNode *Dummy = MDNode::getTemporary(Context, ArrayRef<Value*>());
|
/// (uniqued) with anything else.
|
||||||
MDNode *Root = MDNode::get(Context, Dummy);
|
MDNode *createAnonymousTBAARoot() {
|
||||||
// At this point we have
|
// To ensure uniqueness the root node is self-referential.
|
||||||
// !0 = metadata !{} <- dummy
|
MDNode *Dummy = MDNode::getTemporary(Context, ArrayRef<Value*>());
|
||||||
// !1 = metadata !{metadata !0} <- root
|
MDNode *Root = MDNode::get(Context, Dummy);
|
||||||
// Replace the dummy operand with the root node itself and delete the dummy.
|
// At this point we have
|
||||||
Root->replaceOperandWith(0, Root);
|
// !0 = metadata !{} <- dummy
|
||||||
MDNode::deleteTemporary(Dummy);
|
// !1 = metadata !{metadata !0} <- root
|
||||||
// We now have
|
// Replace the dummy operand with the root node itself and delete the dummy.
|
||||||
// !1 = metadata !{metadata !1} <- self-referential root
|
Root->replaceOperandWith(0, Root);
|
||||||
return Root;
|
MDNode::deleteTemporary(Dummy);
|
||||||
}
|
// We now have
|
||||||
|
// !1 = metadata !{metadata !1} <- self-referential root
|
||||||
/// \brief Return metadata appropriate for a TBAA root node with the given
|
return Root;
|
||||||
/// name. This may be identified (uniqued) with other roots with the same
|
}
|
||||||
/// name.
|
|
||||||
MDNode *createTBAARoot(StringRef Name) {
|
/// \brief Return metadata appropriate for a TBAA root node with the given
|
||||||
return MDNode::get(Context, createString(Name));
|
/// name. This may be identified (uniqued) with other roots with the same
|
||||||
}
|
/// name.
|
||||||
|
MDNode *createTBAARoot(StringRef Name) {
|
||||||
/// \brief Return metadata for a non-root TBAA node with the given name,
|
return MDNode::get(Context, createString(Name));
|
||||||
/// parent in the TBAA tree, and value for 'pointsToConstantMemory'.
|
}
|
||||||
MDNode *createTBAANode(StringRef Name, MDNode *Parent,
|
|
||||||
bool isConstant = false) {
|
/// \brief Return metadata for a non-root TBAA node with the given name,
|
||||||
if (isConstant) {
|
/// parent in the TBAA tree, and value for 'pointsToConstantMemory'.
|
||||||
Constant *Flags = ConstantInt::get(Type::getInt64Ty(Context), 1);
|
MDNode *createTBAANode(StringRef Name, MDNode *Parent,
|
||||||
Value *Ops[3] = { createString(Name), Parent, Flags };
|
bool isConstant = false) {
|
||||||
return MDNode::get(Context, Ops);
|
if (isConstant) {
|
||||||
} else {
|
Constant *Flags = ConstantInt::get(Type::getInt64Ty(Context), 1);
|
||||||
Value *Ops[2] = { createString(Name), Parent };
|
Value *Ops[3] = { createString(Name), Parent, Flags };
|
||||||
return MDNode::get(Context, Ops);
|
return MDNode::get(Context, Ops);
|
||||||
}
|
} else {
|
||||||
}
|
Value *Ops[2] = { createString(Name), Parent };
|
||||||
|
return MDNode::get(Context, Ops);
|
||||||
struct TBAAStructField {
|
|
||||||
uint64_t Offset;
|
|
||||||
uint64_t Size;
|
|
||||||
MDNode *TBAA;
|
|
||||||
TBAAStructField(uint64_t Offset, uint64_t Size, MDNode *TBAA) :
|
|
||||||
Offset(Offset), Size(Size), TBAA(TBAA) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// \brief Return metadata for a tbaa.struct node with the given
|
|
||||||
/// struct field descriptions.
|
|
||||||
MDNode *createTBAAStructNode(ArrayRef<TBAAStructField> Fields) {
|
|
||||||
SmallVector<Value *, 4> Vals(Fields.size() * 3);
|
|
||||||
Type *Int64 = IntegerType::get(Context, 64);
|
|
||||||
for (unsigned i = 0, e = Fields.size(); i != e; ++i) {
|
|
||||||
Vals[i * 3 + 0] = ConstantInt::get(Int64, Fields[i].Offset);
|
|
||||||
Vals[i * 3 + 1] = ConstantInt::get(Int64, Fields[i].Size);
|
|
||||||
Vals[i * 3 + 2] = Fields[i].TBAA;
|
|
||||||
}
|
|
||||||
return MDNode::get(Context, Vals);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TBAAStructField {
|
||||||
|
uint64_t Offset;
|
||||||
|
uint64_t Size;
|
||||||
|
MDNode *TBAA;
|
||||||
|
TBAAStructField(uint64_t Offset, uint64_t Size, MDNode *TBAA) :
|
||||||
|
Offset(Offset), Size(Size), TBAA(TBAA) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// \brief Return metadata for a tbaa.struct node with the given
|
||||||
|
/// struct field descriptions.
|
||||||
|
MDNode *createTBAAStructNode(ArrayRef<TBAAStructField> Fields) {
|
||||||
|
SmallVector<Value *, 4> Vals(Fields.size() * 3);
|
||||||
|
Type *Int64 = IntegerType::get(Context, 64);
|
||||||
|
for (unsigned i = 0, e = Fields.size(); i != e; ++i) {
|
||||||
|
Vals[i * 3 + 0] = ConstantInt::get(Int64, Fields[i].Offset);
|
||||||
|
Vals[i * 3 + 1] = ConstantInt::get(Int64, Fields[i].Size);
|
||||||
|
Vals[i * 3 + 2] = Fields[i].TBAA;
|
||||||
|
}
|
||||||
|
return MDNode::get(Context, Vals);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user