[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-19 Thread Brian Cain via cfe-commits

https://github.com/androm3da closed 
https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-19 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -0,0 +1,24 @@
+/// attribute parsing error cases.
+
+// RUN: not llvm-mc -triple=hexagon -filetype=asm %s 2>&1 \
+// RUN:   | FileCheck %s
+
+  .attribute Tag_unknown_name, 0
+// CHECK: error: attribute name not recognized: Tag_unknown_name

quic-areg wrote:

Done

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -251,7 +251,10 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t 
Machine, unsigned Type) {
 }
 break;
   case ELF::EM_HEXAGON:
-switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_HEX_ORDERED); }
+switch (Type) {
+  STRINGIFY_ENUM_CASE(ELF, SHT_HEX_ORDERED);

quic-areg wrote:

Added 

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -0,0 +1,20 @@
+/// Enabled by default for assembly
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Can be forced on or off for assembly.
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mno-default-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mdefault-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Option ignored C/C++ (since we always emit hardware and ABI build 
attributes
+/// during codegen).
+// RUN: %clang -target hexagon-unknown-elf -### -x c %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### -x c++ %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+
+// CHECK-DISABLED-NOT: "-hexagon-add-build-attributes"
+// CHECK-ENABLED: "-hexagon-add-build-attributes"
+// expected-warning {{argument unused during compilation: 
'-mno-default-build-attributes'}}

quic-areg wrote:

