diff options
author | Chris Lattner <sabre@nondot.org> | 2007-05-06 01:00:28 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-05-06 01:00:28 +0000 |
commit | 9ee4836dde03a05af46a63553e7d4eb44c184c60 (patch) | |
tree | 9a89db741bda28bb01e912baccde1e0bdcebc27d /llvm/lib/Bitcode | |
parent | f25f710c4d7fb7a0df8a3c2c3be0ab4d3111e7fc (diff) | |
download | bcm5719-llvm-9ee4836dde03a05af46a63553e7d4eb44c184c60.tar.gz bcm5719-llvm-9ee4836dde03a05af46a63553e7d4eb44c184c60.zip |
enumerate the operands of a constant before we enumerate the constant itself
This avoids fwd references in the reader.
llvm-svn: 36822
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index ae9e67c8266..f5224d2a7ca 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -165,11 +165,10 @@ void ValueEnumerator::EnumerateValue(const Value *V) { Values[ValueID-1].second++; return; } - - // Add the value. - Values.push_back(std::make_pair(V, 1U)); - ValueID = Values.size(); + // Enumerate the type of this value. + EnumerateType(V->getType()); + if (const Constant *C = dyn_cast<Constant>(V)) { if (isa<GlobalValue>(C)) { // Initializers for globals are handled explicitly elsewhere. @@ -177,16 +176,30 @@ void ValueEnumerator::EnumerateValue(const Value *V) { // Do not enumerate the initializers for an array of simple characters. // The initializers just polute the value table, and we emit the strings // specially. - } else { - // This makes sure that if a constant has uses (for example an array of - // const ints), that they are inserted also. + } else if (C->getNumOperands()) { + // If a constant has operands, enumerate them. This makes sure that if a + // constant has uses (for example an array of const ints), that they are + // inserted also. + + // We prefer to enumerate them with values before we enumerate the user + // itself. This makes it more likely that we can avoid forward references + // in the reader. We know that there can be no cycles in the constants + // graph that don't go through a global variable. for (User::const_op_iterator I = C->op_begin(), E = C->op_end(); I != E; ++I) EnumerateValue(*I); + + // Finally, add the value. Doing this could make the ValueID reference be + // dangling, don't reuse it. + Values.push_back(std::make_pair(V, 1U)); + ValueMap[V] = Values.size(); + return; } } - - EnumerateType(V->getType()); + + // Add the value. + Values.push_back(std::make_pair(V, 1U)); + ValueID = Values.size(); } |