[llvm-commits] [llvm] r92315 - in /llvm/trunk: include/llvm/Metadata.h lib/VMCore/Metadata.cpp
Chris Lattner
sabre at nondot.org
Wed Dec 30 13:42:12 PST 2009
Author: lattner
Date: Wed Dec 30 15:42:11 2009
New Revision: 92315
URL: http://llvm.org/viewvc/llvm-project?rev=92315&view=rev
Log:
do not bother reuniquing mdnodes whose operands drop to null. Doing
so can be a huge performance issue when tearing down modules and mdnodes
are not guaranteed to be unique anyway. This speeds up:
$ time ~/llvm/Release/bin/clang gcc.c -w -S -g
from 72 to 35s, where gcc.c is from:
http://people.csail.mit.edu/smcc/projects/single-file-programs/
Modified:
llvm/trunk/include/llvm/Metadata.h
llvm/trunk/lib/VMCore/Metadata.cpp
Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=92315&r1=92314&r2=92315&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Wed Dec 30 15:42:11 2009
@@ -85,8 +85,6 @@
//===----------------------------------------------------------------------===//
/// MDNode - a tuple of other values.
-/// These contain a list of the values that represent the metadata.
-/// MDNode is always unnamed.
class MDNode : public MetadataBase, public FoldingSetNode {
MDNode(const MDNode &); // DO NOT IMPLEMENT
void operator=(const MDNode &); // DO NOT IMPLEMENT
@@ -97,7 +95,14 @@
// Subclass data enums.
enum {
- FunctionLocalBit = 1
+ /// FunctionLocalBit - This bit is set if this MDNode is function local.
+ /// This is true when it (potentially transitively) contains a reference to
+ /// something in a function, like an argument, basicblock, or instruction.
+ FunctionLocalBit = 1 << 0,
+
+ /// NotUniquedBit - This is set on MDNodes that are not uniqued because they
+ /// have a null perand.
+ NotUniquedBit = 1 << 1
};
// Replace each instance of F from the element list of this node with T.
@@ -138,6 +143,13 @@
return V->getValueID() == MDNodeVal;
}
private:
+ bool isNotUniqued() const {
+ return (getSubclassDataFromValue() & NotUniquedBit) != 0;
+ }
+ void setIsNotUniqued() {
+ setValueSubclassData(getSubclassDataFromValue() | NotUniquedBit);
+ }
+
// Shadow Value::setValueSubclassData with a private forwarding method so that
// any future subclasses cannot accidentally use it.
void setValueSubclassData(unsigned short D) {
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=92315&r1=92314&r2=92315&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Wed Dec 30 15:42:11 2009
@@ -87,8 +87,10 @@
/// ~MDNode - Destroy MDNode.
MDNode::~MDNode() {
- LLVMContextImpl *pImpl = getType()->getContext().pImpl;
- pImpl->MDNodeSet.RemoveNode(this);
+ if (!isNotUniqued()) {
+ LLVMContextImpl *pImpl = getType()->getContext().pImpl;
+ pImpl->MDNodeSet.RemoveNode(this);
+ }
delete [] Operands;
Operands = NULL;
}
@@ -97,6 +99,7 @@
bool isFunctionLocal)
: MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) {
NumOperands = NumVals;
+ // FIXME: Coallocate the operand list. These have fixed arity.
Operands = new MDNodeElement[NumOperands];
for (unsigned i = 0; i != NumVals; ++i)
@@ -146,25 +149,40 @@
if (From == To)
return;
+ // Update the operand.
+ Op->set(To, this);
+
+ // 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;
+
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);
- // Update the operand.
- Op->set(To, this);
-
- // Insert updated "this" into the context's folding node set.
- // If a node with same element list already exist then before inserting
- // updated "this" into the folding node set, replace all uses of existing
- // node with updated "this" node.
+ // If we are dropping an argument to null, we choose to not unique the MDNode
+ // anymore. This commonly occurs during destruction, and uniquing these
+ // brings little reuse.
+ if (To == 0) {
+ setIsNotUniqued();
+ return;
+ }
+
+ // 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
+ // in the set. If it doesn't exist, this returns the position to insert it.
FoldingSetNodeID ID;
Profile(ID);
void *InsertPoint;
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
if (N) {
+ // FIXME:
+ // If it already exists in the set, we don't reinsert it, we just claim it
+ // isn't uniqued.
+
N->replaceAllUsesWith(this);
delete N;
N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
More information about the llvm-commits
mailing list