2009-07-28 23:49:47 +02:00
|
|
|
//===-- Metadata.cpp - Implement Metadata classes -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Metadata classes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Metadata.h"
|
2009-12-28 09:24:16 +01:00
|
|
|
#include "LLVMContextImpl.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "SymbolTableListTraitsImpl.h"
|
2009-10-22 21:36:54 +02:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-09 19:41:24 +02:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Instruction.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2012-06-16 22:33:37 +02:00
|
|
|
#include "llvm/Support/ConstantRange.h"
|
2010-08-21 00:02:26 +02:00
|
|
|
#include "llvm/Support/LeakDetector.h"
|
2009-12-28 09:24:16 +01:00
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2009-07-28 23:49:47 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-07-31 23:35:40 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-19 09:10:59 +02:00
|
|
|
// MDString implementation.
|
2009-07-31 23:35:40 +02:00
|
|
|
//
|
2009-12-28 09:30:43 +01:00
|
|
|
|
2011-12-20 03:50:00 +01:00
|
|
|
void MDString::anchor() { }
|
|
|
|
|
2012-04-10 22:12:16 +02:00
|
|
|
MDString::MDString(LLVMContext &C)
|
|
|
|
: Value(Type::getMetadataTy(C), Value::MDStringVal) {}
|
2009-12-28 09:30:43 +01:00
|
|
|
|
2009-10-22 02:10:15 +02:00
|
|
|
MDString *MDString::get(LLVMContext &Context, StringRef Str) {
|
2009-07-31 23:35:40 +02:00
|
|
|
LLVMContextImpl *pImpl = Context.pImpl;
|
2012-04-10 22:12:16 +02:00
|
|
|
StringMapEntry<Value*> &Entry =
|
2009-07-31 23:35:40 +02:00
|
|
|
pImpl->MDStringCache.GetOrCreateValue(Str);
|
2012-04-10 22:12:16 +02:00
|
|
|
Value *&S = Entry.getValue();
|
|
|
|
if (!S) S = new MDString(Context);
|
|
|
|
S->setValueName(&Entry);
|
|
|
|
return cast<MDString>(S);
|
2009-07-31 23:35:40 +02:00
|
|
|
}
|
|
|
|
|
2009-12-28 08:41:54 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-12-31 02:22:29 +01:00
|
|
|
// MDNodeOperand implementation.
|
2009-12-28 08:41:54 +01:00
|
|
|
//
|
|
|
|
|
2009-12-31 02:22:29 +01:00
|
|
|
// Use CallbackVH to hold MDNode operands.
|
2009-12-28 08:41:54 +01:00
|
|
|
namespace llvm {
|
2009-12-31 02:22:29 +01:00
|
|
|
class MDNodeOperand : public CallbackVH {
|
2012-04-08 12:20:49 +02:00
|
|
|
MDNode *getParent() {
|
|
|
|
MDNodeOperand *Cur = this;
|
|
|
|
|
|
|
|
while (Cur->getValPtrInt() != 1)
|
|
|
|
--Cur;
|
|
|
|
|
|
|
|
assert(Cur->getValPtrInt() == 1 &&
|
|
|
|
"Couldn't find the beginning of the operand list!");
|
|
|
|
return reinterpret_cast<MDNode*>(Cur) - 1;
|
|
|
|
}
|
|
|
|
|
2009-12-28 08:41:54 +01:00
|
|
|
public:
|
2012-04-08 12:20:49 +02:00
|
|
|
MDNodeOperand(Value *V) : CallbackVH(V) {}
|
2009-12-31 02:22:29 +01:00
|
|
|
~MDNodeOperand() {}
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2012-04-26 02:38:42 +02:00
|
|
|
void set(Value *V) {
|
|
|
|
unsigned IsFirst = this->getValPtrInt();
|
|
|
|
this->setValPtr(V);
|
|
|
|
this->setAsFirstOperand(IsFirst);
|
|
|
|
}
|
2012-04-08 12:20:49 +02:00
|
|
|
|
|
|
|
/// setAsFirstOperand - Accessor method to mark the operand as the first in
|
|
|
|
/// the list.
|
|
|
|
void setAsFirstOperand(unsigned V) { this->setValPtrInt(V); }
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-28 08:41:54 +01:00
|
|
|
virtual void deleted();
|
|
|
|
virtual void allUsesReplacedWith(Value *NV);
|
|
|
|
};
|
|
|
|
} // end namespace llvm.
|
|
|
|
|
|
|
|
|
2009-12-31 02:22:29 +01:00
|
|
|
void MDNodeOperand::deleted() {
|
2012-04-08 12:20:49 +02:00
|
|
|
getParent()->replaceOperand(this, 0);
|
2009-12-28 08:41:54 +01:00
|
|
|
}
|
|
|
|
|
2009-12-31 02:22:29 +01:00
|
|
|
void MDNodeOperand::allUsesReplacedWith(Value *NV) {
|
2012-04-08 12:20:49 +02:00
|
|
|
getParent()->replaceOperand(this, NV);
|
2009-12-28 08:41:54 +01:00
|
|
|
}
|
|
|
|
|
2009-07-28 23:49:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-19 09:10:59 +02:00
|
|
|
// MDNode implementation.
|
2009-07-28 23:49:47 +02:00
|
|
|
//
|
2009-12-28 08:41:54 +01:00
|
|
|
|
2009-12-31 02:22:29 +01:00
|
|
|
/// getOperandPtr - Helper function to get the MDNodeOperand's coallocated on
|
2009-12-31 02:05:46 +01:00
|
|
|
/// the end of the MDNode.
|
2009-12-31 02:22:29 +01:00
|
|
|
static MDNodeOperand *getOperandPtr(MDNode *N, unsigned Op) {
|
2010-07-13 21:33:27 +02:00
|
|
|
// Use <= instead of < to permit a one-past-the-end address.
|
|
|
|
assert(Op <= N->getNumOperands() && "Invalid operand number");
|
2012-04-26 02:38:42 +02:00
|
|
|
return reinterpret_cast<MDNodeOperand*>(N + 1) + Op;
|
2009-12-31 02:05:46 +01:00
|
|
|
}
|
|
|
|
|
2012-02-15 10:09:29 +01:00
|
|
|
void MDNode::replaceOperandWith(unsigned i, Value *Val) {
|
|
|
|
MDNodeOperand *Op = getOperandPtr(this, i);
|
|
|
|
replaceOperand(Op, Val);
|
|
|
|
}
|
|
|
|
|
2011-04-21 21:59:31 +02:00
|
|
|
MDNode::MDNode(LLVMContext &C, ArrayRef<Value*> Vals, bool isFunctionLocal)
|
2010-01-22 23:52:10 +01:00
|
|
|
: Value(Type::getMetadataTy(C), Value::MDNodeVal) {
|
2011-04-21 21:59:31 +02:00
|
|
|
NumOperands = Vals.size();
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-31 02:05:46 +01:00
|
|
|
if (isFunctionLocal)
|
|
|
|
setValueSubclassData(getSubclassDataFromValue() | FunctionLocalBit);
|
|
|
|
|
|
|
|
// Initialize the operand list, which is co-allocated on the end of the node.
|
2011-04-21 21:59:31 +02:00
|
|
|
unsigned i = 0;
|
2009-12-31 02:22:29 +01:00
|
|
|
for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands;
|
2012-04-08 12:20:49 +02:00
|
|
|
Op != E; ++Op, ++i) {
|
|
|
|
new (Op) MDNodeOperand(Vals[i]);
|
|
|
|
|
|
|
|
// Mark the first MDNodeOperand as being the first in the list of operands.
|
|
|
|
if (i == 0)
|
|
|
|
Op->setAsFirstOperand(1);
|
|
|
|
}
|
2009-12-31 02:05:46 +01:00
|
|
|
}
|
|
|
|
|
2009-12-28 10:12:35 +01:00
|
|
|
/// ~MDNode - Destroy MDNode.
|
|
|
|
MDNode::~MDNode() {
|
2010-01-10 19:48:49 +01:00
|
|
|
assert((getSubclassDataFromValue() & DestroyFlag) != 0 &&
|
2009-12-31 02:05:46 +01:00
|
|
|
"Not being destroyed through destroy()?");
|
2010-03-13 02:26:15 +01:00
|
|
|
LLVMContextImpl *pImpl = getType()->getContext().pImpl;
|
|
|
|
if (isNotUniqued()) {
|
|
|
|
pImpl->NonUniquedMDNodes.erase(this);
|
|
|
|
} else {
|
2009-12-30 22:42:11 +01:00
|
|
|
pImpl->MDNodeSet.RemoveNode(this);
|
|
|
|
}
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-31 02:05:46 +01:00
|
|
|
// Destroy the operands.
|
2009-12-31 02:22:29 +01:00
|
|
|
for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands;
|
2009-12-31 02:05:46 +01:00
|
|
|
Op != E; ++Op)
|
2009-12-31 02:22:29 +01:00
|
|
|
Op->~MDNodeOperand();
|
2009-12-28 10:12:35 +01:00
|
|
|
}
|
|
|
|
|
2010-01-20 05:45:57 +01:00
|
|
|
static const Function *getFunctionForValue(Value *V) {
|
|
|
|
if (!V) return NULL;
|
2010-05-04 14:43:36 +02:00
|
|
|
if (Instruction *I = dyn_cast<Instruction>(V)) {
|
|
|
|
BasicBlock *BB = I->getParent();
|
|
|
|
return BB ? BB->getParent() : 0;
|
|
|
|
}
|
2010-01-21 22:01:47 +01:00
|
|
|
if (Argument *A = dyn_cast<Argument>(V))
|
|
|
|
return A->getParent();
|
2010-05-04 14:43:36 +02:00
|
|
|
if (BasicBlock *BB = dyn_cast<BasicBlock>(V))
|
|
|
|
return BB->getParent();
|
|
|
|
if (MDNode *MD = dyn_cast<MDNode>(V))
|
|
|
|
return MD->getFunction();
|
2010-01-20 05:45:57 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-14 21:12:34 +01:00
|
|
|
#ifndef NDEBUG
|
2010-01-20 05:45:57 +01:00
|
|
|
static const Function *assertLocalFunction(const MDNode *N) {
|
2010-01-21 22:01:47 +01:00
|
|
|
if (!N->isFunctionLocal()) return 0;
|
2010-01-14 21:12:34 +01:00
|
|
|
|
2010-07-06 23:05:17 +02:00
|
|
|
// FIXME: This does not handle cyclic function local metadata.
|
2010-01-21 22:01:47 +01:00
|
|
|
const Function *F = 0, *NewF = 0;
|
2010-01-14 02:45:14 +01:00
|
|
|
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
|
2010-01-20 05:45:57 +01:00
|
|
|
if (Value *V = N->getOperand(i)) {
|
2010-01-21 22:01:47 +01:00
|
|
|
if (MDNode *MD = dyn_cast<MDNode>(V))
|
|
|
|
NewF = assertLocalFunction(MD);
|
|
|
|
else
|
|
|
|
NewF = getFunctionForValue(V);
|
2010-01-18 21:36:54 +01:00
|
|
|
}
|
2010-01-21 22:01:47 +01:00
|
|
|
if (F == 0)
|
|
|
|
F = NewF;
|
|
|
|
else
|
|
|
|
assert((NewF == 0 || F == NewF) &&"inconsistent function-local metadata");
|
2010-01-14 02:45:14 +01:00
|
|
|
}
|
|
|
|
return F;
|
|
|
|
}
|
2010-01-18 21:36:54 +01:00
|
|
|
#endif
|
2010-01-14 02:45:14 +01:00
|
|
|
|
|
|
|
// getFunction - If this metadata is function-local and recursively has a
|
|
|
|
// function-local operand, return the first such operand's parent function.
|
2010-01-18 23:55:08 +01:00
|
|
|
// Otherwise, return null. getFunction() should not be used for performance-
|
|
|
|
// critical code because it recursively visits all the MDNode's operands.
|
2010-01-20 05:45:57 +01:00
|
|
|
const Function *MDNode::getFunction() const {
|
2010-01-18 21:36:54 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
return assertLocalFunction(this);
|
2012-01-20 22:51:11 +01:00
|
|
|
#else
|
2010-01-14 02:45:14 +01:00
|
|
|
if (!isFunctionLocal()) return NULL;
|
2010-05-04 16:25:42 +02:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
|
|
|
if (const Function *F = getFunctionForValue(getOperand(i)))
|
|
|
|
return F;
|
2010-01-18 21:36:54 +01:00
|
|
|
return NULL;
|
2012-01-20 22:51:11 +01:00
|
|
|
#endif
|
2010-01-14 02:45:14 +01:00
|
|
|
}
|
|
|
|
|
2009-12-31 02:05:46 +01:00
|
|
|
// destroy - Delete this node. Only when there are no uses.
|
|
|
|
void MDNode::destroy() {
|
|
|
|
setValueSubclassData(getSubclassDataFromValue() | DestroyFlag);
|
2012-08-14 03:09:10 +02:00
|
|
|
// Placement delete, then free the memory.
|
2009-12-31 02:05:46 +01:00
|
|
|
this->~MDNode();
|
|
|
|
free(this);
|
2009-07-28 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
2010-04-28 22:16:12 +02:00
|
|
|
/// isFunctionLocalValue - Return true if this is a value that would require a
|
|
|
|
/// function-local MDNode.
|
|
|
|
static bool isFunctionLocalValue(Value *V) {
|
|
|
|
return isa<Instruction>(V) || isa<Argument>(V) || isa<BasicBlock>(V) ||
|
|
|
|
(isa<MDNode>(V) && cast<MDNode>(V)->isFunctionLocal());
|
|
|
|
}
|
|
|
|
|
2011-04-21 21:59:31 +02:00
|
|
|
MDNode *MDNode::getMDNode(LLVMContext &Context, ArrayRef<Value*> Vals,
|
|
|
|
FunctionLocalness FL, bool Insert) {
|
2009-09-03 03:39:20 +02:00
|
|
|
LLVMContextImpl *pImpl = Context.pImpl;
|
2010-08-25 01:21:12 +02:00
|
|
|
|
|
|
|
// Add all the operand pointers. Note that we don't have to add the
|
|
|
|
// isFunctionLocal bit because that's implied by the operands.
|
2010-08-30 23:18:41 +02:00
|
|
|
// Note that if the operands are later nulled out, the node will be
|
|
|
|
// removed from the uniquing map.
|
2010-08-25 01:21:12 +02:00
|
|
|
FoldingSetNodeID ID;
|
2011-04-21 21:59:31 +02:00
|
|
|
for (unsigned i = 0; i != Vals.size(); ++i)
|
2010-08-25 01:21:12 +02:00
|
|
|
ID.AddPointer(Vals[i]);
|
|
|
|
|
|
|
|
void *InsertPoint;
|
2012-03-31 10:20:11 +02:00
|
|
|
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
|
|
|
|
|
|
|
|
if (N || !Insert)
|
2010-08-25 01:21:12 +02:00
|
|
|
return N;
|
2012-03-31 10:20:11 +02:00
|
|
|
|
2010-01-26 03:36:35 +01:00
|
|
|
bool isFunctionLocal = false;
|
|
|
|
switch (FL) {
|
|
|
|
case FL_Unknown:
|
2011-04-21 21:59:31 +02:00
|
|
|
for (unsigned i = 0; i != Vals.size(); ++i) {
|
2010-01-26 03:36:35 +01:00
|
|
|
Value *V = Vals[i];
|
|
|
|
if (!V) continue;
|
2010-04-28 22:16:12 +02:00
|
|
|
if (isFunctionLocalValue(V)) {
|
2010-01-26 03:36:35 +01:00
|
|
|
isFunctionLocal = true;
|
|
|
|
break;
|
2010-01-10 08:14:18 +01:00
|
|
|
}
|
|
|
|
}
|
2010-01-26 03:36:35 +01:00
|
|
|
break;
|
|
|
|
case FL_No:
|
|
|
|
isFunctionLocal = false;
|
|
|
|
break;
|
|
|
|
case FL_Yes:
|
|
|
|
isFunctionLocal = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-01-10 08:14:18 +01:00
|
|
|
|
2010-01-26 03:36:35 +01:00
|
|
|
// Coallocate space for the node and Operands together, then placement new.
|
2012-04-26 02:38:42 +02:00
|
|
|
void *Ptr = malloc(sizeof(MDNode) + Vals.size() * sizeof(MDNodeOperand));
|
2011-04-21 21:59:31 +02:00
|
|
|
N = new (Ptr) MDNode(Context, Vals, isFunctionLocal);
|
2010-01-26 03:36:35 +01:00
|
|
|
|
2012-04-11 16:06:54 +02:00
|
|
|
// Cache the operand hash.
|
|
|
|
N->Hash = ID.ComputeHash();
|
|
|
|
|
2010-01-26 03:36:35 +01:00
|
|
|
// InsertPoint will have been set by the FindNodeOrInsertPos call.
|
|
|
|
pImpl->MDNodeSet.InsertNode(N, InsertPoint);
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-09-03 03:39:20 +02:00
|
|
|
return N;
|
2009-07-31 23:35:40 +02:00
|
|
|
}
|
|
|
|
|
2011-03-04 02:20:33 +01:00
|
|
|
MDNode *MDNode::get(LLVMContext &Context, ArrayRef<Value*> Vals) {
|
2011-04-21 21:59:31 +02:00
|
|
|
return getMDNode(Context, Vals, FL_Unknown);
|
2010-01-10 08:14:18 +01:00
|
|
|
}
|
|
|
|
|
2011-04-21 21:59:31 +02:00
|
|
|
MDNode *MDNode::getWhenValsUnresolved(LLVMContext &Context,
|
|
|
|
ArrayRef<Value*> Vals,
|
|
|
|
bool isFunctionLocal) {
|
|
|
|
return getMDNode(Context, Vals, isFunctionLocal ? FL_Yes : FL_No);
|
2010-01-10 08:14:18 +01:00
|
|
|
}
|
|
|
|
|
2011-04-21 21:59:31 +02:00
|
|
|
MDNode *MDNode::getIfExists(LLVMContext &Context, ArrayRef<Value*> Vals) {
|
|
|
|
return getMDNode(Context, Vals, FL_Unknown, false);
|
2010-01-26 03:36:35 +01:00
|
|
|
}
|
|
|
|
|
2011-04-21 21:59:31 +02:00
|
|
|
MDNode *MDNode::getTemporary(LLVMContext &Context, ArrayRef<Value*> Vals) {
|
|
|
|
MDNode *N =
|
2012-04-26 02:38:42 +02:00
|
|
|
(MDNode *)malloc(sizeof(MDNode) + Vals.size() * sizeof(MDNodeOperand));
|
2011-04-21 21:59:31 +02:00
|
|
|
N = new (N) MDNode(Context, Vals, FL_No);
|
2010-08-21 00:02:26 +02:00
|
|
|
N->setValueSubclassData(N->getSubclassDataFromValue() |
|
|
|
|
NotUniquedBit);
|
|
|
|
LeakDetector::addGarbageObject(N);
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MDNode::deleteTemporary(MDNode *N) {
|
|
|
|
assert(N->use_empty() && "Temporary MDNode has uses!");
|
2010-08-21 04:52:29 +02:00
|
|
|
assert(!N->getContext().pImpl->MDNodeSet.RemoveNode(N) &&
|
2010-08-24 00:32:05 +02:00
|
|
|
"Deleting a non-temporary uniqued node!");
|
|
|
|
assert(!N->getContext().pImpl->NonUniquedMDNodes.erase(N) &&
|
|
|
|
"Deleting a non-temporary non-uniqued node!");
|
2010-08-21 00:02:26 +02:00
|
|
|
assert((N->getSubclassDataFromValue() & NotUniquedBit) &&
|
|
|
|
"Temporary MDNode does not have NotUniquedBit set!");
|
|
|
|
assert((N->getSubclassDataFromValue() & DestroyFlag) == 0 &&
|
2010-08-21 04:52:29 +02:00
|
|
|
"Temporary MDNode has DestroyFlag set!");
|
2010-08-21 00:02:26 +02:00
|
|
|
LeakDetector::removeGarbageObject(N);
|
2010-08-21 17:07:23 +02:00
|
|
|
N->destroy();
|
2010-08-21 00:02:26 +02:00
|
|
|
}
|
|
|
|
|
2009-12-31 02:22:29 +01:00
|
|
|
/// getOperand - Return specified operand.
|
|
|
|
Value *MDNode::getOperand(unsigned i) const {
|
2013-03-08 22:08:23 +01:00
|
|
|
assert(i < getNumOperands() && "Invalid operand number");
|
2009-12-31 02:05:46 +01:00
|
|
|
return *getOperandPtr(const_cast<MDNode*>(this), i);
|
2009-12-28 08:41:54 +01:00
|
|
|
}
|
|
|
|
|
2009-12-31 02:05:46 +01:00
|
|
|
void MDNode::Profile(FoldingSetNodeID &ID) const {
|
2010-08-25 01:21:12 +02:00
|
|
|
// Add all the operand pointers. Note that we don't have to add the
|
|
|
|
// isFunctionLocal bit because that's implied by the operands.
|
2010-08-30 23:18:41 +02:00
|
|
|
// Note that if the operands are later nulled out, the node will be
|
|
|
|
// removed from the uniquing map.
|
2009-12-31 02:22:29 +01:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
|
|
|
ID.AddPointer(getOperand(i));
|
2009-12-31 02:05:46 +01:00
|
|
|
}
|
2009-12-28 08:41:54 +01:00
|
|
|
|
2010-03-13 02:26:15 +01:00
|
|
|
void MDNode::setIsNotUniqued() {
|
|
|
|
setValueSubclassData(getSubclassDataFromValue() | NotUniquedBit);
|
|
|
|
LLVMContextImpl *pImpl = getType()->getContext().pImpl;
|
|
|
|
pImpl->NonUniquedMDNodes.insert(this);
|
2010-02-18 21:53:16 +01:00
|
|
|
}
|
2009-12-28 08:41:54 +01:00
|
|
|
|
2009-12-31 02:22:29 +01:00
|
|
|
// Replace value from this node's operand list.
|
|
|
|
void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
|
2009-12-28 10:32:10 +01:00
|
|
|
Value *From = *Op;
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2010-04-28 22:16:12 +02:00
|
|
|
// If is possible that someone did GV->RAUW(inst), replacing a global variable
|
|
|
|
// with an instruction or some other function-local object. If this is a
|
|
|
|
// non-function-local MDNode, it can't point to a function-local object.
|
|
|
|
// Handle this case by implicitly dropping the MDNode reference to null.
|
2010-05-04 14:43:36 +02:00
|
|
|
// Likewise if the MDNode is function-local but for a different function.
|
|
|
|
if (To && isFunctionLocalValue(To)) {
|
|
|
|
if (!isFunctionLocal())
|
|
|
|
To = 0;
|
|
|
|
else {
|
|
|
|
const Function *F = getFunction();
|
|
|
|
const Function *FV = getFunctionForValue(To);
|
|
|
|
// Metadata can be function-local without having an associated function.
|
|
|
|
// So only consider functions to have changed if non-null.
|
|
|
|
if (F && FV && F != FV)
|
|
|
|
To = 0;
|
|
|
|
}
|
|
|
|
}
|
2010-04-28 22:16:12 +02:00
|
|
|
|
2009-12-28 10:32:10 +01:00
|
|
|
if (From == To)
|
2009-09-03 03:39:20 +02:00
|
|
|
return;
|
|
|
|
|
2009-12-30 22:42:11 +01:00
|
|
|
// Update the operand.
|
2009-12-31 02:05:46 +01:00
|
|
|
Op->set(To);
|
2009-12-30 22:42:11 +01:00
|
|
|
|
|
|
|
// If this node is already not being uniqued (because one of the operands
|
|
|
|
// already went to null), then there is nothing else to do here.
|
|
|
|
if (isNotUniqued()) return;
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-28 10:24:53 +01:00
|
|
|
LLVMContextImpl *pImpl = getType()->getContext().pImpl;
|
|
|
|
|
|
|
|
// Remove "this" from the context map. FoldingSet doesn't have to reprofile
|
|
|
|
// this node to remove it, so we don't care what state the operands are in.
|
|
|
|
pImpl->MDNodeSet.RemoveNode(this);
|
2009-12-28 10:32:10 +01:00
|
|
|
|
2009-12-30 22:42:11 +01:00
|
|
|
// If we are dropping an argument to null, we choose to not unique the MDNode
|
|
|
|
// anymore. This commonly occurs during destruction, and uniquing these
|
2010-08-30 23:18:41 +02:00
|
|
|
// brings little reuse. Also, this means we don't need to include
|
|
|
|
// isFunctionLocal bits in FoldingSetNodeIDs for MDNodes.
|
2009-12-30 22:42:11 +01:00
|
|
|
if (To == 0) {
|
|
|
|
setIsNotUniqued();
|
|
|
|
return;
|
|
|
|
}
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-30 22:42:11 +01:00
|
|
|
// Now that the node is out of the folding set, get ready to reinsert it.
|
|
|
|
// First, check to see if another node with the same operands already exists
|
2010-09-29 00:07:19 +02:00
|
|
|
// in the set. If so, then this node is redundant.
|
2009-09-03 03:39:20 +02:00
|
|
|
FoldingSetNodeID ID;
|
|
|
|
Profile(ID);
|
|
|
|
void *InsertPoint;
|
2010-09-28 23:02:55 +02:00
|
|
|
if (MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint)) {
|
2010-09-29 00:07:19 +02:00
|
|
|
replaceAllUsesWith(N);
|
|
|
|
destroy();
|
|
|
|
return;
|
2009-09-03 03:39:20 +02:00
|
|
|
}
|
|
|
|
|
2012-04-11 16:06:54 +02:00
|
|
|
// Cache the operand hash.
|
|
|
|
Hash = ID.ComputeHash();
|
2009-12-28 10:24:53 +01:00
|
|
|
// InsertPoint will have been set by the FindNodeOrInsertPos call.
|
|
|
|
pImpl->MDNodeSet.InsertNode(this, InsertPoint);
|
2010-09-14 03:37:57 +02:00
|
|
|
|
|
|
|
// If this MDValue was previously function-local but no longer is, clear
|
|
|
|
// its function-local flag.
|
|
|
|
if (isFunctionLocal() && !isFunctionLocalValue(To)) {
|
|
|
|
bool isStillFunctionLocal = false;
|
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
|
|
|
Value *V = getOperand(i);
|
|
|
|
if (!V) continue;
|
|
|
|
if (isFunctionLocalValue(V)) {
|
|
|
|
isStillFunctionLocal = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isStillFunctionLocal)
|
|
|
|
setValueSubclassData(getSubclassDataFromValue() & ~FunctionLocalBit);
|
|
|
|
}
|
2009-09-03 03:39:20 +02:00
|
|
|
}
|
|
|
|
|
2012-06-16 22:33:37 +02:00
|
|
|
MDNode *MDNode::getMostGenericFPMath(MDNode *A, MDNode *B) {
|
|
|
|
if (!A || !B)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
APFloat AVal = cast<ConstantFP>(A->getOperand(0))->getValueAPF();
|
|
|
|
APFloat BVal = cast<ConstantFP>(B->getOperand(0))->getValueAPF();
|
|
|
|
if (AVal.compare(BVal) == APFloat::cmpLessThan)
|
|
|
|
return A;
|
|
|
|
return B;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
|
|
|
|
return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool canBeMerged(const ConstantRange &A, const ConstantRange &B) {
|
|
|
|
return !A.intersectWith(B).isEmptySet() || isContiguous(A, B);
|
|
|
|
}
|
|
|
|
|
2013-07-14 06:42:23 +02:00
|
|
|
static bool tryMergeRange(SmallVectorImpl<Value *> &EndPoints, ConstantInt *Low,
|
2012-06-16 22:33:37 +02:00
|
|
|
ConstantInt *High) {
|
|
|
|
ConstantRange NewRange(Low->getValue(), High->getValue());
|
|
|
|
unsigned Size = EndPoints.size();
|
|
|
|
APInt LB = cast<ConstantInt>(EndPoints[Size - 2])->getValue();
|
|
|
|
APInt LE = cast<ConstantInt>(EndPoints[Size - 1])->getValue();
|
|
|
|
ConstantRange LastRange(LB, LE);
|
|
|
|
if (canBeMerged(NewRange, LastRange)) {
|
|
|
|
ConstantRange Union = LastRange.unionWith(NewRange);
|
|
|
|
Type *Ty = High->getType();
|
|
|
|
EndPoints[Size - 2] = ConstantInt::get(Ty, Union.getLower());
|
|
|
|
EndPoints[Size - 1] = ConstantInt::get(Ty, Union.getUpper());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-14 06:42:23 +02:00
|
|
|
static void addRange(SmallVectorImpl<Value *> &EndPoints, ConstantInt *Low,
|
2012-06-16 22:33:37 +02:00
|
|
|
ConstantInt *High) {
|
|
|
|
if (!EndPoints.empty())
|
|
|
|
if (tryMergeRange(EndPoints, Low, High))
|
|
|
|
return;
|
|
|
|
|
|
|
|
EndPoints.push_back(Low);
|
|
|
|
EndPoints.push_back(High);
|
|
|
|
}
|
|
|
|
|
|
|
|
MDNode *MDNode::getMostGenericRange(MDNode *A, MDNode *B) {
|
|
|
|
// Given two ranges, we want to compute the union of the ranges. This
|
|
|
|
// is slightly complitade by having to combine the intervals and merge
|
|
|
|
// the ones that overlap.
|
|
|
|
|
|
|
|
if (!A || !B)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (A == B)
|
|
|
|
return A;
|
|
|
|
|
|
|
|
// First, walk both lists in older of the lower boundary of each interval.
|
|
|
|
// At each step, try to merge the new interval to the last one we adedd.
|
|
|
|
SmallVector<Value*, 4> EndPoints;
|
|
|
|
int AI = 0;
|
|
|
|
int BI = 0;
|
|
|
|
int AN = A->getNumOperands() / 2;
|
|
|
|
int BN = B->getNumOperands() / 2;
|
|
|
|
while (AI < AN && BI < BN) {
|
|
|
|
ConstantInt *ALow = cast<ConstantInt>(A->getOperand(2 * AI));
|
|
|
|
ConstantInt *BLow = cast<ConstantInt>(B->getOperand(2 * BI));
|
|
|
|
|
|
|
|
if (ALow->getValue().slt(BLow->getValue())) {
|
|
|
|
addRange(EndPoints, ALow, cast<ConstantInt>(A->getOperand(2 * AI + 1)));
|
|
|
|
++AI;
|
|
|
|
} else {
|
|
|
|
addRange(EndPoints, BLow, cast<ConstantInt>(B->getOperand(2 * BI + 1)));
|
|
|
|
++BI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (AI < AN) {
|
|
|
|
addRange(EndPoints, cast<ConstantInt>(A->getOperand(2 * AI)),
|
|
|
|
cast<ConstantInt>(A->getOperand(2 * AI + 1)));
|
|
|
|
++AI;
|
|
|
|
}
|
|
|
|
while (BI < BN) {
|
|
|
|
addRange(EndPoints, cast<ConstantInt>(B->getOperand(2 * BI)),
|
|
|
|
cast<ConstantInt>(B->getOperand(2 * BI + 1)));
|
|
|
|
++BI;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have more than 2 ranges (4 endpoints) we have to try to merge
|
|
|
|
// the last and first ones.
|
|
|
|
unsigned Size = EndPoints.size();
|
|
|
|
if (Size > 4) {
|
|
|
|
ConstantInt *FB = cast<ConstantInt>(EndPoints[0]);
|
|
|
|
ConstantInt *FE = cast<ConstantInt>(EndPoints[1]);
|
|
|
|
if (tryMergeRange(EndPoints, FB, FE)) {
|
|
|
|
for (unsigned i = 0; i < Size - 2; ++i) {
|
|
|
|
EndPoints[i] = EndPoints[i + 2];
|
|
|
|
}
|
|
|
|
EndPoints.resize(Size - 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If in the end we have a single range, it is possible that it is now the
|
|
|
|
// full range. Just drop the metadata in that case.
|
|
|
|
if (EndPoints.size() == 2) {
|
|
|
|
ConstantRange Range(cast<ConstantInt>(EndPoints[0])->getValue(),
|
|
|
|
cast<ConstantInt>(EndPoints[1])->getValue());
|
|
|
|
if (Range.isFullSet())
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MDNode::get(A->getContext(), EndPoints);
|
|
|
|
}
|
|
|
|
|
2009-07-29 02:33:07 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-19 09:10:59 +02:00
|
|
|
// NamedMDNode implementation.
|
2009-07-29 02:33:07 +02:00
|
|
|
//
|
2010-01-12 19:34:06 +01:00
|
|
|
|
2010-07-21 20:01:42 +02:00
|
|
|
static SmallVector<TrackingVH<MDNode>, 4> &getNMDOps(void *Operands) {
|
|
|
|
return *(SmallVector<TrackingVH<MDNode>, 4>*)Operands;
|
2009-12-28 09:07:14 +01:00
|
|
|
}
|
|
|
|
|
2010-07-22 01:38:33 +02:00
|
|
|
NamedMDNode::NamedMDNode(const Twine &N)
|
|
|
|
: Name(N.str()), Parent(0),
|
|
|
|
Operands(new SmallVector<TrackingVH<MDNode>, 4>()) {
|
2009-08-11 20:01:24 +02:00
|
|
|
}
|
|
|
|
|
2009-12-28 09:07:14 +01:00
|
|
|
NamedMDNode::~NamedMDNode() {
|
|
|
|
dropAllReferences();
|
|
|
|
delete &getNMDOps(Operands);
|
|
|
|
}
|
|
|
|
|
2009-12-31 02:22:29 +01:00
|
|
|
/// getNumOperands - Return number of NamedMDNode operands.
|
|
|
|
unsigned NamedMDNode::getNumOperands() const {
|
2009-12-28 09:07:14 +01:00
|
|
|
return (unsigned)getNMDOps(Operands).size();
|
|
|
|
}
|
|
|
|
|
2009-12-31 02:22:29 +01:00
|
|
|
/// getOperand - Return specified operand.
|
2010-01-05 21:41:31 +01:00
|
|
|
MDNode *NamedMDNode::getOperand(unsigned i) const {
|
2009-12-31 02:22:29 +01:00
|
|
|
assert(i < getNumOperands() && "Invalid Operand number!");
|
2010-07-21 20:54:18 +02:00
|
|
|
return dyn_cast<MDNode>(&*getNMDOps(Operands)[i]);
|
2009-12-28 09:07:14 +01:00
|
|
|
}
|
|
|
|
|
2009-12-31 02:22:29 +01:00
|
|
|
/// addOperand - Add metadata Operand.
|
2010-01-05 21:41:31 +01:00
|
|
|
void NamedMDNode::addOperand(MDNode *M) {
|
2010-09-14 03:37:57 +02:00
|
|
|
assert(!M->isFunctionLocal() &&
|
|
|
|
"NamedMDNode operands must not be function-local!");
|
2010-07-21 20:01:42 +02:00
|
|
|
getNMDOps(Operands).push_back(TrackingVH<MDNode>(M));
|
2009-12-28 09:07:14 +01:00
|
|
|
}
|
|
|
|
|
2009-08-03 08:19:01 +02:00
|
|
|
/// eraseFromParent - Drop all references and remove the node from parent
|
|
|
|
/// module.
|
|
|
|
void NamedMDNode::eraseFromParent() {
|
2010-07-22 01:38:33 +02:00
|
|
|
getParent()->eraseNamedMetadata(this);
|
2009-08-03 08:19:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// dropAllReferences - Remove all uses and clear node vector.
|
|
|
|
void NamedMDNode::dropAllReferences() {
|
2009-12-28 09:07:14 +01:00
|
|
|
getNMDOps(Operands).clear();
|
2009-08-03 08:19:01 +02:00
|
|
|
}
|
|
|
|
|
2010-01-07 20:39:36 +01:00
|
|
|
/// getName - Return a constant reference to this named metadata's name.
|
|
|
|
StringRef NamedMDNode::getName() const {
|
|
|
|
return StringRef(Name);
|
|
|
|
}
|
2009-09-16 20:09:00 +02:00
|
|
|
|
2009-12-29 10:01:33 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Instruction Metadata method implementations.
|
|
|
|
//
|
2009-09-29 22:30:57 +02:00
|
|
|
|
2011-12-06 12:50:26 +01:00
|
|
|
void Instruction::setMetadata(StringRef Kind, MDNode *Node) {
|
2009-12-29 10:01:33 +01:00
|
|
|
if (Node == 0 && !hasMetadata()) return;
|
|
|
|
setMetadata(getContext().getMDKindID(Kind), Node);
|
2009-09-16 20:09:00 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 12:50:26 +01:00
|
|
|
MDNode *Instruction::getMetadataImpl(StringRef Kind) const {
|
2009-12-29 10:01:33 +01:00
|
|
|
return getMetadataImpl(getContext().getMDKindID(Kind));
|
2009-12-29 00:41:32 +01:00
|
|
|
}
|
|
|
|
|
2009-12-29 10:01:33 +01:00
|
|
|
/// setMetadata - Set the metadata of of the specified kind to the specified
|
|
|
|
/// node. This updates/replaces metadata if already present, or removes it if
|
|
|
|
/// Node is null.
|
|
|
|
void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
|
|
|
|
if (Node == 0 && !hasMetadata()) return;
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2010-03-31 01:03:27 +02:00
|
|
|
// Handle 'dbg' as a special case since it is not stored in the hash table.
|
|
|
|
if (KindID == LLVMContext::MD_dbg) {
|
2010-04-02 22:21:22 +02:00
|
|
|
DbgLoc = DebugLoc::getFromDILocation(Node);
|
2010-03-31 01:03:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-29 00:41:32 +01:00
|
|
|
// Handle the case when we're adding/updating metadata on an instruction.
|
|
|
|
if (Node) {
|
2009-12-29 10:01:33 +01:00
|
|
|
LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
|
2010-03-31 01:03:27 +02:00
|
|
|
assert(!Info.empty() == hasMetadataHashEntry() &&
|
|
|
|
"HasMetadata bit is wonked");
|
2009-12-29 00:41:32 +01:00
|
|
|
if (Info.empty()) {
|
2010-03-31 01:03:27 +02:00
|
|
|
setHasMetadataHashEntry(true);
|
2009-12-29 00:41:32 +01:00
|
|
|
} else {
|
|
|
|
// Handle replacement of an existing value.
|
|
|
|
for (unsigned i = 0, e = Info.size(); i != e; ++i)
|
2009-12-29 10:01:33 +01:00
|
|
|
if (Info[i].first == KindID) {
|
2009-12-29 00:41:32 +01:00
|
|
|
Info[i].second = Node;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-29 00:41:32 +01:00
|
|
|
// No replacement, just add it to the list.
|
2009-12-29 10:01:33 +01:00
|
|
|
Info.push_back(std::make_pair(KindID, Node));
|
2009-09-29 22:42:25 +02:00
|
|
|
return;
|
2009-12-29 00:41:32 +01:00
|
|
|
}
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-29 00:41:32 +01:00
|
|
|
// Otherwise, we're removing metadata from an instruction.
|
2011-12-27 02:17:40 +01:00
|
|
|
assert((hasMetadataHashEntry() ==
|
|
|
|
getContext().pImpl->MetadataStore.count(this)) &&
|
2009-12-29 00:41:32 +01:00
|
|
|
"HasMetadata bit out of date!");
|
2011-12-27 02:17:40 +01:00
|
|
|
if (!hasMetadataHashEntry())
|
|
|
|
return; // Nothing to remove!
|
2009-12-29 10:01:33 +01:00
|
|
|
LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-29 00:41:32 +01:00
|
|
|
// Common case is removing the only entry.
|
2009-12-29 10:01:33 +01:00
|
|
|
if (Info.size() == 1 && Info[0].first == KindID) {
|
|
|
|
getContext().pImpl->MetadataStore.erase(this);
|
2010-03-31 01:03:27 +02:00
|
|
|
setHasMetadataHashEntry(false);
|
2009-12-29 00:41:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2010-03-31 01:03:27 +02:00
|
|
|
// Handle removal of an existing value.
|
2009-12-29 00:41:32 +01:00
|
|
|
for (unsigned i = 0, e = Info.size(); i != e; ++i)
|
2009-12-29 10:01:33 +01:00
|
|
|
if (Info[i].first == KindID) {
|
2009-12-29 00:41:32 +01:00
|
|
|
Info[i] = Info.back();
|
|
|
|
Info.pop_back();
|
|
|
|
assert(!Info.empty() && "Removing last entry should be handled above");
|
2009-09-29 22:42:25 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-12-29 00:41:32 +01:00
|
|
|
// Otherwise, removing an entry that doesn't exist on the instruction.
|
2009-09-29 22:42:25 +02:00
|
|
|
}
|
2009-11-26 23:54:26 +01:00
|
|
|
|
2009-12-29 00:41:32 +01:00
|
|
|
MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
|
2010-03-31 01:03:27 +02:00
|
|
|
// Handle 'dbg' as a special case since it is not stored in the hash table.
|
|
|
|
if (KindID == LLVMContext::MD_dbg)
|
2010-04-01 07:23:13 +02:00
|
|
|
return DbgLoc.getAsMDNode(getContext());
|
2010-03-31 01:03:27 +02:00
|
|
|
|
|
|
|
if (!hasMetadataHashEntry()) return 0;
|
|
|
|
|
2009-12-29 10:01:33 +01:00
|
|
|
LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
|
2010-03-31 01:03:27 +02:00
|
|
|
assert(!Info.empty() && "bit out of sync with hash table");
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-29 10:01:33 +01:00
|
|
|
for (LLVMContextImpl::MDMapTy::iterator I = Info.begin(), E = Info.end();
|
|
|
|
I != E; ++I)
|
|
|
|
if (I->first == KindID)
|
|
|
|
return I->second;
|
|
|
|
return 0;
|
2009-12-29 00:41:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Instruction::getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,
|
2010-03-31 01:03:27 +02:00
|
|
|
MDNode*> > &Result) const {
|
|
|
|
Result.clear();
|
|
|
|
|
|
|
|
// Handle 'dbg' as a special case since it is not stored in the hash table.
|
2010-04-01 07:23:13 +02:00
|
|
|
if (!DbgLoc.isUnknown()) {
|
|
|
|
Result.push_back(std::make_pair((unsigned)LLVMContext::MD_dbg,
|
|
|
|
DbgLoc.getAsMDNode(getContext())));
|
2010-03-31 01:03:27 +02:00
|
|
|
if (!hasMetadataHashEntry()) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(hasMetadataHashEntry() &&
|
|
|
|
getContext().pImpl->MetadataStore.count(this) &&
|
2009-12-29 10:01:33 +01:00
|
|
|
"Shouldn't have called this");
|
|
|
|
const LLVMContextImpl::MDMapTy &Info =
|
|
|
|
getContext().pImpl->MetadataStore.find(this)->second;
|
|
|
|
assert(!Info.empty() && "Shouldn't have called this");
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-29 10:01:33 +01:00
|
|
|
Result.append(Info.begin(), Info.end());
|
2010-01-10 19:48:49 +01:00
|
|
|
|
2009-12-29 10:01:33 +01:00
|
|
|
// Sort the resulting array so it is stable.
|
|
|
|
if (Result.size() > 1)
|
|
|
|
array_pod_sort(Result.begin(), Result.end());
|
2009-12-29 00:41:32 +01:00
|
|
|
}
|
|
|
|
|
2010-04-01 07:23:13 +02:00
|
|
|
void Instruction::
|
|
|
|
getAllMetadataOtherThanDebugLocImpl(SmallVectorImpl<std::pair<unsigned,
|
|
|
|
MDNode*> > &Result) const {
|
|
|
|
Result.clear();
|
|
|
|
assert(hasMetadataHashEntry() &&
|
|
|
|
getContext().pImpl->MetadataStore.count(this) &&
|
|
|
|
"Shouldn't have called this");
|
|
|
|
const LLVMContextImpl::MDMapTy &Info =
|
2012-04-03 12:50:09 +02:00
|
|
|
getContext().pImpl->MetadataStore.find(this)->second;
|
2010-04-01 07:23:13 +02:00
|
|
|
assert(!Info.empty() && "Shouldn't have called this");
|
|
|
|
Result.append(Info.begin(), Info.end());
|
2012-04-03 12:50:09 +02:00
|
|
|
|
2010-04-01 07:23:13 +02:00
|
|
|
// Sort the resulting array so it is stable.
|
|
|
|
if (Result.size() > 1)
|
|
|
|
array_pod_sort(Result.begin(), Result.end());
|
|
|
|
}
|
|
|
|
|
2010-07-21 00:25:04 +02:00
|
|
|
/// clearMetadataHashEntries - Clear all hashtable-based metadata from
|
|
|
|
/// this instruction.
|
|
|
|
void Instruction::clearMetadataHashEntries() {
|
|
|
|
assert(hasMetadataHashEntry() && "Caller should check");
|
|
|
|
getContext().pImpl->MetadataStore.erase(this);
|
|
|
|
setHasMetadataHashEntry(false);
|
2009-12-29 08:44:16 +01:00
|
|
|
}
|
|
|
|
|