Changed

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -395,7 +396,8 @@ template  class ELFObjectFile : public 
ELFObjectFileBase {
 
 for (const Elf_Shdr  : *SectionsOrErr) {
   if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES ||
-  Sec.sh_type == ELF::SHT_RISCV_ATTRIBUTES) {
+  Sec.sh_type == ELF::SHT_RISCV_ATTRIBUTES ||

quic-areg wrote:

Done

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -652,6 +660,57 @@ bool HexagonAsmParser::MatchAndEmitInstruction(SMLoc 
IDLoc, unsigned ,
 return finishBundle(IDLoc, Out);
   return false;
 }
+/// parseDirectiveAttribute
+///  ::= .attribute int, int
+///  ::= .attribute Tag_name, int
+bool HexagonAsmParser::parseDirectiveAttribute(SMLoc L) {
+  MCAsmParser  = getParser();
+  int64_t Tag;
+  SMLoc TagLoc = Parser.getTok().getLoc();
+  if (Parser.getTok().is(AsmToken::Identifier)) {
+StringRef Name = Parser.getTok().getIdentifier();
+std::optional Ret = ELFAttrs::attrTypeFromString(
+Name, HexagonAttrs::getHexagonAttributeTags());
+if (!Ret)
+  return Error(TagLoc, "attribute name not recognized: " + Name);
+Tag = *Ret;
+Parser.Lex();
+  } else {
+const MCExpr *AttrExpr;
+
+TagLoc = Parser.getTok().getLoc();
+if (Parser.parseExpression(AttrExpr))
+  return true;
+
+const MCConstantExpr *CE = dyn_cast(AttrExpr);
+if (check(!CE, TagLoc, "expected numeric constant"))
+  return true;
+
+Tag = CE->getValue();
+  }
+
+  if (Parser.parseComma())
+return true;
+
+  // We currently only have integer values.
+  int64_t IntegerValue = 0;
+  SMLoc ValueExprLoc = Parser.getTok().getLoc();
+  const MCExpr *ValueExpr;
+  if (Parser.parseExpression(ValueExpr))
+return true;
+
+  const MCConstantExpr *CE = dyn_cast(ValueExpr);
+  if (!CE)
+return Error(ValueExprLoc, "expected numeric constant");
+  IntegerValue = CE->getValue();
+
+  if (Parser.parseEOL())
+return true;
+
+  getTargetStreamer().emitAttribute(Tag, IntegerValue);
+

quic-areg wrote:

Removed

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -79,7 +80,8 @@ static cl::opt ErrorNoncontigiousRegister(
 "merror-noncontigious-register",
 cl::desc("Error for register names that aren't contigious"),
 cl::init(false));
-
+static cl::opt AddBuildAttributes("hexagon-add-build-attributes",
+cl::init(false));

quic-areg wrote:

Removed

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits


@@ -0,0 +1,20 @@
+/// Enabled by default for assembly
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 \

quic-areg wrote:

Done

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-18 Thread via cfe-commits

https://github.com/quic-areg updated 
https://github.com/llvm/llvm-project/pull/85359

>From 997c2741ce4ca85e5e23d7e73b6894fd07b79b8d Mon Sep 17 00:00:00 2001
From: quic-areg 
Date: Thu, 14 Mar 2024 20:31:37 -0700
Subject: [PATCH 1/3] [Hexagon] ELF attributes for Hexagon

Defines a subset of attributes and emits them to a section called
.hexagon.attributes.

The current attributes recorded are the attributes needed by
llvm-objdump to automatically determine target features and eliminate
the need to manually pass features.
---
 clang/lib/Driver/ToolChains/Clang.cpp |  8 ++
 .../Driver/hexagon-default-build-attributes.s | 20 
 llvm/include/llvm/BinaryFormat/ELF.h  |  2 +
 llvm/include/llvm/Object/ELFObjectFile.h  |  1 +
 .../llvm/Support/HexagonAttributeParser.h | 36 +++
 llvm/include/llvm/Support/HexagonAttributes.h | 32 +++
 llvm/lib/Object/ELF.cpp   |  5 +-
 llvm/lib/Object/ELFObjectFile.cpp | 78 +++
 llvm/lib/ObjectYAML/ELFYAML.cpp   |  1 +
 llvm/lib/Support/CMakeLists.txt   |  2 +
 llvm/lib/Support/HexagonAttributeParser.cpp   | 55 +++
 llvm/lib/Support/HexagonAttributes.cpp| 27 ++
 .../Hexagon/AsmParser/HexagonAsmParser.cpp| 63 -
 llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp | 20 
 llvm/lib/Target/Hexagon/HexagonAsmPrinter.h   |  4 +
 .../Target/Hexagon/HexagonTargetStreamer.h|  9 ++
 .../MCTargetDesc/HexagonMCELFStreamer.cpp | 61 
 .../MCTargetDesc/HexagonMCTargetDesc.cpp  | 72 --
 .../MCTargetDesc/HexagonMCTargetDesc.h|  6 +-
 llvm/test/CodeGen/Hexagon/build-attributes.ll | 16 
 .../test/MC/Hexagon/directive-attribute-err.s | 24 +
 llvm/test/MC/Hexagon/directive-attribute.s| 41 
 llvm/test/MC/Hexagon/hexagon_attributes.s | 94 +++
 llvm/tools/llvm-readobj/ELFDumper.cpp |  6 ++
 24 files changed, 674 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/Driver/hexagon-default-build-attributes.s
 create mode 100644 llvm/include/llvm/Support/HexagonAttributeParser.h
 create mode 100644 llvm/include/llvm/Support/HexagonAttributes.h
 create mode 100644 llvm/lib/Support/HexagonAttributeParser.cpp
 create mode 100644 llvm/lib/Support/HexagonAttributes.cpp
 create mode 100644 llvm/test/CodeGen/Hexagon/build-attributes.ll
 create mode 100644 llvm/test/MC/Hexagon/directive-attribute-err.s
 create mode 100644 llvm/test/MC/Hexagon/directive-attribute.s
 create mode 100644 llvm/test/MC/Hexagon/hexagon_attributes.s

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 055884d275ce1b..bcdf2737bc7ae0 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8481,6 +8481,14 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);
 break;
+
+  case llvm::Triple::hexagon:
+if (Args.hasFlag(options::OPT_mdefault_build_attributes,
+ options::OPT_mno_default_build_attributes, true)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-hexagon-add-build-attributes");
+}
+break;
   }
 
   // Consume all the warning flags. Usually this would be handled more
diff --git a/clang/test/Driver/hexagon-default-build-attributes.s 
b/clang/test/Driver/hexagon-default-build-attributes.s
new file mode 100644
index 00..b83181d6d52e01
--- /dev/null
+++ b/clang/test/Driver/hexagon-default-build-attributes.s
@@ -0,0 +1,20 @@
+/// Enabled by default for assembly
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Can be forced on or off for assembly.
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mno-default-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mdefault-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Option ignored C/C++ (since we always emit hardware and ABI build 
attributes
+/// during codegen).
+// RUN: %clang -target hexagon-unknown-elf -### -x c %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### -x c++ %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+
+// CHECK-DISABLED-NOT: "-hexagon-add-build-attributes"
+// CHECK-ENABLED: "-hexagon-add-build-attributes"
+// expected-warning {{argument unused during compilation: 
'-mno-default-build-attributes'}}
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h 
b/llvm/include/llvm/BinaryFormat/ELF.h
index bace3a92677a82..877f3f7862c8ba 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1141,6 +1141,8 @@ enum : unsigned {
 
   SHT_CSKY_ATTRIBUTES = 

[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,24 @@
+/// attribute parsing error cases.
+
+// RUN: not llvm-mc -triple=hexagon -filetype=asm %s 2>&1 \
+// RUN:   | FileCheck %s
+
+  .attribute Tag_unknown_name, 0
+// CHECK: error: attribute name not recognized: Tag_unknown_name

MaskRay wrote:

Newer MC tests try to test the error line/column information like: 
`[[#@LINE-1]]:4: error:`

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread Fangrui Song via cfe-commits


@@ -251,7 +251,10 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t 
Machine, unsigned Type) {
 }
 break;
   case ELF::EM_HEXAGON:
-switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_HEX_ORDERED); }
+switch (Type) {
+  STRINGIFY_ENUM_CASE(ELF, SHT_HEX_ORDERED);

MaskRay wrote:

Add a test to 
llvm/test/tools/llvm-readobj/ELF/machine-specific-section-types.test

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread Fangrui Song via cfe-commits


@@ -395,7 +396,8 @@ template  class ELFObjectFile : public 
ELFObjectFileBase {
 
 for (const Elf_Shdr  : *SectionsOrErr) {
   if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES ||
-  Sec.sh_type == ELF::SHT_RISCV_ATTRIBUTES) {
+  Sec.sh_type == ELF::SHT_RISCV_ATTRIBUTES ||

MaskRay wrote:

These values are all equal. However, we should check `getEMachine() == 
EM_HEXAGON` before testing a processor-specific section type

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread Fangrui Song via cfe-commits


@@ -652,6 +660,57 @@ bool HexagonAsmParser::MatchAndEmitInstruction(SMLoc 
IDLoc, unsigned ,
 return finishBundle(IDLoc, Out);
   return false;
 }
+/// parseDirectiveAttribute
+///  ::= .attribute int, int
+///  ::= .attribute Tag_name, int
+bool HexagonAsmParser::parseDirectiveAttribute(SMLoc L) {
+  MCAsmParser  = getParser();
+  int64_t Tag;
+  SMLoc TagLoc = Parser.getTok().getLoc();
+  if (Parser.getTok().is(AsmToken::Identifier)) {
+StringRef Name = Parser.getTok().getIdentifier();
+std::optional Ret = ELFAttrs::attrTypeFromString(
+Name, HexagonAttrs::getHexagonAttributeTags());
+if (!Ret)
+  return Error(TagLoc, "attribute name not recognized: " + Name);
+Tag = *Ret;
+Parser.Lex();
+  } else {
+const MCExpr *AttrExpr;
+
+TagLoc = Parser.getTok().getLoc();
+if (Parser.parseExpression(AttrExpr))
+  return true;
+
+const MCConstantExpr *CE = dyn_cast(AttrExpr);
+if (check(!CE, TagLoc, "expected numeric constant"))
+  return true;
+
+Tag = CE->getValue();
+  }
+
+  if (Parser.parseComma())
+return true;
+
+  // We currently only have integer values.
+  int64_t IntegerValue = 0;
+  SMLoc ValueExprLoc = Parser.getTok().getLoc();
+  const MCExpr *ValueExpr;
+  if (Parser.parseExpression(ValueExpr))
+return true;
+
+  const MCConstantExpr *CE = dyn_cast(ValueExpr);
+  if (!CE)
+return Error(ValueExprLoc, "expected numeric constant");
+  IntegerValue = CE->getValue();
+
+  if (Parser.parseEOL())
+return true;
+
+  getTargetStreamer().emitAttribute(Tag, IntegerValue);
+

MaskRay wrote:

unneeded blank line

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,20 @@
+/// Enabled by default for assembly
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Can be forced on or off for assembly.
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mno-default-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mdefault-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Option ignored C/C++ (since we always emit hardware and ABI build 
attributes
+/// during codegen).
+// RUN: %clang -target hexagon-unknown-elf -### -x c %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### -x c++ %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+
+// CHECK-DISABLED-NOT: "-hexagon-add-build-attributes"
+// CHECK-ENABLED: "-hexagon-add-build-attributes"
+// expected-warning {{argument unused during compilation: 
'-mno-default-build-attributes'}}

MaskRay wrote:

`expected` directive is for `-verify`. Driver tests use `-###` instead of cc1 
`-verify`

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread Fangrui Song via cfe-commits


@@ -79,7 +80,8 @@ static cl::opt ErrorNoncontigiousRegister(
 "merror-noncontigious-register",
 cl::desc("Error for register names that aren't contigious"),
 cl::init(false));
-
+static cl::opt AddBuildAttributes("hexagon-add-build-attributes",
+cl::init(false));

MaskRay wrote:

omit `init(false)`

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread via cfe-commits

quic-areg wrote:

@MaskRay @androm3da @SundeepKushwaha @sgundapa @shankarke 

https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread via cfe-commits

https://github.com/quic-areg updated 
https://github.com/llvm/llvm-project/pull/85359

>From b035993b477160d9ac6ef01c8d27e6681682f251 Mon Sep 17 00:00:00 2001
From: quic-areg 
Date: Thu, 14 Mar 2024 20:31:37 -0700
Subject: [PATCH 1/2] [Hexagon] ELF attributes for Hexagon

Defines a subset of attributes and emits them to a section called
.hexagon.attributes.

The current attributes recorded are the attributes needed by
llvm-objdump to automatically determine target features and eliminate
the need to manually pass features.
---
 clang/lib/Driver/ToolChains/Clang.cpp |  8 ++
 .../Driver/hexagon-default-build-attributes.s | 20 
 llvm/include/llvm/BinaryFormat/ELF.h  |  2 +
 llvm/include/llvm/Object/ELFObjectFile.h  |  4 +-
 .../llvm/Support/HexagonAttributeParser.h | 36 +++
 llvm/include/llvm/Support/HexagonAttributes.h | 32 +++
 llvm/lib/Object/ELF.cpp   |  5 +-
 llvm/lib/Object/ELFObjectFile.cpp | 78 +++
 llvm/lib/ObjectYAML/ELFYAML.cpp   |  1 +
 llvm/lib/Support/CMakeLists.txt   |  2 +
 llvm/lib/Support/HexagonAttributeParser.cpp   | 55 +++
 llvm/lib/Support/HexagonAttributes.cpp| 27 ++
 .../Hexagon/AsmParser/HexagonAsmParser.cpp| 63 -
 llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp | 20 
 llvm/lib/Target/Hexagon/HexagonAsmPrinter.h   |  4 +
 .../Target/Hexagon/HexagonTargetStreamer.h|  9 ++
 .../MCTargetDesc/HexagonMCELFStreamer.cpp | 61 
 .../MCTargetDesc/HexagonMCTargetDesc.cpp  | 72 --
 .../MCTargetDesc/HexagonMCTargetDesc.h|  6 +-
 llvm/test/CodeGen/Hexagon/build-attributes.ll | 16 
 .../test/MC/Hexagon/directive-attribute-err.s | 24 +
 llvm/test/MC/Hexagon/directive-attribute.s| 41 
 llvm/test/MC/Hexagon/hexagon_attributes.s | 94 +++
 llvm/tools/llvm-readobj/ELFDumper.cpp |  6 ++
 24 files changed, 676 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Driver/hexagon-default-build-attributes.s
 create mode 100644 llvm/include/llvm/Support/HexagonAttributeParser.h
 create mode 100644 llvm/include/llvm/Support/HexagonAttributes.h
 create mode 100644 llvm/lib/Support/HexagonAttributeParser.cpp
 create mode 100644 llvm/lib/Support/HexagonAttributes.cpp
 create mode 100644 llvm/test/CodeGen/Hexagon/build-attributes.ll
 create mode 100644 llvm/test/MC/Hexagon/directive-attribute-err.s
 create mode 100644 llvm/test/MC/Hexagon/directive-attribute.s
 create mode 100644 llvm/test/MC/Hexagon/hexagon_attributes.s

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3a7a1cf99c79ac..5628a6cd002b82 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8477,6 +8477,14 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);
 break;
+
+  case llvm::Triple::hexagon:
+if (Args.hasFlag(options::OPT_mdefault_build_attributes,
+ options::OPT_mno_default_build_attributes, true)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-hexagon-add-build-attributes");
+}
+break;
   }
 
   // Consume all the warning flags. Usually this would be handled more
diff --git a/clang/test/Driver/hexagon-default-build-attributes.s 
b/clang/test/Driver/hexagon-default-build-attributes.s
new file mode 100644
index 00..b83181d6d52e01
--- /dev/null
+++ b/clang/test/Driver/hexagon-default-build-attributes.s
@@ -0,0 +1,20 @@
+/// Enabled by default for assembly
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Can be forced on or off for assembly.
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mno-default-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mdefault-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Option ignored C/C++ (since we always emit hardware and ABI build 
attributes
+/// during codegen).
+// RUN: %clang -target hexagon-unknown-elf -### -x c %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### -x c++ %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+
+// CHECK-DISABLED-NOT: "-hexagon-add-build-attributes"
+// CHECK-ENABLED: "-hexagon-add-build-attributes"
+// expected-warning {{argument unused during compilation: 
'-mno-default-build-attributes'}}
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h 
b/llvm/include/llvm/BinaryFormat/ELF.h
index bace3a92677a82..877f3f7862c8ba 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1141,6 +1141,8 @@ enum : unsigned {
 
   SHT_CSKY_ATTRIBUTES = 

[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff c3a1eb6207d85cb37ea29306481b40c9f6402309 
b035993b477160d9ac6ef01c8d27e6681682f251 -- 
llvm/include/llvm/Support/HexagonAttributeParser.h 
llvm/include/llvm/Support/HexagonAttributes.h 
llvm/lib/Support/HexagonAttributeParser.cpp 
llvm/lib/Support/HexagonAttributes.cpp clang/lib/Driver/ToolChains/Clang.cpp 
llvm/include/llvm/BinaryFormat/ELF.h llvm/include/llvm/Object/ELFObjectFile.h 
llvm/lib/Object/ELF.cpp llvm/lib/Object/ELFObjectFile.cpp 
llvm/lib/ObjectYAML/ELFYAML.cpp 
llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp 
llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp 
llvm/lib/Target/Hexagon/HexagonAsmPrinter.h 
llvm/lib/Target/Hexagon/HexagonTargetStreamer.h 
llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp 
llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp 
llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.h 
llvm/tools/llvm-readobj/ELFDumper.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/Support/HexagonAttributeParser.h 
b/llvm/include/llvm/Support/HexagonAttributeParser.h
index c7d866af08..1116dd42b1 100644
--- a/llvm/include/llvm/Support/HexagonAttributeParser.h
+++ b/llvm/include/llvm/Support/HexagonAttributeParser.h
@@ -28,7 +28,8 @@ public:
   : ELFAttributeParser(SP, HexagonAttrs::getHexagonAttributeTags(),
"hexagon") {}
   HexagonAttributeParser()
-  : ELFAttributeParser(HexagonAttrs::getHexagonAttributeTags(), "hexagon") 
{}
+  : ELFAttributeParser(HexagonAttrs::getHexagonAttributeTags(), "hexagon") 
{
+  }
 };
 
 } // namespace llvm

