mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
NamedMDNode is a collection MDNodes.
llvm-svn: 92761
This commit is contained in:
parent
c233521d45
commit
ab66612f1b
@ -2329,6 +2329,9 @@ has undefined behavior.</p>
|
||||
event that a value is deleted, it will be replaced with a typeless
|
||||
"<tt>null</tt>", such as "<tt>metadata !{null, i32 10}</tt>".</p>
|
||||
|
||||
<p>A named metadata is a collection of metadata nodes. For example: "<tt>!foo =
|
||||
metadata !{!4, !3}</tt>".
|
||||
|
||||
<p>Optimizations may rely on metadata to provide additional information about
|
||||
the program that isn't available in the instructions, or that isn't easily
|
||||
computable. Similarly, the code generator may expect a certain metadata
|
||||
|
@ -167,7 +167,7 @@ private:
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// NamedMDNode - a tuple of other metadata.
|
||||
/// NamedMDNode - a tuple of MDNodes.
|
||||
/// NamedMDNode is always named. All NamedMDNode operand has a type of metadata.
|
||||
class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
|
||||
friend class SymbolTableListTraits<NamedMDNode, Module>;
|
||||
@ -176,15 +176,15 @@ class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
|
||||
NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT
|
||||
|
||||
Module *Parent;
|
||||
void *Operands; // SmallVector<TrackingVH<MetadataBase>, 4>
|
||||
void *Operands; // SmallVector<WeakVH<MDNode>, 4>
|
||||
|
||||
void setParent(Module *M) { Parent = M; }
|
||||
protected:
|
||||
explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const *Vals,
|
||||
explicit NamedMDNode(LLVMContext &C, const Twine &N, MDNode*const *Vals,
|
||||
unsigned NumVals, Module *M = 0);
|
||||
public:
|
||||
static NamedMDNode *Create(LLVMContext &C, const Twine &N,
|
||||
MetadataBase *const *MDs,
|
||||
MDNode *const *MDs,
|
||||
unsigned NumMDs, Module *M = 0) {
|
||||
return new NamedMDNode(C, N, MDs, NumMDs, M);
|
||||
}
|
||||
@ -206,13 +206,13 @@ public:
|
||||
inline const Module *getParent() const { return Parent; }
|
||||
|
||||
/// getOperand - Return specified operand.
|
||||
MetadataBase *getOperand(unsigned i) const;
|
||||
MDNode *getOperand(unsigned i) const;
|
||||
|
||||
/// getNumOperands - Return the number of NamedMDNode operands.
|
||||
unsigned getNumOperands() const;
|
||||
|
||||
/// addOperand - Add metadata operand.
|
||||
void addOperand(MetadataBase *M);
|
||||
void addOperand(MDNode *M);
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
static inline bool classof(const NamedMDNode *) { return true; }
|
||||
|
@ -510,12 +510,11 @@ bool LLParser::ParseNamedMetadata() {
|
||||
ParseToken(lltok::lbrace, "Expected '{' here"))
|
||||
return true;
|
||||
|
||||
SmallVector<MetadataBase *, 8> Elts;
|
||||
SmallVector<MDNode *, 8> Elts;
|
||||
do {
|
||||
if (ParseToken(lltok::exclaim, "Expected '!' here"))
|
||||
return true;
|
||||
|
||||
// FIXME: This rejects MDStrings. Are they legal in an named MDNode or not?
|
||||
MDNode *N = 0;
|
||||
if (ParseMDNodeID(N)) return true;
|
||||
Elts.push_back(N);
|
||||
|
@ -787,11 +787,11 @@ bool BitcodeReader::ParseMetadata() {
|
||||
|
||||
// Read named metadata elements.
|
||||
unsigned Size = Record.size();
|
||||
SmallVector<MetadataBase*, 8> Elts;
|
||||
SmallVector<MDNode *, 8> Elts;
|
||||
for (unsigned i = 0; i != Size; ++i) {
|
||||
Value *MD = MDValueList.getValueFwdRef(Record[i]);
|
||||
if (MetadataBase *B = dyn_cast<MetadataBase>(MD))
|
||||
Elts.push_back(B);
|
||||
if (MDNode *B = dyn_cast_or_null<MDNode>(MD))
|
||||
Elts.push_back(B);
|
||||
}
|
||||
Value *V = NamedMDNode::Create(Context, Name.str(), Elts.data(),
|
||||
Elts.size(), TheModule);
|
||||
|
@ -210,21 +210,21 @@ void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
|
||||
//===----------------------------------------------------------------------===//
|
||||
// NamedMDNode implementation.
|
||||
//
|
||||
static SmallVector<TrackingVH<MetadataBase>, 4> &getNMDOps(void *Operands) {
|
||||
return *(SmallVector<TrackingVH<MetadataBase>, 4>*)Operands;
|
||||
static SmallVector<WeakVH, 4> &getNMDOps(void *Operands) {
|
||||
return *(SmallVector<WeakVH, 4>*)Operands;
|
||||
}
|
||||
|
||||
NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
|
||||
MetadataBase *const *MDs,
|
||||
MDNode *const *MDs,
|
||||
unsigned NumMDs, Module *ParentModule)
|
||||
: MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
|
||||
setName(N);
|
||||
|
||||
Operands = new SmallVector<TrackingVH<MetadataBase>, 4>();
|
||||
Operands = new SmallVector<WeakVH, 4>();
|
||||
|
||||
SmallVector<TrackingVH<MetadataBase>, 4> &Node = getNMDOps(Operands);
|
||||
SmallVector<WeakVH, 4> &Node = getNMDOps(Operands);
|
||||
for (unsigned i = 0; i != NumMDs; ++i)
|
||||
Node.push_back(TrackingVH<MetadataBase>(MDs[i]));
|
||||
Node.push_back(WeakVH(MDs[i]));
|
||||
|
||||
if (ParentModule)
|
||||
ParentModule->getNamedMDList().push_back(this);
|
||||
@ -232,7 +232,7 @@ NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
|
||||
|
||||
NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) {
|
||||
assert(NMD && "Invalid source NamedMDNode!");
|
||||
SmallVector<MetadataBase *, 4> Elems;
|
||||
SmallVector<MDNode *, 4> Elems;
|
||||
Elems.reserve(NMD->getNumOperands());
|
||||
|
||||
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
|
||||
@ -252,14 +252,14 @@ unsigned NamedMDNode::getNumOperands() const {
|
||||
}
|
||||
|
||||
/// getOperand - Return specified operand.
|
||||
MetadataBase *NamedMDNode::getOperand(unsigned i) const {
|
||||
MDNode *NamedMDNode::getOperand(unsigned i) const {
|
||||
assert(i < getNumOperands() && "Invalid Operand number!");
|
||||
return getNMDOps(Operands)[i];
|
||||
return dyn_cast_or_null<MDNode>(getNMDOps(Operands)[i]);
|
||||
}
|
||||
|
||||
/// addOperand - Add metadata Operand.
|
||||
void NamedMDNode::addOperand(MetadataBase *M) {
|
||||
getNMDOps(Operands).push_back(TrackingVH<MetadataBase>(M));
|
||||
void NamedMDNode::addOperand(MDNode *M) {
|
||||
getNMDOps(Operands).push_back(WeakVH(M));
|
||||
}
|
||||
|
||||
/// eraseFromParent - Drop all references and remove the node from parent
|
||||
|
@ -123,7 +123,7 @@ TEST(NamedMDNodeTest, Search) {
|
||||
MDNode *n = MDNode::get(Context, &V, 1);
|
||||
MDNode *n2 = MDNode::get(Context, &V2, 1);
|
||||
|
||||
MetadataBase *Nodes[2] = { n, n2 };
|
||||
MDNode *Nodes[2] = { n, n2 };
|
||||
|
||||
Module *M = new Module("MyModule", getGlobalContext());
|
||||
const char *Name = "llvm.NMD1";
|
||||
|
Loading…
Reference in New Issue
Block a user