[lld] [LLD] Merge .hexagon.attributes sections (PR #148098)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 13 14:11:31 PDT 2025
================
@@ -415,4 +422,117 @@ int64_t Hexagon::getImplicitAddend(const uint8_t *buf, RelType type) const {
}
}
+namespace {
+class HexagonAttributesSection final : public SyntheticSection {
+public:
+ HexagonAttributesSection(Ctx &ctx)
+ : SyntheticSection(ctx, ".hexagon.attributes", SHT_HEXAGON_ATTRIBUTES, 0,
+ 1) {}
+
+ size_t getSize() const override { return size; }
+ void writeTo(uint8_t *buf) override;
+
+ static constexpr StringRef vendor = "hexagon";
+ DenseMap<unsigned, unsigned> intAttr;
+ size_t size = 0;
+};
+} // namespace
+
+static HexagonAttributesSection *
+mergeAttributesSection(Ctx &ctx,
+ const SmallVector<InputSectionBase *, 0> §ions) {
+ ctx.in.hexagonAttributes = std::make_unique<HexagonAttributesSection>(ctx);
+ auto &merged =
+ static_cast<HexagonAttributesSection &>(*ctx.in.hexagonAttributes);
+
+ // Collect all tags values from attributes section.
+ const auto &attributesTags = HexagonAttrs::getHexagonAttributeTags();
+ for (const InputSectionBase *sec : sections) {
+ HexagonAttributeParser parser;
+ if (Error e = parser.parse(sec->content(), llvm::endianness::little))
+ Warn(ctx) << sec << ": " << std::move(e);
+ for (const auto &tag : attributesTags) {
+ switch (HexagonAttrs::AttrType(tag.attr)) {
+ case HexagonAttrs::ARCH:
+ case HexagonAttrs::HVXARCH:
+ if (auto i = parser.getAttributeValue(tag.attr)) {
+ auto r = merged.intAttr.try_emplace(tag.attr, *i);
+ if (!r.second && r.first->second != *i) {
+ if (r.first->second < *i)
+ r.first->second = *i;
+ }
+ }
+ continue;
+
+ case HexagonAttrs::HVXIEEEFP:
+ case HexagonAttrs::HVXQFLOAT:
+ case HexagonAttrs::ZREG:
+ case HexagonAttrs::AUDIO:
+ case HexagonAttrs::CABAC:
+ if (auto i = parser.getAttributeValue(tag.attr)) {
+ auto r = merged.intAttr.try_emplace(tag.attr, *i);
+ if (!r.second && r.first->second != *i) {
----------------
MaskRay wrote:
drop braces for this single-line single-statement body. We can remove `&& r.first->second != *i`.
https://github.com/llvm/llvm-project/pull/148098
More information about the llvm-commits
mailing list