[llvm] r267345 - BitcodeReader: Delay metadata parsing until reading a function body

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 24 08:04:28 PDT 2016


Author: dexonsmith
Date: Sun Apr 24 10:04:28 2016
New Revision: 267345

URL: http://llvm.org/viewvc/llvm-project?rev=267345&view=rev
Log:
BitcodeReader: Delay metadata parsing until reading a function body

There's hardly any functionality change here.  Instead of calling
materializeMetadata on the first call to materialize(GlobalValue*), wait
until the first one that's actually going to do something.  Noticed by
inspection; I don't have a concrete case where this makes a difference.

Added an assertion in materializeMetadata to be sure this (or a future
change) doesn't delay materializeMetadata after function-level metadata.

Modified:
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=267345&r1=267344&r2=267345&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Sun Apr 24 10:04:28 2016
@@ -2108,6 +2108,9 @@ void PlaceholderQueue::flush(BitcodeRead
 /// Parse a METADATA_BLOCK. If ModuleLevel is true then we are parsing
 /// module level metadata.
 std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
+  assert((ModuleLevel || DeferredMetadataInfo.empty()) &&
+         "Must read all module-level metadata before function-level");
+
   IsMetadataMaterialized = true;
   unsigned NextMetadataNo = MetadataList.size();
 
@@ -5547,9 +5550,6 @@ std::error_code BitcodeReader::findFunct
 void BitcodeReader::releaseBuffer() { Buffer.release(); }
 
 std::error_code BitcodeReader::materialize(GlobalValue *GV) {
-  if (std::error_code EC = materializeMetadata())
-    return EC;
-
   Function *F = dyn_cast<Function>(GV);
   // If it's not a function or is already material, ignore the request.
   if (!F || !F->isMaterializable())
@@ -5563,6 +5563,10 @@ std::error_code BitcodeReader::materiali
     if (std::error_code EC = findFunctionInStream(F, DFII))
       return EC;
 
+  // Materialize metadata before parsing any function bodies.
+  if (std::error_code EC = materializeMetadata())
+    return EC;
+
   // Move the bit stream to the saved position of the deferred function body.
   Stream.JumpToBit(DFII->second);
 




More information about the llvm-commits mailing list