mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-15 09:33:39 +00:00
Switch the representation of the location in instruction from
being a TrackingVH<MDNode> to a NewDebugLoc, shrinking sizeof(Instruction) a lot, and providing clients the ability to deal with locations in terms of NewDebugLoc instead of having to deal with Metadata. This is still fully compatible with all clients that *do* use MDNodes for everything of course. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100088 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b45218f7c8
commit
61336ae001
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#include "llvm/User.h"
|
#include "llvm/User.h"
|
||||||
#include "llvm/ADT/ilist_node.h"
|
#include "llvm/ADT/ilist_node.h"
|
||||||
#include "llvm/Support/ValueHandle.h"
|
#include "llvm/Support/DebugLoc.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ class Instruction : public User, public ilist_node<Instruction> {
|
|||||||
Instruction(const Instruction &); // Do not implement
|
Instruction(const Instruction &); // Do not implement
|
||||||
|
|
||||||
BasicBlock *Parent;
|
BasicBlock *Parent;
|
||||||
TrackingVH<MDNode> DbgInfo; // 'dbg' Metadata cache.
|
NewDebugLoc DbgLoc; // 'dbg' Metadata cache.
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
/// HasMetadataBit - This is a bit stored in the SubClassData field which
|
/// HasMetadataBit - This is a bit stored in the SubClassData field which
|
||||||
@ -125,7 +125,13 @@ public:
|
|||||||
/// hasMetadata() - Return true if this instruction has any metadata attached
|
/// hasMetadata() - Return true if this instruction has any metadata attached
|
||||||
/// to it.
|
/// to it.
|
||||||
bool hasMetadata() const {
|
bool hasMetadata() const {
|
||||||
return DbgInfo != 0 || hasMetadataHashEntry();
|
return !DbgLoc.isUnknown() || hasMetadataHashEntry();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// hasMetadataOtherThanDebugLoc - Return true if this instruction has
|
||||||
|
/// metadata attached to it other than a debug location.
|
||||||
|
bool hasMetadataOtherThanDebugLoc() const {
|
||||||
|
return hasMetadataHashEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getMetadata - Get the metadata of given kind attached to this Instruction.
|
/// getMetadata - Get the metadata of given kind attached to this Instruction.
|
||||||
@ -150,6 +156,14 @@ public:
|
|||||||
getAllMetadataImpl(MDs);
|
getAllMetadataImpl(MDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// getAllMetadataOtherThanDebugLoc - This does the same thing as
|
||||||
|
/// getAllMetadata, except that it filters out the debug location.
|
||||||
|
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl<std::pair<unsigned,
|
||||||
|
MDNode*> > &MDs) const {
|
||||||
|
if (hasMetadataOtherThanDebugLoc())
|
||||||
|
getAllMetadataOtherThanDebugLocImpl(MDs);
|
||||||
|
}
|
||||||
|
|
||||||
/// setMetadata - Set the metadata of the specified kind to the specified
|
/// setMetadata - Set the metadata of the specified kind to the specified
|
||||||
/// node. This updates/replaces metadata if already present, or removes it if
|
/// node. This updates/replaces metadata if already present, or removes it if
|
||||||
/// Node is null.
|
/// Node is null.
|
||||||
@ -163,9 +177,15 @@ public:
|
|||||||
/// getDbgMetadata - This is just an optimized helper function that is
|
/// getDbgMetadata - This is just an optimized helper function that is
|
||||||
/// equivalent to calling getMetadata("dbg").
|
/// equivalent to calling getMetadata("dbg").
|
||||||
MDNode *getDbgMetadata() const {
|
MDNode *getDbgMetadata() const {
|
||||||
return DbgInfo;
|
return DbgLoc.getAsMDNode(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// setDebugLoc - Set the debug location information for this instruction.
|
||||||
|
void setDebugLoc(const NewDebugLoc &Loc) { DbgLoc = Loc; }
|
||||||
|
|
||||||
|
/// getDebugLoc - Return the debug location for this node as a DebugLoc.
|
||||||
|
const NewDebugLoc &getDebugLoc() const { return DbgLoc; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// hasMetadataHashEntry - Return true if we have an entry in the on-the-side
|
/// hasMetadataHashEntry - Return true if we have an entry in the on-the-side
|
||||||
/// metadata hash.
|
/// metadata hash.
|
||||||
@ -177,6 +197,8 @@ private:
|
|||||||
MDNode *getMetadataImpl(unsigned KindID) const;
|
MDNode *getMetadataImpl(unsigned KindID) const;
|
||||||
MDNode *getMetadataImpl(const char *Kind) const;
|
MDNode *getMetadataImpl(const char *Kind) const;
|
||||||
void getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,MDNode*> > &)const;
|
void getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,MDNode*> > &)const;
|
||||||
|
void getAllMetadataOtherThanDebugLocImpl(SmallVectorImpl<std::pair<unsigned,
|
||||||
|
MDNode*> > &) const;
|
||||||
void removeAllMetadata();
|
void removeAllMetadata();
|
||||||
public:
|
public:
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
|
@ -22,7 +22,7 @@ using namespace llvm;
|
|||||||
|
|
||||||
Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
|
Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
|
||||||
Instruction *InsertBefore)
|
Instruction *InsertBefore)
|
||||||
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0), DbgInfo(0) {
|
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
|
||||||
// Make sure that we get added to a basicblock
|
// Make sure that we get added to a basicblock
|
||||||
LeakDetector::addGarbageObject(this);
|
LeakDetector::addGarbageObject(this);
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
|
|||||||
|
|
||||||
Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
|
Instruction::Instruction(const Type *ty, unsigned it, Use *Ops, unsigned NumOps,
|
||||||
BasicBlock *InsertAtEnd)
|
BasicBlock *InsertAtEnd)
|
||||||
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0), DbgInfo(0) {
|
: User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) {
|
||||||
// Make sure that we get added to a basicblock
|
// Make sure that we get added to a basicblock
|
||||||
LeakDetector::addGarbageObject(this);
|
LeakDetector::addGarbageObject(this);
|
||||||
|
|
||||||
|
@ -425,7 +425,7 @@ MDNode *Instruction::getMetadataImpl(const char *Kind) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Instruction::setDbgMetadata(MDNode *Node) {
|
void Instruction::setDbgMetadata(MDNode *Node) {
|
||||||
DbgInfo = Node;
|
DbgLoc = NewDebugLoc::getFromDILocation(Node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// setMetadata - Set the metadata of of the specified kind to the specified
|
/// setMetadata - Set the metadata of of the specified kind to the specified
|
||||||
@ -436,7 +436,7 @@ void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
|
|||||||
|
|
||||||
// Handle 'dbg' as a special case since it is not stored in the hash table.
|
// Handle 'dbg' as a special case since it is not stored in the hash table.
|
||||||
if (KindID == LLVMContext::MD_dbg) {
|
if (KindID == LLVMContext::MD_dbg) {
|
||||||
DbgInfo = Node;
|
DbgLoc = NewDebugLoc::getFromDILocation(Node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,7 +488,7 @@ void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
|
|||||||
MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
|
MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
|
||||||
// Handle 'dbg' as a special case since it is not stored in the hash table.
|
// Handle 'dbg' as a special case since it is not stored in the hash table.
|
||||||
if (KindID == LLVMContext::MD_dbg)
|
if (KindID == LLVMContext::MD_dbg)
|
||||||
return DbgInfo;
|
return DbgLoc.getAsMDNode(getContext());
|
||||||
|
|
||||||
if (!hasMetadataHashEntry()) return 0;
|
if (!hasMetadataHashEntry()) return 0;
|
||||||
|
|
||||||
@ -507,8 +507,9 @@ void Instruction::getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,
|
|||||||
Result.clear();
|
Result.clear();
|
||||||
|
|
||||||
// Handle 'dbg' as a special case since it is not stored in the hash table.
|
// Handle 'dbg' as a special case since it is not stored in the hash table.
|
||||||
if (DbgInfo) {
|
if (!DbgLoc.isUnknown()) {
|
||||||
Result.push_back(std::make_pair((unsigned)LLVMContext::MD_dbg, DbgInfo));
|
Result.push_back(std::make_pair((unsigned)LLVMContext::MD_dbg,
|
||||||
|
DbgLoc.getAsMDNode(getContext())));
|
||||||
if (!hasMetadataHashEntry()) return;
|
if (!hasMetadataHashEntry()) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -526,10 +527,29 @@ void Instruction::getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,
|
|||||||
array_pod_sort(Result.begin(), Result.end());
|
array_pod_sort(Result.begin(), Result.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 =
|
||||||
|
getContext().pImpl->MetadataStore.find(this)->second;
|
||||||
|
assert(!Info.empty() && "Shouldn't have called this");
|
||||||
|
|
||||||
|
Result.append(Info.begin(), Info.end());
|
||||||
|
|
||||||
|
// Sort the resulting array so it is stable.
|
||||||
|
if (Result.size() > 1)
|
||||||
|
array_pod_sort(Result.begin(), Result.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// removeAllMetadata - Remove all metadata from this instruction.
|
/// removeAllMetadata - Remove all metadata from this instruction.
|
||||||
void Instruction::removeAllMetadata() {
|
void Instruction::removeAllMetadata() {
|
||||||
assert(hasMetadata() && "Caller should check");
|
assert(hasMetadata() && "Caller should check");
|
||||||
DbgInfo = 0;
|
DbgLoc = NewDebugLoc();
|
||||||
if (hasMetadataHashEntry()) {
|
if (hasMetadataHashEntry()) {
|
||||||
getContext().pImpl->MetadataStore.erase(this);
|
getContext().pImpl->MetadataStore.erase(this);
|
||||||
setHasMetadataHashEntry(false);
|
setHasMetadataHashEntry(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user