[WebAssembly] Identify COMDATs by index rather than string. NFC
This will enable an optimisation in LLD.
Differential Revision: https://reviews.llvm.org/D44343
llvm-svn: 327522
diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp
index 1abd7b8..29bf9b5 100644
--- a/llvm/tools/obj2yaml/wasm2yaml.cpp
+++ b/llvm/tools/obj2yaml/wasm2yaml.cpp
@@ -62,15 +62,12 @@
CustomSec = std::move(NameSec);
} else if (WasmSec.Name == "linking") {
std::unique_ptr<WasmYAML::LinkingSection> LinkingSec = make_unique<WasmYAML::LinkingSection>();
- std::map<StringRef,size_t> ComdatIndexes;
- for (StringRef ComdatName : Obj.comdats()) {
- ComdatIndexes[ComdatName] = LinkingSec->Comdats.size();
+ ArrayRef<StringRef> Comdats = Obj.linkingData().Comdats;
+ for (StringRef ComdatName : Comdats)
LinkingSec->Comdats.emplace_back(WasmYAML::Comdat{ComdatName, {}});
- }
for (auto &Func : Obj.functions()) {
- if (!Func.Comdat.empty()) {
- auto &Comdat = LinkingSec->Comdats[ComdatIndexes[Func.Comdat]];
- Comdat.Entries.emplace_back(
+ if (Func.Comdat != UINT32_MAX) {
+ LinkingSec->Comdats[Func.Comdat].Entries.emplace_back(
WasmYAML::ComdatEntry{wasm::WASM_COMDAT_FUNCTION, Func.Index});
}
}
@@ -84,9 +81,8 @@
SegmentInfo.Flags = Segment.Data.Flags;
LinkingSec->SegmentInfos.push_back(SegmentInfo);
}
- if (!Segment.Data.Comdat.empty()) {
- auto &Comdat = LinkingSec->Comdats[ComdatIndexes[Segment.Data.Comdat]];
- Comdat.Entries.emplace_back(
+ if (Segment.Data.Comdat != UINT32_MAX) {
+ LinkingSec->Comdats[Segment.Data.Comdat].Entries.emplace_back(
WasmYAML::ComdatEntry{wasm::WASM_COMDAT_DATA, SegmentIndex});
}
SegmentIndex++;