Changes in directory llvm/lib/Bitcode/Writer:
ValueEnumerator.cpp updated: 1.12 -> 1.13 --- Log message: enumerate the operands of a constant before we enumerate the constant itself This avoids fwd references in the reader. --- Diffs of the changes: (+22 -9) ValueEnumerator.cpp | 31 ++++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-) Index: llvm/lib/Bitcode/Writer/ValueEnumerator.cpp diff -u llvm/lib/Bitcode/Writer/ValueEnumerator.cpp:1.12 llvm/lib/Bitcode/Writer/ValueEnumerator.cpp:1.13 --- llvm/lib/Bitcode/Writer/ValueEnumerator.cpp:1.12 Sat May 5 19:35:24 2007 +++ llvm/lib/Bitcode/Writer/ValueEnumerator.cpp Sat May 5 20:00:28 2007 @@ -165,11 +165,10 @@ 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 @@ // 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(); } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits