[llvm] r197735 - Ensure deterministic when printing ARM assembler constant pools

David Peixotto dpeixott at codeaurora.org
Thu Dec 19 14:41:56 PST 2013


Author: dpeixott
Date: Thu Dec 19 16:41:56 2013
New Revision: 197735

URL: http://llvm.org/viewvc/llvm-project?rev=197735&view=rev
Log:
Ensure deterministic when printing ARM assembler constant pools

We dump any non-empty assembler constant pools after a successful
parse of an assembly file that uses the ldr pseudo opcode. These
per-section constant pools should be output in a deterministic order
to ensure that we always generate the same output when printing the
output with an AsmStreamer.

This patch changes the map data struture used to associate a section
with its constant pool to a MapVector to ensure deterministic
output. Because this map type does not support deletion, we now
check that the constant pool is not empty before dumping its entries
and clear the entries after emitting them with the streamer.

Modified:
    llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=197735&r1=197734&r2=197735&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Thu Dec 19 16:41:56 2013
@@ -16,6 +16,7 @@
 #include "MCTargetDesc/ARMBaseInfo.h"
 #include "MCTargetDesc/ARMMCExpr.h"
 #include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -73,7 +74,9 @@ public:
   }
 
   // Emit the contents of the constant pool using the provided streamer.
-  void emitEntries(MCStreamer &Streamer) const {
+  void emitEntries(MCStreamer &Streamer) {
+    if (Entries.empty())
+      return;
     Streamer.EmitCodeAlignment(4); // align to 4-byte address
     Streamer.EmitDataRegion(MCDR_DataRegion);
     for (EntryVecTy::const_iterator I = Entries.begin(), E = Entries.end();
@@ -82,6 +85,12 @@ public:
       Streamer.EmitValue(I->second, 4);
     }
     Streamer.EmitDataRegion(MCDR_DataRegionEnd);
+    Entries.clear();
+  }
+
+  // Return true if the constant pool is empty
+  bool empty() {
+    return Entries.empty();
   }
 };
 
@@ -93,7 +102,13 @@ public:
 // an opcode to the ldr. After we have parsed all the user input we
 // output the (label, value) pairs in each constant pool at the end of the
 // section.
-typedef std::map<const MCSection *, ConstantPool> ConstantPoolMapTy;
+//
+// We use the MapVector for the map type to ensure stable iteration of
+// the sections at the end of the parse. We need to iterate over the
+// sections in a stable order to ensure that we have print the
+// constant pools in a deterministic order when printing an assembly
+// file.
+typedef MapVector<const MCSection *, ConstantPool> ConstantPoolMapTy;
 
 class ARMAsmParser : public MCTargetAsmParser {
   MCSubtargetInfo &STI;
@@ -115,10 +130,6 @@ class ARMAsmParser : public MCTargetAsmP
     return ConstantPools[Section];
   }
 
-  void destroyConstantPool(const MCSection *Section) {
-    ConstantPools.erase(Section);
-  }
-
   ARMTargetStreamer &getTargetStreamer() {
     MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
     return static_cast<ARMTargetStreamer &>(TS);
@@ -8459,9 +8470,8 @@ bool ARMAsmParser::parseDirectiveLtorg(S
   const MCSection *Section = Streamer.getCurrentSection().first;
 
   if (ConstantPool *CP = getConstantPool(Section)) {
-    CP->emitEntries(Streamer);
-    CP = 0;
-    destroyConstantPool(Section);
+    if (!CP->empty())
+      CP->emitEntries(Streamer);
   }
   return false;
 }
@@ -8504,8 +8514,10 @@ void ARMAsmParser::finishParse() {
     const MCSection *Section = CPI->first;
     ConstantPool &CP = CPI->second;
 
-    // Dump assembler constant pools at the end of the section.
-    Streamer.SwitchSection(Section);
-    CP.emitEntries(Streamer);
+    // Dump non-empty assembler constant pools at the end of the section.
+    if (!CP.empty()) {
+      Streamer.SwitchSection(Section);
+      CP.emitEntries(Streamer);
+    }
   }
 }





More information about the llvm-commits mailing list