[llvm] r327522 - [WebAssembly] Identify COMDATs by index rather than string. NFC
Nicholas Wilson via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 14 08:44:45 PDT 2018
Author: ncw
Date: Wed Mar 14 08:44:45 2018
New Revision: 327522
URL: http://llvm.org/viewvc/llvm-project?rev=327522&view=rev
Log:
[WebAssembly] Identify COMDATs by index rather than string. NFC
This will enable an optimisation in LLD.
Differential Revision: https://reviews.llvm.org/D44343
Modified:
llvm/trunk/include/llvm/BinaryFormat/Wasm.h
llvm/trunk/include/llvm/Object/Wasm.h
llvm/trunk/lib/Object/WasmObjectFile.cpp
llvm/trunk/tools/obj2yaml/wasm2yaml.cpp
Modified: llvm/trunk/include/llvm/BinaryFormat/Wasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/Wasm.h?rev=327522&r1=327521&r2=327522&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BinaryFormat/Wasm.h (original)
+++ llvm/trunk/include/llvm/BinaryFormat/Wasm.h Wed Mar 14 08:44:45 2018
@@ -101,7 +101,7 @@ struct WasmFunction {
uint32_t CodeSectionOffset;
uint32_t Size;
StringRef Name; // from the "linking" or "names" section
- StringRef Comdat; // from the "comdat info" section
+ uint32_t Comdat; // from the "comdat info" section
};
struct WasmDataSegment {
@@ -111,7 +111,7 @@ struct WasmDataSegment {
StringRef Name;
uint32_t Alignment;
uint32_t Flags;
- StringRef Comdat; // from the "comdat info" section
+ uint32_t Comdat; // from the "comdat info" section
};
struct WasmElemSegment {
@@ -160,6 +160,7 @@ struct WasmFunctionName {
struct WasmLinkingData {
std::vector<WasmInitFunc> InitFunctions;
+ std::vector<StringRef> Comdats;
std::vector<WasmSymbolInfo> SymbolTable;
};
Modified: llvm/trunk/include/llvm/Object/Wasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Wasm.h?rev=327522&r1=327521&r2=327522&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Wasm.h (original)
+++ llvm/trunk/include/llvm/Object/Wasm.h Wed Mar 14 08:44:45 2018
@@ -141,7 +141,6 @@ public:
ArrayRef<wasm::WasmElemSegment> elements() const { return ElemSegments; }
ArrayRef<WasmSegment> dataSegments() const { return DataSegments; }
ArrayRef<wasm::WasmFunction> functions() const { return Functions; }
- ArrayRef<StringRef> comdats() const { return Comdats; }
ArrayRef<wasm::WasmFunctionName> debugNames() const { return DebugNames; }
uint32_t startFunction() const { return StartFunction; }
uint32_t getNumImportedGlobals() const { return NumImportedGlobals; }
@@ -255,7 +254,6 @@ private:
std::vector<WasmSegment> DataSegments;
std::vector<wasm::WasmFunction> Functions;
std::vector<WasmSymbol> Symbols;
- std::vector<StringRef> Comdats;
std::vector<wasm::WasmFunctionName> DebugNames;
uint32_t StartFunction = -1;
bool HasLinkingSection = false;
Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=327522&r1=327521&r2=327522&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Wed Mar 14 08:44:45 2018
@@ -485,12 +485,12 @@ Error WasmObjectFile::parseLinkingSectio
{
uint32_t ComdatCount = readVaruint32(Ptr);
StringSet<> ComdatSet;
- while (ComdatCount--) {
+ for (unsigned ComdatIndex = 0; ComdatIndex < ComdatCount; ++ComdatIndex) {
StringRef Name = readString(Ptr);
if (Name.empty() || !ComdatSet.insert(Name).second)
return make_error<GenericBinaryError>("Bad/duplicate COMDAT name " + Twine(Name),
object_error::parse_failed);
- Comdats.emplace_back(Name);
+ LinkingData.Comdats.emplace_back(Name);
uint32_t Flags = readVaruint32(Ptr);
if (Flags != 0)
return make_error<GenericBinaryError>("Unsupported COMDAT flags",
@@ -508,19 +508,19 @@ Error WasmObjectFile::parseLinkingSectio
if (Index >= DataSegments.size())
return make_error<GenericBinaryError>("COMDAT data index out of range",
object_error::parse_failed);
- if (!DataSegments[Index].Data.Comdat.empty())
+ if (DataSegments[Index].Data.Comdat != UINT32_MAX)
return make_error<GenericBinaryError>("Data segment in two COMDATs",
object_error::parse_failed);
- DataSegments[Index].Data.Comdat = Name;
+ DataSegments[Index].Data.Comdat = ComdatIndex;
break;
case wasm::WASM_COMDAT_FUNCTION:
if (!isDefinedFunctionIndex(Index))
return make_error<GenericBinaryError>("COMDAT function index out of range",
object_error::parse_failed);
- if (!getDefinedFunction(Index).Comdat.empty())
+ if (getDefinedFunction(Index).Comdat != UINT32_MAX)
return make_error<GenericBinaryError>("Function in two COMDATs",
object_error::parse_failed);
- getDefinedFunction(Index).Comdat = Name;
+ getDefinedFunction(Index).Comdat = ComdatIndex;
break;
}
}
@@ -878,6 +878,8 @@ Error WasmObjectFile::parseCodeSection(c
uint32_t BodySize = FunctionEnd - Ptr;
Function.Body = ArrayRef<uint8_t>(Ptr, BodySize);
+ // This will be set later when reading in the linking metadata section.
+ Function.Comdat = UINT32_MAX;
Ptr += BodySize;
assert(Ptr == FunctionEnd);
Functions.push_back(Function);
@@ -924,8 +926,11 @@ Error WasmObjectFile::parseDataSection(c
return Err;
uint32_t Size = readVaruint32(Ptr);
Segment.Data.Content = ArrayRef<uint8_t>(Ptr, Size);
+ // The rest of these Data fields are set later, when reading in the linking
+ // metadata section.
Segment.Data.Alignment = 0;
Segment.Data.Flags = 0;
+ Segment.Data.Comdat = UINT32_MAX;
Segment.SectionOffset = Ptr - Start;
Ptr += Size;
DataSegments.push_back(Segment);
Modified: llvm/trunk/tools/obj2yaml/wasm2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/wasm2yaml.cpp?rev=327522&r1=327521&r2=327522&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/wasm2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/wasm2yaml.cpp Wed Mar 14 08:44:45 2018
@@ -62,15 +62,12 @@ std::unique_ptr<WasmYAML::CustomSection>
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 @@ std::unique_ptr<WasmYAML::CustomSection>
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++;
More information about the llvm-commits
mailing list