From 845b03cea46d5f9d071384dc74786977ae9e70f5 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 20 Jul 2023 00:06:47 -0700 Subject: [PATCH] [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). --- llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp index b9e6e0f..d492bec 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> CustomSections; + MapVector> CustomSections; const ConstantArray *CA = cast(V->getOperand(0)); for (Value *Op : CA->operands()) { auto *CS = cast(Op); @@ -580,15 +580,14 @@ void WebAssemblyAsmPrinter::EmitFunctionAttributes(Module &M) { auto *GV = cast(CS->getOperand(1)->stripPointerCasts()); StringRef AnnotationString; getConstantStringInfo(GV, AnnotationString); - std::string Name = "annotate." + AnnotationString.str(); auto *Sym = cast(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); -- 2.7.4