[llvm] 845b03c - [WebAssembly] Use MapVector to stabilize iteration order after D150803

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 20 00:06:51 PDT 2023


Author: Fangrui Song
Date: 2023-07-20T00:06:47-07:00
New Revision: 845b03cea46d5f9d071384dc74786977ae9e70f5

URL: https://github.com/llvm/llvm-project/commit/845b03cea46d5f9d071384dc74786977ae9e70f5
DIFF: https://github.com/llvm/llvm-project/commit/845b03cea46d5f9d071384dc74786977ae9e70f5.diff

LOG: [WebAssembly] Use MapVector to stabilize iteration order after D150803

StringMap iteration order is not guaranteed to be deterministic
(https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).

Added: 
    

Modified: 
    llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index b9e6e0f534198f..d492bec97d463f 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -25,9 +25,9 @@
 #include "WebAssemblyRegisterInfo.h"
 #include "WebAssemblyRuntimeLibcallSignatures.h"
 #include "WebAssemblyTargetMachine.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/StringMap.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/BinaryFormat/Wasm.h"
 #include "llvm/CodeGen/Analysis.h"
@@ -565,7 +565,7 @@ void WebAssemblyAsmPrinter::EmitFunctionAttributes(Module &M) {
     return;
 
   // Group all the custom attributes by name.
-  StringMap<SmallVector<MCSymbol *, 4>> CustomSections;
+  MapVector<StringRef, SmallVector<MCSymbol *, 4>> CustomSections;
   const ConstantArray *CA = cast<ConstantArray>(V->getOperand(0));
   for (Value *Op : CA->operands()) {
     auto *CS = cast<ConstantStruct>(Op);
@@ -580,15 +580,14 @@ void WebAssemblyAsmPrinter::EmitFunctionAttributes(Module &M) {
     auto *GV = cast<GlobalVariable>(CS->getOperand(1)->stripPointerCasts());
     StringRef AnnotationString;
     getConstantStringInfo(GV, AnnotationString);
-    std::string Name = "annotate." + AnnotationString.str();
     auto *Sym = cast<MCSymbolWasm>(getSymbol(F));
-    CustomSections[Name].push_back(Sym);
+    CustomSections[AnnotationString].push_back(Sym);
   }
 
   // Emit a custom section for each unique attribute.
   for (const auto &[Name, Symbols] : CustomSections) {
     MCSectionWasm *CustomSection = OutContext.getWasmSection(
-        ".custom_section.llvm.func_attr." + Name, SectionKind::getMetadata());
+        ".custom_section.llvm.func_attr.annotate." + Name, SectionKind::getMetadata());
     OutStreamer->pushSection();
     OutStreamer->switchSection(CustomSection);
 


        


More information about the llvm-commits mailing list