``




https://github.com/llvm/llvm-project/pull/85359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-objectyaml
@llvm/pr-subscribers-mc

@llvm/pr-subscribers-clang-driver

Author: None (quic-areg)


Changes

Defines a subset of attributes and emits them to a section called 
.hexagon.attributes.

The current attributes recorded are the attributes needed by llvm-objdump to 
automatically determine target features and eliminate the need to manually pass 
features.

---

Patch is 36.92 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/85359.diff


24 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+8) 
- (added) clang/test/Driver/hexagon-default-build-attributes.s (+20) 
- (modified) llvm/include/llvm/BinaryFormat/ELF.h (+2) 
- (modified) llvm/include/llvm/Object/ELFObjectFile.h (+3-1) 
- (added) llvm/include/llvm/Support/HexagonAttributeParser.h (+36) 
- (added) llvm/include/llvm/Support/HexagonAttributes.h (+32) 
- (modified) llvm/lib/Object/ELF.cpp (+4-1) 
- (modified) llvm/lib/Object/ELFObjectFile.cpp (+78) 
- (modified) llvm/lib/ObjectYAML/ELFYAML.cpp (+1) 
- (modified) llvm/lib/Support/CMakeLists.txt (+2) 
- (added) llvm/lib/Support/HexagonAttributeParser.cpp (+55) 
- (added) llvm/lib/Support/HexagonAttributes.cpp (+27) 
- (modified) llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp (+62-1) 
- (modified) llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp (+20) 
- (modified) llvm/lib/Target/Hexagon/HexagonAsmPrinter.h (+4) 
- (modified) llvm/lib/Target/Hexagon/HexagonTargetStreamer.h (+9) 
- (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp 
(+61) 
- (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp 
(+66-6) 
- (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.h (+5-1) 
- (added) llvm/test/CodeGen/Hexagon/build-attributes.ll (+16) 
- (added) llvm/test/MC/Hexagon/directive-attribute-err.s (+24) 
- (added) llvm/test/MC/Hexagon/directive-attribute.s (+41) 
- (added) llvm/test/MC/Hexagon/hexagon_attributes.s (+94) 
- (modified) llvm/tools/llvm-readobj/ELFDumper.cpp (+6) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3a7a1cf99c79ac..5628a6cd002b82 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8477,6 +8477,14 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);
 break;
+
+  case llvm::Triple::hexagon:
+if (Args.hasFlag(options::OPT_mdefault_build_attributes,
+ options::OPT_mno_default_build_attributes, true)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-hexagon-add-build-attributes");
+}
+break;
   }
 
   // Consume all the warning flags. Usually this would be handled more
diff --git a/clang/test/Driver/hexagon-default-build-attributes.s 
b/clang/test/Driver/hexagon-default-build-attributes.s
new file mode 100644
index 00..b83181d6d52e01
--- /dev/null
+++ b/clang/test/Driver/hexagon-default-build-attributes.s
@@ -0,0 +1,20 @@
+/// Enabled by default for assembly
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Can be forced on or off for assembly.
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mno-default-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mdefault-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Option ignored C/C++ (since we always emit hardware and ABI build 
attributes
+/// during codegen).
+// RUN: %clang -target hexagon-unknown-elf -### -x c %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### -x c++ %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+
+// CHECK-DISABLED-NOT: "-hexagon-add-build-attributes"
+// CHECK-ENABLED: "-hexagon-add-build-attributes"
+// expected-warning {{argument unused during compilation: 
'-mno-default-build-attributes'}}
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h 
b/llvm/include/llvm/BinaryFormat/ELF.h
index bace3a92677a82..877f3f7862c8ba 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1141,6 +1141,8 @@ enum : unsigned {
 
   SHT_CSKY_ATTRIBUTES = 0x7001U,
 
+  SHT_HEXAGON_ATTRIBUTES = 0x7003U,
+
   SHT_HIPROC = 0x7fff, // Highest processor arch-specific type.
   SHT_LOUSER = 0x8000, // Lowest type reserved for applications.
   SHT_HIUSER = 0x  // Highest type reserved for applications.
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h 
b/llvm/include/llvm/Object/ELFObjectFile.h
index c9227da65708cc..7d04d8f8d54bf8 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -60,6 

[clang] [llvm] [Hexagon] ELF attributes for Hexagon (PR #85359)

2024-03-14 Thread via cfe-commits

https://github.com/quic-areg created 
https://github.com/llvm/llvm-project/pull/85359

Defines a subset of attributes and emits them to a section called 
.hexagon.attributes.

The current attributes recorded are the attributes needed by llvm-objdump to 
automatically determine target features and eliminate the need to manually pass 
features.

>From b035993b477160d9ac6ef01c8d27e6681682f251 Mon Sep 17 00:00:00 2001
From: quic-areg 
Date: Thu, 14 Mar 2024 20:31:37 -0700
Subject: [PATCH] [Hexagon] ELF attributes for Hexagon

Defines a subset of attributes and emits them to a section called
.hexagon.attributes.

The current attributes recorded are the attributes needed by
llvm-objdump to automatically determine target features and eliminate
the need to manually pass features.
---
 clang/lib/Driver/ToolChains/Clang.cpp |  8 ++
 .../Driver/hexagon-default-build-attributes.s | 20 
 llvm/include/llvm/BinaryFormat/ELF.h  |  2 +
 llvm/include/llvm/Object/ELFObjectFile.h  |  4 +-
 .../llvm/Support/HexagonAttributeParser.h | 36 +++
 llvm/include/llvm/Support/HexagonAttributes.h | 32 +++
 llvm/lib/Object/ELF.cpp   |  5 +-
 llvm/lib/Object/ELFObjectFile.cpp | 78 +++
 llvm/lib/ObjectYAML/ELFYAML.cpp   |  1 +
 llvm/lib/Support/CMakeLists.txt   |  2 +
 llvm/lib/Support/HexagonAttributeParser.cpp   | 55 +++
 llvm/lib/Support/HexagonAttributes.cpp| 27 ++
 .../Hexagon/AsmParser/HexagonAsmParser.cpp| 63 -
 llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp | 20 
 llvm/lib/Target/Hexagon/HexagonAsmPrinter.h   |  4 +
 .../Target/Hexagon/HexagonTargetStreamer.h|  9 ++
 .../MCTargetDesc/HexagonMCELFStreamer.cpp | 61 
 .../MCTargetDesc/HexagonMCTargetDesc.cpp  | 72 --
 .../MCTargetDesc/HexagonMCTargetDesc.h|  6 +-
 llvm/test/CodeGen/Hexagon/build-attributes.ll | 16 
 .../test/MC/Hexagon/directive-attribute-err.s | 24 +
 llvm/test/MC/Hexagon/directive-attribute.s| 41 
 llvm/test/MC/Hexagon/hexagon_attributes.s | 94 +++
 llvm/tools/llvm-readobj/ELFDumper.cpp |  6 ++
 24 files changed, 676 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Driver/hexagon-default-build-attributes.s
 create mode 100644 llvm/include/llvm/Support/HexagonAttributeParser.h
 create mode 100644 llvm/include/llvm/Support/HexagonAttributes.h
 create mode 100644 llvm/lib/Support/HexagonAttributeParser.cpp
 create mode 100644 llvm/lib/Support/HexagonAttributes.cpp
 create mode 100644 llvm/test/CodeGen/Hexagon/build-attributes.ll
 create mode 100644 llvm/test/MC/Hexagon/directive-attribute-err.s
 create mode 100644 llvm/test/MC/Hexagon/directive-attribute.s
 create mode 100644 llvm/test/MC/Hexagon/hexagon_attributes.s

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3a7a1cf99c79ac..5628a6cd002b82 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8477,6 +8477,14 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);
 break;
+
+  case llvm::Triple::hexagon:
+if (Args.hasFlag(options::OPT_mdefault_build_attributes,
+ options::OPT_mno_default_build_attributes, true)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-hexagon-add-build-attributes");
+}
+break;
   }
 
   // Consume all the warning flags. Usually this would be handled more
diff --git a/clang/test/Driver/hexagon-default-build-attributes.s 
b/clang/test/Driver/hexagon-default-build-attributes.s
new file mode 100644
index 00..b83181d6d52e01
--- /dev/null
+++ b/clang/test/Driver/hexagon-default-build-attributes.s
@@ -0,0 +1,20 @@
+/// Enabled by default for assembly
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Can be forced on or off for assembly.
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mno-default-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### %s 2>&1 
-mdefault-build-attributes \
+// RUN:| FileCheck %s -check-prefix CHECK-ENABLED
+
+/// Option ignored C/C++ (since we always emit hardware and ABI build 
attributes
+/// during codegen).
+// RUN: %clang -target hexagon-unknown-elf -### -x c %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+// RUN: %clang -target hexagon-unknown-elf -### -x c++ %s 
-mdefault-build-attributes 2>&1 \
+// RUN:| FileCheck %s -check-prefix CHECK-DISABLED
+
+// CHECK-DISABLED-NOT: "-hexagon-add-build-attributes"
+// CHECK-ENABLED: "-hexagon-add-build-attributes"
+// expected-warning {{argument unused during compilation: 
'-mno-default-build-attributes'}}
diff --git