[PATCH] D110130: [clangd] Semantic highlighting for lambda init-capture

2021-09-22 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 374130.
nridge added a comment.

address review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110130/new/

https://reviews.llvm.org/D110130

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -729,6 +729,14 @@
   }
 };
   )cpp",
+  // init-captures
+  R"cpp(
+void $Function_decl[[foo]]() {
+  int $LocalVariable_decl[[a]], $LocalVariable_decl[[b]];
+  [ $LocalVariable_decl[[c]] = $LocalVariable[[a]],
+$LocalVariable_decl[[d]]($LocalVariable[[b]]) ]() {}();
+}
+  )cpp",
   };
   for (const auto &TestCase : TestCases)
 // Mask off scope modifiers to keep the tests manageable.
@@ -797,7 +805,7 @@
   )cpp",
   R"cpp(
 // Lambdas are considered functions, not classes.
-auto $Variable_fileScope[[x]] = [m(42)] { // FIXME: annotate capture
+auto $Variable_fileScope[[x]] = 
[$LocalVariable_functionScope[[m]](42)] {
   return $LocalVariable_functionScope[[m]];
 };
   )cpp",
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -514,8 +514,15 @@
   return true;
 if (auto K = kindForType(AT->getDeducedType().getTypePtrOrNull(),
  H.getResolver())) {
-  auto &Tok = H.addToken(D->getTypeSpecStartLoc(), *K)
-  .addModifier(HighlightingModifier::Deduced);
+  SourceLocation StartLoc = D->getTypeSpecStartLoc();
+  // The AutoType may not have a corresponding token, e.g. in the case of
+  // init-captures, so there's nothing to color.
+  // Detect this case by checking if the type specifier's location
+  // is the same as the location of the declared name itself.
+  if (StartLoc == D->getLocation())
+return true;
+  auto &Tok =
+  H.addToken(StartLoc, *K).addModifier(HighlightingModifier::Deduced);
   const Type *Deduced = AT->getDeducedType().getTypePtrOrNull();
   if (auto Mod = scopeModifier(Deduced))
 Tok.addModifier(*Mod);


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -729,6 +729,14 @@
   }
 };
   )cpp",
+  // init-captures
+  R"cpp(
+void $Function_decl[[foo]]() {
+  int $LocalVariable_decl[[a]], $LocalVariable_decl[[b]];
+  [ $LocalVariable_decl[[c]] = $LocalVariable[[a]],
+$LocalVariable_decl[[d]]($LocalVariable[[b]]) ]() {}();
+}
+  )cpp",
   };
   for (const auto &TestCase : TestCases)
 // Mask off scope modifiers to keep the tests manageable.
@@ -797,7 +805,7 @@
   )cpp",
   R"cpp(
 // Lambdas are considered functions, not classes.
-auto $Variable_fileScope[[x]] = [m(42)] { // FIXME: annotate capture
+auto $Variable_fileScope[[x]] = [$LocalVariable_functionScope[[m]](42)] {
   return $LocalVariable_functionScope[[m]];
 };
   )cpp",
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -514,8 +514,15 @@
   return true;
 if (auto K = kindForType(AT->getDeducedType().getTypePtrOrNull(),
  H.getResolver())) {
-  auto &Tok = H.addToken(D->getTypeSpecStartLoc(), *K)
-  .addModifier(HighlightingModifier::Deduced);
+  SourceLocation StartLoc = D->getTypeSpecStartLoc();
+  // The AutoType may not have a corresponding token, e.g. in the case of
+  // init-captures, so there's nothing to color.
+  // Detect this case by checking if the type specifier's location
+  // is the same as the location of the declared name itself.
+  if (StartLoc == D->getLocation())
+return true;
+  auto &Tok =
+  H.addToken(StartLoc, *K).addModifier(HighlightingModifier::Deduced);
   const Type *Deduced = AT->getDeducedType().getTypePtrOrNull();
   if (auto Mod = scopeModifier(Deduced))
 Tok.addModifier(*Mod);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://list

[PATCH] D110130: [clangd] Ensure lambda init-capture gets semantic token

2021-09-22 Thread Nathan Ridge via Phabricator via cfe-commits
nridge marked an inline comment as done.
nridge added a comment.

In D110130#3012748 , @kadircet wrote:

> Naming of the patch is a little bit confusing. We're actually dropping the 
> semantic highlighting for the type of lambdacaptures, which was showing up in 
> the declarator names since there was no explicit type spelled in the source 
> code. This turns on highlighting for the capture variables because we're left 
> with a single token now.
>
> Can you reword the description to reflect that?

Updated patch description. (Also, I forgot to link to 
https://github.com/clangd/clangd/issues/868 which contains additional context, 
sorry!)




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:522
+  // is the same as the location of the declared name itself.
+  if (StartLoc != D->getLocation()) {
+auto &Tok =

kadircet wrote:
> nridge wrote:
> > Note, I initially tried `D->getTypeSpecStartLoc() != 
> > D->getTypeSpecEndLoc()`, but it turns out they are equal both in the 
> > init-capture case and in the regular `auto` case, so that check cannot be 
> > used to discriminate between the two.
> why not just check if `D` is implicit?
If you mean `D->isImplicit()`, that returns false for init-captures.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110130/new/

https://reviews.llvm.org/D110130

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109517: [Clang][ARM][AArch64] Add support for Armv9-A, Armv9.1-A and Armv9.2-A

2021-09-22 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer accepted this revision.
SjoerdMeijer added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/Driver/ToolChains/Arch/AArch64.cpp:419
+
+  // Enable SVE2 by default on Armv9-A
+  // It can still be disabled if +nosve2 is present

Nit: some `.`s missing at the end of this sentence and the next below.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109517/new/

https://reviews.llvm.org/D109517

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2021-09-22 Thread Shao-Ce Sun via Phabricator via cfe-commits
achieveartificialintelligence updated this revision to Diff 374131.
achieveartificialintelligence added a comment.

Address @jrtc27 's comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93298/new/

https://reviews.llvm.org/D93298

Files:
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZdinx.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfinx.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZhinx.td
  llvm/lib/Target/RISCV/RISCVRegisterInfo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/MC/RISCV/rv32i-invalid.s
  llvm/test/MC/RISCV/rv32zdinx-invalid.s
  llvm/test/MC/RISCV/rv32zdinx-valid.s
  llvm/test/MC/RISCV/rv32zfinx-invalid.s
  llvm/test/MC/RISCV/rv32zfinx-valid.s
  llvm/test/MC/RISCV/rv32zhinx-invalid.s
  llvm/test/MC/RISCV/rv32zhinx-valid.s
  llvm/test/MC/RISCV/rv32zhinxmin-invalid.s
  llvm/test/MC/RISCV/rv32zhinxmin-valid.s
  llvm/test/MC/RISCV/rv64zdinx-invalid.s
  llvm/test/MC/RISCV/rv64zdinx-valid.s
  llvm/test/MC/RISCV/rv64zfinx-invalid.s
  llvm/test/MC/RISCV/rv64zfinx-valid.s
  llvm/test/MC/RISCV/rv64zhinx-invalid.s
  llvm/test/MC/RISCV/rv64zhinx-valid.s
  llvm/test/MC/RISCV/rv64zhinxmin-valid.s
  llvm/test/MC/RISCV/rvzdinx-aliases-valid.s
  llvm/test/MC/RISCV/rvzfinx-aliases-valid.s
  llvm/test/MC/RISCV/rvzhinx-aliases-valid.s

Index: llvm/test/MC/RISCV/rvzhinx-aliases-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvzhinx-aliases-valid.s
@@ -0,0 +1,83 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zhinx -riscv-no-aliases \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zhinx \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zhinx -riscv-no-aliases \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zhinx \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zhinx < %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zhinx -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zhinx < %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zhinx - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zhinx < %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zhinx -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zhinx < %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zhinx - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+
+##===--===##
+## Assembler Pseudo Instructions (User-Level ISA, Version 2.2, Chapter 20)
+##===--===##
+
+# CHECK-INST: fsgnjx.h s1, s2, s2
+# CHECK-ALIAS: fabs.h s1, s2
+fabs.h s1, s2
+# CHECK-INST: fsgnjn.h s2, s3, s3
+# CHECK-ALIAS: fneg.h s2, s3
+fneg.h s2, s3
+
+# CHECK-INST: flt.h tp, s6, s5
+# CHECK-ALIAS: flt.h tp, s6, s5
+fgt.h x4, s5, s6
+# CHECK-INST: fle.h t2, s1, s0
+# CHECK-ALIAS: fle.h t2, s1, s0
+fge.h x7, x8, x9
+
+
+##===--===##
+## Aliases which omit the rounding mode.
+##===--===##
+
+# CHECK-INST: fmadd.h a0, a1, a2, a3, dyn
+# CHECK-ALIAS: fmadd.h a0, a1, a2, a3{{[[:space:]]}}
+fmadd.h x10, x11, x12, x13
+# CHECK-INST: fmsub.h a4, a5, a6, a7, dyn
+# CHECK-ALIAS: fmsub.h a4, a5, a6, a7{{[[:space:]]}}
+fmsub.h x14, x15, x16, x17
+# CHECK-INST: fnmsub.h s2, s3, s4, s5, dyn
+# CHECK-ALIAS: fnmsub.h s2, s3, s4, s5{{[[:space:]]}}
+fnmsub.h x18, x19, x20, x21
+# CHECK-INST: fnmadd.h s6, s7, s8, s9, dyn
+# CHECK-ALIAS: fnmadd.h s6, s7, s8, s9{{[[:space:]]}}
+fnmadd.h x22, x23, x24, x25
+# CHECK-INST: fadd.h s10, s11, t3, dyn
+# CHECK-ALIAS: fadd.h s10, s11, t3{{[[:space:]]}}
+fadd.h x26, x27, x28
+# CHECK-INST: fsub.h t4, t5, t6, dyn
+# CHECK-ALIAS: fsub.h t4, t5, t6{{[[:space:]]}}
+fsub.h x29, x30, x31
+# CHECK-INST: fmul.h s0, s1, s2, dyn
+# CHECK-ALIAS: fmul.h s0, s1, s2{{[[:space:]]}}
+fmul.h s0, s1, s2
+# CHECK-INST: fdiv.h s3, s4, s5, dyn
+# CHECK-ALIAS: fdiv.h s3, s4, s5{{[[:space:]]}}
+fdiv.h s3, s4, s5
+# CHECK-INST: fsqrt.h s6, s7, dyn
+# CHECK-ALIAS: fsqrt.h s6, s7{{[[:space:]]}}
+fsqrt.h s6, s7
+# CHECK-INST: fcvt.w.h a0, s5, dyn
+# CHECK-ALIAS: fcvt.w.h a0, s5{{[[:space:]]}}
+fcvt.w.h a0, s5
+# CHECK-INST: fcvt.wu.h a1, s6, dyn
+# CHECK-ALIAS: fcvt.wu.h a1, s6{{[[:space:]]}}
+fc

[PATCH] D109967: Simplify handling of builtin with inline redefinition

2021-09-22 Thread serge via Phabricator via cfe-commits
serge-sans-paille marked 3 inline comments as done.
serge-sans-paille added a comment.

In D109967#3013552 , @nickdesaulniers 
wrote:

> Looks reasonable. Can you give us some time to test this on the Linux kernel?

Sure, who can refuse some extra testing? Please ping the thread once you're 
done with the extra testing.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109967/new/

https://reviews.llvm.org/D109967

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7ce6385 - [clang][ASTImporter] Generic attribute import handling (first step).

2021-09-22 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2021-09-22T10:14:03+02:00
New Revision: 7ce638538bcf323cd15ed5dfbc43013312b0e3e3

URL: 
https://github.com/llvm/llvm-project/commit/7ce638538bcf323cd15ed5dfbc43013312b0e3e3
DIFF: 
https://github.com/llvm/llvm-project/commit/7ce638538bcf323cd15ed5dfbc43013312b0e3e3.diff

LOG: [clang][ASTImporter] Generic attribute import handling (first step).

Import of Attr objects was incomplete in ASTImporter.
This change introduces support for a generic way of importing an attribute.
For an usage example import of the attribute AssertCapability is
added to ASTImporter.
Updating the old attribute import code and adding new attributes or extending
the generic functions (if needed) is future work.

Reviewed By: steakhal, martong

Differential Revision: https://reviews.llvm.org/D109608

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 57aceec7d2a0a..4e4ca7a207f57 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -186,22 +186,6 @@ namespace clang {
   return import(*From);
 }
 
-// Helper for chaining together multiple imports. If an error is detected,
-// subsequent imports will return default constructed nodes, so that 
failure
-// can be detected with a single conditional branch after a sequence of
-// imports.
-template  T importChecked(Error &Err, const T &From) {
-  // Don't attempt to import nodes if we hit an error earlier.
-  if (Err)
-return T{};
-  Expected MaybeVal = import(From);
-  if (!MaybeVal) {
-Err = MaybeVal.takeError();
-return T{};
-  }
-  return *MaybeVal;
-}
-
 ExplicitSpecifier importExplicitSpecifier(Error &Err,
   ExplicitSpecifier ESpec);
 
@@ -669,6 +653,22 @@ namespace clang {
 ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E);
 ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E);
 
+// Helper for chaining together multiple imports. If an error is detected,
+// subsequent imports will return default constructed nodes, so that 
failure
+// can be detected with a single conditional branch after a sequence of
+// imports.
+template  T importChecked(Error &Err, const T &From) {
+  // Don't attempt to import nodes if we hit an error earlier.
+  if (Err)
+return T{};
+  Expected MaybeVal = import(From);
+  if (!MaybeVal) {
+Err = MaybeVal.takeError();
+return T{};
+  }
+  return *MaybeVal;
+}
+
 template
 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
   using ItemT = std::remove_reference_t;
@@ -8408,8 +8408,118 @@ Expected 
ASTImporter::Import(TypeSourceInfo *FromTSI) {
   return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
 }
 
+// To use this object, it should be created before the new attribute is 
created,
+// and destructed after it is created. The construction already performs the
+// import of the data.
+template  struct AttrArgImporter {
+  AttrArgImporter(const AttrArgImporter &) = delete;
+  AttrArgImporter(AttrArgImporter &&) = default;
+  AttrArgImporter &operator=(const AttrArgImporter &) = delete;
+  AttrArgImporter &operator=(AttrArgImporter &&) = default;
+
+  AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
+  : To(I.importChecked(Err, From)) {}
+
+  const T &value() { return To; }
+
+private:
+  T To;
+};
+
+// To use this object, it should be created before the new attribute is 
created,
+// and destructed after it is created. The construction already performs the
+// import of the data. The array data is accessible in a pointer form, this 
form
+// is used by the attribute classes. This object should be created once for the
+// array data to be imported (the array size is not imported, just copied).
+template  struct AttrArgArrayImporter {
+  AttrArgArrayImporter(const AttrArgArrayImporter &) = delete;
+  AttrArgArrayImporter(AttrArgArrayImporter &&) = default;
+  AttrArgArrayImporter &operator=(const AttrArgArrayImporter &) = delete;
+  AttrArgArrayImporter &operator=(AttrArgArrayImporter &&) = default;
+
+  AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
+   const llvm::iterator_range &From,
+   unsigned ArraySize) {
+if (Err)
+  return;
+To.reserve(ArraySize);
+Err = I.ImportContainerChecked(From, To);
+  }
+
+  T *value() { return To.data(); }
+
+private:
+  llvm::SmallVector To;
+};
+
+class AttrImporter {
+  Error Err = Error::success();
+  ASTImporter &Importer;
+  ASTNodeImporter NImporter;
+
+public:
+  AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
+
+  // Create an "importer" for an attribute parameter.
+  // Result of the 'value()' of that obj

[PATCH] D109608: [clang][ASTImporter] Generic attribute import handling (first step).

2021-09-22 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7ce638538bcf: [clang][ASTImporter] Generic attribute import 
handling (first step). (authored by balazske).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109608/new/

https://reviews.llvm.org/D109608

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6406,6 +6406,83 @@
 ToSM.getBufferOrFake(ImportedID, SourceLocation()).getBuffer());
 }
 
+struct ImportAttributes : public ASTImporterOptionSpecificTestBase {
+  void checkAttrImportCommon(const Attr *From, const Attr *To,
+ const Decl *ToD) {
+
+// Verify that dump does not crash because invalid data.
+ToD->dump(llvm::nulls());
+
+EXPECT_EQ(From->getParsedKind(), To->getParsedKind());
+EXPECT_EQ(From->getSyntax(), To->getSyntax());
+if (From->getAttrName()) {
+  EXPECT_TRUE(To->getAttrName());
+  EXPECT_STREQ(From->getAttrName()->getNameStart(),
+   To->getAttrName()->getNameStart());
+} else {
+  EXPECT_FALSE(To->getAttrName());
+}
+if (From->getScopeName()) {
+  EXPECT_TRUE(To->getScopeName());
+  EXPECT_STREQ(From->getScopeName()->getNameStart(),
+   To->getScopeName()->getNameStart());
+} else {
+  EXPECT_FALSE(To->getScopeName());
+}
+EXPECT_EQ(From->getSpellingListIndex(), To->getSpellingListIndex());
+EXPECT_STREQ(From->getSpelling(), To->getSpelling());
+EXPECT_EQ(From->isInherited(), To->isInherited());
+EXPECT_EQ(From->isImplicit(), To->isImplicit());
+EXPECT_EQ(From->isPackExpansion(), To->isPackExpansion());
+EXPECT_EQ(From->isLateParsed(), To->isLateParsed());
+  }
+
+  template 
+  void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) {
+static_assert(std::is_base_of::value, "AT should be an Attr");
+static_assert(std::is_base_of::value, "DT should be a Decl");
+
+Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
+DT *FromD =
+FirstDeclMatcher().match(FromTU, namedDecl(hasName("test")));
+ASSERT_TRUE(FromD);
+
+DT *ToD = Import(FromD, Lang_CXX11);
+ASSERT_TRUE(ToD);
+
+FromAttr = FromD->template getAttr();
+ToAttr = ToD->template getAttr();
+ASSERT_TRUE(FromAttr);
+EXPECT_TRUE(ToAttr);
+
+checkAttrImportCommon(FromAttr, ToAttr, ToD);
+  }
+
+  template  void checkImported(const T *From, const T *To) {
+EXPECT_TRUE(To);
+EXPECT_NE(From, To);
+  }
+
+  template 
+  void checkImportVariadicArg(const llvm::iterator_range &From,
+  const llvm::iterator_range &To) {
+for (auto FromI = From.begin(), ToI = To.begin(); FromI != From.end();
+ ++FromI, ++ToI) {
+  ASSERT_NE(ToI, To.end());
+  checkImported(*FromI, *ToI);
+}
+  }
+};
+
+template <>
+void ImportAttributes::checkImported(const Decl *From, const Decl *To) {
+  EXPECT_TRUE(To);
+  EXPECT_NE(From, To);
+  EXPECT_EQ(To->getTranslationUnitDecl(),
+ToAST->getASTContext().getTranslationUnitDecl());
+}
+
+// FIXME: Use ImportAttributes for this test.
 TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
   // Test if import of these packed and aligned attributes does not trigger an
   // error situation where source location from 'From' context is referenced in
@@ -6441,6 +6518,7 @@
   EXPECT_TRUE(ToA);
 }
 
+// FIXME: Use ImportAttributes for this test.
 TEST_P(ASTImporterOptionSpecificTestBase, ImportFormatAttr) {
   Decl *FromTU = getTuDecl(
   R"(
@@ -6466,6 +6544,15 @@
 ToAttr->getAttributeSpellingListIndex());
   EXPECT_EQ(FromAttr->getType()->getName(), ToAttr->getType()->getName());
 }
+
+TEST_P(ImportAttributes, ImportAssertCapability) {
+  AssertCapabilityAttr *FromAttr, *ToAttr;
+  importAttr(
+  "void test(int A1, int A2) __attribute__((assert_capability(A1, A2)));",
+  FromAttr, ToAttr);
+  checkImportVariadicArg(FromAttr->args(), ToAttr->args());
+}
+
 template 
 auto ExtendWithOptions(const T &Values, const std::vector &Args) {
   auto Copy = Values;
@@ -6849,5 +6936,8 @@
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ImportWithExternalSource,
  DefaultTestValuesForRunOptions);
 
+INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ImportAttributes,
+ DefaultTestValuesForRunOptions);
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -186,22 +186,6 @@
   return import(*From);
 }
 
-// H

[PATCH] D110128: [Driver] Correctly handle static C++ standard library

2021-09-22 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 374154.
phosek marked 5 inline comments as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110128/new/

https://reviews.llvm.org/D110128

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/fuchsia.cpp
  clang/test/Driver/linux-ld.c

Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -496,6 +496,24 @@
 // CHECK-GCC-VERSION1: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-GCC-VERSION1: "{{.*}}/Inputs/basic_linux_tree/usr/lib/gcc/i386-unknown-linux/10.2.0{{/|}}crtbegin.o"
 
+// RUN: %clangxx -x c++ %s -### 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-SHARED %s
+// CHECK-BASIC-LIBCXX-SHARED: "--push-state"
+// CHECK-BASIC-LIBCXX-SHARED-SAME: {{^}} "-lc++"
+// CHECK-BASIC-LIBCXX-SHARED-SAME: {{^}} "--pop-state"
+// CHECK-BASIC-LIBCXX-SHARED-SAME: {{^}} "-lm"
+// RUN: %clangxx  -x c++ %s -### 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ -static-libstdc++ \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-STATIC %s
+// CHECK-BASIC-LIBCXX-STATIC: "--push-state"
+// CHECK-BASIC-LIBCXX-STATIC-SAME: {{^}} "-Bstatic"
+// CHECK-BASIC-LIBCXX-STATIC-SAME: {{^}} "-lc++"
+// CHECK-BASIC-LIBCXX-STATIC-SAME: {{^}} "--pop-state"
+// CHECK-BASIC-LIBCXX-STATIC-SAME: {{^}} "-lm"
+
 // Test a simulated installation of libc++ on Linux, both through sysroot and
 // the installation path of Clang.
 // RUN: %clangxx -no-canonical-prefixes -x c++ %s -### -o %t.o 2>&1 \
@@ -542,7 +560,7 @@
 // CHECK-BASIC-LIBCXX-C-LINK: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
 // CHECK-BASIC-LIBCXX-C-LINK: "--sysroot=[[SYSROOT]]"
 // CHECK-BASIC-LIBCXX-C-LINK: "-L[[SYSROOT]]/usr/bin/../lib"
-//
+
 // Check multi arch support on Ubuntu 12.04 LTS.
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: --target=arm-unknown-linux-gnueabihf -rtlib=platform \
Index: clang/test/Driver/fuchsia.cpp
===
--- clang/test/Driver/fuchsia.cpp
+++ clang/test/Driver/fuchsia.cpp
@@ -37,8 +37,8 @@
 // CHECK: "--push-state"
 // CHECK: "--as-needed"
 // CHECK: "-lc++"
-// CHECK: "-lm"
 // CHECK: "--pop-state"
+// CHECK: "-lm"
 // CHECK-X86_64: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}x86_64-unknown-fuchsia{{/|}}libclang_rt.builtins.a"
 // CHECK-AARCH64: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}aarch64-unknown-fuchsia{{/|}}libclang_rt.builtins.a"
 // CHECK-RISCV64: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}riscv64-unknown-fuchsia{{/|}}libclang_rt.builtins.a"
@@ -55,12 +55,10 @@
 // RUN: -fuse-ld=lld 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-STATIC
 // CHECK-STATIC: "--push-state"
-// CHECK-STATIC: "--as-needed"
 // CHECK-STATIC: "-Bstatic"
 // CHECK-STATIC: "-lc++"
-// CHECK-STATIC: "-Bdynamic"
-// CHECK-STATIC: "-lm"
 // CHECK-STATIC: "--pop-state"
+// CHECK-STATIC: "-lm"
 // CHECK-STATIC: "-lc"
 
 // RUN: %clangxx %s -### --target=x86_64-unknown-fuchsia -nostdlib++ -fuse-ld=lld 2>&1 \
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -577,11 +577,11 @@
 if (ToolChain.ShouldLinkCXXStdlib(Args)) {
   bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
  !Args.hasArg(options::OPT_static);
+  CmdArgs.push_back("--push-state");
   if (OnlyLibstdcxxStatic)
 CmdArgs.push_back("-Bstatic");
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
-  if (OnlyLibstdcxxStatic)
-CmdArgs.push_back("-Bdynamic");
+  CmdArgs.push_back("--pop-state");
 }
 CmdArgs.push_back("-lm");
   }
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -138,14 +138,13 @@
 bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
!Args.hasArg(options::OPT_static);
 CmdArgs.push_back("--push-state");
-CmdArgs.push_back("--as-needed");
 if (OnlyLibstdcxxStatic)
   CmdArgs.push_back("-Bstatic");
+else
+  CmdArgs.push_back("--as-needed");
 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
-if (OnlyLibstdcxxStatic)
-  CmdArgs.push_back("-Bdynamic");
-CmdArgs.push_back("-lm");
 CmdArgs.push_back("--pop-state");
+CmdArgs.push_back("-lm");
   }
 }
 
___
cfe-commits mailing list
cfe-commi

[PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

2021-09-22 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal added a comment.

It looks like from IR diff that this patch is adding use of kmpc_alloc_shared 
method. These methods likely won't work on AMDGPU as device malloc is not 
available. Not sure what could be done apart from marking those tests as XFAIL 
on amdgcn. :(


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102107/new/

https://reviews.llvm.org/D102107

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106876: Remove non-affecting module maps from PCM files.

2021-09-22 Thread Ilya Kuteev via Phabricator via cfe-commits
ilyakuteev updated this revision to Diff 374156.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106876/new/

https://reviews.llvm.org/D106876

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
  clang/test/Modules/add-remove-irrelevant-mobile-map.m
  clang/test/SemaCXX/Inputs/compare.modulemap
  clang/test/SemaCXX/compare-modules-cxx2a.cpp

Index: clang/test/SemaCXX/compare-modules-cxx2a.cpp
===
--- clang/test/SemaCXX/compare-modules-cxx2a.cpp
+++ clang/test/SemaCXX/compare-modules-cxx2a.cpp
@@ -1,15 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -fcxx-exceptions -verify -std=c++2a -fmodules -I%S/Inputs %s -fno-modules-error-recovery
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
 
-#pragma clang module build compare
-module compare {
-  explicit module cmp {}
-  explicit module other {}
-}
-#pragma clang module contents
-#pragma clang module begin compare.cmp
-#include "std-compare.h"
-#pragma clang module end
-#pragma clang module endbuild
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fcxx-exceptions -verify -std=c++2a -fmodules -fmodules-cache-path=%t.mcp -I%S/Inputs %s -fno-modules-error-recovery -fmodule-map-file=%S/Inputs/compare.modulemap
 
 struct CC { CC(...); };
 
@@ -24,10 +16,10 @@
 
 // expected-note@std-compare.h:* 2+{{not reachable}}
 
-void b() { void(0 <=> 0); } // expected-error 1+{{missing '#include "std-compare.h"'; 'strong_ordering' must be defined}}
+void b() { void(0 <=> 0); } // expected-error 1+{{definition of 'strong_ordering' must be imported from module 'compare.cmp' before it is required}}
 
 struct B {
-  CC operator<=>(const B&) const = default; // expected-error 1+{{missing '#include "std-compare.h"'; 'strong_ordering' must be defined}}
+  CC operator<=>(const B&) const = default; // expected-error 1+{{definition of 'strong_ordering' must be imported from module 'compare.cmp' before it is required}}
 };
 auto vb = B() <=> B(); // expected-note {{required here}}
 
Index: clang/test/SemaCXX/Inputs/compare.modulemap
===
--- /dev/null
+++ clang/test/SemaCXX/Inputs/compare.modulemap
@@ -0,0 +1,6 @@
+module compare {
+  explicit module cmp {
+header "std-compare.h"
+  }
+  explicit module other {}
+}
Index: clang/test/Modules/add-remove-irrelevant-mobile-map.m
===
--- /dev/null
+++ clang/test/Modules/add-remove-irrelevant-mobile-map.m
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
+
+// Build without b.modulemap
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
+// RUN: cp %t.mcp/a.pcm %t/a.pcm
+
+// Build with b.modulemap
+// RUN: rm -rf %t.mcp
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
+// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+
+// expected-no-diagnostics
+
+@import a;
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
@@ -0,0 +1 @@
+module b { }
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
@@ -0,0 +1 @@
+module a { }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -149,6 +149,59 @@
 
 namespace {
 
+std::set GetAllModuleMaps(const HeaderSearch &HS,
+ Module *RootModule) {
+  std::set ModuleMaps{};
+  std::set ProcessedModules;
+  SmallVector ModulesToProcess{RootModule};
+
+  SmallVector FilesByUID;
+  HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
+
+  if (FilesByUID.size() > HS.header_file_size())
+FilesByUID.resize(HS.header_file_size());
+
+  for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
+const FileEntry *File = FilesByUID[UID];
+if (!File)
+  continue;
+
+const HeaderFileInfo *HFI =
+HS.getExistingFileInfo(File, /*WantExternal*/ false);
+if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
+  continue;
+
+for (const auto &KH : HS.findAllModulesForHeader(File)) {
+  if (!KH.getModule())

[PATCH] D104285: [analyzer] Retrieve a value from list initialization of constant array declaration in a global scope.

2021-09-22 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1696
+  const llvm::APSInt &Idx = CI->getValue();
+  const uint64_t I = static_cast(Idx.getExtValue());
+  // Use `getZExtValue` because array extent can not be negative.

martong wrote:
> ASDenysPetrov wrote:
> > ASDenysPetrov wrote:
> > > martong wrote:
> > > > aaron.ballman wrote:
> > > > > 
> > > > This `static_cast` seems to be dangerous to me, it might overflow. 
> > > > Can't we compare `Idx` directly to `Extent`? I see that `Idx` is an 
> > > > `APSint` and `Extent` is an `APInt`, but  I think we should be able to 
> > > > handle the comparison on the APInt level b/c that takes care of the 
> > > > signedness. And the overflow situation should be handled as well 
> > > > properly with `APInt`, given from it's name "arbitrary precision int". 
> > > > In this sense I don't see why do we need `I` at all.
> > > We can't get rid of `I` because we use it below anyway in `I >= 
> > > InitList->getNumInits()` and `InitList->getInit(I)`.
> > > I couldn't find any appropriate function to compare without additional 
> > > checking for signedness or bit-width adjusting.
> > > I'll try to improve this snippet.
> > This is not dangerous because we check for negatives separately in `Idx < 
> > 0`, so we can be sure that `I` is positive while `I >= Extent`. 
> > Unfortunately, I didn't find any suitable way to compare `APSint` //of 
> > unknown sign and bitwidth// with //signless// `APInt` without adding 
> > another checks for sign and bitwidth conversions. In this way I prefer the 
> > currect condition `I >= Extent`.
> I think it would be possible to use `bool llvm::APInt::uge` that does an 
> Unsigned greater or equal comparison. Or you could use `sge` for the signed 
> comparison. Also, both have overload that take another APInt as parameter.
I considered them. First of all choosing between `uge` and `sge` we 
additionally need to check for signedness. Moreover, these functions require 
bitwidth to be equal. Thus we need additional checks and transformations. I 
found this approach too verbose. Mine one seems to me simpler and works under 
natural rules of comparison.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104285/new/

https://reviews.llvm.org/D104285

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109517: [Clang][ARM][AArch64] Add support for Armv9-A, Armv9.1-A and Armv9.2-A

2021-09-22 Thread Victor Campos via Phabricator via cfe-commits
vhscampos updated this revision to Diff 374162.
vhscampos added a comment.

Add missing . to end of sentences in comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109517/new/

https://reviews.llvm.org/D109517

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arm-cortex-cpus.c
  clang/test/Preprocessor/aarch64-target-features.c
  clang/test/Preprocessor/arm-target-features.c
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/lib/Support/ARMTargetParser.cpp
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
  llvm/test/MC/AArch64/SME/directives-negative.s
  llvm/test/MC/AArch64/SME/directives.s
  llvm/test/MC/AArch64/SVE2/directive-arch-negative.s
  llvm/test/MC/AArch64/SVE2/directive-arch.s
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -31,6 +31,7 @@
 "armv8.5a","armv8.6-a","armv8.6a","armv8.7-a","armv8.7a",
 "armv8-r", "armv8r",   "armv8-m.base","armv8m.base",  "armv8-m.main",
 "armv8m.main", "iwmmxt",   "iwmmxt2", "xscale",   "armv8.1-m.main",
+"armv9-a", "armv9.1-a","armv9.2-a",
 };
 
 template 
@@ -492,6 +493,15 @@
   EXPECT_TRUE(
   testARMArch("armv8.7-a", "generic", "v8.7a",
   ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(
+  testARMArch("armv9-a", "generic", "v9a",
+  ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(
+  testARMArch("armv9.1-a", "generic", "v9.1a",
+  ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(
+  testARMArch("armv9.2-a", "generic", "v9.2a",
+  ARMBuildAttrs::CPUArch::v8_A));
   EXPECT_TRUE(
   testARMArch("armv8-r", "cortex-r52", "v8r",
   ARMBuildAttrs::CPUArch::v8_R));
@@ -821,6 +831,9 @@
 case ARM::ArchKind::ARMV8_5A:
 case ARM::ArchKind::ARMV8_6A:
 case ARM::ArchKind::ARMV8_7A:
+case ARM::ArchKind::ARMV9A:
+case ARM::ArchKind::ARMV9_1A:
+case ARM::ArchKind::ARMV9_2A:
   EXPECT_EQ(ARM::ProfileKind::A, ARM::parseArchProfile(ARMArch[i]));
   break;
 default:
@@ -1204,6 +1217,12 @@
   ARMBuildAttrs::CPUArch::v8_A));
   EXPECT_TRUE(testAArch64Arch("armv8.7-a", "generic", "v8.7a",
   ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(testAArch64Arch("armv9-a", "generic", "v9a",
+  ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(testAArch64Arch("armv9.1-a", "generic", "v9.1a",
+  ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(testAArch64Arch("armv9.2-a", "generic", "v9.2a",
+  ARMBuildAttrs::CPUArch::v8_A));
 }
 
 bool testAArch64Extension(StringRef CPUName, AArch64::ArchKind AK,
Index: llvm/test/MC/AArch64/SVE2/directive-arch.s
===
--- llvm/test/MC/AArch64/SVE2/directive-arch.s
+++ llvm/test/MC/AArch64/SVE2/directive-arch.s
@@ -1,21 +1,21 @@
 // RUN: llvm-mc -triple aarch64 -filetype asm -o - %s 2>&1 | FileCheck %s
 
-.arch armv8-a+sve2
+.arch armv9-a+sve2
 tbx z0.b, z1.b, z2.b
 // CHECK: tbx z0.b, z1.b, z2.b
 
-.arch armv8-a+sve2-aes
+.arch armv9-a+sve2-aes
 aesd z23.b, z23.b, z13.b
 // CHECK: aesd z23.b, z23.b, z13.b
 
-.arch armv8-a+sve2-sm4
+.arch armv9-a+sve2-sm4
 sm4e z0.s, z0.s, z0.s
 // CHECK: sm4e z0.s, z0.s, z0.s
 
-.arch armv8-a+sve2-sha3
+.arch armv9-a+sve2-sha3
 rax1 z0.d, z0.d, z0.d
 // CHECK: rax1 z0.d, z0.d, z0.d
 
-.arch armv8-a+sve2-bitperm
+.arch armv9-a+sve2-bitperm
 bgrp z21.s, z10.s, z21.s
 // CHECK: bgrp z21.s, z10.s, z21.s
Index: llvm/test/MC/AArch64/SVE2/directive-arch-negative.s
===
--- llvm/test/MC/AArch64/SVE2/directive-arch-negative.s
+++ llvm/test/MC/AArch64/SVE2/directive-arch-negative.s
@@ -1,31 +1,31 @@
 // RUN: not llvm-mc -triple aarch64 -filetype asm -o - %s 2>&1 | FileCheck %s
 
-.arch armv8-a+sve2
-.arch armv8-a+nosve2
+.arch armv9-a+sve2
+.arch armv9-a+nosve2
 tbx z0.b, z1.b, z2.b
 // CHECK: error: instruction requires: streaming-sve or sve2
 // CHECK-NEXT: tbx z0.b, z1.b, z2.b
 
-.arch armv8-a+sve2-aes
-.arch a

[PATCH] D109818: [HIPSPV] Convert HIP kernels to SPIR-V kernels

2021-09-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:10221
+ABIArgInfo SPIRABIInfo::classifyKernelArgumentType(QualType Ty) const {
+  if (getContext().getLangOpts().HIP && getTarget().getTriple().isSPIRV()) {
+// Coerce pointer arguments with default address space to CrossWorkGroup

linjamaki wrote:
> Anastasia wrote:
> > It feels like this needs to be in `SPIRVABIInfo`  or something? Or can this 
> > be generalized to both  - SPIR and SPIR-V?
> A comment was added in D109144 to state that the SPIRABIInfo is an ABI 
> implementation for both the SPIR and SPIR-V. For now, there is not much 
> difference between SPIR and SPIR-V for this class. Would it be satisfactory 
> if the class is renamed to something more general (like CommonSPIRABIInfo)?
It might be reasonable to rename indeed or we can just amend its documentation 
to clarify what it is used for both...

However if you need to specialize different logic I think the conventional way 
in clang would be to create a subclass...

This is related to a wider discussion that is ongoing about the best way to 
reuse SPIR for SPIR-V and their evolution... CCing @bader here too.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:10224
+// pointers for HIPSPV. When the language mode is HIP, the SPIRTargetInfo
+// maps cuda_device to SPIR-V's CrossWorkGroup address space.
+llvm::Type *LTy = CGT.ConvertType(Ty);

linjamaki wrote:
> Anastasia wrote:
> > Can you explain why this mapping is needed? We already have an address 
> > space map to perform the mapping of address spaces b/w language and target. 
> > It would be good if we don't replicate similar logic in too many places.
> HIP does not require address space qualifiers on kernel pointer arguments 
> (e.g. see hipspv-kernel.cpp) nor there are AS qualifiers that can be placed 
> on them. With the default logic, provided by SPIRVTargetInfo’s address space 
> map, the kernel pointer arguments get converted to generic pointers which are 
> not allowed by the OpenCL SPIR-V Environment Specification.
I feel that it is the same for SYCL... It might be good to check with @bader 
whether there is already a way to handle this that can be reused for HIP...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109818/new/

https://reviews.llvm.org/D109818

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110184: [OpenCL] Constructor address space test adjusted for C++ for OpenCL 2021

2021-09-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110184/new/

https://reviews.llvm.org/D110184

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

2021-09-22 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

In D102107#3014599 , @pdhaliwal wrote:

> It looks like from IR diff that this patch is adding use of kmpc_alloc_shared 
> method. These methods likely won't work on AMDGPU as device malloc is not 
> available. Not sure what could be done apart from marking those tests as 
> XFAIL on amdgcn. :(

That's a good theory. Could confirm by patching the amdgpu malloc to return 
0xdeadbeef or similar instead of 0 and seeing if that number shows up in the 
invalid memory access error. If so there's two problems:
1/ malloc on the gpu can fail, so it would mean we're missing a check on the 
return code of malloc in the devicertl
2/ increased importance for getting malloc running on amdgpu
The openmp in rocm/aomp does have a malloc, so it would also be interesting to 
see if they run OK with this patch applied


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102107/new/

https://reviews.llvm.org/D102107

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102478: [Matrix] Emit assumption that matrix indices are valid.

2021-09-22 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

All required changes to make use of this have recently landed or are ready to 
land. So I am going to commit this momentarily.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102478/new/

https://reviews.llvm.org/D102478

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

2021-09-22 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal added a comment.

I got this after changing __kmpc_impl_malloc to return 0xdeadbeef. So, this 
confirms that missing malloc implementation is the root cause.

> Memory access fault by GPU node-4 (Agent handle: 0x1bc5000) on address 
> 0xdeadb000. Reason: Page not present or supervisor privilege.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102107/new/

https://reviews.llvm.org/D102107

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

2021-09-22 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

In D102107#3014743 , @pdhaliwal wrote:

> I got this after changing __kmpc_impl_malloc to return 0xdeadbeef. So, this 
> confirms that missing malloc implementation is the root cause.
>
>> Memory access fault by GPU node-4 (Agent handle: 0x1bc5000) on address 
>> 0xdeadb000. Reason: Page not present or supervisor privilege.

Nice! In that case I think the way to go is to audit the (probably few) places 
where kmpc_impl_malloc are called and add a check for whether the return value 
is 0. With that in place we can reland this and get more graceful failure (at a 
guess we should fall back to the host when gpu memory is exhausted? or maybe 
just print a 'out of gpu heap memory' style message and abort, don't know).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102107/new/

https://reviews.llvm.org/D102107

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106876: Remove non-affecting module maps from PCM files.

2021-09-22 Thread Ilya Kuteev via Phabricator via cfe-commits
ilyakuteev updated this revision to Diff 374173.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106876/new/

https://reviews.llvm.org/D106876

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
  clang/test/Modules/add-remove-irrelevant-mobile-map.m
  clang/test/SemaCXX/Inputs/compare.modulemap
  clang/test/SemaCXX/compare-modules-cxx2a.cpp

Index: clang/test/SemaCXX/compare-modules-cxx2a.cpp
===
--- clang/test/SemaCXX/compare-modules-cxx2a.cpp
+++ clang/test/SemaCXX/compare-modules-cxx2a.cpp
@@ -1,15 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -fcxx-exceptions -verify -std=c++2a -fmodules -I%S/Inputs %s -fno-modules-error-recovery
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
 
-#pragma clang module build compare
-module compare {
-  explicit module cmp {}
-  explicit module other {}
-}
-#pragma clang module contents
-#pragma clang module begin compare.cmp
-#include "std-compare.h"
-#pragma clang module end
-#pragma clang module endbuild
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fcxx-exceptions -verify -std=c++2a -fmodules -fmodules-cache-path=%t.mcp -I%S/Inputs %s -fno-modules-error-recovery -fmodule-map-file=%S/Inputs/compare.modulemap
 
 struct CC { CC(...); };
 
@@ -24,10 +16,10 @@
 
 // expected-note@std-compare.h:* 2+{{not reachable}}
 
-void b() { void(0 <=> 0); } // expected-error 1+{{missing '#include "std-compare.h"'; 'strong_ordering' must be defined}}
+void b() { void(0 <=> 0); } // expected-error 1+{{definition of 'strong_ordering' must be imported from module 'compare.cmp' before it is required}}
 
 struct B {
-  CC operator<=>(const B&) const = default; // expected-error 1+{{missing '#include "std-compare.h"'; 'strong_ordering' must be defined}}
+  CC operator<=>(const B&) const = default; // expected-error 1+{{definition of 'strong_ordering' must be imported from module 'compare.cmp' before it is required}}
 };
 auto vb = B() <=> B(); // expected-note {{required here}}
 
Index: clang/test/SemaCXX/Inputs/compare.modulemap
===
--- /dev/null
+++ clang/test/SemaCXX/Inputs/compare.modulemap
@@ -0,0 +1,6 @@
+module compare {
+  explicit module cmp {
+header "std-compare.h"
+  }
+  explicit module other {}
+}
Index: clang/test/Modules/add-remove-irrelevant-mobile-map.m
===
--- /dev/null
+++ clang/test/Modules/add-remove-irrelevant-mobile-map.m
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
+
+// Build without b.modulemap
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
+// RUN: cp %t.mcp/a.pcm %t/a.pcm
+
+// Build with b.modulemap
+// RUN: rm -rf %t.mcp
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
+// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+
+// expected-no-diagnostics
+
+@import a;
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
@@ -0,0 +1 @@
+module b { }
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
@@ -0,0 +1 @@
+module a { }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -149,6 +149,59 @@
 
 namespace {
 
+std::set GetAllModuleMaps(const HeaderSearch &HS,
+ Module *RootModule) {
+  std::set ModuleMaps{};
+  std::set ProcessedModules;
+  SmallVector ModulesToProcess{RootModule};
+
+  SmallVector FilesByUID;
+  HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
+
+  if (FilesByUID.size() > HS.header_file_size())
+FilesByUID.resize(HS.header_file_size());
+
+  for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
+const FileEntry *File = FilesByUID[UID];
+if (!File)
+  continue;
+
+const HeaderFileInfo *HFI =
+HS.getExistingFileInfo(File, /*WantExternal*/ false);
+if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
+  continue;
+
+for (const auto &KH : HS.findAllModulesForHeader(File)) {
+  if (!KH.getModule())

[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-09-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 374174.
kbobyrev marked 4 inline comments as done.
kbobyrev added a comment.

Improve structure, address review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108194/new/

https://reviews.llvm.org/D108194

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h

Index: clang-tools-extra/clangd/ParsedAST.h
===
--- clang-tools-extra/clangd/ParsedAST.h
+++ clang-tools-extra/clangd/ParsedAST.h
@@ -116,6 +116,8 @@
 return Resolver.get();
   }
 
+  std::vector computeUnusedIncludes();
+
 private:
   ParsedAST(llvm::StringRef Version,
 std::shared_ptr Preamble,
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,6 +18,7 @@
 #include "FeatureModule.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"
@@ -614,5 +615,35 @@
 return llvm::None;
   return llvm::StringRef(Preamble->Version);
 }
+
+std::vector ParsedAST::computeUnusedIncludes() {
+  const auto &SM = getSourceManager();
+
+  auto Refs = findReferencedLocations(*this);
+  auto ReferencedFileIDs = findReferencedFiles(Refs, SM);
+  llvm::DenseSet ReferencedFiles;
+  ReferencedFiles.reserve(ReferencedFileIDs.size());
+  for (FileID FID : ReferencedFileIDs) {
+const FileEntry *FE = SM.getFileEntryForID(FID);
+if (!FE) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;
+}
+const auto File = Includes.getFile(FE);
+if (!File) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;
+}
+ReferencedFiles.insert(*File);
+  }
+  auto MainFileIndex =
+  Includes.getFile(SM.getFileEntryForID(SM.getMainFileID()));
+  if (!MainFileIndex) {
+elog("Missing MainFile in the IncludeStructure");
+return {};
+  }
+  return getUnused(*MainFileIndex, Includes, ReferencedFiles, SM);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -25,6 +25,7 @@
 #include "ParsedAST.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseSet.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -46,6 +47,29 @@
 /// - err on the side of reporting all possible locations
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
+/// Retrieves IDs of all files containing SourceLocations from \p Locs.
+/// FIXME: Those locations could be within macro expansions and are resolved to
+/// their spelling/expansion locations.
+llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
+   const SourceManager &SM);
+
+inline llvm::DenseMap directlyReferencedFiles(
+const IncludeStructure::AbstractIncludeGraph &Graph,
+const llvm::DenseSet &Referenced,
+unsigned EntryPoint) {
+  llvm::DenseMap Result;
+  for (IncludeStructure::File Inclusion : Graph.lookup(EntryPoint))
+Result.try_emplace(Inclusion, Referenced.contains(Inclusion));
+  return Result;
+}
+
+/// Retrieves headers that are referenced from the main file (\p EntryPoint)
+/// but not used.
+std::vector
+getUnused(IncludeStructure::File EntryPoint, const IncludeStructure &Structure,
+  const llvm::DenseSet &ReferencedFiles,
+  const SourceManager &SM);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -98,6 +98,35 @@
   llvm::DenseSet Visited;
 };
 
+// Given a set of referenced FileIDs, determines all the potentially-referenced
+// files and macros by traversing expansion/spelling locations of macro IDs.
+// This is used to map the referenced SourceLocations onto real files.
+struct ReferencedFiles {
+  ReferencedFiles(const SourceManager &SM) : SM(SM) {}
+  llvm::DenseSet Files;
+  llvm::DenseSet Macros;
+  const SourceManager &SM;
+
+  void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
+
+  void add(FileID FID, SourceLocation Loc) {
+if (FID.isInvalid())
+  return;
+assert(SM.isInFileID(Loc, FID));
+if (Loc.isFileID()) {
+  Files.insert(FID);
+  return;
+}
+// Don't process the same macro FID twice.
+if (!Macros.insert(FID

[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-09-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

Hey, sorry for the gigantic turn around. I still need to cover the code with 
few tests and polish it a bit more but I've updated the majority of it and 
pushed to get some early feedback before I do that. Please let me know if you 
have any concerns/see some problems with the approach I went for!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108194/new/

https://reviews.llvm.org/D108194

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109818: [HIPSPV] Convert HIP kernels to SPIR-V kernels

2021-09-22 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:10224
+// pointers for HIPSPV. When the language mode is HIP, the SPIRTargetInfo
+// maps cuda_device to SPIR-V's CrossWorkGroup address space.
+llvm::Type *LTy = CGT.ConvertType(Ty);

Anastasia wrote:
> linjamaki wrote:
> > Anastasia wrote:
> > > Can you explain why this mapping is needed? We already have an address 
> > > space map to perform the mapping of address spaces b/w language and 
> > > target. It would be good if we don't replicate similar logic in too many 
> > > places.
> > HIP does not require address space qualifiers on kernel pointer arguments 
> > (e.g. see hipspv-kernel.cpp) nor there are AS qualifiers that can be placed 
> > on them. With the default logic, provided by SPIRVTargetInfo’s address 
> > space map, the kernel pointer arguments get converted to generic pointers 
> > which are not allowed by the OpenCL SPIR-V Environment Specification.
> I feel that it is the same for SYCL... It might be good to check with @bader 
> whether there is already a way to handle this that can be reused for HIP...
We need to do similar transformation for SYCL, but it's not exactly the same. 
For SYCL kernels, which represented as function objects, compiler generates 
SPIR kernel function and fixes up the address space for pointer arguments in 
compiler generated declaration. For more details, see the description of 
https://reviews.llvm.org/D71016  and `handlePointerType` function code in 
clang/lib/Sema/SemaSYCL.cpp of this review request (lines 848-876). As address 
space is fixed in Sema, it works for all targets SYCL currently supports SPIR, 
NVPTX and AMDGPU.

If I understand it correctly, we are trying to do minimal amount of work for 
convert HIP kernel function to SPIR kernel function, i.e. fix calling 
convention and address spaces. 
Are these two fixes enough or we need more fixes to enable more sophisticated 
kernels?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109818/new/

https://reviews.llvm.org/D109818

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ea21d68 - [Matrix] Emit assumption that matrix indices are valid.

2021-09-22 Thread Florian Hahn via cfe-commits

Author: Florian Hahn
Date: 2021-09-22T12:27:37+01:00
New Revision: ea21d688dc0a420b9fc385562a46017fb39b13e5

URL: 
https://github.com/llvm/llvm-project/commit/ea21d688dc0a420b9fc385562a46017fb39b13e5
DIFF: 
https://github.com/llvm/llvm-project/commit/ea21d688dc0a420b9fc385562a46017fb39b13e5.diff

LOG: [Matrix] Emit assumption that matrix indices are valid.

The matrix extension requires the indices for matrix subscript
expression to be valid and it is UB otherwise.

extract/insertelement produce poison if the index is invalid, which
limits the optimizer to not be bale to scalarize load/extract pairs for
example, which causes very suboptimal code to be generated when using
matrix subscript expressions with variable indices for large matrixes.

This patch updates IRGen to emit assumes to for index expression to
convey the information that the index must be valid.

This also adjusts the order in which operations are emitted slightly, so
indices & assumes are added before the load of the matrix value.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D102478

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGen/matrix-type-operators.c
clang/test/CodeGenCXX/matrix-type-operators.cpp
clang/test/CodeGenObjC/matrix-type-operators.m
llvm/include/llvm/IR/MatrixBuilder.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index e07f95c60c5ff..fafaaf4472346 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -35,6 +35,7 @@
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/MatrixBuilder.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Path.h"
@@ -1939,10 +1940,15 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, 
SourceLocation Loc) {
 return EmitLoadOfGlobalRegLValue(LV);
 
   if (LV.isMatrixElt()) {
+llvm::Value *Idx = LV.getMatrixIdx();
+if (CGM.getCodeGenOpts().OptimizationLevel > 0) {
+  const auto *const MatTy = LV.getType()->getAs();
+  llvm::MatrixBuilder MB(Builder);
+  MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());
+}
 llvm::LoadInst *Load =
 Builder.CreateLoad(LV.getMatrixAddress(), LV.isVolatileQualified());
-return RValue::get(
-Builder.CreateExtractElement(Load, LV.getMatrixIdx(), "matrixext"));
+return RValue::get(Builder.CreateExtractElement(Load, Idx, "matrixext"));
   }
 
   assert(LV.isBitField() && "Unknown LValue type!");
@@ -2080,9 +2086,15 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
   return EmitStoreThroughGlobalRegLValue(Src, Dst);
 
 if (Dst.isMatrixElt()) {
-  llvm::Value *Vec = Builder.CreateLoad(Dst.getMatrixAddress());
-  Vec = Builder.CreateInsertElement(Vec, Src.getScalarVal(),
-Dst.getMatrixIdx(), "matins");
+  llvm::Value *Idx = Dst.getMatrixIdx();
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0) {
+const auto *const MatTy = Dst.getType()->getAs();
+llvm::MatrixBuilder MB(Builder);
+MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());
+  }
+  llvm::Instruction *Load = Builder.CreateLoad(Dst.getMatrixAddress());
+  llvm::Value *Vec =
+  Builder.CreateInsertElement(Load, Src.getScalarVal(), Idx, "matins");
   Builder.CreateStore(Vec, Dst.getMatrixAddress(),
   Dst.isVolatileQualified());
   return;

diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index fe62e63521a1e..67c581b46eae7 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1775,13 +1775,18 @@ Value 
*ScalarExprEmitter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
   // integer value.
   Value *RowIdx = Visit(E->getRowIdx());
   Value *ColumnIdx = Visit(E->getColumnIdx());
+
+  const auto *MatrixTy = E->getBase()->getType()->castAs();
+  unsigned NumRows = MatrixTy->getNumRows();
+  llvm::MatrixBuilder MB(Builder);
+  Value *Idx = MB.CreateIndex(RowIdx, ColumnIdx, NumRows);
+  if (CGF.CGM.getCodeGenOpts().OptimizationLevel > 0)
+MB.CreateIndexAssumption(Idx, MatrixTy->getNumElementsFlattened());
+
   Value *Matrix = Visit(E->getBase());
 
   // TODO: Should we emit bounds checks with SanitizerKind::ArrayBounds?
-  llvm::MatrixBuilder MB(Builder);
-  return MB.CreateExtractElement(
-  Matrix, RowIdx, ColumnIdx,
-  E->getBase()->getType()->castAs()->getNumRows());
+  return Builder.CreateExtractElement(Matrix, Idx, "matrixext");
 }
 
 static int getMaskElt(llvm::ShuffleVectorInst *SVI, unsigned Idx,

diff  --git a/clang/test/CodeGen/matrix-type-operators.c 
b/clang/test/CodeGen/matrix-type-operators.c
index 7d

[PATCH] D102478: [Matrix] Emit assumption that matrix indices are valid.

2021-09-22 Thread Florian Hahn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGea21d688dc0a: [Matrix] Emit assumption that matrix indices 
are valid. (authored by fhahn).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102478/new/

https://reviews.llvm.org/D102478

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/matrix-type-operators.c
  clang/test/CodeGenCXX/matrix-type-operators.cpp
  clang/test/CodeGenObjC/matrix-type-operators.m
  llvm/include/llvm/IR/MatrixBuilder.h

Index: llvm/include/llvm/IR/MatrixBuilder.h
===
--- llvm/include/llvm/IR/MatrixBuilder.h
+++ llvm/include/llvm/IR/MatrixBuilder.h
@@ -231,9 +231,23 @@
: (IsUnsigned ? B.CreateUDiv(LHS, RHS) : B.CreateSDiv(LHS, RHS));
   }
 
-  /// Extracts the element at (\p RowIdx, \p ColumnIdx) from \p Matrix.
-  Value *CreateExtractElement(Value *Matrix, Value *RowIdx, Value *ColumnIdx,
-  unsigned NumRows, Twine const &Name = "") {
+  /// Create an assumption that \p Idx is less than \p NumElements.
+  void CreateIndexAssumption(Value *Idx, unsigned NumElements,
+ Twine const &Name = "") {
+
+Value *NumElts =
+B.getIntN(Idx->getType()->getScalarSizeInBits(), NumElements);
+auto *Cmp = B.CreateICmpULT(Idx, NumElts);
+if (auto *ConstCond = dyn_cast(Cmp))
+  assert(ConstCond->isOne() && "Index must be valid!");
+else
+  B.CreateAssumption(Cmp);
+  }
+
+  /// Compute the index to access the element at (\p RowIdx, \p ColumnIdx) from
+  /// a matrix with \p NumRows embedded in a vector.
+  Value *CreateIndex(Value *RowIdx, Value *ColumnIdx, unsigned NumRows,
+ Twine const &Name = "") {
 
 unsigned MaxWidth = std::max(RowIdx->getType()->getScalarSizeInBits(),
  ColumnIdx->getType()->getScalarSizeInBits());
@@ -241,9 +255,7 @@
 RowIdx = B.CreateZExt(RowIdx, IntTy);
 ColumnIdx = B.CreateZExt(ColumnIdx, IntTy);
 Value *NumRowsV = B.getIntN(MaxWidth, NumRows);
-return B.CreateExtractElement(
-Matrix, B.CreateAdd(B.CreateMul(ColumnIdx, NumRowsV), RowIdx),
-"matext");
+return B.CreateAdd(B.CreateMul(ColumnIdx, NumRowsV), RowIdx);
   }
 };
 
Index: clang/test/CodeGenObjC/matrix-type-operators.m
===
--- clang/test/CodeGenObjC/matrix-type-operators.m
+++ clang/test/CodeGenObjC/matrix-type-operators.m
@@ -22,9 +22,9 @@
 // CHECK-NEXT:[[IV2_PTR:%.*]] = bitcast %0* [[IV2]] to i8*
 // CHECK-NEXT:[[CALL1:%.*]] = call i32 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 (i8*, i8*)*)(i8* [[IV2_PTR]], i8* [[SEL2]])
 // CHECK-NEXT:[[CONV2:%.*]] = sext i32 [[CALL1]] to i64
-// CHECK-NEXT:[[MAT:%.*]] = load <16 x double>, <16 x double>* {{.*}} align 8
 // CHECK-NEXT:[[IDX1:%.*]] = mul i64 [[CONV2]], 4
 // CHECK-NEXT:[[IDX2:%.*]] = add i64 [[IDX1]], [[CONV]]
+// CHECK-NEXT:[[MAT:%.*]] = load <16 x double>, <16 x double>* {{.*}} align 8
 // CHECK-NEXT:[[MATEXT:%.*]] = extractelement <16 x double> [[MAT]], i64 [[IDX2]]
 // CHECK-NEXT:ret double [[MATEXT]]
 //
@@ -49,12 +49,12 @@
 // CHECK-NEXT:[[IV2_PTR:%.*]] = bitcast %0* [[IV2]] to i8*
 // CHECK-NEXT:[[CALL1:%.*]] = call i32 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 (i8*, i8*)*)(i8* [[IV2_PTR]], i8* [[SEL2]])
 // CHECK-NEXT:[[CONV2:%.*]] = sext i32 [[CALL1]] to i64
+// CHECK-NEXT:[[IDX1:%.*]] = mul i64 [[CONV2]], 4
+// CHECK-NEXT:[[IDX2:%.*]] = add i64 [[IDX1]], [[CONV]]
 // CHECK-NEXT:[[M:%.*]] = load %1*, %1** %m.addr, align 8
 // CHECK-NEXT:[[SEL3:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_, align 8, !invariant.load !7
 // CHECK-NEXT:[[M_PTR:%.*]] = bitcast %1* [[M]] to i8*
 // CHECK-NEXT:[[MAT:%.*]] = call <16 x double> bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to <16 x double> (i8*, i8*)*)(i8* [[M_PTR]], i8* [[SEL3]])
-// CHECK-NEXT:[[IDX1:%.*]] = mul i64 [[CONV2]], 4
-// CHECK-NEXT:[[IDX2:%.*]] = add i64 [[IDX1]], [[CONV]]
 // CHECK-NEXT:[[MATEXT:%.*]] = extractelement <16 x double> [[MAT]], i64 [[IDX2]]
 // CHECK-NEXT:ret double [[MATEXT]]
 //
Index: clang/test/CodeGenCXX/matrix-type-operators.cpp
===
--- clang/test/CodeGenCXX/matrix-type-operators.cpp
+++ clang/test/CodeGenCXX/matrix-type-operators.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 -O0 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 -O1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-pas

[clang] 1ee851c - Revert "[CodeGen] regenerate test checks; NFC"

2021-09-22 Thread Sanjay Patel via cfe-commits

Author: Sanjay Patel
Date: 2021-09-22T07:45:21-04:00
New Revision: 1ee851c5859fdb36eca57a46347a1e7b8e1ff236

URL: 
https://github.com/llvm/llvm-project/commit/1ee851c5859fdb36eca57a46347a1e7b8e1ff236
DIFF: 
https://github.com/llvm/llvm-project/commit/1ee851c5859fdb36eca57a46347a1e7b8e1ff236.diff

LOG: Revert "[CodeGen] regenerate test checks; NFC"

This reverts commit 52832cd917af00e2b9c6a9d1476ba79754dcabff.
The motivating commit 2f6b07316f5 caused several bots to hit
an infinite loop at stage 2, so that needs to be reverted too
while figuring out how to fix that.

Added: 


Modified: 
clang/test/CodeGen/aapcs-bitfield.c

Removed: 




diff  --git a/clang/test/CodeGen/aapcs-bitfield.c 
b/clang/test/CodeGen/aapcs-bitfield.c
index 316986c764bc..13db68d6ae81 100644
--- a/clang/test/CodeGen/aapcs-bitfield.c
+++ b/clang/test/CodeGen/aapcs-bitfield.c
@@ -1034,7 +1034,7 @@ struct st6 {
 // LE-NEXT:[[BF_ASHR:%.*]] = ashr exact i16 [[BF_SHL]], 4
 // LE-NEXT:[[BF_CAST:%.*]] = sext i16 [[BF_ASHR]] to i32
 // LE-NEXT:[[B:%.*]] = getelementptr inbounds [[STRUCT_ST6]], %struct.st6* 
[[M]], i32 0, i32 1
-// LE-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, !tbaa 
[[TBAA3:![0-9]+]]
+// LE-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, !tbaa !3
 // LE-NEXT:[[CONV:%.*]] = sext i8 [[TMP1]] to i32
 // LE-NEXT:[[ADD:%.*]] = add nsw i32 [[BF_CAST]], [[CONV]]
 // LE-NEXT:[[C:%.*]] = getelementptr inbounds [[STRUCT_ST6]], %struct.st6* 
[[M]], i32 0, i32 2
@@ -1052,7 +1052,7 @@ struct st6 {
 // BE-NEXT:[[BF_ASHR:%.*]] = ashr i16 [[BF_LOAD]], 4
 // BE-NEXT:[[BF_CAST:%.*]] = sext i16 [[BF_ASHR]] to i32
 // BE-NEXT:[[B:%.*]] = getelementptr inbounds [[STRUCT_ST6]], %struct.st6* 
[[M]], i32 0, i32 1
-// BE-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, !tbaa 
[[TBAA3:![0-9]+]]
+// BE-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, !tbaa !3
 // BE-NEXT:[[CONV:%.*]] = sext i8 [[TMP1]] to i32
 // BE-NEXT:[[ADD:%.*]] = add nsw i32 [[BF_CAST]], [[CONV]]
 // BE-NEXT:[[C:%.*]] = getelementptr inbounds [[STRUCT_ST6]], %struct.st6* 
[[M]], i32 0, i32 2
@@ -1070,7 +1070,7 @@ struct st6 {
 // LENUMLOADS-NEXT:[[BF_ASHR:%.*]] = ashr exact i16 [[BF_SHL]], 4
 // LENUMLOADS-NEXT:[[BF_CAST:%.*]] = sext i16 [[BF_ASHR]] to i32
 // LENUMLOADS-NEXT:[[B:%.*]] = getelementptr inbounds [[STRUCT_ST6]], 
%struct.st6* [[M]], i32 0, i32 1
-// LENUMLOADS-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, 
!tbaa [[TBAA3:![0-9]+]]
+// LENUMLOADS-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, 
!tbaa !3
 // LENUMLOADS-NEXT:[[CONV:%.*]] = sext i8 [[TMP1]] to i32
 // LENUMLOADS-NEXT:[[ADD:%.*]] = add nsw i32 [[BF_CAST]], [[CONV]]
 // LENUMLOADS-NEXT:[[C:%.*]] = getelementptr inbounds [[STRUCT_ST6]], 
%struct.st6* [[M]], i32 0, i32 2
@@ -1088,7 +1088,7 @@ struct st6 {
 // BENUMLOADS-NEXT:[[BF_ASHR:%.*]] = ashr i16 [[BF_LOAD]], 4
 // BENUMLOADS-NEXT:[[BF_CAST:%.*]] = sext i16 [[BF_ASHR]] to i32
 // BENUMLOADS-NEXT:[[B:%.*]] = getelementptr inbounds [[STRUCT_ST6]], 
%struct.st6* [[M]], i32 0, i32 1
-// BENUMLOADS-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, 
!tbaa [[TBAA3:![0-9]+]]
+// BENUMLOADS-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, 
!tbaa !3
 // BENUMLOADS-NEXT:[[CONV:%.*]] = sext i8 [[TMP1]] to i32
 // BENUMLOADS-NEXT:[[ADD:%.*]] = add nsw i32 [[BF_CAST]], [[CONV]]
 // BENUMLOADS-NEXT:[[C:%.*]] = getelementptr inbounds [[STRUCT_ST6]], 
%struct.st6* [[M]], i32 0, i32 2
@@ -1106,7 +1106,7 @@ struct st6 {
 // LEWIDTH-NEXT:[[BF_ASHR:%.*]] = ashr exact i16 [[BF_SHL]], 4
 // LEWIDTH-NEXT:[[BF_CAST:%.*]] = sext i16 [[BF_ASHR]] to i32
 // LEWIDTH-NEXT:[[B:%.*]] = getelementptr inbounds [[STRUCT_ST6]], 
%struct.st6* [[M]], i32 0, i32 1
-// LEWIDTH-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, !tbaa 
[[TBAA3:![0-9]+]]
+// LEWIDTH-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, !tbaa 
!3
 // LEWIDTH-NEXT:[[CONV:%.*]] = sext i8 [[TMP1]] to i32
 // LEWIDTH-NEXT:[[ADD:%.*]] = add nsw i32 [[BF_CAST]], [[CONV]]
 // LEWIDTH-NEXT:[[C:%.*]] = getelementptr inbounds [[STRUCT_ST6]], 
%struct.st6* [[M]], i32 0, i32 2
@@ -1124,7 +1124,7 @@ struct st6 {
 // BEWIDTH-NEXT:[[BF_ASHR:%.*]] = ashr i16 [[BF_LOAD]], 4
 // BEWIDTH-NEXT:[[BF_CAST:%.*]] = sext i16 [[BF_ASHR]] to i32
 // BEWIDTH-NEXT:[[B:%.*]] = getelementptr inbounds [[STRUCT_ST6]], 
%struct.st6* [[M]], i32 0, i32 1
-// BEWIDTH-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, !tbaa 
[[TBAA3:![0-9]+]]
+// BEWIDTH-NEXT:[[TMP1:%.*]] = load volatile i8, i8* [[B]], align 2, !tbaa 
!3
 // BEWIDTH-NEXT:[[CONV:%.*]] = sext i8 [[TMP1]] to i32
 // BEWIDTH-NEXT:[[ADD:%.*]] = add nsw i32 [[BF_CAST]], [[CONV]]
 // BEWIDTH-NEXT:[[C:%.*]] = getele

[PATCH] D108567: Implement #pragma clang final extension

2021-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:3979
+   #undef FINAL_MACRO  // warning: FINAL_MACRO is marked final and should not 
be undefined
+   #define FINAL_MACRO // warning: FINAL_MACRO is marked final and should not 
be redefined
+

beanz wrote:
> aaron.ballman wrote:
> > What happens if the redefinition is to the same token sequence as the 
> > original definition? e.g.,
> > ```
> > #define FINAL_MACRO 1+1
> > #pragma clang final(FINAL_MACRO)
> > #define FINAL_MACRO 1+1 // ok?
> > #define FINAL_MACRO (1+1) // Whoa...slow your roll there, champ!
> > ```
> `-Wmacro-redefined` currently warns on redefinitions even if they are the 
> same as the existing definition.
> 
> The implementation in this patch only triggers on redefining macros that have 
> been undef'd and relies on `-Wmacro-redefined` to catch masking 
> redefinitions. Although I should probably change that so that final catches 
> on both.
> -Wmacro-redefined currently warns on redefinitions even if they are the same 
> as the existing definition.

Okay, SGTM.

> The implementation in this patch only triggers on redefining macros that have 
> been undef'd and relies on -Wmacro-redefined to catch masking redefinitions. 
> Although I should probably change that so that final catches on both.

+1



Comment at: clang/test/Lexer/final-macro.c:5-8
+// expected-note@+4{{macro marked 'final' here}}
+// expected-note@+3{{macro marked 'final' here}}
+// expected-note@+2{{macro marked 'final' here}}
+// expected-note@+1{{macro marked 'final' here}}

99% sure I got the syntax right, but you can specify a number to avoid 
duplicating the diagnostic multiple times and I'm pretty sure it works with the 
`@+N` syntax as well, but I don't recall trying in recent history.



Comment at: clang/test/Lexer/final-macro.c:10-11
+#pragma clang final(Foo)
+#pragma clang deprecated(Foo)
+#pragma clang header_unsafe(Foo)
+

If the goal is to test that mention of the macro here does not cause 
diagnostics, I'd recommend adding this to the end of the file instead of the 
beginning -- from there it's more obvious that none of the preceding 
diagnostics are triggered because of those pragmas.



Comment at: clang/test/Lexer/final-macro.c:14
+// expected-warning@+2{{macro 'Foo' has been marked as final and should not be 
redefined}}
+// expected-note@+1{{previous definition is here}}
+#define Foo 1

This previous definition marker looks wrong to me -- it should be pointing to 
line 4, right?



Comment at: clang/test/Lexer/final-macro.c:18
+// expected-warning@+2{{macro 'Foo' has been marked as final and should not be 
redefined}}
+// expected-warning@+1{{'Foo' macro redefined}}
+#define Foo 2

Should we suppress this diagnostic when we know we're already issuing the 
previous one? I get why they both are issued, but it does seem a bit unclean to 
have two warnings that are  basically both "you are redefining this macro and 
maybe you should reconsider that" diagnostics. (I don't feel strongly, mostly 
wondering out loud.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108567/new/

https://reviews.llvm.org/D108567

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104285: [analyzer] Retrieve a value from list initialization of constant array declaration in a global scope.

2021-09-22 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1696-1697
+  const auto I = static_cast(Idx.getExtValue());
+  // Use `getZExtValue` because array extent can not be negative.
+  const uint64_t Extent = CAT->getSize().getZExtValue();
+  // Check for `Idx < 0`, NOT for `I < 0`, because `Idx` CAN be

Do you think it would make sense to `assert(CAT->getSize().isSigned())`?



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1696
+  const llvm::APSInt &Idx = CI->getValue();
+  const uint64_t I = static_cast(Idx.getExtValue());
+  // Use `getZExtValue` because array extent can not be negative.

ASDenysPetrov wrote:
> martong wrote:
> > ASDenysPetrov wrote:
> > > ASDenysPetrov wrote:
> > > > martong wrote:
> > > > > aaron.ballman wrote:
> > > > > > 
> > > > > This `static_cast` seems to be dangerous to me, it might overflow. 
> > > > > Can't we compare `Idx` directly to `Extent`? I see that `Idx` is an 
> > > > > `APSint` and `Extent` is an `APInt`, but  I think we should be able 
> > > > > to handle the comparison on the APInt level b/c that takes care of 
> > > > > the signedness. And the overflow situation should be handled as well 
> > > > > properly with `APInt`, given from it's name "arbitrary precision 
> > > > > int". In this sense I don't see why do we need `I` at all.
> > > > We can't get rid of `I` because we use it below anyway in `I >= 
> > > > InitList->getNumInits()` and `InitList->getInit(I)`.
> > > > I couldn't find any appropriate function to compare without additional 
> > > > checking for signedness or bit-width adjusting.
> > > > I'll try to improve this snippet.
> > > This is not dangerous because we check for negatives separately in `Idx < 
> > > 0`, so we can be sure that `I` is positive while `I >= Extent`. 
> > > Unfortunately, I didn't find any suitable way to compare `APSint` //of 
> > > unknown sign and bitwidth// with //signless// `APInt` without adding 
> > > another checks for sign and bitwidth conversions. In this way I prefer 
> > > the currect condition `I >= Extent`.
> > I think it would be possible to use `bool llvm::APInt::uge` that does an 
> > Unsigned greater or equal comparison. Or you could use `sge` for the signed 
> > comparison. Also, both have overload that take another APInt as parameter.
> I considered them. First of all choosing between `uge` and `sge` we 
> additionally need to check for signedness. Moreover, these functions require 
> bitwidth to be equal. Thus we need additional checks and transformations. I 
> found this approach too verbose. Mine one seems to me simpler and works under 
> natural rules of comparison.
Okay, thanks for thinking it through and answering my concerns!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104285/new/

https://reviews.llvm.org/D104285

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106102: [analyzer][solver] Introduce reasoning for not equal to operator

2021-09-22 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

This is promising! Gentle ping @manas @vsavchenko


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106102/new/

https://reviews.llvm.org/D106102

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97874: [analyzer] Improve SVal cast from integer to bool using known RangeSet

2021-09-22 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.
Herald added a subscriber: manas.

@ASDenysPetrov I think the dependent patch https://reviews.llvm.org/D97296 is 
too much and contains unnecessary things for this change.

If you could you please incorporate the minimum needed changes from that patch 
to here then this patch could land.
If I am not mistaken then we need only the below changes:

  SVal evalCastKind(ProgramStateRef State, UndefinedVal V, QualType CastTy,
  SVal evalCastSubKind(ProgramStateRef State, nonloc::SymbolVal V,


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97874/new/

https://reviews.llvm.org/D97874

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97960: [clang-tidy] bugprone-signal-handler improvements: display call chain

2021-09-22 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

So, about the tests, gentle ping @njames93


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97960/new/

https://reviews.llvm.org/D97960

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110130: [clangd] Ensure lambda init-capture gets semantic token

2021-09-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks, LGTM!




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:518
+  SourceLocation StartLoc = D->getTypeSpecStartLoc();
+  // The AutoType may not have a corresponding token, e.g. in the case of
+  // init-captures, so there's nothing to color.

i think the comment might be more explicit about doing this to ensure we are 
not attributing the highlighting to some closeby token.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:515
   return true;
 if (auto K = kindForType(AT->getDeducedType().getTypePtrOrNull(),
  H.getResolver())) {

kadircet wrote:
> nit: while here do you mind turning this into an early exit as well? the 
> nesting below seems a little distracting.
sorry I was also talking about also turning `if(auto K = ...)` to
```
auto K = ...
if (!K)
  return true;
```



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:522
+  // is the same as the location of the declared name itself.
+  if (StartLoc != D->getLocation()) {
+auto &Tok =

nridge wrote:
> kadircet wrote:
> > nridge wrote:
> > > Note, I initially tried `D->getTypeSpecStartLoc() != 
> > > D->getTypeSpecEndLoc()`, but it turns out they are equal both in the 
> > > init-capture case and in the regular `auto` case, so that check cannot be 
> > > used to discriminate between the two.
> > why not just check if `D` is implicit?
> If you mean `D->isImplicit()`, that returns false for init-captures.
ah nvm, I was looking at the fielddecl implicitly introduced into the lambda, 
not the vardecl that was created with the capture 
(https://github.com/llvm/llvm-project/tree/main/clang/lib/Sema/SemaLambda.cpp#L1739).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110130/new/

https://reviews.llvm.org/D110130

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86295: [analyzer] Reorder the layout of MemRegion and cache by hand for optimal size

2021-09-22 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.
Herald added a subscriber: manas.

In D86295#2539431 , @steakhal wrote:

> In D86295#2519851 , @ASDenysPetrov 
> wrote:
>
>> What about this change? Did you make more measurements?
>
> IMO it needs more justification and measurement to land it.
>
> If my measurement was correct then it would decrease the readability of the 
> code without any benefit.
> It could be the case due to the allocation strategy & alignment stuff that we 
> don't gain anything by making its layout more compact.

@steakhal Since then we have our fancy csa-testbench based jenkins job(s) to do 
measurement even on huge projects. Do you think it would make sense to give it 
another measure with that?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86295/new/

https://reviews.llvm.org/D86295

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86295: [analyzer] Reorder the layout of MemRegion and cache by hand for optimal size

2021-09-22 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D86295#3014990 , @martong wrote:

> @steakhal Since then we have our fancy csa-testbench based jenkins job(s) to 
> do measurement even on huge projects. Do you think it would make sense to 
> give it another measure with that?

I was actually thinking about that. We could give it another try. I'm not 
expecting a measurable difference though.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86295/new/

https://reviews.llvm.org/D86295

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108301: [MSP430][Clang] Update hard-coded MCU data

2021-09-22 Thread Jozef Lawrynowicz via Phabricator via cfe-commits
jozefl updated this revision to Diff 374200.
jozefl added a comment.
Herald added subscribers: llvm-commits, ormris, hiraditya.
Herald added a project: LLVM.

Rebase to fix patch application failure for
clang/test/Misc/target-invalid-cpu-note.c.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108301/new/

https://reviews.llvm.org/D108301

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/MSP430Target.def
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/MSP430.h
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MSP430.cpp
  clang/lib/Driver/ToolChains/MSP430.h
  clang/test/Driver/msp430-cpu.c
  clang/test/Driver/msp430-hwmult.c
  clang/test/Driver/msp430-mmcu.c
  clang/test/Driver/msp430-toolchain.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/msp430-defs.c
  llvm/lib/Target/MSP430/MSP430.td
  llvm/lib/Target/MSP430/MSP430Subtarget.cpp
  llvm/lib/Target/MSP430/MSP430Subtarget.h
  llvm/test/CodeGen/MSP430/build-attrs.ll

Index: llvm/test/CodeGen/MSP430/build-attrs.ll
===
--- llvm/test/CodeGen/MSP430/build-attrs.ll
+++ llvm/test/CodeGen/MSP430/build-attrs.ll
@@ -8,6 +8,8 @@
 ; RUN:   | llvm-readelf -A - | FileCheck %s --check-prefixes COMMON,MSP430,SMALL
 ; RUN: llc -mtriple=msp430 -mcpu=msp430x -filetype=obj < %s \
 ; RUN:   | llvm-readelf -A - | FileCheck %s --check-prefixes COMMON,MSP430X,SMALL
+; RUN: llc -mtriple=msp430 -mcpu=msp430xv2 -filetype=obj < %s \
+; RUN:   | llvm-readelf -A - | FileCheck %s --check-prefixes COMMON,MSP430X,SMALL
 
 ; COMMON: BuildAttributes {
 ; COMMON: FormatVersion: 0x41
Index: llvm/lib/Target/MSP430/MSP430Subtarget.h
===
--- llvm/lib/Target/MSP430/MSP430Subtarget.h
+++ llvm/lib/Target/MSP430/MSP430Subtarget.h
@@ -36,7 +36,7 @@
 
 private:
   virtual void anchor();
-  bool ExtendedInsts = false;
+  bool MSP430X = false;
   HWMultEnum HWMultMode = NoHWMult;
   MSP430FrameLowering FrameLowering;
   MSP430InstrInfo InstrInfo;
@@ -60,6 +60,8 @@
   bool hasHWMult32() const { return HWMultMode == HWMult32; }
   bool hasHWMultF5() const { return HWMultMode == HWMultF5; }
 
+  bool hasMSP430X() const { return MSP430X; }
+
   const TargetFrameLowering *getFrameLowering() const override {
 return &FrameLowering;
   }
Index: llvm/lib/Target/MSP430/MSP430Subtarget.cpp
===
--- llvm/lib/Target/MSP430/MSP430Subtarget.cpp
+++ llvm/lib/Target/MSP430/MSP430Subtarget.cpp
@@ -40,9 +40,6 @@
 
 MSP430Subtarget &
 MSP430Subtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
-  ExtendedInsts = false;
-  HWMultMode = NoHWMult;
-
   StringRef CPUName = CPU;
   if (CPUName.empty())
 CPUName = "msp430";
Index: llvm/lib/Target/MSP430/MSP430.td
===
--- llvm/lib/Target/MSP430/MSP430.td
+++ llvm/lib/Target/MSP430/MSP430.td
@@ -18,8 +18,8 @@
 // Subtarget Features. 
 //===--===//
 def FeatureX
- : SubtargetFeature<"ext", "ExtendedInsts", "true",
-"Enable MSP430-X extensions">;
+ : SubtargetFeature<"msp430x", "MSP430X", "true",
+"Enable MSP430X extensions">;
 
 def FeatureHWMult16
  : SubtargetFeature<"hwmult16", "HWMultMode", "HWMult16",
@@ -42,6 +42,7 @@
 def : Proc<"generic", []>;
 def : Proc<"msp430",  []>;
 def : Proc<"msp430x", [FeatureX]>;
+def : Proc<"msp430xv2",   [FeatureX]>;
 
 //===--===//
 // Register File Description
Index: clang/test/Preprocessor/msp430-defs.c
===
--- /dev/null
+++ clang/test/Preprocessor/msp430-defs.c
@@ -0,0 +1,20 @@
+// Check the correct macros are defined for each CPU.
+
+// RUN: %clang -target msp430 -x c -E -dM %s -o - | FileCheck  %s
+// RUN: %clang -target msp430 -mcpu=generic -x c -E -dM %s -o - | FileCheck %s
+// RUN: %clang -target msp430 -mcpu=msp430 -x c -E -dM %s -o - | FileCheck %s
+
+// CHECK: MSP430
+// CHECK: __ELF__
+// CHECK-NOT: __MSP430X__
+// CHECK: __MSP430__
+
+// RUN: %clang -target msp430 -mcpu=msp430x -x c -E -dM %s -o - \
+// RUN:   | FileCheck --check-prefix=MSP430X %s
+// RUN: %clang -target msp430 -mcpu=msp430xv2 -x c -E -dM %s -o - \
+// RUN:   | FileCheck --check-prefix=MSP430X %s
+
+// MSP430X: MSP430
+// MSP430X: __ELF__
+// MSP430X: __MSP430X__
+// MSP430X: __MSP430__
Index: clang/test/Misc/target-invalid-cpu-note.c
===
--- clang/test/Misc/target-invalid-cpu-note.c
+++ clang/test/Misc/target-invalid-cpu-note.c
@@ -209,3 +209,7 @@
 // RUN: not %clang_cc1 -t

[PATCH] D110241: [docs] List support for Armv9-A, Armv9.1-A and Armv9.2-A in LLVM and Clang

2021-09-22 Thread Victor Campos via Phabricator via cfe-commits
vhscampos created this revision.
Herald added a subscriber: kristof.beyls.
vhscampos requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110241

Files:
  clang/docs/ReleaseNotes.rst
  llvm/docs/ReleaseNotes.rst


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -72,12 +72,12 @@
 Changes to the AArch64 Backend
 --
 
-* ...
+* Added support for Armv9-A, Armv9.1-A and Armv9.2-A architectures.
 
 Changes to the ARM Backend
 --
 
-During this release ...
+* Added support for Armv9-A, Armv9.1-A and Armv9.2-A architectures.
 
 Changes to the MIPS Target
 --
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -83,6 +83,12 @@
   - RISC-V SiFive S54 (``sifive-s54``).
   - RISC-V SiFive S76 (``sifive-s76``).
 
+- Support has been added for the following architectures (``-march`` 
identifiers in parentheses):
+
+  - Armv9-A (``armv9-a``).
+  - Armv9.1-A (``armv9.1-a``).
+  - Armv9.2-A (``armv9.2-a``).
+
 Removed Compiler Flags
 -
 


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -72,12 +72,12 @@
 Changes to the AArch64 Backend
 --
 
-* ...
+* Added support for Armv9-A, Armv9.1-A and Armv9.2-A architectures.
 
 Changes to the ARM Backend
 --
 
-During this release ...
+* Added support for Armv9-A, Armv9.1-A and Armv9.2-A architectures.
 
 Changes to the MIPS Target
 --
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -83,6 +83,12 @@
   - RISC-V SiFive S54 (``sifive-s54``).
   - RISC-V SiFive S76 (``sifive-s76``).
 
+- Support has been added for the following architectures (``-march`` identifiers in parentheses):
+
+  - Armv9-A (``armv9-a``).
+  - Armv9.1-A (``armv9.1-a``).
+  - Armv9.2-A (``armv9.2-a``).
+
 Removed Compiler Flags
 -
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105191: [Clang][OpenMP] Add support for Static Device Libraries

2021-09-22 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal added inline comments.



Comment at: clang/test/Driver/fat_archive.cpp:9
+// could be resolved correctly.
+// RUN: env 
LIBRARY_PATH=%T/../../../../../runtimes/runtimes-bins/openmp/libomptarget 
%clang -O2 -target x86_64-pc-linux-gnu -fopenmp 
-fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa 
-march=gfx906 %s -L%S/Inputs/hip_dev_lib -lFatArchive -o - | FileCheck %s 
-check-prefix=LINKERROR
+// LINKERROR-NOT: error: linker command failed with exit code 1

Here, LIBRARY_PATH is specifying path to build directory of openmp runtime 
which might not be available when openmp is not built. Why not use %S/Inputs 
directory and put the required files into that?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105191/new/

https://reviews.llvm.org/D105191

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110241: [docs] List support for Armv9-A, Armv9.1-A and Armv9.2-A in LLVM and Clang

2021-09-22 Thread Victor Campos via Phabricator via cfe-commits
vhscampos updated this revision to Diff 374207.
vhscampos added a comment.

Added 'the' for better phrasing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110241/new/

https://reviews.llvm.org/D110241

Files:
  clang/docs/ReleaseNotes.rst
  llvm/docs/ReleaseNotes.rst


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -72,12 +72,12 @@
 Changes to the AArch64 Backend
 --
 
-* ...
+* Added support for the Armv9-A, Armv9.1-A and Armv9.2-A architectures.
 
 Changes to the ARM Backend
 --
 
-During this release ...
+* Added support for the Armv9-A, Armv9.1-A and Armv9.2-A architectures.
 
 Changes to the MIPS Target
 --
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -83,6 +83,12 @@
   - RISC-V SiFive S54 (``sifive-s54``).
   - RISC-V SiFive S76 (``sifive-s76``).
 
+- Support has been added for the following architectures (``-march`` 
identifiers in parentheses):
+
+  - Armv9-A (``armv9-a``).
+  - Armv9.1-A (``armv9.1-a``).
+  - Armv9.2-A (``armv9.2-a``).
+
 Removed Compiler Flags
 -
 


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -72,12 +72,12 @@
 Changes to the AArch64 Backend
 --
 
-* ...
+* Added support for the Armv9-A, Armv9.1-A and Armv9.2-A architectures.
 
 Changes to the ARM Backend
 --
 
-During this release ...
+* Added support for the Armv9-A, Armv9.1-A and Armv9.2-A architectures.
 
 Changes to the MIPS Target
 --
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -83,6 +83,12 @@
   - RISC-V SiFive S54 (``sifive-s54``).
   - RISC-V SiFive S76 (``sifive-s76``).
 
+- Support has been added for the following architectures (``-march`` identifiers in parentheses):
+
+  - Armv9-A (``armv9-a``).
+  - Armv9.1-A (``armv9.1-a``).
+  - Armv9.2-A (``armv9.2-a``).
+
 Removed Compiler Flags
 -
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110241: [docs] List support for Armv9-A, Armv9.1-A and Armv9.2-A in LLVM and Clang

2021-09-22 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas accepted this revision.
pratlucas added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110241/new/

https://reviews.llvm.org/D110241

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110226: [InstCombine] Update InstCombine to use poison instead of undef for shufflevector's placeholder (1/3)

2021-09-22 Thread Hyeongyu Kim via Phabricator via cfe-commits
hyeongyukim updated this revision to Diff 374210.
hyeongyukim added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix comment, update test file(wasm.c)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110226/new/

https://reviews.llvm.org/D110226

Files:
  clang/test/CodeGen/arm-neon-dot-product.c
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/X86/x86-f16c-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-f16c.ll
  llvm/test/Transforms/InstCombine/cast.ll
  llvm/test/Transforms/InstCombine/shuffle-cast-dist.ll
  llvm/test/Transforms/InstCombine/shufflevec-bitcast-inseltpoison.ll
  llvm/test/Transforms/InstCombine/shufflevec-bitcast.ll
  llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
  llvm/test/Transforms/InstCombine/trunc.ll
  llvm/test/Transforms/InstCombine/vector-casts.ll

Index: llvm/test/Transforms/InstCombine/vector-casts.ll
===
--- llvm/test/Transforms/InstCombine/vector-casts.ll
+++ llvm/test/Transforms/InstCombine/vector-casts.ll
@@ -414,7 +414,7 @@
 define <4 x float> @sitofp_shuf(<4 x i32> %x) {
 ; CHECK-LABEL: @sitofp_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = sitofp <4 x i32> [[X:%.*]] to <4 x float>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> undef, <4 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x float> [[R]]
 ;
   %s = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> 
@@ -425,7 +425,7 @@
 define <3 x half> @uitofp_shuf(<3 x i16> %x) {
 ; CHECK-LABEL: @uitofp_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = uitofp <3 x i16> [[X:%.*]] to <3 x half>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <3 x half> [[TMP1]], <3 x half> undef, <3 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <3 x half> [[TMP1]], <3 x half> poison, <3 x i32> 
 ; CHECK-NEXT:ret <3 x half> [[R]]
 ;
   %s = shufflevector <3 x i16> %x, <3 x i16> poison, <3 x i32> 
@@ -436,7 +436,7 @@
 define <4 x i64> @fptosi_shuf(<4 x double> %x) {
 ; CHECK-LABEL: @fptosi_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = fptosi <4 x double> [[X:%.*]] to <4 x i64>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x i64> [[TMP1]], <4 x i64> undef, <4 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x i64> [[TMP1]], <4 x i64> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x i64> [[R]]
 ;
   %s = shufflevector <4 x double> %x, <4 x double> poison, <4 x i32> 
@@ -447,7 +447,7 @@
 define <2 x i32> @fptoui_shuf(<2 x float> %x) {
 ; CHECK-LABEL: @fptoui_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = fptoui <2 x float> [[X:%.*]] to <2 x i32>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <2 x i32> 
 ; CHECK-NEXT:ret <2 x i32> [[R]]
 ;
   %s = shufflevector <2 x float> %x, <2 x float> poison, <2 x i32> 
Index: llvm/test/Transforms/InstCombine/trunc.ll
===
--- llvm/test/Transforms/InstCombine/trunc.ll
+++ llvm/test/Transforms/InstCombine/trunc.ll
@@ -922,7 +922,7 @@
 define <4 x i8> @wide_splat1(<4 x i32> %x) {
 ; CHECK-LABEL: @wide_splat1(
 ; CHECK-NEXT:[[TMP1:%.*]] = trunc <4 x i32> [[X:%.*]] to <4 x i8>
-; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> undef, <4 x i32> 
+; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x i8> [[TRUNC]]
 ;
   %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> 
@@ -936,7 +936,7 @@
 define <3 x i31> @wide_splat2(<3 x i33> %x) {
 ; CHECK-LABEL: @wide_splat2(
 ; CHECK-NEXT:[[TMP1:%.*]] = trunc <3 x i33> [[X:%.*]] to <3 x i31>
-; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <3 x i31> [[TMP1]], <3 x i31> undef, <3 x i32> 
+; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <3 x i31> [[TMP1]], <3 x i31> poison, <3 x i32> 
 ; CHECK-NEXT:ret <3 x i31> [[TRUNC]]
 ;
   %shuf = shufflevector <3 x i33> %x, <3 x i33> undef, <3 x i32> 
Index: llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
===
--- llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
+++ llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
@@ -922,7 +922,7 @@
 define <4 x i8> @wide_splat1(<4 x i32> %x) {
 ; CHECK-LABEL: @wide_splat1(
 ; CHECK-NEXT:[[TMP1:%.*]] = trunc <4 x i32> [[X:%.*]] to <4 x i8>
-; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> undef, <4 x i32> 
+; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x i8> [[TRUNC]]
 ;
   %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> 
@@ -936,7 +936,7 @@
 define <3 x i31> @wide_splat2(<3 x i33> %x) {
 ; CHECK-LABEL: @wid

[PATCH] D110226: [InstCombine] Update InstCombine to use poison instead of undef for shufflevector's placeholder (1/3)

2021-09-22 Thread Hyeongyu Kim via Phabricator via cfe-commits
hyeongyukim updated this revision to Diff 374212.
hyeongyukim added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110226/new/

https://reviews.llvm.org/D110226

Files:
  llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
===
--- llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
@@ -368,7 +368,6 @@
   SDValue PromoteIntOp_BUILD_VECTOR(SDNode *N);
   SDValue PromoteIntOp_INSERT_VECTOR_ELT(SDNode *N, unsigned OpNo);
   SDValue PromoteIntOp_EXTRACT_VECTOR_ELT(SDNode *N);
-  SDValue PromoteIntOp_EXTRACT_SUBVECTOR(SDNode *N);
   SDValue PromoteIntOp_INSERT_SUBVECTOR(SDNode *N);
   SDValue PromoteIntOp_CONCAT_VECTORS(SDNode *N);
   SDValue PromoteIntOp_SCALAR_TO_VECTOR(SDNode *N);
Index: llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -1577,7 +1577,6 @@
   case ISD::UINT_TO_FP:   Res = PromoteIntOp_UINT_TO_FP(N); break;
   case ISD::STRICT_UINT_TO_FP:  Res = PromoteIntOp_STRICT_UINT_TO_FP(N); break;
   case ISD::ZERO_EXTEND:  Res = PromoteIntOp_ZERO_EXTEND(N); break;
-  case ISD::EXTRACT_SUBVECTOR: Res = PromoteIntOp_EXTRACT_SUBVECTOR(N); break;
   case ISD::INSERT_SUBVECTOR: Res = PromoteIntOp_INSERT_SUBVECTOR(N); break;
 
   case ISD::SHL:
@@ -5094,16 +5093,6 @@
   return DAG.getAnyExtOrTrunc(Ext, dl, N->getValueType(0));
 }
 
-SDValue DAGTypeLegalizer::PromoteIntOp_EXTRACT_SUBVECTOR(SDNode *N) {
-  SDLoc dl(N);
-  SDValue V0 = GetPromotedInteger(N->getOperand(0));
-  MVT InVT = V0.getValueType().getSimpleVT();
-  MVT OutVT = MVT::getVectorVT(InVT.getVectorElementType(),
-   N->getValueType(0).getVectorNumElements());
-  SDValue Ext = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, OutVT, V0, 
N->getOperand(1));
-  return DAG.getNode(ISD::TRUNCATE, dl, N->getValueType(0), Ext);
-}
-
 SDValue DAGTypeLegalizer::PromoteIntOp_CONCAT_VECTORS(SDNode *N) {
   SDLoc dl(N);
 


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
===
--- llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
@@ -368,7 +368,6 @@
   SDValue PromoteIntOp_BUILD_VECTOR(SDNode *N);
   SDValue PromoteIntOp_INSERT_VECTOR_ELT(SDNode *N, unsigned OpNo);
   SDValue PromoteIntOp_EXTRACT_VECTOR_ELT(SDNode *N);
-  SDValue PromoteIntOp_EXTRACT_SUBVECTOR(SDNode *N);
   SDValue PromoteIntOp_INSERT_SUBVECTOR(SDNode *N);
   SDValue PromoteIntOp_CONCAT_VECTORS(SDNode *N);
   SDValue PromoteIntOp_SCALAR_TO_VECTOR(SDNode *N);
Index: llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -1577,7 +1577,6 @@
   case ISD::UINT_TO_FP:   Res = PromoteIntOp_UINT_TO_FP(N); break;
   case ISD::STRICT_UINT_TO_FP:  Res = PromoteIntOp_STRICT_UINT_TO_FP(N); break;
   case ISD::ZERO_EXTEND:  Res = PromoteIntOp_ZERO_EXTEND(N); break;
-  case ISD::EXTRACT_SUBVECTOR: Res = PromoteIntOp_EXTRACT_SUBVECTOR(N); break;
   case ISD::INSERT_SUBVECTOR: Res = PromoteIntOp_INSERT_SUBVECTOR(N); break;
 
   case ISD::SHL:
@@ -5094,16 +5093,6 @@
   return DAG.getAnyExtOrTrunc(Ext, dl, N->getValueType(0));
 }
 
-SDValue DAGTypeLegalizer::PromoteIntOp_EXTRACT_SUBVECTOR(SDNode *N) {
-  SDLoc dl(N);
-  SDValue V0 = GetPromotedInteger(N->getOperand(0));
-  MVT InVT = V0.getValueType().getSimpleVT();
-  MVT OutVT = MVT::getVectorVT(InVT.getVectorElementType(),
-   N->getValueType(0).getVectorNumElements());
-  SDValue Ext = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, OutVT, V0, N->getOperand(1));
-  return DAG.getNode(ISD::TRUNCATE, dl, N->getValueType(0), Ext);
-}
-
 SDValue DAGTypeLegalizer::PromoteIntOp_CONCAT_VECTORS(SDNode *N) {
   SDLoc dl(N);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110226: [InstCombine] Update InstCombine to use poison instead of undef for shufflevector's placeholder (1/3)

2021-09-22 Thread Hyeongyu Kim via Phabricator via cfe-commits
hyeongyukim updated this revision to Diff 374213.
hyeongyukim added a comment.
Herald added subscribers: aheejin, sbc100.

Correct the wrong rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110226/new/

https://reviews.llvm.org/D110226

Files:
  clang/test/Headers/wasm.c
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/X86/x86-f16c-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-f16c.ll
  llvm/test/Transforms/InstCombine/cast.ll
  llvm/test/Transforms/InstCombine/shuffle-cast-dist.ll
  llvm/test/Transforms/InstCombine/shufflevec-bitcast-inseltpoison.ll
  llvm/test/Transforms/InstCombine/shufflevec-bitcast.ll
  llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
  llvm/test/Transforms/InstCombine/trunc.ll
  llvm/test/Transforms/InstCombine/vector-casts.ll

Index: llvm/test/Transforms/InstCombine/vector-casts.ll
===
--- llvm/test/Transforms/InstCombine/vector-casts.ll
+++ llvm/test/Transforms/InstCombine/vector-casts.ll
@@ -414,7 +414,7 @@
 define <4 x float> @sitofp_shuf(<4 x i32> %x) {
 ; CHECK-LABEL: @sitofp_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = sitofp <4 x i32> [[X:%.*]] to <4 x float>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> undef, <4 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x float> [[R]]
 ;
   %s = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> 
@@ -425,7 +425,7 @@
 define <3 x half> @uitofp_shuf(<3 x i16> %x) {
 ; CHECK-LABEL: @uitofp_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = uitofp <3 x i16> [[X:%.*]] to <3 x half>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <3 x half> [[TMP1]], <3 x half> undef, <3 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <3 x half> [[TMP1]], <3 x half> poison, <3 x i32> 
 ; CHECK-NEXT:ret <3 x half> [[R]]
 ;
   %s = shufflevector <3 x i16> %x, <3 x i16> poison, <3 x i32> 
@@ -436,7 +436,7 @@
 define <4 x i64> @fptosi_shuf(<4 x double> %x) {
 ; CHECK-LABEL: @fptosi_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = fptosi <4 x double> [[X:%.*]] to <4 x i64>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x i64> [[TMP1]], <4 x i64> undef, <4 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x i64> [[TMP1]], <4 x i64> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x i64> [[R]]
 ;
   %s = shufflevector <4 x double> %x, <4 x double> poison, <4 x i32> 
@@ -447,7 +447,7 @@
 define <2 x i32> @fptoui_shuf(<2 x float> %x) {
 ; CHECK-LABEL: @fptoui_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = fptoui <2 x float> [[X:%.*]] to <2 x i32>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <2 x i32> 
 ; CHECK-NEXT:ret <2 x i32> [[R]]
 ;
   %s = shufflevector <2 x float> %x, <2 x float> poison, <2 x i32> 
Index: llvm/test/Transforms/InstCombine/trunc.ll
===
--- llvm/test/Transforms/InstCombine/trunc.ll
+++ llvm/test/Transforms/InstCombine/trunc.ll
@@ -922,7 +922,7 @@
 define <4 x i8> @wide_splat1(<4 x i32> %x) {
 ; CHECK-LABEL: @wide_splat1(
 ; CHECK-NEXT:[[TMP1:%.*]] = trunc <4 x i32> [[X:%.*]] to <4 x i8>
-; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> undef, <4 x i32> 
+; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x i8> [[TRUNC]]
 ;
   %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> 
@@ -936,7 +936,7 @@
 define <3 x i31> @wide_splat2(<3 x i33> %x) {
 ; CHECK-LABEL: @wide_splat2(
 ; CHECK-NEXT:[[TMP1:%.*]] = trunc <3 x i33> [[X:%.*]] to <3 x i31>
-; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <3 x i31> [[TMP1]], <3 x i31> undef, <3 x i32> 
+; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <3 x i31> [[TMP1]], <3 x i31> poison, <3 x i32> 
 ; CHECK-NEXT:ret <3 x i31> [[TRUNC]]
 ;
   %shuf = shufflevector <3 x i33> %x, <3 x i33> undef, <3 x i32> 
Index: llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
===
--- llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
+++ llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
@@ -922,7 +922,7 @@
 define <4 x i8> @wide_splat1(<4 x i32> %x) {
 ; CHECK-LABEL: @wide_splat1(
 ; CHECK-NEXT:[[TMP1:%.*]] = trunc <4 x i32> [[X:%.*]] to <4 x i8>
-; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> undef, <4 x i32> 
+; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x i8> [[TRUNC]]
 ;
   %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> 
@@ -936,7 +936,7 @@
 define <3 x i31> @wide_splat2(<3 x i33> %x) {
 ; CHECK-LABEL: @wide_splat2(
 ; CHECK-NEXT:[[TMP1:%.*]] = trunc <3 x i3

[PATCH] D105014: added some example code for llvm::Expected

2021-09-22 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

> Out of interest, did you see 
> https://llvm.org/docs/ProgrammersManual.html#error-handling ? If not (and if 
> you find it helpful) then maybe we need to make that document more 
> discoverable. If that document is not helpful then we should improve it.

No I wasn't aware of the documentation page and just took a quick look. This 
looks quite useful. I wish I had known about that part when trying to use 
Expected.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105014/new/

https://reviews.llvm.org/D105014

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-09-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 374219.
kbobyrev added a comment.

Populate Inclusion.ID, add a test (failing for now).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108194/new/

https://reviews.llvm.org/D108194

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -131,6 +131,35 @@
   }
 }
 
+TEST(IncludeCleaner, GetUnusedHeaders) {
+  llvm::StringLiteral MainFile = R"cpp(
+#include "a.h"
+#include "b.h"
+#include "dir/c.h"
+#include "unused.h"
+void foo() {
+  a();
+  b();
+  c();
+})cpp";
+  // Build expected ast with symbols coming from headers.
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  TU.AdditionalFiles["foo.h"] = "void foo();";
+  TU.AdditionalFiles["a.h"] = "void a();";
+  TU.AdditionalFiles["b.h"] = "void b();";
+  TU.AdditionalFiles["dir/c.h"] = "void c();";
+  TU.AdditionalFiles["unused.h"] = "void unused();";
+  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.Code = MainFile.str();
+  ParsedAST AST = TU.build();
+  auto UnusedIncludes = AST.computeUnusedIncludes();
+  std::vector UnusedHeaders;
+  for (const auto &Include : UnusedIncludes) {
+UnusedHeaders.push_back(Include.Written);
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.h
===
--- clang-tools-extra/clangd/ParsedAST.h
+++ clang-tools-extra/clangd/ParsedAST.h
@@ -116,6 +116,8 @@
 return Resolver.get();
   }
 
+  std::vector computeUnusedIncludes();
+
 private:
   ParsedAST(llvm::StringRef Version,
 std::shared_ptr Preamble,
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,6 +18,7 @@
 #include "FeatureModule.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"
@@ -614,5 +615,35 @@
 return llvm::None;
   return llvm::StringRef(Preamble->Version);
 }
+
+std::vector ParsedAST::computeUnusedIncludes() {
+  const auto &SM = getSourceManager();
+
+  auto Refs = findReferencedLocations(*this);
+  auto ReferencedFileIDs = findReferencedFiles(Refs, SM);
+  llvm::DenseSet ReferencedFiles;
+  ReferencedFiles.reserve(ReferencedFileIDs.size());
+  for (FileID FID : ReferencedFileIDs) {
+const FileEntry *FE = SM.getFileEntryForID(FID);
+if (!FE) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;
+}
+const auto File = Includes.getFile(FE);
+if (!File) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;
+}
+ReferencedFiles.insert(*File);
+  }
+  auto MainFileIndex =
+  Includes.getFile(SM.getFileEntryForID(SM.getMainFileID()));
+  if (!MainFileIndex) {
+elog("Missing MainFile in the IncludeStructure");
+return {};
+  }
+  return getUnused(*MainFileIndex, Includes, ReferencedFiles, SM);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -25,6 +25,7 @@
 #include "ParsedAST.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseSet.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -46,6 +47,29 @@
 /// - err on the side of reporting all possible locations
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
+/// Retrieves IDs of all files containing SourceLocations from \p Locs.
+/// FIXME: Those locations could be within macro expansions and are resolved to
+/// their spelling/expansion locations.
+llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
+   const SourceManager &SM);
+
+inline llvm::DenseMap directlyReferencedFiles(
+const IncludeStructure::AbstractIncludeGraph &Graph,
+const llvm::DenseSet &Referenced,
+unsigned EntryPoint) {
+  llvm::DenseMap Result;
+  for (IncludeStructure::File Inclusion : Graph.lookup(EntryPoint))
+Result.try_emplace(Inclusion, Referenced.contains(Inclusion));
+  return Result;
+}
+
+/// Retrieves headers that are referenced from the main file (\p EntryPoint)
+/

[PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

2021-09-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D102107#3014759 , @JonChesterfield 
wrote:

> In D102107#3014743 , @pdhaliwal 
> wrote:
>
>> I got this after changing __kmpc_impl_malloc to return 0xdeadbeef. So, this 
>> confirms that missing malloc implementation is the root cause.
>>
>>> Memory access fault by GPU node-4 (Agent handle: 0x1bc5000) on address 
>>> 0xdeadb000. Reason: Page not present or supervisor privilege.
>
> Nice! In that case I think the way to go is to audit the (probably few) 
> places where kmpc_impl_malloc are called and add a check for whether the 
> return value is 0. With that in place we can reland this and get more 
> graceful failure (at a guess we should fall back to the host when gpu memory 
> is exhausted? or maybe just print a 'out of gpu heap memory' style message 
> and abort, don't know).

We should only fail to remove the __kmpc_shared_alloc with O0. Since we need 
__kmpc_shared_alloc for all non-trivial codes, they would always fail on 
AMDGPU. That said,
why is the shared memory stack not catching this. It's a 64 byte stack for the 
main thread and we are looking at at 24 byte allocation for 
`declare_mapper_target.cpp`.
Can you determine why first two conditionals in `__kmpc_alloc_shared` don't 
catch this and return proper memory?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102107/new/

https://reviews.llvm.org/D102107

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110252: Added note about Whatstyle and Unformat

2021-09-22 Thread Volker Weißmann via Phabricator via cfe-commits
Volker-Weissmann created this revision.
Volker-Weissmann added a reviewer: sdesmalen.
Volker-Weissmann requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I added a note about Whatstyle  and Unformat 
 in the docs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110252

Files:
  clang/docs/ClangFormatStyleOptions.rst


Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -88,6 +88,11 @@
 
   -style='{key1: value1, key2: value2, ...}'
 
+`Whatstyle `_ and `Unformat
+`_ can generate a .clang-format file
+from an existing codebase. Note that both of those tools are not officially
+supported and work on a best-effort basis.
+
 
 Disabling Formatting on a Piece of Code
 ===


Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -88,6 +88,11 @@
 
   -style='{key1: value1, key2: value2, ...}'
 
+`Whatstyle `_ and `Unformat
+`_ can generate a .clang-format file
+from an existing codebase. Note that both of those tools are not officially
+supported and work on a best-effort basis.
+
 
 Disabling Formatting on a Piece of Code
 ===
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110029: [OpenMP][Offloading] Use bitset to indicate execution mode instead of value

2021-09-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110029/new/

https://reviews.llvm.org/D110029

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e5aaf03 - [InstCombine] Update InstCombine to use poison instead of undef for shufflevector's placeholder (1/3)

2021-09-22 Thread hyeongyu kim via cfe-commits

Author: hyeongyu kim
Date: 2021-09-22T23:18:51+09:00
New Revision: e5aaf0332670577cc19ac67b07b10261da6fc1e1

URL: 
https://github.com/llvm/llvm-project/commit/e5aaf0332670577cc19ac67b07b10261da6fc1e1
DIFF: 
https://github.com/llvm/llvm-project/commit/e5aaf0332670577cc19ac67b07b10261da6fc1e1.diff

LOG: [InstCombine] Update InstCombine to use poison instead of undef for 
shufflevector's placeholder (1/3)

This patch is for fixing potential shufflevector-related bugs like D93818.
As D93818, this patch change shufflevector's default placeholder to poison.
To reduce risk, it was divided into several patches, and this patch is for 
InstCombineCasts.

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D110226

Added: 


Modified: 
clang/test/Headers/wasm.c
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/X86/x86-f16c-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/x86-f16c.ll
llvm/test/Transforms/InstCombine/cast.ll
llvm/test/Transforms/InstCombine/shuffle-cast-dist.ll
llvm/test/Transforms/InstCombine/shufflevec-bitcast-inseltpoison.ll
llvm/test/Transforms/InstCombine/shufflevec-bitcast.ll
llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
llvm/test/Transforms/InstCombine/trunc.ll
llvm/test/Transforms/InstCombine/vector-casts.ll

Removed: 




diff  --git a/clang/test/Headers/wasm.c b/clang/test/Headers/wasm.c
index ce24f4269ab92..f4e4e9dad47aa 100644
--- a/clang/test/Headers/wasm.c
+++ b/clang/test/Headers/wasm.c
@@ -825,7 +825,7 @@ v128_t test_u64x2_replace_lane(v128_t a, uint64_t b) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <4 x float> undef, float 
[[A:%.*]], i32 0
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x float> [[VECINIT_I]] to <4 x i32>
-// CHECK-NEXT:[[TMP1:%.*]] = shufflevector <4 x i32> [[TMP0]], <4 x i32> 
undef, <4 x i32> zeroinitializer
+// CHECK-NEXT:[[TMP1:%.*]] = shufflevector <4 x i32> [[TMP0]], <4 x i32> 
poison, <4 x i32> zeroinitializer
 // CHECK-NEXT:ret <4 x i32> [[TMP1]]
 //
 v128_t test_f32x4_splat(float a) {
@@ -1598,7 +1598,7 @@ v128_t test_i8x16_popcnt(v128_t a) {
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <16 x i8>
 // CHECK-NEXT:[[TMP1:%.*]] = trunc i32 [[B:%.*]] to i8
 // CHECK-NEXT:[[TMP2:%.*]] = insertelement <16 x i8> undef, i8 [[TMP1]], 
i32 0
-// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP2]], <16 x 
i8> undef, <16 x i32> zeroinitializer
+// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP2]], <16 x 
i8> poison, <16 x i32> zeroinitializer
 // CHECK-NEXT:[[SHL_I:%.*]] = shl <16 x i8> [[TMP0]], [[SH_PROM_I]]
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[SHL_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP3]]
@@ -1612,7 +1612,7 @@ v128_t test_i8x16_shl(v128_t a, uint32_t b) {
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <16 x i8>
 // CHECK-NEXT:[[TMP1:%.*]] = trunc i32 [[B:%.*]] to i8
 // CHECK-NEXT:[[TMP2:%.*]] = insertelement <16 x i8> undef, i8 [[TMP1]], 
i32 0
-// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP2]], <16 x 
i8> undef, <16 x i32> zeroinitializer
+// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP2]], <16 x 
i8> poison, <16 x i32> zeroinitializer
 // CHECK-NEXT:[[SHR_I:%.*]] = ashr <16 x i8> [[TMP0]], [[SH_PROM_I]]
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[SHR_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP3]]
@@ -1626,7 +1626,7 @@ v128_t test_i8x16_shr(v128_t a, uint32_t b) {
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <16 x i8>
 // CHECK-NEXT:[[TMP1:%.*]] = trunc i32 [[B:%.*]] to i8
 // CHECK-NEXT:[[TMP2:%.*]] = insertelement <16 x i8> undef, i8 [[TMP1]], 
i32 0
-// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP2]], <16 x 
i8> undef, <16 x i32> zeroinitializer
+// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <16 x i8> [[TMP2]], <16 x 
i8> poison, <16 x i32> zeroinitializer
 // CHECK-NEXT:[[SHR_I:%.*]] = lshr <16 x i8> [[TMP0]], [[SH_PROM_I]]
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[SHR_I]] to <4 x i32>
 // CHECK-NEXT:ret <4 x i32> [[TMP3]]
@@ -1819,7 +1819,7 @@ uint32_t test_i16x8_bitmask(v128_t a) {
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <8 x i16>
 // CHECK-NEXT:[[TMP1:%.*]] = trunc i32 [[B:%.*]] to i16
 // CHECK-NEXT:[[TMP2:%.*]] = insertelement <8 x i16> undef, i16 [[TMP1]], 
i32 0
-// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <8 x i16> [[TMP2]], <8 x 
i16> undef, <8 x i32> zeroinitializer
+// CHECK-NEXT:[[SH_PROM_I:%.*]] = shufflevector <8 x i16> [[TMP2]], <8 x 
i16> poison, <8 x i32> zeroinitializer
 // CHECK-NEXT:[[SHL_I:%.*]] = shl <8 x i16> [[TMP0]], [[SH_PROM_I]]
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast <8 x i16> [[SHL_

[PATCH] D110226: [InstCombine] Update InstCombine to use poison instead of undef for shufflevector's placeholder (1/3)

2021-09-22 Thread Hyeongyu Kim via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe5aaf0332670: [InstCombine] Update InstCombine to use poison 
instead of undef for… (authored by hyeongyukim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110226/new/

https://reviews.llvm.org/D110226

Files:
  clang/test/Headers/wasm.c
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/X86/x86-f16c-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-f16c.ll
  llvm/test/Transforms/InstCombine/cast.ll
  llvm/test/Transforms/InstCombine/shuffle-cast-dist.ll
  llvm/test/Transforms/InstCombine/shufflevec-bitcast-inseltpoison.ll
  llvm/test/Transforms/InstCombine/shufflevec-bitcast.ll
  llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
  llvm/test/Transforms/InstCombine/trunc.ll
  llvm/test/Transforms/InstCombine/vector-casts.ll

Index: llvm/test/Transforms/InstCombine/vector-casts.ll
===
--- llvm/test/Transforms/InstCombine/vector-casts.ll
+++ llvm/test/Transforms/InstCombine/vector-casts.ll
@@ -414,7 +414,7 @@
 define <4 x float> @sitofp_shuf(<4 x i32> %x) {
 ; CHECK-LABEL: @sitofp_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = sitofp <4 x i32> [[X:%.*]] to <4 x float>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> undef, <4 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x float> [[R]]
 ;
   %s = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> 
@@ -425,7 +425,7 @@
 define <3 x half> @uitofp_shuf(<3 x i16> %x) {
 ; CHECK-LABEL: @uitofp_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = uitofp <3 x i16> [[X:%.*]] to <3 x half>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <3 x half> [[TMP1]], <3 x half> undef, <3 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <3 x half> [[TMP1]], <3 x half> poison, <3 x i32> 
 ; CHECK-NEXT:ret <3 x half> [[R]]
 ;
   %s = shufflevector <3 x i16> %x, <3 x i16> poison, <3 x i32> 
@@ -436,7 +436,7 @@
 define <4 x i64> @fptosi_shuf(<4 x double> %x) {
 ; CHECK-LABEL: @fptosi_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = fptosi <4 x double> [[X:%.*]] to <4 x i64>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x i64> [[TMP1]], <4 x i64> undef, <4 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <4 x i64> [[TMP1]], <4 x i64> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x i64> [[R]]
 ;
   %s = shufflevector <4 x double> %x, <4 x double> poison, <4 x i32> 
@@ -447,7 +447,7 @@
 define <2 x i32> @fptoui_shuf(<2 x float> %x) {
 ; CHECK-LABEL: @fptoui_shuf(
 ; CHECK-NEXT:[[TMP1:%.*]] = fptoui <2 x float> [[X:%.*]] to <2 x i32>
-; CHECK-NEXT:[[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> 
+; CHECK-NEXT:[[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <2 x i32> 
 ; CHECK-NEXT:ret <2 x i32> [[R]]
 ;
   %s = shufflevector <2 x float> %x, <2 x float> poison, <2 x i32> 
Index: llvm/test/Transforms/InstCombine/trunc.ll
===
--- llvm/test/Transforms/InstCombine/trunc.ll
+++ llvm/test/Transforms/InstCombine/trunc.ll
@@ -922,7 +922,7 @@
 define <4 x i8> @wide_splat1(<4 x i32> %x) {
 ; CHECK-LABEL: @wide_splat1(
 ; CHECK-NEXT:[[TMP1:%.*]] = trunc <4 x i32> [[X:%.*]] to <4 x i8>
-; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> undef, <4 x i32> 
+; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x i8> [[TRUNC]]
 ;
   %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> 
@@ -936,7 +936,7 @@
 define <3 x i31> @wide_splat2(<3 x i33> %x) {
 ; CHECK-LABEL: @wide_splat2(
 ; CHECK-NEXT:[[TMP1:%.*]] = trunc <3 x i33> [[X:%.*]] to <3 x i31>
-; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <3 x i31> [[TMP1]], <3 x i31> undef, <3 x i32> 
+; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <3 x i31> [[TMP1]], <3 x i31> poison, <3 x i32> 
 ; CHECK-NEXT:ret <3 x i31> [[TRUNC]]
 ;
   %shuf = shufflevector <3 x i33> %x, <3 x i33> undef, <3 x i32> 
Index: llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
===
--- llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
+++ llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
@@ -922,7 +922,7 @@
 define <4 x i8> @wide_splat1(<4 x i32> %x) {
 ; CHECK-LABEL: @wide_splat1(
 ; CHECK-NEXT:[[TMP1:%.*]] = trunc <4 x i32> [[X:%.*]] to <4 x i8>
-; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> undef, <4 x i32> 
+; CHECK-NEXT:[[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x i8> [[TRUNC]]
 ;
   %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> 
@@ -936,7 +936,7 @@
 define <3 x 

[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-09-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 374226.
kbobyrev added a comment.

Make sure FileEntry* is not nullptr


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108194/new/

https://reviews.llvm.org/D108194

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -131,6 +131,35 @@
   }
 }
 
+TEST(IncludeCleaner, GetUnusedHeaders) {
+  llvm::StringLiteral MainFile = R"cpp(
+#include "a.h"
+#include "b.h"
+#include "dir/c.h"
+#include "unused.h"
+void foo() {
+  a();
+  b();
+  c();
+})cpp";
+  // Build expected ast with symbols coming from headers.
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  TU.AdditionalFiles["foo.h"] = "void foo();";
+  TU.AdditionalFiles["a.h"] = "void a();";
+  TU.AdditionalFiles["b.h"] = "void b();";
+  TU.AdditionalFiles["dir/c.h"] = "void c();";
+  TU.AdditionalFiles["unused.h"] = "void unused();";
+  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.Code = MainFile.str();
+  ParsedAST AST = TU.build();
+  auto UnusedIncludes = AST.computeUnusedIncludes();
+  std::vector UnusedHeaders;
+  for (const auto &Include : UnusedIncludes) {
+UnusedHeaders.push_back(Include.Written);
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.h
===
--- clang-tools-extra/clangd/ParsedAST.h
+++ clang-tools-extra/clangd/ParsedAST.h
@@ -116,6 +116,8 @@
 return Resolver.get();
   }
 
+  std::vector computeUnusedIncludes();
+
 private:
   ParsedAST(llvm::StringRef Version,
 std::shared_ptr Preamble,
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,6 +18,7 @@
 #include "FeatureModule.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"
@@ -614,5 +615,35 @@
 return llvm::None;
   return llvm::StringRef(Preamble->Version);
 }
+
+std::vector ParsedAST::computeUnusedIncludes() {
+  const auto &SM = getSourceManager();
+
+  auto Refs = findReferencedLocations(*this);
+  auto ReferencedFileIDs = findReferencedFiles(Refs, SM);
+  llvm::DenseSet ReferencedFiles;
+  ReferencedFiles.reserve(ReferencedFileIDs.size());
+  for (FileID FID : ReferencedFileIDs) {
+const FileEntry *FE = SM.getFileEntryForID(FID);
+if (!FE) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;
+}
+const auto File = Includes.getFile(FE);
+if (!File) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;
+}
+ReferencedFiles.insert(*File);
+  }
+  auto MainFileIndex =
+  Includes.getFile(SM.getFileEntryForID(SM.getMainFileID()));
+  if (!MainFileIndex) {
+elog("Missing MainFile in the IncludeStructure");
+return {};
+  }
+  return getUnused(*MainFileIndex, Includes, ReferencedFiles, SM);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -25,6 +25,7 @@
 #include "ParsedAST.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseSet.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -46,6 +47,29 @@
 /// - err on the side of reporting all possible locations
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
+/// Retrieves IDs of all files containing SourceLocations from \p Locs.
+/// FIXME: Those locations could be within macro expansions and are resolved to
+/// their spelling/expansion locations.
+llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
+   const SourceManager &SM);
+
+inline llvm::DenseMap directlyReferencedFiles(
+const IncludeStructure::AbstractIncludeGraph &Graph,
+const llvm::DenseSet &Referenced,
+unsigned EntryPoint) {
+  llvm::DenseMap Result;
+  for (IncludeStructure::File Inclusion : Graph.lookup(EntryPoint))
+Result.try_emplace(Inclusion, Referenced.contains(Inclusion));
+  return Result;
+}
+
+/// Retrieves headers that are referenced from the main file (\p EntryPoint)
+/// but not used.

[PATCH] D110255: Change error for storage-class to mean linkage, fix lang-linkage diag

2021-09-22 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added a reviewer: aaron.ballman.
erichkeane requested review of this revision.

Allow multiversioning declarations to match when the actual formal
linkage matches, not just when the storage class is identical.
Additionally, change the ambiguous 'linkage' mismatch to be more
specific and say 'language linkage'.


https://reviews.llvm.org/D110255

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/attr-cpuspecific.cpp
  clang/test/SemaCXX/attr-target-mv.cpp

Index: clang/test/SemaCXX/attr-target-mv.cpp
===
--- clang/test/SemaCXX/attr-target-mv.cpp
+++ clang/test/SemaCXX/attr-target-mv.cpp
@@ -27,17 +27,26 @@
 
 static int __attribute__((target("sse4.2"))) bar(void) { return 0; }
 static int __attribute__((target("arch=sandybridge"))) bar(void);
-//expected-error@+1 {{multiversioned function declaration has a different storage class}}
+//expected-error@+1 {{multiversioned function declaration has a different linkage}}
 int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;}
 static int __attribute__((target("default"))) bar(void) { return 2; }
 
 int __attribute__((target("sse4.2"))) bar2(void) { return 0; }
-//expected-error@+1 {{multiversioned function declaration has a different storage class}}
+//expected-error@+1 {{multiversioned function declaration has a different linkage}}
 static int __attribute__((target("arch=sandybridge"))) bar2(void);
 int __attribute__((target("arch=ivybridge"))) bar2(void) {return 1;}
 int __attribute__((target("default"))) bar2(void) { return 2; }
 
 
+// no diagnostic, since this doesn't change the linkage.
+int __attribute__((target("sse4.2"))) bar3(void) { return 0; }
+extern int __attribute__((target("arch=sandybridge"))) bar2(void);
+
+namespace {
+int __attribute__((target("sse4.2"))) bar4(void) { return 0; }
+static int __attribute__((target("arch=sandybridge"))) bar4(void);
+}
+
 inline int __attribute__((target("sse4.2"))) baz(void) { return 0; }
 inline int __attribute__((target("arch=sandybridge"))) baz(void);
 //expected-error@+1 {{multiversioned function declaration has a different inline specification}}
@@ -102,7 +111,7 @@
 extern "C" {
 int __attribute__((target("sse4.2"))) diff_mangle(void) { return 0; }
 }
-//expected-error@+1 {{multiversioned function declaration has a different linkage}}
+//expected-error@+1 {{multiversioned function declaration has a different language linkage}}
 int __attribute__((target("arch=sandybridge"))) diff_mangle(void) { return 0; }
 
 // expected-error@+1 {{multiversioned functions do not yet support deduced return types}}
Index: clang/test/SemaCXX/attr-cpuspecific.cpp
===
--- clang/test/SemaCXX/attr-cpuspecific.cpp
+++ clang/test/SemaCXX/attr-cpuspecific.cpp
@@ -34,9 +34,19 @@
 constexpr int __attribute__((cpu_specific(ivybridge))) foo2(void);
 
 static int __attribute__((cpu_specific(sandybridge))) bar(void);
-//expected-error@+1 {{multiversioned function declaration has a different storage class}}
+//expected-error@+1 {{multiversioned function declaration has a different linkage}}
 int __attribute__((cpu_dispatch(ivybridge))) bar(void) {}
 
+// OK
+extern int __attribute__((cpu_specific(sandybridge))) bar2(void);
+int __attribute__((cpu_dispatch(ivybridge))) bar2(void) {}
+
+namespace {
+int __attribute__((cpu_specific(sandybridge))) bar3(void);
+static int __attribute__((cpu_dispatch(ivybridge))) bar3(void) {}
+}
+
+
 inline int __attribute__((cpu_specific(sandybridge))) baz(void);
 //expected-error@+1 {{multiversioned function declaration has a different inline specification}}
 int __attribute__((cpu_specific(ivybridge))) baz(void) {return 1;}
@@ -74,7 +84,7 @@
 extern "C" {
 int __attribute__((cpu_specific(atom))) diff_mangle(void) { return 0; }
 }
-//expected-error@+1 {{multiversioned function declaration has a different linkage}}
+//expected-error@+1 {{multiversioned function declaration has a different language linkage}}
 int __attribute__((cpu_specific(sandybridge))) diff_mangle(void) { return 0; }
 
 __attribute__((cpu_specific(atom))) void DiffDecl();
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -10320,8 +10320,8 @@
 ReturnType = 1,
 ConstexprSpec = 2,
 InlineSpec = 3,
-StorageClass = 4,
-Linkage = 5,
+Linkage = 4,
+LanguageLinkage = 5,
   };
 
   if (NoProtoDiagID.getDiagID() != 0 && OldFD &&
@@ -10395,11 +10395,11 @@
 if (OldFD->isInlineSpecified() != NewFD->isInlineSpecified())
   return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << InlineSpec;
 
-if (OldFD->getStorageClass() != NewFD->getStorageClass())
-  return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << StorageClass;
+if (OldFD->getFormalLinkage(

[PATCH] D110129: [DebugInfo] Support typedef with btf_tag attributes

2021-09-22 Thread Paul Robinson via Phabricator via cfe-commits
probinson accepted this revision.
probinson added a comment.
This revision is now accepted and ready to land.

In D110129#3013946 , @yonghong-song 
wrote:

> - The only thing left is for llvm/test/DebugInfo/X86/attr-btf_tag-typedef.ll 
> for which I didn't use `%itanium_abi_triple` as it seems only available for 
> %clang ... and not available for llc.

Oh right, that's just a clang thing.  An explicit triple is fine.
LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110129/new/

https://reviews.llvm.org/D110129

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110257: [CFE][Codegen] Do not the break contiguity of static allocas.

2021-09-22 Thread Mahesha S via Phabricator via cfe-commits
hsmhsm created this revision.
hsmhsm added reviewers: arsenm, rampitec, jdoerfert, lebedev.ri, nhaehnle, 
rjmccall, yaxunl, AndreyChurbanov.
Herald added a subscriber: jvesely.
hsmhsm requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, wdng.
Herald added a project: clang.

Do not break the contiguity of static allocas by inserting addressspace
casts in between static allocas, otherwise, inliner's attempt to move
static allocas from callee to caller will fail, and which in turn will
have serious side effects on code transformation/optimzation.

Make sure that all addressspace casts of static allocas are inserted just
after all static allocas.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110257

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGenCUDA/builtins-amdgcn.cu
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
  clang/test/CodeGenCXX/vla.cpp
  clang/test/CodeGenSYCL/address-space-deduction.cpp
  clang/test/OpenMP/amdgcn_target_init_temp_alloca.cpp
  clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/nvptx_allocate_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/parallel_if_codegen.cpp
  clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
  clang/test/OpenMP/parallel_master_taskloop_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_codegen.cpp
  clang/test/OpenMP/target_codegen_global_capture.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/task_codegen.c
  clang/test/OpenMP/teams_distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/vla_crash.c

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110258: [AArch64][Clang] Always add -tune-cpu argument to -cc1 driver

2021-09-22 Thread David Sherwood via Phabricator via cfe-commits
david-arm created this revision.
david-arm added reviewers: sdesmalen, c-rhodes, peterwaller-arm, dmgreen.
Herald added a subscriber: kristof.beyls.
david-arm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch ensures that we always tune for a given CPU on AArch64
targets. If the user explicitly specified the CPU to tune for we
use that, otherwise if the "-mcpu=" flag was not set we tune for
a generic CPU.

Tests added here:

  clang/test/Driver/aarch64-mtune.c


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110258

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aarch64-mtune.c


Index: clang/test/Driver/aarch64-mtune.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-mtune.c
@@ -0,0 +1,42 @@
+// Ensure we support the -mtune flag.
+
+// Default mtune should be generic.
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=notune
+// notune: "-tune-cpu" "generic"
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -mtune=generic 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=generic
+// generic: "-tune-cpu" "generic"
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -mtune=neoverse-n1 
2>&1 \
+// RUN:   | FileCheck %s -check-prefix=neoverse-n1
+// neoverse-n1: "-tune-cpu" "neoverse-n1"
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -mtune=thunderx2t99 
2>&1 \
+// RUN:   | FileCheck %s -check-prefix=thunderx2t99
+// thunderx2t99: "-tune-cpu" "thunderx2t99"
+
+// Check interaction between march and mtune.
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -march=armv8-a 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=marcharmv8a
+// marcharmv8a: "-target-cpu" "generic"
+// marcharmv8a: "-tune-cpu" "generic"
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -march=armv8-a 
-mtune=cortex-a75 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=marcharmv8a-a75
+// marcharmv8a-a75: "-target-cpu" "generic"
+// marcharmv8a-a75: "-tune-cpu" "cortex-a75"
+
+// Check interaction between mcpu and mtune.
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -mcpu=thunderx 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=mcputhunderx
+// mcputhunderx: "-target-cpu" "thunderx"
+// mcputhunderx-NOT: "-tune-cpu"
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -mcpu=cortex-a75 
-mtune=cortex-a57 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=mcpua75-mtunea57
+// mcpua75-mtunea57: "-target-cpu" "cortex-a75"
+// mcpua75-mtunea57: "-tune-cpu" "cortex-a57"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -1837,6 +1837,27 @@
   }
 
   AddAAPCSVolatileBitfieldArgs(Args, CmdArgs);
+
+  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
+StringRef Name = A->getValue();
+
+std::string TuneCPU;
+if (Name == "native") {
+  Name = llvm::sys::getHostCPUName();
+  if (!Name.empty())
+TuneCPU = std::string(Name);
+  else
+TuneCPU = "generic";
+} else
+  TuneCPU = std::string(Name);
+
+CmdArgs.push_back("-tune-cpu");
+CmdArgs.push_back(Args.MakeArgString(TuneCPU));
+  }
+  else if (!Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+CmdArgs.push_back("generic");
+  }
 }
 
 void Clang::AddMIPSTargetArgs(const ArgList &Args,


Index: clang/test/Driver/aarch64-mtune.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-mtune.c
@@ -0,0 +1,42 @@
+// Ensure we support the -mtune flag.
+
+// Default mtune should be generic.
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=notune
+// notune: "-tune-cpu" "generic"
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -mtune=generic 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=generic
+// generic: "-tune-cpu" "generic"
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -mtune=neoverse-n1 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=neoverse-n1
+// neoverse-n1: "-tune-cpu" "neoverse-n1"
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -mtune=thunderx2t99 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=thunderx2t99
+// thunderx2t99: "-tune-cpu" "thunderx2t99"
+
+// Check interaction between march and mtune.
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -march=armv8-a 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=marcharmv8a
+// marcharmv8a: "-target-cpu" "generic"
+// marcharmv8a: "-tune-cpu" "generic"
+
+// RUN: %clang -target aarch64-unknown-unknown -c -### %s -march=armv8-a -mtune=cortex-a75 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=marcharmv8a-a75
+// marcharmv8a-a75: "-target

[PATCH] D108370: [clang-tidy] Fix wrong FixIt about union in cppcoreguidelines-pro-type-member-init

2021-09-22 Thread gehry via Phabricator via cfe-commits
Sockke added a comment.

Hi, Could you please take some time to review this diff again? @aaron.ballman


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108370/new/

https://reviews.llvm.org/D108370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110258: [AArch64][Clang] Always add -tune-cpu argument to -cc1 driver

2021-09-22 Thread Dave Green via Phabricator via cfe-commits
dmgreen added a comment.

My understanding is that -mtune doesn't work sensibly for Arm backends. The 
tuning features and architecture features are not separated out at the 
subtarget level.

Is the idea to teach people to start using it? That sounds dangerous without 
fixing the issues with it first. Or is this to make sure it's set to something?

(Fixing it properly would be a really good thing.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110258/new/

https://reviews.llvm.org/D110258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110142: [clang][Driver] Correct runtime path for Arm hard float targets

2021-09-22 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

So would you expect to see libraries in 
`lib/clang/14.0.0/lib/armv8l-unknown-linux-gnueabihf` and not change clang's 
logic?

The output dir is worked out in cmake by `get_compiler_rt_output_dir` which 
calls `get_compiler_rt_target` which takes the arch given and adds it to the 
suffix of the triple. So it adds "armhf" to "-unknown-linux-gnueabihf". (which 
is why the "hf" is duplicated)

A few places look for "armhf" specifically as the arch, so it's not as easy as 
just not converting "armv8l" into that. But if we can confirm what the goal is 
here then I can find out how to properly handle those.

You can just bodge `get_compiler_rt_target` to just use the target triple but 
of course that breaks any build for multiple targets. If I'm reading 
`test_targets` correctly, it builds a list of architectures to build as opposed 
to finding the first working one.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110142/new/

https://reviews.llvm.org/D110142

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110258: [AArch64][Clang] Always add -tune-cpu argument to -cc1 driver

2021-09-22 Thread David Sherwood via Phabricator via cfe-commits
david-arm added a comment.

Hi @dmgreen, this is specifically being introduced for SVE targets to help make 
informed cost model decisions regarding the value of vscale - see D110259 
. We thought that using the "tune-cpu" 
attribute might be a good way of doing this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110258/new/

https://reviews.llvm.org/D110258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ca999f7 - [OpenMP][Offloading] Use bitset to indicate execution mode instead of value

2021-09-22 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2021-09-22T11:40:52-04:00
New Revision: ca999f719117f916b333a794cc8c59984ae40dd2

URL: 
https://github.com/llvm/llvm-project/commit/ca999f719117f916b333a794cc8c59984ae40dd2
DIFF: 
https://github.com/llvm/llvm-project/commit/ca999f719117f916b333a794cc8c59984ae40dd2.diff

LOG: [OpenMP][Offloading] Use bitset to indicate execution mode instead of value

The execution mode of a kernel is stored in a global variable, whose value 
means:
- 0 - SPMD mode
- 1 - indicates generic mode
- 2 - SPMD mode execution with generic mode semantics

We are going to add support for SIMD execution mode. It will be come with 
another
execution mode, such as SIMD-generic mode. As a result, this value-based 
indicator
is not flexible.

This patch changes to bitset based solution to encode execution mode. Each
position is:
[0] - generic mode
[1] - SPMD mode
[2] - SIMD mode (will be added later)

In this way, `0x1` is generic mode, `0x2` is SPMD mode, and `0x3` is SPMD mode
execution with generic mode semantics. In the future after we add the support 
for
SIMD mode, `0b1xx` will be in SIMD mode.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D110029

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
clang/test/OpenMP/nvptx_target_simd_codegen.cpp
clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll
llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll
llvm/test/Transforms/OpenMP/spmdization.ll
llvm/test/Transforms/OpenMP/spmdization_assumes.ll
llvm/test/Transforms/OpenMP/spmdization_guarding.ll
openmp/libomptarget/plugins/cuda/CMakeLists.txt
openmp/libomptarget/plugins/cuda/src/rtl.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 9d28b42dc8e3f..16f1b0b00b095 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1112,11 +1112,12 @@ void CGOpenMPRuntimeGPU::emitSPMDKernel(const 
OMPExecutableDirective &D,
 // warps participate in parallel work.
 static void setPropertyExecutionMode(CodeGenModule &CGM, StringRef Name,
  bool Mode) {
-  auto *GVMode =
-  new llvm::GlobalVariable(CGM.getModule(), CGM.Int8Ty, 
/*isConstant=*/true,
-   llvm::GlobalValue::WeakAnyLinkage,
-   llvm::ConstantInt::get(CGM.Int8Ty, Mode ? 0 : 
1),
-   Twine(Name, "_exec_mode"));
+  auto *GVMode = new llvm::GlobalVariable(
+  CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true,
+  llvm::GlobalValue::WeakAnyLinkage,
+  llvm::ConstantInt::get(CGM.Int8Ty, Mode ? OMP_TGT_EXEC_MODE_SPMD
+  : OMP_TGT_EXEC_MODE_GENERIC),
+  Twine(Name, "_exec_mode"));
   CGM.addCompilerUsedGlobal(GVMode);
 }
 

diff  --git a/clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp 
b/clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
index 8eaff644888e2..71d8d7757214d 100644
--- a/clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
+++ b/clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
@@ -16,9 +16,9 @@
 #define HEADER
 
 // Check that the execution mode of all 3 target regions on the gpu is set to 
SPMD Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l29}}_exec_mode = weak constant i8 0
-// CHECK-DAG: {{@__omp_offloading_.+l33}}_exec_mode = weak constant i8 0
-// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l29}}_exec_mode = weak constant i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l33}}_exec_mode = weak constant i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak constant i8 2
 
 template
 tx ftemplate(int n) {

diff  --git a/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp 
b/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
index 43a17c9cece51..fdba4e95b329b 100644
--- a/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
+++ b/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
@@ -12,9 +12,9 @@
 // CHECK-DAG: [[TRANSFER_STORAGE:@.+]] = weak 
addrspace([[SHARED_ADDRSPACE:[0-9]+]]) global [32 x i32]
 
 // Check that the execution mode of all 3 target regions is set to Spmd Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l27}}_exec_mode = weak constant i8 0
-// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak constant i8 0
-// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l27}}_ex

[PATCH] D110029: [OpenMP][Offloading] Use bitset to indicate execution mode instead of value

2021-09-22 Thread Shilei Tian via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGca999f719117: [OpenMP][Offloading] Use bitset to indicate 
execution mode instead of value (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110029/new/

https://reviews.llvm.org/D110029

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll
  llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll
  llvm/test/Transforms/OpenMP/spmdization.ll
  llvm/test/Transforms/OpenMP/spmdization_assumes.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  openmp/libomptarget/plugins/cuda/CMakeLists.txt
  openmp/libomptarget/plugins/cuda/src/rtl.cpp

Index: openmp/libomptarget/plugins/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -28,6 +28,8 @@
 
 #include "MemoryManager.h"
 
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+
 // Utility for retrieving and printing CUDA error string.
 #ifdef OMPTARGET_DEBUG
 #define CUDA_ERR_STRING(err)   \
@@ -71,28 +73,17 @@
   std::vector<__tgt_offload_entry> Entries;
 };
 
-enum ExecutionModeType {
-  SPMD, // constructors, destructors,
-// combined constructs (`teams distribute parallel for [simd]`)
-  GENERIC,  // everything else
-  SPMD_GENERIC, // Generic kernel with SPMD execution
-  NONE
-};
-
 /// Use a single entity to encode a kernel and a set of flags.
 struct KernelTy {
   CUfunction Func;
 
   // execution mode of kernel
-  // 0 - SPMD mode (without master warp)
-  // 1 - Generic mode (with master warp)
-  // 2 - SPMD mode execution with Generic mode semantics.
-  int8_t ExecutionMode;
+  llvm::omp::OMPTgtExecModeFlags ExecutionMode;
 
   /// Maximal number of threads per block for this kernel.
   int MaxThreadsPerBlock = 0;
 
-  KernelTy(CUfunction _Func, int8_t _ExecutionMode)
+  KernelTy(CUfunction _Func, llvm::omp::OMPTgtExecModeFlags _ExecutionMode)
   : Func(_Func), ExecutionMode(_ExecutionMode) {}
 };
 
@@ -867,7 +858,7 @@
  DPxPTR(E - HostBegin), E->name, DPxPTR(Func));
 
   // default value GENERIC (in case symbol is missing from cubin file)
-  int8_t ExecModeVal = ExecutionModeType::GENERIC;
+  llvm::omp::OMPTgtExecModeFlags ExecModeVal;
   std::string ExecModeNameStr(E->name);
   ExecModeNameStr += "_exec_mode";
   const char *ExecModeName = ExecModeNameStr.c_str();
@@ -876,9 +867,9 @@
   size_t CUSize;
   Err = cuModuleGetGlobal(&ExecModePtr, &CUSize, Module, ExecModeName);
   if (Err == CUDA_SUCCESS) {
-if (CUSize != sizeof(int8_t)) {
+if (CUSize != sizeof(llvm::omp::OMPTgtExecModeFlags)) {
   DP("Loading global exec_mode '%s' - size mismatch (%zd != %zd)\n",
- ExecModeName, CUSize, sizeof(int8_t));
+ ExecModeName, CUSize, sizeof(llvm::omp::OMPTgtExecModeFlags));
   return nullptr;
 }
 
@@ -890,12 +881,6 @@
   CUDA_ERR_STRING(Err);
   return nullptr;
 }
-
-if (ExecModeVal < 0 || ExecModeVal > 2) {
-  DP("Error wrong exec_mode value specified in cubin file: %d\n",
- ExecModeVal);
-  return nullptr;
-}
   } else {
 DP("Loading global exec_mode '%s' - symbol missing, using default "
"value GENERIC (1)\n",
@@ -1098,12 +1083,19 @@
 
 KernelTy *KernelInfo = reinterpret_cast(TgtEntryPtr);
 
+const bool IsSPMDGenericMode =
+KernelInfo->ExecutionMode == llvm::omp::OMP_TGT_EXEC_MODE_GENERIC_SPMD;
+const bool IsSPMDMode =
+KernelInfo->ExecutionMode == llvm::omp::OMP_TGT_EXEC_MODE_SPMD;
+const bool IsGenericMode =
+KernelInfo->ExecutionMode == llvm::omp::OMP_TGT_EXEC_MODE_GENERIC;
+
 int CudaThreadsPerBlock;
 if (ThreadLimit > 0) {
   DP("Setting CUDA threads per block to requested %d\n", ThreadLimit);
   CudaThreadsPerBlock = ThreadLimit;
   // Add master warp if necessary
-  if (KernelInfo->ExecutionMode == GENERIC) {
+  if (IsGenericMode) {
 DP("Adding master warp: +%d threads\n", DeviceData[DeviceId].WarpSize);
 CudaThreadsPerBlock += DeviceData[DeviceId].WarpSize;
   }
@@ -1136,13 +1128,21 @@
 unsigned int CudaBlocksPerGrid;
 if (TeamNum <= 0) {
   if (LoopTripCount > 0 && EnvNumTeams < 0) {
-if (KernelInfo->ExecutionMode == SPM

[PATCH] D110230: [InstCombine] Update InstCombine to use poison instead of undef for shufflevector's placeholder (3/3)

2021-09-22 Thread Hyeongyu Kim via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG98e96663f6a7: [InstCombine] Update InstCombine to use poison 
instead of undef for… (authored by hyeongyukim).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D110230?vs=374192&id=374249#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110230/new/

https://reviews.llvm.org/D110230

Files:
  clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
  clang/test/CodeGen/aarch64-neon-dot-product.c
  clang/test/CodeGen/arm-neon-dot-product.c
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  llvm/test/Transforms/InstCombine/X86/x86-avx512-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-avx512.ll
  llvm/test/Transforms/InstCombine/X86/x86-f16c-inseltpoison.ll
  llvm/test/Transforms/InstCombine/X86/x86-f16c.ll
  llvm/test/Transforms/InstCombine/broadcast-inseltpoison.ll
  llvm/test/Transforms/InstCombine/broadcast.ll
  llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll
  llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
  llvm/test/Transforms/InstCombine/obfuscated_splat-inseltpoison.ll
  llvm/test/Transforms/InstCombine/obfuscated_splat.ll
  llvm/test/Transforms/InstCombine/reduction-shufflevector.ll
  llvm/test/Transforms/InstCombine/shuffle-cast-dist.ll
  llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
  llvm/test/Transforms/InstCombine/trunc.ll
  llvm/test/Transforms/InstCombine/vec_demanded_elts-inseltpoison.ll
  llvm/test/Transforms/InstCombine/vec_demanded_elts.ll
  llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll
  llvm/test/Transforms/InstCombine/vec_shuffle.ll

Index: llvm/test/Transforms/InstCombine/vec_shuffle.ll
===
--- llvm/test/Transforms/InstCombine/vec_shuffle.ll
+++ llvm/test/Transforms/InstCombine/vec_shuffle.ll
@@ -713,8 +713,8 @@
 ; Do not reorder shuffle and binop if LHS of shuffles are of different size
 define <2 x i32> @pr19717(<4 x i32> %in0, <2 x i32> %in1) {
 ; CHECK-LABEL: @pr19717(
-; CHECK-NEXT:[[SHUFFLE:%.*]] = shufflevector <4 x i32> [[IN0:%.*]], <4 x i32> undef, <2 x i32> zeroinitializer
-; CHECK-NEXT:[[SHUFFLE4:%.*]] = shufflevector <2 x i32> [[IN1:%.*]], <2 x i32> undef, <2 x i32> zeroinitializer
+; CHECK-NEXT:[[SHUFFLE:%.*]] = shufflevector <4 x i32> [[IN0:%.*]], <4 x i32> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:[[SHUFFLE4:%.*]] = shufflevector <2 x i32> [[IN1:%.*]], <2 x i32> poison, <2 x i32> zeroinitializer
 ; CHECK-NEXT:[[MUL:%.*]] = mul <2 x i32> [[SHUFFLE]], [[SHUFFLE4]]
 ; CHECK-NEXT:ret <2 x i32> [[MUL]]
 ;
@@ -1413,7 +1413,7 @@
 
 define <4 x double> @insert_subvector_shuffles_identity(<2 x double> %x) {
 ; CHECK-LABEL: @insert_subvector_shuffles_identity(
-; CHECK-NEXT:[[S3:%.*]] = shufflevector <2 x double> [[X:%.*]], <2 x double> undef, <4 x i32> 
+; CHECK-NEXT:[[S3:%.*]] = shufflevector <2 x double> [[X:%.*]], <2 x double> poison, <4 x i32> 
 ; CHECK-NEXT:ret <4 x double> [[S3]]
 ;
   %s1 = shufflevector <2 x double> %x, <2 x double> undef, <4 x i32> 
@@ -1458,7 +1458,7 @@
 define <4 x float> @insert_subvector_crash_invalid_mask_elt(<2 x float> %x, <4 x float>* %p) {
 ; CHECK-LABEL: @insert_subvector_crash_invalid_mask_elt(
 ; CHECK-NEXT:[[WIDEN:%.*]] = shufflevector <2 x float> [[X:%.*]], <2 x float> undef, <4 x i32> 
-; CHECK-NEXT:[[I:%.*]] = shufflevector <2 x float> [[X]], <2 x float> undef, <4 x i32> 
+; CHECK-NEXT:[[I:%.*]] = shufflevector <2 x float> [[X]], <2 x float> poison, <4 x i32> 
 ; CHECK-NEXT:store <4 x float> [[I]], <4 x float>* [[P:%.*]], align 16
 ; CHECK-NEXT:ret <4 x float> [[WIDEN]]
 ;
Index: llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll
===
--- llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll
+++ llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll
@@ -713,8 +713,8 @@
 ; Do not reorder shuffle and binop if LHS of shuffles are of different size
 define <2 x i32> @pr19717(<4 x i32> %in0, <2 x i32> %in1) {
 ; CHECK-LABEL: @pr19717(
-; CHECK-NEXT:[[SHUFFLE:%.*]] = shufflevector <4 x i32> [[IN0:%.*]], <4 x i32> undef, <2 x i32> zeroinitializer
-; CHECK-NEXT:[[SHUFFLE4:%.*]] = shufflevector <2 x i32> [[IN1:%.*]], <2 x i32> undef, <2 x i32> zeroinitializer
+; CHECK-NEXT:[[SHUFFLE:%.*]] = shufflevector <4 x i32> [[IN0:%.*]], <4 x i32> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:[[SHUFFLE4:%.*]] = shufflevector <2 x i32> [[IN1:%.*]], <2 x i32> poison, <2 x i32> zeroinitializer
 ; CHECK-NEXT:[[MUL:%.*]] = mul <2 x i32> [[SHUFFLE]], [[SHUFFLE4]]
 ; CHECK-NEXT:ret <2 x i32> [[MUL]]
 ;
@@ -1413,7 +1413,7 @@
 
 define <4 x double> @insert_subvector_shuffles_identity(<2 x dou

[clang] 98e9666 - [InstCombine] Update InstCombine to use poison instead of undef for shufflevector's placeholder (3/3)

2021-09-22 Thread hyeongyu kim via cfe-commits

Author: hyeongyu kim
Date: 2021-09-23T00:48:24+09:00
New Revision: 98e96663f6a77ee06c5db3f25cdcf19b56ac8f04

URL: 
https://github.com/llvm/llvm-project/commit/98e96663f6a77ee06c5db3f25cdcf19b56ac8f04
DIFF: 
https://github.com/llvm/llvm-project/commit/98e96663f6a77ee06c5db3f25cdcf19b56ac8f04.diff

LOG: [InstCombine] Update InstCombine to use poison instead of undef for 
shufflevector's placeholder (3/3)

This patch is for fixing potential shufflevector-related bugs like D93818.
As D93818, this patch change shufflevector's default placeholder to poison.
To reduce risk, it was divided into several patches, and this patch is for 
InstCombineVectorOps.

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D110230

Added: 


Modified: 
clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
clang/test/CodeGen/aarch64-neon-dot-product.c
clang/test/CodeGen/arm-neon-dot-product.c
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/X86/x86-avx512-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/x86-avx512.ll
llvm/test/Transforms/InstCombine/X86/x86-f16c-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/x86-f16c.ll
llvm/test/Transforms/InstCombine/broadcast-inseltpoison.ll
llvm/test/Transforms/InstCombine/broadcast.ll
llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll
llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
llvm/test/Transforms/InstCombine/obfuscated_splat-inseltpoison.ll
llvm/test/Transforms/InstCombine/obfuscated_splat.ll
llvm/test/Transforms/InstCombine/reduction-shufflevector.ll
llvm/test/Transforms/InstCombine/shuffle-cast-dist.ll
llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
llvm/test/Transforms/InstCombine/trunc.ll
llvm/test/Transforms/InstCombine/vec_demanded_elts-inseltpoison.ll
llvm/test/Transforms/InstCombine/vec_demanded_elts.ll
llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll
llvm/test/Transforms/InstCombine/vec_shuffle.ll

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c 
b/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
index 6772c37c9723e..a4d2901b5d474 100644
--- a/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
+++ b/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
@@ -53,11 +53,11 @@ bfloat16x4_t test_vld1_dup_bf16(bfloat16_t const *ptr) {
 // CHECK-LABEL: test_vld1_dup_bf16
 // CHECK64: %0 = load bfloat, bfloat* %ptr, align 2
 // CHECK64-NEXT: %1 = insertelement <4 x bfloat> undef, bfloat %0, i32 0
-// CHECK64-NEXT: %lane = shufflevector <4 x bfloat> %1, <4 x bfloat> undef, <4 
x i32> zeroinitializer
+// CHECK64-NEXT: %lane = shufflevector <4 x bfloat> %1, <4 x bfloat> poison, 
<4 x i32> zeroinitializer
 // CHECK64-NEXT: ret <4 x bfloat> %lane
 // CHECK32: %0 = load bfloat, bfloat* %ptr, align 2
 // CHECK32-NEXT: %1 = insertelement <4 x bfloat> undef, bfloat %0, i32 0
-// CHECK32-NEXT: %lane = shufflevector <4 x bfloat> %1, <4 x bfloat> undef, <4 
x i32> zeroinitializer
+// CHECK32-NEXT: %lane = shufflevector <4 x bfloat> %1, <4 x bfloat> poison, 
<4 x i32> zeroinitializer
 // CHECK32-NEXT: ret <4 x bfloat> %lane
 
 bfloat16x4x2_t test_vld1_bf16_x2(bfloat16_t const *ptr) {
@@ -108,11 +108,11 @@ bfloat16x8_t test_vld1q_dup_bf16(bfloat16_t const *ptr) {
 // CHECK-LABEL: test_vld1q_dup_bf16
 // CHECK64: %0 = load bfloat, bfloat* %ptr, align 2
 // CHECK64-NEXT: %1 = insertelement <8 x bfloat> undef, bfloat %0, i32 0
-// CHECK64-NEXT: %lane = shufflevector <8 x bfloat> %1, <8 x bfloat> undef, <8 
x i32> zeroinitializer
+// CHECK64-NEXT: %lane = shufflevector <8 x bfloat> %1, <8 x bfloat> poison, 
<8 x i32> zeroinitializer
 // CHECK64-NEXT: ret <8 x bfloat> %lane
 // CHECK32: %0 = load bfloat, bfloat* %ptr, align 2
 // CHECK32-NEXT: %1 = insertelement <8 x bfloat> undef, bfloat %0, i32 0
-// CHECK32-NEXT: %lane = shufflevector <8 x bfloat> %1, <8 x bfloat> undef, <8 
x i32> zeroinitializer
+// CHECK32-NEXT: %lane = shufflevector <8 x bfloat> %1, <8 x bfloat> poison, 
<8 x i32> zeroinitializer
 // CHECK32-NEXT: ret <8 x bfloat> %lane
 
 bfloat16x4x2_t test_vld2_bf16(bfloat16_t const *ptr) {

diff  --git a/clang/test/CodeGen/aarch64-neon-dot-product.c 
b/clang/test/CodeGen/aarch64-neon-dot-product.c
index 5893553b0d2c9..1cae3e1bc619b 100644
--- a/clang/test/CodeGen/aarch64-neon-dot-product.c
+++ b/clang/test/CodeGen/aarch64-neon-dot-product.c
@@ -38,7 +38,7 @@ int32x4_t test_vdotq_s32(int32x4_t a, int8x16_t b, int8x16_t 
c) {
 uint32x2_t test_vdot_lane_u32(uint32x2_t a, uint8x8_t b, uint8x8_t c) {
 // CHECK-LABEL: define{{.*}} <2 x i32> @test_vdot_lane_u32(<2 x i32> %a, <8 x 
i8> %b, <8 x i8> %c)
 // CHECK: [[CAST1:%.*]] = bitcast <8 x i8> %c to <2 x i32>
-// CHECK: [[SHUFFLE:%.*]] = shufflevector <2 x i32> [[CAST1]], <2 x i32> 
undef, <2 x i32> 
+// CHECK: [[SHUFFLE:%.*]] = shuffleve

[PATCH] D110260: [ORC] Minor renaming and typo fixes (NFC)

2021-09-22 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz created this revision.
sgraenitz added a reviewer: lhames.
Herald added subscribers: hiraditya, mgorny.
sgraenitz requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

One typo, one unsused include and some leftovers from the TargetProcessControl 
-> ExecutorProcessControl renaming


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110260

Files:
  clang/docs/ClangFormattedStatus.rst
  llvm/examples/OrcV2Examples/CMakeLists.txt
  llvm/examples/OrcV2Examples/LLJITWithExecutorProcessControl/CMakeLists.txt
  
llvm/examples/OrcV2Examples/LLJITWithExecutorProcessControl/LLJITWithExecutorProcessControl.cpp
  llvm/examples/OrcV2Examples/LLJITWithTargetProcessControl/CMakeLists.txt
  
llvm/examples/OrcV2Examples/LLJITWithTargetProcessControl/LLJITWithTargetProcessControl.cpp
  llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
  llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp

Index: llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp
===
--- llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp
+++ llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp
@@ -223,7 +223,7 @@
 
 if (MsgSize < FDMsgHeader::Size) {
   Err = joinErrors(std::move(Err),
-   make_error("Mesasge size too small",
+   make_error("Message size too small",
inconvertibleErrorCode()));
   break;
 }
Index: llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
===
--- llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
+++ llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
@@ -15,7 +15,6 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FunctionExtras.h"
-#include "llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h"
 #include "llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h"
 #include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
 #include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
Index: llvm/examples/OrcV2Examples/LLJITWithTargetProcessControl/LLJITWithTargetProcessControl.cpp
===
--- /dev/null
+++ llvm/examples/OrcV2Examples/LLJITWithTargetProcessControl/LLJITWithTargetProcessControl.cpp
@@ -1,197 +0,0 @@
-//===- LLJITWithExecutorProcessControl.cpp - LLJIT example with EPC utils -===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// In this example we will use the lazy re-exports utility to lazily compile
-// IR modules. We will do this in seven steps:
-//
-// 1. Create an LLJIT instance.
-// 2. Install a transform so that we can see what is being compiled.
-// 3. Create an indirect stubs manager and lazy call-through manager.
-// 4. Add two modules that will be conditionally compiled, plus a main module.
-// 5. Add lazy-rexports of the symbols in the conditionally compiled modules.
-// 6. Dump the ExecutionSession state to see the symbol table prior to
-//executing any code.
-// 7. Verify that only modules containing executed code are compiled.
-//
-//===--===//
-
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
-#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
-#include "llvm/ExecutionEngine/Orc/EPCIndirectionUtils.h"
-#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
-#include "llvm/ExecutionEngine/Orc/LLJIT.h"
-#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
-#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
-#include "llvm/Support/InitLLVM.h"
-#include "llvm/Support/TargetSelect.h"
-#include "llvm/Support/raw_ostream.h"
-
-#include "../ExampleModules.h"
-
-#include 
-
-using namespace llvm;
-using namespace llvm::orc;
-
-ExitOnError ExitOnErr;
-
-// Example IR modules.
-//
-// Note that in the conditionally compiled modules, FooMod and BarMod, functions
-// have been given an _body suffix. This is to ensure that their names do not
-// clash with their lazy-reexports.
-// For clients who do not wish to rename function bodies (e.g. because they want
-// to re-use cached objects between static and JIT compiles) techniques exist to
-// avoid renaming. See the lazy-reexports section of the ORCv2 design doc.
-
-const llvm::StringRef FooMod =
-R"(
-  declare i32 @return1()
-
-  define i32 @foo_body() {
-  entry:
-%0 = call i32 @return1()
-ret i32 %0
-  }
-)";
-
-const llvm::StringRef BarMod =
-R"(
-  declare i32 @return2()
-
-  define i32 @bar_body() {
-  entry:
-

[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Mahesha S via Phabricator via cfe-commits
hsmhsm updated this revision to Diff 374252.
hsmhsm added a comment.

Update source comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110257/new/

https://reviews.llvm.org/D110257

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGenCUDA/builtins-amdgcn.cu
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
  clang/test/CodeGenCXX/vla.cpp
  clang/test/CodeGenSYCL/address-space-deduction.cpp
  clang/test/OpenMP/amdgcn_target_init_temp_alloca.cpp
  clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/nvptx_allocate_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/parallel_if_codegen.cpp
  clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
  clang/test/OpenMP/parallel_master_taskloop_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_codegen.cpp
  clang/test/OpenMP/target_codegen_global_capture.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/task_codegen.c
  clang/test/OpenMP/teams_distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/vla_crash.c

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d9b511d - [CSSPGO] Set PseudoProbeInserter as a default pass.

2021-09-22 Thread Hongtao Yu via cfe-commits

Author: Hongtao Yu
Date: 2021-09-22T09:09:48-07:00
New Revision: d9b511d8e8c43f79e0e277be287656693dd6563f

URL: 
https://github.com/llvm/llvm-project/commit/d9b511d8e8c43f79e0e277be287656693dd6563f
DIFF: 
https://github.com/llvm/llvm-project/commit/d9b511d8e8c43f79e0e277be287656693dd6563f.diff

LOG: [CSSPGO] Set PseudoProbeInserter as a default pass.

Currenlty PseudoProbeInserter is a pass conditioned on a target switch. It 
works well with a single clang invocation. It doesn't work so well when the 
backend is called separately (i.e, through the linker or llc), where user has 
always to pass -pseudo-probe-for-profiling explictly. I'm making the pass a 
default pass that requires no command line arg to trigger, but will be actually 
run depending on whether the CU comes with `llvm.pseudo_probe_desc` metadata.

Reviewed By: wenlei

Differential Revision: https://reviews.llvm.org/D110209

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/LTO.cpp
lld/ELF/Options.td
lld/test/ELF/lto/pseudo-probe-lto.ll
llvm/include/llvm/CodeGen/CommandFlags.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/CodeGen/PseudoProbeInserter.cpp
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/lib/Target/X86/X86TargetMachine.cpp
llvm/test/CodeGen/X86/O0-pipeline.ll
llvm/test/CodeGen/X86/opt-pipeline.ll
llvm/test/Transforms/SampleProfile/pseudo-probe-dangle.ll
llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
llvm/test/Transforms/SampleProfile/pseudo-probe-instsched.ll
llvm/test/tools/llvm-profgen/truncated-pseudoprobe.test

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e31fa3f9f94de..99e33b227f792 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -576,7 +576,6 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
   Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
   Options.EnableAIXExtendedAltivecABI = 
CodeGenOpts.EnableAIXExtendedAltivecABI;
-  Options.PseudoProbeForProfiling = CodeGenOpts.PseudoProbeForProfiling;
   Options.ValueTrackingVariableLocations =
   CodeGenOpts.ValueTrackingVariableLocations;
   Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex;

diff  --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index f9851d03e78bf..65101d29136e2 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -183,7 +183,6 @@ struct Configuration {
   bool ltoDebugPassManager;
   bool ltoEmitAsm;
   bool ltoNewPassManager;
-  bool ltoPseudoProbeForProfiling;
   bool ltoUniqueBasicBlockSectionNames;
   bool ltoWholeProgramVisibility;
   bool mergeArmExidx;

diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 6607c0fe15a4b..8cb81987163fc 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1084,8 +1084,6 @@ static void readConfigs(opt::InputArgList &args) {
   config->ltoo = args::getInteger(args, OPT_lto_O, 2);
   config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path_eq);
   config->ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);
-  config->ltoPseudoProbeForProfiling =
-  args.hasArg(OPT_lto_pseudo_probe_for_profiling);
   config->ltoSampleProfile = args.getLastArgValue(OPT_lto_sample_profile);
   config->ltoBasicBlockSections =
   args.getLastArgValue(OPT_lto_basic_block_sections);

diff  --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 1f60e1e8a395c..fb354f81d49d6 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -112,7 +112,6 @@ static lto::Config createConfig() {
 }
   }
 
-  c.Options.PseudoProbeForProfiling = config->ltoPseudoProbeForProfiling;
   c.Options.UniqueBasicBlockSectionNames =
   config->ltoUniqueBasicBlockSectionNames;
 

diff  --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index 874399d5f41f2..852a27d62812b 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -574,8 +574,6 @@ def lto_sample_profile: JJ<"lto-sample-profile=">,
 defm lto_whole_program_visibility: BB<"lto-whole-program-visibility",
   "Asserts that the LTO link has whole program visibility",
   "Asserts that the LTO link does not have whole program visibility">;
-def lto_pseudo_probe_for_profiling: F<"lto-pseudo-probe-for-profiling">,
-  HelpText<"Emit pseudo probes for sample profiling">;
 def disable_verify: F<"disable-verify">;
 defm mllvm: Eq<"mllvm", "Additional arguments to forward to LLVM's option 
processing">;
 def opt_remarks_filename: Separate<["--"], "opt-remarks-filename">,
@@ -651,8 +649,6 @@ def: F<"plugin-opt=opt-remarks-with-hotness">,
 def: J<"plugin-opt=opt-remarks-hotness-threshold=">,
   Alias,
   HelpText<"Alias for --opt-remarks-hotness-threshold">;
-def: J<"plugin-opt=p

[PATCH] D110209: [CSSPGO] Set PseudoProbeInserter as a default pass.

2021-09-22 Thread Hongtao Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd9b511d8e8c4: [CSSPGO] Set PseudoProbeInserter as a default 
pass. (authored by hoy).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110209/new/

https://reviews.llvm.org/D110209

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/pseudo-probe-lto.ll
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/PseudoProbeInserter.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-dangle.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-instsched.ll
  llvm/test/tools/llvm-profgen/truncated-pseudoprobe.test

Index: llvm/test/tools/llvm-profgen/truncated-pseudoprobe.test
===
--- llvm/test/tools/llvm-profgen/truncated-pseudoprobe.test
+++ llvm/test/tools/llvm-profgen/truncated-pseudoprobe.test
@@ -20,5 +20,5 @@
 ; CHECK-NEXT:  !Attributes: 1
 
 ; truncated-pseudoprobe.perfbin is from the following compile commands:
-; llc -pseudo-probe-for-profiling truncated-pseudoprobe.ll -filetype=obj -o truncated-pseudoprobe.o
+; llc truncated-pseudoprobe.ll -filetype=obj -o truncated-pseudoprobe.o
 ; clang truncated-pseudoprobe.o -o truncated-pseudoprobe.perfbin
Index: llvm/test/Transforms/SampleProfile/pseudo-probe-instsched.ll
===
--- llvm/test/Transforms/SampleProfile/pseudo-probe-instsched.ll
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-instsched.ll
@@ -1,5 +1,5 @@
 ; REQUIRES: x86_64-linux
-; RUN: llc < %s -mcpu=generic -mtriple=x86_64-- -pseudo-probe-for-profiling -O3 | FileCheck %s
+; RUN: llc < %s -mcpu=generic -mtriple=x86_64-- -O3 | FileCheck %s
 
 define float @foo(float %x) #0 {
   %tmp1 = fmul float %x, 3.00e+00
Index: llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
===
--- llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
@@ -1,10 +1,10 @@
 ; REQUIRES: x86_64-linux
 ; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
 ; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
-; RUN: llc %t -pseudo-probe-for-profiling -stop-after=pseudo-probe-inserter -o - | FileCheck %s --check-prefix=CHECK-MIR
-; RUN: llc %t -pseudo-probe-for-profiling -function-sections -filetype=asm -o %t1
+; RUN: llc %t -stop-after=pseudo-probe-inserter -o - | FileCheck %s --check-prefix=CHECK-MIR
+; RUN: llc %t -function-sections -filetype=asm -o %t1
 ; RUN: FileCheck %s < %t1 --check-prefix=CHECK-ASM
-; RUN: llc %t -pseudo-probe-for-profiling -function-sections -filetype=obj -o %t2
+; RUN: llc %t -function-sections -filetype=obj -o %t2
 ; RUN: llvm-objdump --section-headers  %t2 | FileCheck %s --check-prefix=CHECK-OBJ
 ; RUN: llvm-mc %t1 -filetype=obj -o %t3
 ; RUN: llvm-objdump --section-headers  %t3 | FileCheck %s --check-prefix=CHECK-OBJ
Index: llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
===
--- llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
@@ -1,9 +1,9 @@
 ; REQUIRES: x86_64-linux
 ; RUN: opt < %s -passes='pseudo-probe,cgscc(inline)' -function-sections -mtriple=x86_64-unknown-linux-gnu -S -o %t
 ; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
-; RUN: llc -pseudo-probe-for-profiling -function-sections <%t -filetype=asm -o %t1
+; RUN: llc -function-sections <%t -filetype=asm -o %t1
 ; RUN: FileCheck %s < %t1 --check-prefix=CHECK-ASM
-; RUN: llc -pseudo-probe-for-profiling -function-sections <%t -filetype=obj -o %t2
+; RUN: llc -function-sections <%t -filetype=obj -o %t2
 ; RUN: llvm-objdump --section-headers  %t2 | FileCheck %s --check-prefix=CHECK-OBJ
 ; RUN: llvm-mc -filetype=asm <%t1 -o %t3
 ; RUN: FileCheck %s < %t3 --check-prefix=CHECK-ASM
Index: llvm/test/Transforms/SampleProfile/pseudo-probe-dangle.ll
===
--- llvm/test/Transforms/SampleProfile/pseudo-probe-dangle.ll
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-dangle.ll
@@ -1,9 +1,9 @@
 ; REQUIRES: x86_64-linux
 ; RUN: opt < %s -passes='pseudo-probe,jump-threading' -S -o %t
 ; RUN: FileCheck %s < %t --check-prefix=JT
-; RUN: llc -pseudo-probe-for-profiling -function-sections <%t -filetype=asm | FileCheck %s --check-prefix=

[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

I do think it's cleaner/more canonical IR to cluster these at the top of the 
block, but I don't understand this comment:

> otherwise, inliner's attempt to move static allocas from callee to caller 
> will fail,

The inliner successfully moves allocas to the caller's entry block, even with 
addrspacecasts interspersed.




Comment at: clang/lib/CodeGen/CGExpr.cpp:102-106
+  auto *EBB = AllocaInsertPt->getParent();
+  auto Iter = AllocaInsertPt->getIterator();
+  if (Iter != EBB->end())
+++Iter;
+  Builder.SetInsertPoint(EBB, Iter);

Where are the addrspacecasts inserted? Could you just adjust where those are 
inserted instead?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110257/new/

https://reviews.llvm.org/D110257

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108301: [MSP430][Clang] Update hard-coded MCU data

2021-09-22 Thread Jozef Lawrynowicz via Phabricator via cfe-commits
jozefl updated this revision to Diff 374255.
jozefl added a comment.

Undo incorrect rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108301/new/

https://reviews.llvm.org/D108301

Files:
  clang/include/clang/Basic/MSP430Target.def
  clang/lib/Driver/ToolChains/MSP430.cpp
  clang/test/Driver/msp430-hwmult.c
  clang/test/Driver/msp430-mmcu.c
  clang/test/Driver/msp430-toolchain.c

Index: clang/test/Driver/msp430-toolchain.c
===
--- clang/test/Driver/msp430-toolchain.c
+++ clang/test/Driver/msp430-toolchain.c
@@ -253,6 +253,10 @@
 // RUN:   | FileCheck -check-prefix=HWMult-32BIT %s
 // HWMult-32BIT: "--start-group" "-lmul_32"
 
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430fr5969 --sysroot="" 2>&1 \
+// RUN:   | FileCheck -check-prefix=HWMult-F5 %s
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430fr5969 -mhwmult=auto --sysroot="" 2>&1 \
+// RUN:   | FileCheck -check-prefix=HWMult-F5 %s
 // RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=f5series --sysroot="" 2>&1 \
 // RUN:   | FileCheck -check-prefix=HWMult-F5 %s
 // HWMult-F5: "--start-group" "-lmul_f5"
Index: clang/test/Driver/msp430-mmcu.c
===
--- clang/test/Driver/msp430-mmcu.c
+++ clang/test/Driver/msp430-mmcu.c
@@ -1,15 +1,62 @@
+// This file tests that various different values passed to -mmcu= select the
+// correct target features and linker scripts, and create MCU-specific defines.
+
+// Test the lexicographic ordering of MCUs in MSP430Target.def.
+//
+// The MCU "msp430f110" should appear before "msp430f1101" when the data has
+// been sorted lexicographically. Some sorts will put "msp430f110" *after*
+// "msp430f1101", so when this happens, Clang will not be able to find this MCU.
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f110 2>&1 \
+// RUN:   | FileCheck %s
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f1101 2>&1 \
+// RUN:   | FileCheck %s
+
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f1101a 2>&1 \
+// RUN:   | FileCheck %s
+
+// CHECK-NOT: error: the clang compiler does not support
+
+// Test the symbol definitions, linker scripts and hardware multiply features
+// selected for different MCUs.
+
 // RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430c111 2>&1 \
 // RUN:   | FileCheck -check-prefix=MSP430-C111 %s
 
 // MSP430-C111: clang{{.*}} "-cc1" {{.*}} "-D__MSP430C111__"
+// MSP430-C111-NOT: "-target-feature" "+hwmult16"
+// MSP430-C111-NOT: "-target-feature" "+hwmult32"
+// MSP430-C111-NOT: "-target-feature" "+hwmultf5"
 // MSP430-C111: msp430-elf-ld{{.*}} "-Tmsp430c111.ld"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430i2020 2>&1 \
 // RUN:   | FileCheck -check-prefix=MSP430-I2020 %s
 
 // MSP430-I2020: clang{{.*}} "-cc1" {{.*}} "-D__MSP430i2020__"
+// MSP430-I2020: "-target-feature" "+hwmult16"
 // MSP430-I2020: msp430-elf-ld{{.*}} "-Tmsp430i2020.ld"
 
+// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f47126 2>&1 \
+// RUN:   | FileCheck -check-prefix=MSP430-F47126 %s
+
+// MSP430-F47126: clang{{.*}} "-cc1" {{.*}} "-D__MSP430F47126__"
+// MSP430-F47126: "-target-feature" "+hwmult32"
+// MSP430-F47126: msp430-elf-ld{{.*}} "-Tmsp430f47126.ld"
+
+// RAN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430fr5969 2>&1 \
+// RAN:   | FileCheck -check-prefix=MSP430-FR5969 %s
+
+// MSP430-FR5969: clang{{.*}} "-cc1" {{.*}} "-D__MSP430FR5969__"
+// MSP430-FR5969: "-target-feature" "+hwmultf5"
+// MSP430-FR5969: msp430-elf-ld{{.*}} "-Tmsp430fr5969.ld"
+
+// Test for the error message emitted when an invalid MCU is selected.
+//
+// Note that if this test is ever modified because the expected error message is
+// changed, the check prefixes at the top of this file, used to validate the
+// ordering of the hard-coded MCU data, also need to be updated.
+//
 // RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=not-a-mcu 2>&1 \
 // RUN:   | FileCheck -check-prefix=MSP430-UNSUP %s
 
Index: clang/test/Driver/msp430-hwmult.c
===
--- clang/test/Driver/msp430-hwmult.c
+++ clang/test/Driver/msp430-hwmult.c
@@ -3,17 +3,13 @@
 
 // RUN: %clang -### -target msp430 %s 2>&1 | FileCheck %s
 // RUN: %clang -### -target msp430 %s -mhwmult=auto 2>&1 | FileCheck %s
+// RUN: %clang -### -target msp430 %s -mhwmult=none 2>&1 | FileCheck %s
+// RUN: %clang -### -target msp430 %s -mhwmult=none -mmcu=msp430f147 2>&1 | FileCheck %s
+// RUN: %clang -### -target msp430 %s -mhwmult=none -mmcu=msp430f4783 2>&1 | FileCheck %s
 // CHECK-NOT: "-target-feature" "+hwmult16"
 // CHECK-NOT: "-target-feature" "+hwmult32"
 // CHECK-NOT: "-target-feature" "+hwmultf5"
 
-// RUN: %clang

[PATCH] D109174: [MSP430][Clang] Infer CPU type from -mcpu= or -mmcu=

2021-09-22 Thread Jozef Lawrynowicz via Phabricator via cfe-commits
jozefl updated this revision to Diff 374257.
jozefl added a comment.

Rebase to fix patch application failure for
clang/test/Misc/target-invalid-cpu-note.c.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109174/new/

https://reviews.llvm.org/D109174

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Basic/Targets/MSP430.cpp
  clang/lib/Basic/Targets/MSP430.h
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MSP430.cpp
  clang/lib/Driver/ToolChains/MSP430.h
  clang/test/Driver/msp430-cpu.c
  clang/test/Driver/msp430-mmcu.c
  clang/test/Driver/msp430-toolchain.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/msp430-defs.c
  llvm/lib/Target/MSP430/MSP430.td
  llvm/lib/Target/MSP430/MSP430Subtarget.cpp
  llvm/lib/Target/MSP430/MSP430Subtarget.h
  llvm/test/CodeGen/MSP430/build-attrs.ll

Index: llvm/test/CodeGen/MSP430/build-attrs.ll
===
--- llvm/test/CodeGen/MSP430/build-attrs.ll
+++ llvm/test/CodeGen/MSP430/build-attrs.ll
@@ -8,6 +8,8 @@
 ; RUN:   | llvm-readelf -A - | FileCheck %s --check-prefixes COMMON,MSP430,SMALL
 ; RUN: llc -mtriple=msp430 -mcpu=msp430x -filetype=obj < %s \
 ; RUN:   | llvm-readelf -A - | FileCheck %s --check-prefixes COMMON,MSP430X,SMALL
+; RUN: llc -mtriple=msp430 -mcpu=msp430xv2 -filetype=obj < %s \
+; RUN:   | llvm-readelf -A - | FileCheck %s --check-prefixes COMMON,MSP430X,SMALL
 
 ; COMMON: BuildAttributes {
 ; COMMON: FormatVersion: 0x41
Index: llvm/lib/Target/MSP430/MSP430Subtarget.h
===
--- llvm/lib/Target/MSP430/MSP430Subtarget.h
+++ llvm/lib/Target/MSP430/MSP430Subtarget.h
@@ -36,7 +36,7 @@
 
 private:
   virtual void anchor();
-  bool ExtendedInsts = false;
+  bool MSP430X = false;
   HWMultEnum HWMultMode = NoHWMult;
   MSP430FrameLowering FrameLowering;
   MSP430InstrInfo InstrInfo;
@@ -60,6 +60,8 @@
   bool hasHWMult32() const { return HWMultMode == HWMult32; }
   bool hasHWMultF5() const { return HWMultMode == HWMultF5; }
 
+  bool hasMSP430X() const { return MSP430X; }
+
   const TargetFrameLowering *getFrameLowering() const override {
 return &FrameLowering;
   }
Index: llvm/lib/Target/MSP430/MSP430Subtarget.cpp
===
--- llvm/lib/Target/MSP430/MSP430Subtarget.cpp
+++ llvm/lib/Target/MSP430/MSP430Subtarget.cpp
@@ -40,9 +40,6 @@
 
 MSP430Subtarget &
 MSP430Subtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
-  ExtendedInsts = false;
-  HWMultMode = NoHWMult;
-
   StringRef CPUName = CPU;
   if (CPUName.empty())
 CPUName = "msp430";
Index: llvm/lib/Target/MSP430/MSP430.td
===
--- llvm/lib/Target/MSP430/MSP430.td
+++ llvm/lib/Target/MSP430/MSP430.td
@@ -18,8 +18,8 @@
 // Subtarget Features. 
 //===--===//
 def FeatureX
- : SubtargetFeature<"ext", "ExtendedInsts", "true",
-"Enable MSP430-X extensions">;
+ : SubtargetFeature<"msp430x", "MSP430X", "true",
+"Enable MSP430X extensions">;
 
 def FeatureHWMult16
  : SubtargetFeature<"hwmult16", "HWMultMode", "HWMult16",
@@ -42,6 +42,7 @@
 def : Proc<"generic", []>;
 def : Proc<"msp430",  []>;
 def : Proc<"msp430x", [FeatureX]>;
+def : Proc<"msp430xv2",   [FeatureX]>;
 
 //===--===//
 // Register File Description
Index: clang/test/Preprocessor/msp430-defs.c
===
--- /dev/null
+++ clang/test/Preprocessor/msp430-defs.c
@@ -0,0 +1,20 @@
+// Check the correct macros are defined for each CPU.
+
+// RUN: %clang -target msp430 -x c -E -dM %s -o - | FileCheck  %s
+// RUN: %clang -target msp430 -mcpu=generic -x c -E -dM %s -o - | FileCheck %s
+// RUN: %clang -target msp430 -mcpu=msp430 -x c -E -dM %s -o - | FileCheck %s
+
+// CHECK: MSP430
+// CHECK: __ELF__
+// CHECK-NOT: __MSP430X__
+// CHECK: __MSP430__
+
+// RUN: %clang -target msp430 -mcpu=msp430x -x c -E -dM %s -o - \
+// RUN:   | FileCheck --check-prefix=MSP430X %s
+// RUN: %clang -target msp430 -mcpu=msp430xv2 -x c -E -dM %s -o - \
+// RUN:   | FileCheck --check-prefix=MSP430X %s
+
+// MSP430X: MSP430
+// MSP430X: __ELF__
+// MSP430X: __MSP430X__
+// MSP430X: __MSP430__
Index: clang/test/Misc/target-invalid-cpu-note.c
===
--- clang/test/Misc/target-invalid-cpu-note.c
+++ clang/test/Misc/target-invalid-cpu-note.c
@@ -209,3 +209,7 @@
 // RUN: not %clang_cc1 -triple riscv64 -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix TUNE-RISCV64
 // TUNE-RISCV64: error: unknown target CPU 'not-a-cpu'
 // TUNE-RISCV6

[PATCH] D110111: [WebAssembly] Add relaxed-simd feature

2021-09-22 Thread Ng Zhi An via Phabricator via cfe-commits
ngzhian updated this revision to Diff 374262.
ngzhian marked an inline comment as done.
ngzhian added a comment.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Fix fallthrough, add feature to WebAssembly subtarget


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110111/new/

https://reviews.llvm.org/D110111

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Basic/Targets/WebAssembly.h
  clang/test/Preprocessor/wasm-target-features.c
  llvm/lib/Target/WebAssembly/WebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h

Index: llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
===
--- llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
+++ llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
@@ -36,6 +36,7 @@
   enum SIMDEnum {
 NoSIMD,
 SIMD128,
+RelaxedSIMD,
   } SIMDLevel = NoSIMD;
 
   bool HasAtomics = false;
@@ -89,6 +90,7 @@
   // Predicates used by WebAssemblyInstrInfo.td.
   bool hasAddr64() const { return TargetTriple.isArch64Bit(); }
   bool hasSIMD128() const { return SIMDLevel >= SIMD128; }
+  bool hasRelaxedSIMD() const { return SIMDLevel >= RelaxedSIMD; }
   bool hasAtomics() const { return HasAtomics; }
   bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }
   bool hasSignExt() const { return HasSignExt; }
Index: llvm/lib/Target/WebAssembly/WebAssembly.td
===
--- llvm/lib/Target/WebAssembly/WebAssembly.td
+++ llvm/lib/Target/WebAssembly/WebAssembly.td
@@ -25,6 +25,9 @@
 def FeatureSIMD128 : SubtargetFeature<"simd128", "SIMDLevel", "SIMD128",
   "Enable 128-bit SIMD">;
 
+def FeatureRelaxedSIMD : SubtargetFeature<"relaxed-simd", "SIMDLevel", "RelaxedSIMD",
+  "Enable relaxed-simd instructions">;
+
 def FeatureAtomics : SubtargetFeature<"atomics", "HasAtomics", "true",
   "Enable Atomics">;
 
Index: clang/test/Preprocessor/wasm-target-features.c
===
--- clang/test/Preprocessor/wasm-target-features.c
+++ clang/test/Preprocessor/wasm-target-features.c
@@ -7,6 +7,15 @@
 //
 // SIMD128:#define __wasm_simd128__ 1{{$}}
 
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -mrelaxed-simd \
+// RUN:   | FileCheck %s -check-prefix=RELAXED-SIMD
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -mrelaxed-simd \
+// RUN:   | FileCheck %s -check-prefix=RELAXED-SIMD
+//
+// RELAXED-SIMD:#define __wasm_relaxed_simd__ 1{{$}}
+
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mnontrapping-fptoint \
 // RUN:   | FileCheck %s -check-prefix=NONTRAPPING-FPTOINT
Index: clang/lib/Basic/Targets/WebAssembly.h
===
--- clang/lib/Basic/Targets/WebAssembly.h
+++ clang/lib/Basic/Targets/WebAssembly.h
@@ -27,6 +27,7 @@
   enum SIMDEnum {
 NoSIMD,
 SIMD128,
+RelaxedSIMD,
   } SIMDLevel = NoSIMD;
 
   bool HasNontrappingFPToInt = false;
Index: clang/lib/Basic/Targets/WebAssembly.cpp
===
--- clang/lib/Basic/Targets/WebAssembly.cpp
+++ clang/lib/Basic/Targets/WebAssembly.cpp
@@ -46,6 +46,7 @@
 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
   return llvm::StringSwitch(Feature)
   .Case("simd128", SIMDLevel >= SIMD128)
+  .Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
   .Case("nontrapping-fptoint", HasNontrappingFPToInt)
   .Case("sign-ext", HasSignExt)
   .Case("exception-handling", HasExceptionHandling)
@@ -72,6 +73,8 @@
   defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
   if (SIMDLevel >= SIMD128)
 Builder.defineMacro("__wasm_simd128__");
+  if (SIMDLevel >= RelaxedSIMD)
+Builder.defineMacro("__wasm_relaxed_simd__");
   if (HasNontrappingFPToInt)
 Builder.defineMacro("__wasm_nontrapping_fptoint__");
   if (HasSignExt)
@@ -96,6 +99,9 @@
  SIMDEnum Level, bool Enabled) {
   if (Enabled) {
 switch (Level) {
+case RelaxedSIMD:
+  Features["relaxed-simd"] = true;
+  LLVM_FALLTHROUGH;
 case SIMD128:
   Features["simd128"] = true;
   LLVM_FALLTHROUGH;
@@ -109,6 +115,9 @@
   case NoSIMD:
   case SIMD128:
 Features["simd128"] = false;
+LLVM_FALLTHROUGH;
+  case RelaxedSIMD:
+Features["relaxed-simd"] = false;
 break;
   }
 }
@@ -118,6 +127,8 @@
   bool Enabled) const {
   if (Name == "simd128")
 setSIMDLevel(Features, SIMD128, Enabled);
+  else if (Name == "relaxed-simd")
+setSIMDLevel(Features, RelaxedSIMD, Enabled);
   else
 Features[Name] = Enable

[PATCH] D110111: [WebAssembly] Add relaxed-simd feature

2021-09-22 Thread Ng Zhi An via Phabricator via cfe-commits
ngzhian added a comment.

In D110111#3013948 , @tlively wrote:

> Nice! Thanks for writing this :D Do you know what happens when you actually 
> try to compile some code with `-mrelaxed-simd`? I'm concerned that it will 
> throw an error because the "relaxed-simd" target feature has not yet been 
> defined in the backend (specifically in WebAssembly.td and in 
> WebAssemblySubtarget.{h,cpp}).

It output "'+relaxed-simd' is not a recognized feature for this target 
(ignoring feature)" but didn't fail compilation. I fixed it by adding to 
WebAssembly.td and WebAssemblySubtarget.h, thanks!

> Edit: Here's the corresponding previous patch that added the target feature 
> in the backend: https://reviews.llvm.org/D56501.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110111/new/

https://reviews.llvm.org/D110111

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110142: [clang][Driver] Correct runtime path for Arm hard float targets

2021-09-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D110142#3015482 , @DavidSpickett 
wrote:

> So would you expect to see libraries in 
> `lib/clang/14.0.0/lib/armv8l-unknown-linux-gnueabihf` and not change clang's 
> logic?

I'd hope that it works this way (`armv8l-*`) :)

> The output dir is worked out in cmake by `get_compiler_rt_output_dir` which 
> calls `get_compiler_rt_target` which takes the arch given and adds it to the 
> suffix of the triple. So it adds "armhf" to "-unknown-linux-gnueabihf". 
> (which is why the "hf" is duplicated)
>
> A few places look for "armhf" specifically as the arch, so it's not as easy 
> as just not converting "armv8l" into that. But if we can confirm what the 
> goal is here then I can find out how to properly handle those.

I took a glance at `get_compiler_rt_target`... It is complex. If you can figure 
it out, that will be great!

> You can just bodge `get_compiler_rt_target` to just use the target triple but 
> of course that breaks any build for multiple targets. If I'm reading 
> `test_targets` correctly, it builds a list of architectures to build as 
> opposed to finding the first working one.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110142/new/

https://reviews.llvm.org/D110142

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99797: [analyzer] Implemented RangeSet::Factory::unite function to handle intersections and adjacency

2021-09-22 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 374265.
ASDenysPetrov added a comment.

Rebased. Review, please.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99797/new/

https://reviews.llvm.org/D99797

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/unittests/StaticAnalyzer/RangeSetTest.cpp

Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp
===
--- clang/unittests/StaticAnalyzer/RangeSetTest.cpp
+++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp
@@ -35,12 +35,34 @@
   const RangeSet &Set) {
   return OS << toString(Set);
 }
+// We need it here for better fail diagnostics from gtest.
+LLVM_ATTRIBUTE_UNUSED static std::ostream &operator<<(std::ostream &OS,
+  const Range &R) {
+  return OS << toString(R);
+}
 
 } // namespace ento
 } // namespace clang
 
 namespace {
 
+template  struct TestValues {
+  static constexpr T MIN = std::numeric_limits::min();
+  static constexpr T MAX = std::numeric_limits::max();
+  // MID is a value in the middle of the range
+  // which unary minus does not affect on,
+  // e.g. int8/int32(0), uint8(128), uint32(2147483648).
+  static constexpr T MID =
+  std::is_signed::value ? 0 : ~(static_cast(-1) / static_cast(2));
+  static constexpr T A = MID - (MAX - MID) / 3 * 2;
+  static constexpr T B = MID - (MAX - MID) / 3;
+  static constexpr T C = -B;
+  static constexpr T D = -A;
+
+  static_assert(MIN < A && A < B && B < MID && MID < C && C < D && D < MAX,
+"Values shall be in an ascending order");
+};
+
 template  class RangeSetTest : public testing::Test {
 public:
   // Init block
@@ -55,24 +77,11 @@
   using RawRange = std::pair;
   using RawRangeSet = std::initializer_list;
 
-  static constexpr BaseType getMin() {
-return std::numeric_limits::min();
-  }
-  static constexpr BaseType getMax() {
-return std::numeric_limits::max();
-  }
-  static constexpr BaseType getMid() {
-return isSigned() ? 0 : ~(fromInt(-1) / fromInt(2));
-  }
-
-  static constexpr bool isSigned() { return std::is_signed::value; }
-  static constexpr BaseType fromInt(int X) { return static_cast(X); }
-
-  static llvm::APSInt Base;
   const llvm::APSInt &from(BaseType X) {
-llvm::APSInt Dummy = Base;
-Dummy = X;
-return BVF.getValue(Dummy);
+static llvm::APSInt Base{sizeof(BaseType) * 8,
+ std::is_unsigned::value};
+Base = X;
+return BVF.getValue(Base);
   }
 
   Range from(const RawRange &Init) {
@@ -160,7 +169,7 @@
 
   void checkAdd(RawRangeSet RawLHS, RawRangeSet RawRHS,
 RawRangeSet RawExpected) {
-wrap(&Self::checkAddImpl, RawRHS, RawLHS, RawExpected);
+wrap(&Self::checkAddImpl, RawLHS, RawRHS, RawExpected);
   }
 
   void checkAdd(RawRangeSet RawLHS, BaseType RawRHS, RawRangeSet RawExpected) {
@@ -168,6 +177,29 @@
  RawExpected);
   }
 
+  template 
+  void checkUniteImpl(RangeSet LHS, RHSType RHS, RangeSet Expected) {
+RangeSet Result = F.unite(LHS, RHS);
+EXPECT_EQ(Result, Expected)
+<< "while uniting " << toString(LHS) << " and " << toString(RHS);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, RawRange RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS, RawExpected);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, RawRangeSet RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS, RawExpected);
+  }
+
+  void checkUnite(RawRangeSet RawLHS, BaseType RawRHS,
+  RawRangeSet RawExpected) {
+wrap(&Self::checkUniteImpl, RawLHS, RawRHS,
+ RawExpected);
+  }
+
   void checkDeleteImpl(const llvm::APSInt &Point, RangeSet From,
RangeSet Expected) {
 RangeSet Result = F.deletePoint(From, Point);
@@ -183,29 +215,19 @@
 
 } // namespace
 
-template 
-llvm::APSInt RangeSetTest::Base{sizeof(BaseType) * 8, !isSigned()};
-
 using IntTypes = ::testing::Types;
 TYPED_TEST_SUITE(RangeSetTest, IntTypes, );
 
 TYPED_TEST(RangeSetTest, RangeSetNegateTest) {
-  // Use next values of the range {MIN, A, B, MID, C, D, MAX}.
-
-  constexpr TypeParam MIN = TestFixture::getMin();
-  constexpr TypeParam MAX = TestFixture::getMax();
-  // MID is a value in the middle of the range
-  // which unary minus does not affect on,
-  // e.g. int8/int32(0), uint8(128), uint32(2147483648).
-  constexpr TypeParam MID = TestFixture::getMid();
-  constexpr TypeParam A = MID - TestFixture::fromInt(42 + 42);
-  constexpr TypeParam B = MID - TestFixture::fromInt(42);
-  constexpr TypeParam C = -B;
-  constexpr TypeParam D = -A;
-
-  static_assert(MIN < A && A < B && B < MID && MID < C && C < D && D < MAX,
-"Values shall be in an ascending order");
+  using TV = 

[PATCH] D103094: [analyzer] Implemented RangeSet::Factory::castTo function to perform promotions, truncations and conversions.

2021-09-22 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 374267.
ASDenysPetrov added a comment.

Rebased.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103094/new/

https://reviews.llvm.org/D103094

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/unittests/StaticAnalyzer/RangeSetTest.cpp

Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp
===
--- clang/unittests/StaticAnalyzer/RangeSetTest.cpp
+++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp
@@ -40,12 +40,18 @@
   const Range &R) {
   return OS << toString(R);
 }
+LLVM_ATTRIBUTE_UNUSED static std::ostream &operator<<(std::ostream &OS,
+  APSIntType Ty) {
+  return OS << (Ty.isUnsigned() ? "u" : "s") << Ty.getBitWidth();
+}
 
 } // namespace ento
 } // namespace clang
 
 namespace {
 
+template  constexpr bool is_signed_v = std::is_signed::value;
+
 template  struct TestValues {
   static constexpr T MIN = std::numeric_limits::min();
   static constexpr T MAX = std::numeric_limits::max();
@@ -53,7 +59,7 @@
   // which unary minus does not affect on,
   // e.g. int8/int32(0), uint8(128), uint32(2147483648).
   static constexpr T MID =
-  std::is_signed::value ? 0 : ~(static_cast(-1) / static_cast(2));
+  is_signed_v ? 0 : ~(static_cast(-1) / static_cast(2));
   static constexpr T A = MID - (MAX - MID) / 3 * 2;
   static constexpr T B = MID - (MAX - MID) / 3;
   static constexpr T C = -B;
@@ -61,8 +67,40 @@
 
   static_assert(MIN < A && A < B && B < MID && MID < C && C < D && D < MAX,
 "Values shall be in an ascending order");
+  // Clear bits in low bytes by the given amount.
+  template 
+  static const T ClearLowBytes = static_cast(static_cast(Value)
+<< ((Bytes >= 8) ? 0 : Bytes) *
+   8);
+
+  template 
+  static constexpr T TruncZeroOf = ClearLowBytes;
+
+  // Random number with active bits in every byte. 0x'
+  static constexpr T XAAA = static_cast(
+  0b10101010'10101010'10101010'10101010'10101010'10101010'10101010'10101010);
+  template 
+  static constexpr T XAAATruncZeroOf = TruncZeroOf; // 0x'AB00
+
+  // Random number with active bits in every byte. 0x'
+  static constexpr T X555 = static_cast(
+  0b01010101'01010101'01010101'01010101'01010101'01010101'01010101'01010101);
+  template 
+  static constexpr T X555TruncZeroOf = TruncZeroOf; // 0x'5600
+
+  // Numbers for ranges with the same bits in the lowest byte.
+  // 0x'AA2A
+  static constexpr T FromA = ClearLowBytes + 42;
+  static constexpr T ToA = FromA + 2; // 0x'AA2C
+  // 0x'552A
+  static constexpr T FromB = ClearLowBytes + 42;
+  static constexpr T ToB = FromB + 2; // 0x'552C
 };
 
+template 
+static constexpr APSIntType APSIntTy = APSIntType(sizeof(T) * 8,
+  !is_signed_v);
+
 template  class RangeSetTest : public testing::Test {
 public:
   // Init block
@@ -74,21 +112,24 @@
   // End init block
 
   using Self = RangeSetTest;
-  using RawRange = std::pair;
-  using RawRangeSet = std::initializer_list;
-
-  const llvm::APSInt &from(BaseType X) {
-static llvm::APSInt Base{sizeof(BaseType) * 8,
- std::is_unsigned::value};
-Base = X;
-return BVF.getValue(Base);
+  template  using RawRangeT = std::pair;
+  template 
+  using RawRangeSetT = std::initializer_list>;
+  using RawRange = RawRangeT;
+  using RawRangeSet = RawRangeSetT;
+
+  template  const llvm::APSInt &from(T X) {
+static llvm::APSInt Int = APSIntTy.getZeroValue();
+Int = X;
+return BVF.getValue(Int);
   }
 
-  Range from(const RawRange &Init) {
+  template  Range from(const RawRangeT &Init) {
 return Range(from(Init.first), from(Init.second));
   }
 
-  RangeSet from(const RawRangeSet &Init) {
+  template 
+  RangeSet from(RawRangeSetT Init, APSIntType Ty = APSIntTy) {
 RangeSet RangeSet = F.getEmptySet();
 for (const auto &Raw : Init) {
   RangeSet = F.add(RangeSet, from(Raw));
@@ -211,9 +252,20 @@
RawRangeSet RawExpected) {
 wrap(&Self::checkDeleteImpl, Point, RawFrom, RawExpected);
   }
-};
 
-} // namespace
+  void checkCastToImpl(RangeSet What, APSIntType Ty, RangeSet Expected) {
+RangeSet Result = F.castTo(What, Ty);
+EXPECT_EQ(Result, Expected)
+<< "while casting " << toString(What) << " to " << Ty;
+  }
+
+  template 
+  void checkCastTo(RawRangeSetT What, RawRangeSetT Expected) {
+static constexpr APSIntType FromTy = APSIntTy;
+static constexpr APSIntType ToTy = APSIntTy;
+this->checkCastToImpl(from(What, FromTy), ToTy, from(Expected, ToTy)

[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Mahesha S via Phabricator via cfe-commits
hsmhsm added a comment.

In D110257#3015553 , @arsenm wrote:

> I do think it's cleaner/more canonical IR to cluster these at the top of the 
> block, but I don't understand this comment:
>
>> otherwise, inliner's attempt to move static allocas from callee to caller 
>> will fail,
>
> The inliner successfully moves allocas to the caller's entry block, even with 
> addrspacecasts interspersed.

The logic at 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/InlineFunction.cpp#L2093
 assumes that static allocas (within callee) are contiguous.




Comment at: clang/lib/CodeGen/CGExpr.cpp:102-106
+  auto *EBB = AllocaInsertPt->getParent();
+  auto Iter = AllocaInsertPt->getIterator();
+  if (Iter != EBB->end())
+++Iter;
+  Builder.SetInsertPoint(EBB, Iter);

arsenm wrote:
> Where are the addrspacecasts inserted? Could you just adjust where those are 
> inserted instead?
The addressspace casts are inserted immediately after all static allocas (top 
static alloca cluster).

An example:

Before this patch:

```
entry:
  %N.addr = alloca i64, align 8, addrspace(5)
  %N.addr.ascast = addrspacecast i64 addrspace(5)* %N.addr to i64*
  %vla.addr = alloca i64, align 8, addrspace(5)
  %vla.addr.ascast = addrspacecast i64 addrspace(5)* %vla.addr to i64*
  %a.addr = alloca i32*, align 8, addrspace(5)
  %a.addr.ascast = addrspacecast i32* addrspace(5)* %a.addr to i32**
  %vla.addr2 = alloca i64, align 8, addrspace(5)
  %vla.addr2.ascast = addrspacecast i64 addrspace(5)* %vla.addr2 to i64*
  %b.addr = alloca i32*, align 8, addrspace(5)
  %b.addr.ascast = addrspacecast i32* addrspace(5)* %b.addr to i32**
  %N.casted = alloca i64, align 8, addrspace(5)
  %N.casted.ascast = addrspacecast i64 addrspace(5)* %N.casted to i64*
  %.zero.addr = alloca i32, align 4, addrspace(5)
  %.zero.addr.ascast = addrspacecast i32 addrspace(5)* %.zero.addr to i32*
  %.threadid_temp. = alloca i32, align 4, addrspace(5)
  %.threadid_temp..ascast = addrspacecast i32 addrspace(5)* %.threadid_temp. to 
i32*  
  store i64 %N, i64* %N.addr.ascast, align 8
```

With this patch:

```
entry:
  %N.addr = alloca i64, align 8, addrspace(5)
  %vla.addr = alloca i64, align 8, addrspace(5)
  %a.addr = alloca i32*, align 8, addrspace(5)
  %vla.addr2 = alloca i64, align 8, addrspace(5)
  %b.addr = alloca i32*, align 8, addrspace(5)
  %N.casted = alloca i64, align 8, addrspace(5)
  %.zero.addr = alloca i32, align 4, addrspace(5)
  %.threadid_temp. = alloca i32, align 4, addrspace(5)
  %.threadid_temp..ascast = addrspacecast i32 addrspace(5)* %.threadid_temp. to 
i32*
  %.zero.addr.ascast = addrspacecast i32 addrspace(5)* %.zero.addr to i32*
  %N.casted.ascast = addrspacecast i64 addrspace(5)* %N.casted to i64*
  %b.addr.ascast = addrspacecast i32* addrspace(5)* %b.addr to i32**
  %vla.addr2.ascast = addrspacecast i64 addrspace(5)* %vla.addr2 to i64*
  %a.addr.ascast = addrspacecast i32* addrspace(5)* %a.addr to i32**
  %vla.addr.ascast = addrspacecast i64 addrspace(5)* %vla.addr to i64*
  %N.addr.ascast = addrspacecast i64 addrspace(5)* %N.addr to i64*
  store i64 %N, i64* %N.addr.ascast, align 8
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110257/new/

https://reviews.llvm.org/D110257

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110258: [AArch64][Clang] Always add -tune-cpu argument to -cc1 driver

2021-09-22 Thread Dave Green via Phabricator via cfe-commits
dmgreen added a comment.

In D110258#3015484 , @david-arm wrote:

> Hi @dmgreen, this is specifically being introduced for SVE targets to help 
> make informed cost model decisions regarding the value of vscale - see 
> D110259 . We thought that using the 
> "tune-cpu" attribute might be a good way of doing this.

Yeah. I added comments there. It would feel strange to me to have a single part 
of the tuning features for a cpu based on a `tune-cpu`, where everything else 
uses the `target-cpu`. We should try and make -mtune work better, but we should 
aim to do that consistently in a way that doesn't just make thing _more_ 
confusing!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110258/new/

https://reviews.llvm.org/D110258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105340: [analyzer] Produce SymbolCast symbols for integral types in SValBuilder::evalCast

2021-09-22 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 374270.
ASDenysPetrov added a comment.

Rebased.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105340/new/

https://reviews.llvm.org/D105340

Files:
  clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
  clang/test/Analysis/symbol-integral-cast.cpp

Index: clang/test/Analysis/symbol-integral-cast.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-integral-cast.cpp
@@ -0,0 +1,374 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -analyzer-config eagerly-assume=false -analyzer-config support-symbolic-integer-casts=true -verify %s
+
+template 
+void clang_analyzer_eval(T);
+void clang_analyzer_warnIfReached();
+
+typedef short int16_t;
+typedef int int32_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+
+void test1(int x) {
+  // Even if two lower bytes of `x` equal to zero, it doesn't mean that
+  // the entire `x` is zero. We are not able to know the exact value of x.
+  // It can be one of  65536 possible values like [0, 65536, 131072, ...]
+  // and so on. To avoid huge range sets we still assume `x` in the range
+  // [INT_MIN, INT_MAX].
+  if (!(short)x) {
+if (!x)
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test2(int x) {
+  // If two lower bytes of `x` equal to zero, and we know x to be 65537,
+  // which is not truncated to short as zero. Thus the branch is infisible.
+  short s = x;
+  if (!s) {
+if (x == 65537)
+  clang_analyzer_warnIfReached(); // no-warning
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test3(int x, short s) {
+  s = x;
+  if ((short)x > -10 && s < 10) {
+if (x > 0 && x < 10) {
+  // If the range of the whole variable was constrained then reason again
+  // about truncated bytes to make the ranges more precise.
+  clang_analyzer_eval((short)x <= 0); // expected-warning {{FALSE}}
+}
+  }
+}
+
+void test4(unsigned x) {
+  if ((char)x > 8) {
+// Constraint the range of the lowest byte of `x` to [9, CHAR_MAX].
+// The original range of `x` still remains [0, UINT_MAX].
+clang_analyzer_eval((char)x < 42); // expected-warning {{UNKNOWN}}
+if (x < 42) {
+  // Constraint the original range to [0, 42] and update (re-constraint)
+  // the range of the lowest byte of 'x' to [9, 42].
+  clang_analyzer_eval((char)x < 42); // expected-warning {{TRUE}}
+}
+  }
+}
+
+void test5(unsigned x) {
+  if ((char)x > -10 && (char)x < 10) {
+if ((short)x == 8) {
+  // If the range of higher bytes(short) was constrained then reason again
+  // about smaller truncated ranges(char) to make it more precise.
+  clang_analyzer_eval((char)x == 8);  // expected-warning {{TRUE}}
+  clang_analyzer_eval((short)x == 8); // expected-warning {{TRUE}}
+  // We still assume full version of `x` in the range [INT_MIN, INT_MAX].
+  clang_analyzer_eval(x == 8); // expected-warning {{UNKNOWN}}
+}
+  }
+}
+
+void test6(int x) {
+  // Even if two lower bytes of `x` less than zero, it doesn't mean that `x`
+  // can't be greater than zero. Thence we don't change the native range of
+  // `x` and this branch is feasible.
+  if (x > 0)
+if ((short)x < 0)
+  clang_analyzer_eval(x > 0); // expected-warning {{TRUE}}
+}
+
+void test7(int x) {
+  // The range of two lower bytes of `x` [1, SHORT_MAX] is enough to cover
+  // all possible values of char [CHAR_MIN, CHAR_MAX]. So the lowest byte
+  // can be lower than zero.
+  if ((short)x > 0) {
+if ((char)x < 0)
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+else
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  }
+}
+
+void test8(int x) {
+  // Promotion from `signed int` to `signed long long` also reasoning about the
+  // original range, because we know the fact that even after promotion it
+  // remains in the range [INT_MIN, INT_MAX].
+  if ((long long)x < 0)
+clang_analyzer_eval(x < 0); // expected-warning {{TRUE}}
+}
+
+void test9(signed int x) {
+  // Any cast `signed` to `unsigned` produces an unsigned range, which is
+  // [0, UNSIGNED_MAX] and can not be lower than zero.
+  if ((unsigned long long)x < 0)
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+
+  if ((unsigned int)x < 0)
+clang_analyzer_warnIfReached(); // no-warning
+  else
+clang_analyzer_warnIfReached(); // expected-warning {{REACH

[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D110257#3015641 , @hsmhsm wrote:

> In D110257#3015553 , @arsenm wrote:
>
>> I do think it's cleaner/more canonical IR to cluster these at the top of the 
>> block, but I don't understand this comment:
>>
>>> otherwise, inliner's attempt to move static allocas from callee to caller 
>>> will fail,
>>
>> The inliner successfully moves allocas to the caller's entry block, even 
>> with addrspacecasts interspersed.
>
> The logic at 
> https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/InlineFunction.cpp#L2093
>  assumes that static allocas (within callee) are contiguous.

True. Even worse. It will bail if a static alloca is used as an `inalloca` 
argument.
So, if you now interleave allocas that may be used in `inalloca` you also break 
the "canonical form". 
I assume this hits mostly windows but still.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110257/new/

https://reviews.llvm.org/D110257

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fe16d33 - Add document numbers for the C99 status page.

2021-09-22 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-09-22T13:02:25-04:00
New Revision: fe16d331d345acfb06a01da15100d5899efb0c51

URL: 
https://github.com/llvm/llvm-project/commit/fe16d331d345acfb06a01da15100d5899efb0c51
DIFF: 
https://github.com/llvm/llvm-project/commit/fe16d331d345acfb06a01da15100d5899efb0c51.diff

LOG: Add document numbers for the C99 status page.

This doesn't add all of the document numbers, but it adds a bunch of
them. Not all of the documents are available on the committee page
(they're old enough that they come from a time when the mailing was
comprised of physical pieces of paper), so some of the documents listed
are assumed to be correct based on my reading of editor's reports.

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 386859125a82a..d61e4af47501e 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -84,7 +84,13 @@ C89 implementation status
 C99 implementation status
 
 Clang implements a significant portion of the ISO 9899:1999 (C99) standard, 
but the status of individual proposals is still under investigation.
-Note, the list of C99 features comes from the C99 committee draft. A list 
of N-numbered documents for these features does not appear in either the 
standard or in any available editor's report, so this section does not track 
document numbers currently.
+Note, the list of C99 features comes from the C99 committee draft. Not all 
C99 documents are publicly available, so the documents referenced in this 
section may be inaccurate, unknown, or not linked.
+
 You can use Clang in C99 mode with the -std=c99 option.
 
 
@@ -93,237 +99,281 @@ C99 implementation status
 
  
 Language Feature
-
+C99 Proposal
 Available in Clang?
  
 
   restricted character set support via digraphs and 

-
+  Unknown
   Unknown
 
 
   more precise aliasing rules via effective type
-
+  Unknown
   Unknown
 
 
   restricted pointers
-
+  N448
   Unknown
 
 
   variable length arrays
-
+  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n683.htm";>N683
   Yes
 
 
   flexible array members
-
+  Unknown
   Yes
 
 
   static and type qualifiers in parameter array declarators
-
+  Unknown
   Yes
 
 
   more precise aliasing rules via effective type
-
+  Unknown
   Unknown
 
-
-  complex and imaginary support in 
-
-  Unknown
+
+  complex and imaginary support in 
 
+  
+http://www.open-std.org/jtc1/sc22/wg14/www/docs/n620.ps";>N620
+Unknown
+  
+  
+http://www.open-std.org/jtc1/sc22/wg14/www/docs/n638.ps";>N638
+Unknown
+  
+  
+http://www.open-std.org/jtc1/sc22/wg14/www/docs/n657.ps";>N657
+Unknown
+  
+  
+http://www.open-std.org/jtc1/sc22/wg14/www/docs/n694.ps";>N694
+Unknown
+  
+  
+http://www.open-std.org/jtc1/sc22/wg14/www/docs/n809.ps";>N809
+Unknown
+  
 
   type-generic math macros in 
-
+  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n693.ps";>N693
   Yes
 
 
   the long long int type
-
+  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n601.ps";>N601
   Yes
 
 
   increase minimum translation limits
-
+  N590
   Unknown
 
 
   additional floating-point characteristics in 
-
+  Unknown
   Unknown
 
-
-  remove implicit int
-
-  Unknown
+
+  remove implicit int
 
+  
+http://www.open-std.org/jtc1/sc22/wg14/www/docs/n635.htm";>N635
+Yes
+  
+  
+http://www.open-std.org/jtc1/sc22/wg14/www/docs/n692.htm";>N692
+Yes
+  
+  
+http://www.open-std.org/jtc1/sc22/wg14/www/docs/n722.htm";>N722
+Yes
+  
 
   reliable integer division
-
+  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n617.htm";>N617
   Unknown
 
 
   universal character names (\u and \U)
-
+  Unknown
   Yes
 
 
   extended identifiers
-
+  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n717.htm";>N717
   Unknown
 
 
   hexadecimal floating-point constants
-
+  N308
+  
   Yes
 
 
   compound literals
-
+  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n716.htm";>N716
   Yes
 
 
   designated initializers
-
+  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n494.pdf";>N494
   Yes
 
 
   // comments
-
+  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n644.htm";>N644
   Yes
 
 
   extended integer types and library functions in  
and 
-
+  Unknown
+  
   Yes
  

[PATCH] D104285: [analyzer] Retrieve a value from list initialization of constant array declaration in a global scope.

2021-09-22 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1696-1697
+  const auto I = static_cast(Idx.getExtValue());
+  // Use `getZExtValue` because array extent can not be negative.
+  const uint64_t Extent = CAT->getSize().getZExtValue();
+  // Check for `Idx < 0`, NOT for `I < 0`, because `Idx` CAN be

martong wrote:
> Do you think it would make sense to `assert(CAT->getSize().isSigned())`?
`getSize` return `APInt` which is //signless// and has no `isSigned` method. 
But we know that an array extent shall be of type `std​::​size_­t` 
(http://eel.is/c++draft/dcl.array#1) which is //unsigned// 
(http://eel.is/c++draft/support.types.layout#3). So we can confidently get the 
size with `getZExtValue`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104285/new/

https://reviews.llvm.org/D104285

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104285: [analyzer] Retrieve a value from list initialization of constant array declaration in a global scope.

2021-09-22 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@martong
Thank you for your time!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104285/new/

https://reviews.llvm.org/D104285

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110089: [CUDA] Implement experimental support for texture lookups.

2021-09-22 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D110089#3014388 , @jlebar wrote:

>> One alternative would be to use run-time dispatch, but, given that texture 
>> lookup is a single instruction, the overhead would be 
>> substantial-to-prohibitive.
>
> I guess I'm confused...  Is the parameter value that we're "overloading" on 
> usually/always a constant?  In that case, there's no overhead with runtime 
> dispatch.  Or, is it not a constant?  In which case, how does nvcc generate a 
> single instruction for this idiom at all?

It's a string literal.  And you're actually right, clang does manage to 
optimize strcmp with a known value. https://godbolt.org/z/h351hfsMf

However, it's only part of the problem. Depending on which particular operation 
is used, the arguments vary, too. I still need to use templates that 
effectively need to be parameterized by that string literal argument and I 
can't easily do it until C++20.
I'd need to push strcmp-based runtime dispatch down to the implementation of 
the texture lookups with the same operand signature. That's harder to 
generalize, as I'd have to implement string-based dispatch for quite a few 
subsets of the operations -- basically for each variant of cartesian product of 
`{dimensionality, Lod, Level, Sparse}`.

Another downside is that the string comparison code will result in functions 
being much larger than necessary. Probably not a big thing overall, but why add 
overhead that would be paid for by all users and which does not buy us 
anything? Having one trivial compiler builtin that simplifies things a lot is a 
better trade-off, IMO.

> But then I see `switch` statements in the code, so now I'm extra confused.  :)

That switch is for a special case of texture lookup which may result in one of 
four texture instruction variants. All others map 1:1.

> Overall, I am unsure of why we need all of this magic.  We can rely on LLVM 
> to optimize away constant integer comparisons, and also even comparisons 
> between string literals.

It makes it possible to usa a string literal to parameterize templates, which 
allows to generate variants of `__nv_tex_surf_handler` in a relatively concise 
way.

> What specifically would be inefficient if this were a series of "real" 
> overloaded functions, with none of the macros, templates, or builtins?  
> (Assuming efficiency is the concern here?)

It's both efficiency and avoidance of typos in repetitive nearly identical 
code. 
There are ~2500 variants of high-level texture lookup variants. They end up 
calling about 600 different `__nv_tex_surf_handler` overloads that, in turn,  
end up generating ~70 unique inline assembly variants. 
The current code structure reflects that hierarchy. This is essentially the 
reason for the parameterization by the operation name happening early, instead 
of being used as a key for runtime dispatch at the end.




Comment at: clang/lib/AST/ExprConstant.cpp:11097
 
+static int EvaluateTextureOp(const CallExpr *E) {
+  // Sorted list of known operations stuuported by '__nv_tex_surf_handler'

jlebar wrote:
> Write a comment explaining what this function does?
> 
> (It seems to...translate a string into an integer?  If so, to me, it's 
> strange that it uses a sorted list for this because...what if I add another 
> function?  Won't that mess up all the numbers?  Anyway, to be clarified in 
> the comment.)
> 
> Now that I read more, I see that you don't care about this being a stable 
> mapping etc etc...
> 
> I don't really get why this has to be a builtin at all, though.  If it's 
> always a string literal, a simple strcmp will do the job, LLVM can optimize 
> this?  And I'm almost sure you can assert that the char* is always a string 
> literal, so you can guarantee that it's always optimized away.
Yes, it's just a 1:1 map.  We do not care about specific values as they only 
matter within one TU. I'll document that.

I can't easily use string literal to parameterize a template. 

Hmm. Perhaps I can implement a `constexpr perfect_hash(literal)` in a header. 
This would eliminate the need for the builtin.
E.g. https://godbolt.org/z/bzzMbaKhe

Let me give it a try.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110089/new/

https://reviews.llvm.org/D110089

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109951: [clang-format] Constructor initializer lists format with pp directives

2021-09-22 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109951/new/

https://reviews.llvm.org/D109951

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109658: [X86][FP16] Change the order of the operands in complex FMA intrinsics to allow swap between the mul operands.

2021-09-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Headers/avx512fp16intrin.h:2972
 #define _mm_mask_fcmadd_round_sch(A, U, B, C, R)   
\
   ((__m128h)__builtin_ia32_selectps_128(   
\
   (__mmask8)(U & 1),   
\

Why is this intrinsic written like this? We can't evaluate macro arguments like 
A and U twice. It can cause surprising results.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109658/new/

https://reviews.llvm.org/D109658

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103314: [Analyzer][solver] Simplify existing constraints when a new constraint is added

2021-09-22 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx added a comment.

I believe this commit exposed a new false-positive bug in [core.DivideZero].  
I've filed the report here: https://bugs.llvm.org/show_bug.cgi?id=51940


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103314/new/

https://reviews.llvm.org/D103314

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109951: [clang-format] Constructor initializer lists format with pp directives

2021-09-22 Thread Josh Learn via Phabricator via cfe-commits
guitard0g added a comment.

@MyDeveloperDay @HazardyKnusperkeks I don't have commit access, could one of 
you commit this for me? Thanks so much for your review!

Name: Josh Learn
Email: joshua_le...@apple.com

(The test failures seem to be unrelated, but I'm fine waiting until they start 
passing again if necessary)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109951/new/

https://reviews.llvm.org/D109951

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109967: Simplify handling of builtin with inline redefinition

2021-09-22 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 374290.
serge-sans-paille added a comment.

Set default as suggested by @nickdesaulniers


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109967/new/

https://reviews.llvm.org/D109967

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/memcpy-inline-builtin.c
  clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.c
  clang/test/CodeGen/memcpy-nobuiltin.c
  clang/test/CodeGen/pr9614.c

Index: clang/test/CodeGen/pr9614.c
===
--- clang/test/CodeGen/pr9614.c
+++ clang/test/CodeGen/pr9614.c
@@ -32,14 +32,14 @@
 
 // CHECK-LABEL: define{{.*}} void @f()
 // CHECK: call void @foo()
-// CHECK: call i32 @abs(i32 0)
+// CHECK: call i32 @abs(i32 %0)
 // CHECK: call i8* @strrchr(
 // CHECK: call void @llvm.prefetch.p0i8(
 // CHECK: call i8* @memchr(
 // CHECK: ret void
 
 // CHECK: declare void @foo()
-// CHECK: declare i32 @abs(i32
 // CHECK: declare i8* @strrchr(i8*, i32)
 // CHECK: declare i8* @memchr(
+// CHECK: declare i32 @abs(i32
 // CHECK: declare void @llvm.prefetch.p0i8(
Index: clang/test/CodeGen/memcpy-nobuiltin.c
===
--- clang/test/CodeGen/memcpy-nobuiltin.c
+++ clang/test/CodeGen/memcpy-nobuiltin.c
@@ -4,7 +4,8 @@
 //
 // CHECK-WITH-DECL-NOT: @llvm.memcpy
 // CHECK-NO-DECL: @llvm.memcpy
-// CHECK-SELF-REF-DECL: @llvm.memcpy
+// CHECK-SELF-REF-DECL-LABEL: define dso_local i8* @memcpy.inline
+// CHECK-SELF-REF-DECL:   @memcpy(
 //
 #include 
 void test(void *dest, void const *from, size_t n) {
Index: clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.c
===
--- clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.c
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - %s | FileCheck %s
-//
-// Verifies that clang doesn't mark an inline builtin definition as `nobuiltin`
-// if the builtin isn't emittable.
-
-typedef unsigned long size_t;
-
-// always_inline is used so clang will emit this body. Otherwise, we need >=
-// -O1.
-#define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) \
-__attribute__((gnu_inline))
-
-AVAILABLE_EXTERNALLY void *memcpy(void *a, const void *b, size_t c) {
-  return __builtin_memcpy(a, b, c);
-}
-
-// CHECK-LABEL: define{{.*}} void @foo
-void foo(void *a, const void *b, size_t c) {
-  // Clang will always _emit_ this as memcpy. LLVM turns it into @llvm.memcpy
-  // later on if optimizations are enabled.
-  // CHECK: call i8* @memcpy
-  memcpy(a, b, c);
-}
-
-// CHECK-NOT: nobuiltin
Index: clang/test/CodeGen/memcpy-inline-builtin.c
===
--- /dev/null
+++ clang/test/CodeGen/memcpy-inline-builtin.c
@@ -0,0 +1,44 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -o - %s | FileCheck %s
+//
+// Verifies that clang detects memcpy inline version and uses it instead of the builtin.
+
+typedef unsigned long size_t;
+
+// Clang requires these attributes for a function to be redefined.
+#define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) __attribute__((gnu_inline))
+
+// Clang recognizes an inline builtin and renames it to prevent conflict with builtins.
+AVAILABLE_EXTERNALLY void *memcpy(void *a, const void *b, size_t c) {
+  asm("# memcpy.inline marker");
+  return __builtin_memcpy(a, b, c);
+}
+
+// CHECK-LABEL: @foo(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR_I:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[B_ADDR_I:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[C_ADDR_I:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[C_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store i8* [[A:%.*]], i8** [[A_ADDR]], align 8
+// CHECK-NEXT:store i8* [[B:%.*]], i8** [[B_ADDR]], align 8
+// CHECK-NEXT:store i64 [[C:%.*]], i64* [[C_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8*, i8** [[A_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i8*, i8** [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP2:%.*]] = load i64, i64* [[C_ADDR]], align 8
+// CHECK-NEXT:store i8* [[TMP0]], i8** [[A_ADDR_I]], align 8
+// CHECK-NEXT:store i8* [[TMP1]], i8** [[B_ADDR_I]], align 8
+// CHECK-NEXT:store i64 [[TMP2]], i64* [[C_ADDR_I]], align 8
+// CHECK-NEXT:call void asm sideeffect "# memcpy.inline marker", "~{dirflag},~{fpsr},~{flags}"() #[[ATTR2:[0-9]+]], !srcloc !2
+// CHECK-NEXT:[[TMP3:%.*]] = load i8*, i8** [[A_ADDR_I]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = load i8*, i8** [[B_ADDR_I]], align 8
+// CHECK-NEXT:[[TMP5:%.*]] = load i64, i64* [[C_ADDR_I]], align 8
+// CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.

[PATCH] D36850: [ThinLTO] Add norecurse function attribute propagation

2021-09-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Thanks for your patience, finally had a chance to go through everything much 
more carefully. Looks good, mostly a bunch of small or nitpicky final 
suggestions. The main comment/question of significance relates to where 
hasUnknownCall is being set currently.

Patch title and summary need an update.




Comment at: clang/test/CodeGen/thinlto-funcattr-prop.ll:14
+
+; RUN: llvm-dis %t/b.bc -o - | FileCheck %s
+

This is checking the summary generated by opt, not the result of the llvm-lto2 
run.



Comment at: llvm/include/llvm/IR/ModuleSummaryIndex.h:575
 unsigned AlwaysInline : 1;
+unsigned NoUnwind : 1;
+// Indicate if function contains instructions that mayThrow

No Unwind needs a comment. And probably a note that it will be updated by 
function attr propagation. Depends on how we want to handle inline asm calls 
and other cases that currently set this true below (see my comment there).



Comment at: llvm/include/llvm/IR/ModuleSummaryIndex.h:580
+// If there are calls to unknown targets (e.g. indirect)
+unsigned hasUnknownCall : 1;
+

tejohnson wrote:
> modimo wrote:
> > tejohnson wrote:
> > > Now that we have MayThrow, can we avoid a separate hasUnknownCall bool 
> > > and just conservatively set MayThrow true in that case?
> > hasUnknownCall is used for norecurse and other future flags as well to stop 
> > propagation.
> Ah that makes sense.
nit, maybe change this to hasIndirectCall which I think is more specific?



Comment at: llvm/include/llvm/LTO/LTO.h:26
 #include "llvm/Support/thread.h"
+#include "llvm/Transforms/IPO/FunctionAttrs.h"
 #include "llvm/Transforms/IPO/FunctionImport.h"

Is this needed?



Comment at: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp:379
   } else {
+HasUnknownCall = true;
 // Skip inline assembly calls.

Should this be moved below the following checks for inline asm and direct 
calls? (Not sure what the direct calls case is given that we handle direct 
calls to "known functions" above though).

If it should stay where it is and treat the below cases as unknown, probably 
should add tests for them.



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:342
+// prevailing definitions and linkage types
+static FunctionSummary *calculateDefinitiveAttributes(
+ValueInfo VI, DenseMap &CachedAttributes,

Suggest renaming calculateDefinitiveAttributes and CachedAttributes to 
something like calculatePrevailingSummary and CachedPrevailingSummary which are 
more accurate now.



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:484
+if (!CalleeSummary->fflags().NoUnwind ||
+CallerSummary->fflags().MayThrow)
+  InferredFlags.NoUnwind = false;

You've already set InferredFlags.NoUnwind to false above this loop in the case 
where MayThrow was set on the CallerSummary.



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:499
+  ++NumThinLinkNoRecurse;
+  CachedAttributes[V]->setNoRecurse();
+}

I think you can remove this and the below setNoUnwind() call on 
CachedAttributes[V] since presumably this points to one of the function 
summaries we update in the below loop.



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:531
+
+/// Insert function attributes in the Index back into the \p TheModule
+void llvm::thinLTOInsertFunctionAttrsForModule(

nit: suggest "Insert propagated function attributes from the Index ..."



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:537
+
+  for (Function &F : TheModule) {
+const auto &GV = DefinedGlobals.find(F.getGUID());

Consider consolidating this function with thinLTOResolvePrevailingInModule, to 
reduce the number of walks of the module and lookups into the DefinedGlobals 
map.



Comment at: llvm/test/ThinLTO/X86/funcattrs-prop-indirect.ll:3
+; RUN: opt -thinlto-bc %s -thin-link-bitcode-file=%t1.thinlink.bc -o %t1.bc
+; RUN: llvm-lto2 run -disable-thinlto-funcattrs=0 %t1.bc -o %t.o -r 
%t1.bc,indirect,px -save-temps
+; RUN: llvm-dis -o - %t.o.1.3.import.bc | FileCheck %s

Have a second version that tests with -thinlto-funcattrs-optimistic-indirect? I 
don't see a test for that option anywhere. Or maybe just remove that option - 
is it really needed?



Comment at: llvm/test/ThinLTO/X86/funcattrs-prop-indirect.ll:9
+
+; CHECK-NOT: ; Function Attrs: norecurse nounwind
+; CHECK: define i32 @indirect(i32 ()* nocapture %0) {

Perhaps this CHECK-NOT should just look for "Function Attrs:" as you do in some 
other tests below, in case some other attr is ever added to the IR that isn't 
related to this propagation, which could all

[PATCH] D36850: [ThinLTO] Add norecurse function attribute propagation

2021-09-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/include/llvm/IR/ModuleSummaryIndex.h:575
 unsigned AlwaysInline : 1;
+unsigned NoUnwind : 1;
+// Indicate if function contains instructions that mayThrow

tejohnson wrote:
> No Unwind needs a comment. And probably a note that it will be updated by 
> function attr propagation. Depends on how we want to handle inline asm calls 
> and other cases that currently set this true below (see my comment there).
Woops, the second sentence here "Depends on how we want to handle inline asm 
calls and other cases that currently set this true below (see my comment 
there)." I meant to add to the comment further below about the name of 
hasUnknownCall.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D36850/new/

https://reviews.llvm.org/D36850

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] af99236 - Don't diagnose unused but set when the Cleanup attribute is used.

2021-09-22 Thread Michael Benfield via cfe-commits

Author: Michael Benfield
Date: 2021-09-22T17:48:09Z
New Revision: af99236747872af7e77092cbf6ddd18fa8623a2f

URL: 
https://github.com/llvm/llvm-project/commit/af99236747872af7e77092cbf6ddd18fa8623a2f
DIFF: 
https://github.com/llvm/llvm-project/commit/af99236747872af7e77092cbf6ddd18fa8623a2f.diff

LOG: Don't diagnose unused but set when the Cleanup attribute is used.

This applies to -Wunused-but-set-variable and
-Wunused-but-set-parameter.

This addresses bug 51865.

Differential Revision: https://reviews.llvm.org/D109862

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/warn-unused-but-set-variables.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index cc3417d4ccba..13389ebdd72f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1921,8 +1921,10 @@ void Sema::DiagnoseUnusedDecl(const NamedDecl *D) {
 }
 
 void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD) {
-  // If it's not referenced, it can't be set.
-  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr())
+  // If it's not referenced, it can't be set. If it has the Cleanup attribute,
+  // it's not really unused.
+  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr() ||
+  VD->hasAttr())
 return;
 
   const auto *Ty = VD->getType().getTypePtr()->getBaseElementTypeUnsafe();

diff  --git a/clang/test/Sema/warn-unused-but-set-variables.c 
b/clang/test/Sema/warn-unused-but-set-variables.c
index a8d05243321f..38042ba014c4 100644
--- a/clang/test/Sema/warn-unused-but-set-variables.c
+++ b/clang/test/Sema/warn-unused-but-set-variables.c
@@ -49,3 +49,13 @@ void f2 (void) {
   x = 0;
   (void) sizeof(x);
 }
+
+void for_cleanup(int *x) {
+  *x = 0;
+}
+
+void f3(void) {
+  // Don't warn if the __cleanup__ attribute is used.
+  __attribute__((__cleanup__(for_cleanup))) int x;
+  x = 5;
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109862: Don't diagnose unused but set when the Cleanup attribute is used.

2021-09-22 Thread Michael Benfield via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf9923674787: Don't diagnose unused but set when the 
Cleanup attribute is used. (authored by mbenfield).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109862/new/

https://reviews.llvm.org/D109862

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/warn-unused-but-set-variables.c


Index: clang/test/Sema/warn-unused-but-set-variables.c
===
--- clang/test/Sema/warn-unused-but-set-variables.c
+++ clang/test/Sema/warn-unused-but-set-variables.c
@@ -49,3 +49,13 @@
   x = 0;
   (void) sizeof(x);
 }
+
+void for_cleanup(int *x) {
+  *x = 0;
+}
+
+void f3(void) {
+  // Don't warn if the __cleanup__ attribute is used.
+  __attribute__((__cleanup__(for_cleanup))) int x;
+  x = 5;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1921,8 +1921,10 @@
 }
 
 void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD) {
-  // If it's not referenced, it can't be set.
-  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr())
+  // If it's not referenced, it can't be set. If it has the Cleanup attribute,
+  // it's not really unused.
+  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr() ||
+  VD->hasAttr())
 return;
 
   const auto *Ty = VD->getType().getTypePtr()->getBaseElementTypeUnsafe();


Index: clang/test/Sema/warn-unused-but-set-variables.c
===
--- clang/test/Sema/warn-unused-but-set-variables.c
+++ clang/test/Sema/warn-unused-but-set-variables.c
@@ -49,3 +49,13 @@
   x = 0;
   (void) sizeof(x);
 }
+
+void for_cleanup(int *x) {
+  *x = 0;
+}
+
+void f3(void) {
+  // Don't warn if the __cleanup__ attribute is used.
+  __attribute__((__cleanup__(for_cleanup))) int x;
+  x = 5;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1921,8 +1921,10 @@
 }
 
 void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD) {
-  // If it's not referenced, it can't be set.
-  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr())
+  // If it's not referenced, it can't be set. If it has the Cleanup attribute,
+  // it's not really unused.
+  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr() ||
+  VD->hasAttr())
 return;
 
   const auto *Ty = VD->getType().getTypePtr()->getBaseElementTypeUnsafe();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110255: Change error for storage-class to mean linkage, fix lang-linkage diag

2021-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110255/new/

https://reviews.llvm.org/D110255

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 97b2f20 - Change error for storage-class to mean linkage, fix lang-linkage diag

2021-09-22 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2021-09-22T10:51:05-07:00
New Revision: 97b2f20a446e54f4354d8f950dfab62c37e6ddf4

URL: 
https://github.com/llvm/llvm-project/commit/97b2f20a446e54f4354d8f950dfab62c37e6ddf4
DIFF: 
https://github.com/llvm/llvm-project/commit/97b2f20a446e54f4354d8f950dfab62c37e6ddf4.diff

LOG: Change error for storage-class to mean linkage, fix lang-linkage diag

Allow multiversioning declarations to match when the actual formal
linkage matches, not just when the storage class is identical.
Additionally, change the ambiguous 'linkage' mismatch to be more
specific and say 'language linkage'.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/attr-cpuspecific.cpp
clang/test/SemaCXX/attr-target-mv.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3cadd986b8ae..0e803ee028ce 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11208,8 +11208,8 @@ def err_multiversion_mismatched_attrs
 "%0 %select{is missing|has 
diff erent arguments}1">;
 def err_multiversion_
diff  : Error<
   "multiversioned function declaration has a 
diff erent %select{calling convention"
-  "|return type|constexpr specification|inline specification|storage class|"
-  "linkage}0">;
+  "|return type|constexpr specification|inline specification|linkage|"
+  "language linkage}0">;
 def err_multiversion_doesnt_support : Error<
   "attribute '%select{target|cpu_specific|cpu_dispatch}0' multiversioned 
functions do not "
   "yet support %select{function templates|virtual functions|"

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 13389ebdd72f..79080098026c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10322,8 +10322,8 @@ bool Sema::areMultiversionVariantFunctionsCompatible(
 ReturnType = 1,
 ConstexprSpec = 2,
 InlineSpec = 3,
-StorageClass = 4,
-Linkage = 5,
+Linkage = 4,
+LanguageLinkage = 5,
   };
 
   if (NoProtoDiagID.getDiagID() != 0 && OldFD &&
@@ -10397,11 +10397,11 @@ bool Sema::areMultiversionVariantFunctionsCompatible(
 if (OldFD->isInlineSpecified() != NewFD->isInlineSpecified())
   return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << InlineSpec;
 
-if (OldFD->getStorageClass() != NewFD->getStorageClass())
-  return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << StorageClass;
+if (OldFD->getFormalLinkage() != NewFD->getFormalLinkage())
+  return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << Linkage;
 
 if (!CLinkageMayDiffer && OldFD->isExternC() != NewFD->isExternC())
-  return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << Linkage;
+  return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << LanguageLinkage;
 
 if (CheckEquivalentExceptionSpec(
 OldFD->getType()->getAs(), OldFD->getLocation(),

diff  --git a/clang/test/SemaCXX/attr-cpuspecific.cpp 
b/clang/test/SemaCXX/attr-cpuspecific.cpp
index 861711b46383..fe4635816654 100644
--- a/clang/test/SemaCXX/attr-cpuspecific.cpp
+++ b/clang/test/SemaCXX/attr-cpuspecific.cpp
@@ -34,9 +34,19 @@ int __attribute__((cpu_specific(sandybridge))) foo2(void);
 constexpr int __attribute__((cpu_specific(ivybridge))) foo2(void);
 
 static int __attribute__((cpu_specific(sandybridge))) bar(void);
-//expected-error@+1 {{multiversioned function declaration has a 
diff erent storage class}}
+//expected-error@+1 {{multiversioned function declaration has a 
diff erent linkage}}
 int __attribute__((cpu_dispatch(ivybridge))) bar(void) {}
 
+// OK
+extern int __attribute__((cpu_specific(sandybridge))) bar2(void);
+int __attribute__((cpu_dispatch(ivybridge))) bar2(void) {}
+
+namespace {
+int __attribute__((cpu_specific(sandybridge))) bar3(void);
+static int __attribute__((cpu_dispatch(ivybridge))) bar3(void) {}
+}
+
+
 inline int __attribute__((cpu_specific(sandybridge))) baz(void);
 //expected-error@+1 {{multiversioned function declaration has a 
diff erent inline specification}}
 int __attribute__((cpu_specific(ivybridge))) baz(void) {return 1;}
@@ -74,7 +84,7 @@ struct S {
 extern "C" {
 int __attribute__((cpu_specific(atom))) 
diff _mangle(void) { return 0; }
 }
-//expected-error@+1 {{multiversioned function declaration has a 
diff erent linkage}}
+//expected-error@+1 {{multiversioned function declaration has a 
diff erent language linkage}}
 int __attribute__((cpu_specific(sandybridge))) 
diff _mangle(void) { return 0; }
 
 __attribute__((cpu_specific(atom))) void DiffDecl();

diff  --git a/clang/test/SemaCXX/attr-target-mv.cpp 
b/clang/test/SemaCXX/attr-target-mv.cpp
index 5ef1d398d2d8..5b2f0fc825f3 100644
--- a/clang/test/SemaCXX/attr-target-mv.cpp
+++ b/clang/test/SemaCXX/attr-target-mv.cpp
@@ -27,17 +27,26 @

[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-09-22 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 374294.
MyDeveloperDay marked 3 inline comments as done.
MyDeveloperDay added a comment.

Remove use of Typenamemacros (we'll solve this a different way later)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69764/new/

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -0,0 +1,879 @@
+//===- unittest/Format/QualifierFixerTest.cpp - Formatting unit tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "FormatTestUtils.h"
+#include "TestLexer.h"
+#include "gtest/gtest.h"
+
+#include "../../lib/Format/QualifierAlignmentFixer.h"
+
+#define DEBUG_TYPE "format-qualifier-fixer-test"
+
+using testing::ScopedTrace;
+
+namespace clang {
+namespace format {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class QualifierFixerTest : public ::testing::Test {
+protected:
+  enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
+
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+
+  std::string format(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ StatusCheck CheckComplete = SC_ExpectComplete) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(0, Code.size()));
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, Ranges, "", &Status);
+if (CheckComplete != SC_DoNotCheck) {
+  bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
+  EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
+  << Code << "\n\n";
+}
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
+Style.ColumnLimit = ColumnLimit;
+return Style;
+  }
+
+  FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style));
+if (Style.Language == FormatStyle::LK_Cpp) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+_verifyFormat(File, Line, Code, test::messUp(Code), Style);
+  }
+
+  void _verifyIncompleteFormat(const char *File, int Line, llvm::StringRef Code,
+   const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() <

[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-09-22 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 374298.
MyDeveloperDay added a comment.

Use better vector initialization


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69764/new/

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -0,0 +1,809 @@
+//===- unittest/Format/QualifierFixerTest.cpp - Formatting unit tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "FormatTestUtils.h"
+#include "TestLexer.h"
+#include "gtest/gtest.h"
+
+#include "../../lib/Format/QualifierAlignmentFixer.h"
+
+#define DEBUG_TYPE "format-qualifier-fixer-test"
+
+using testing::ScopedTrace;
+
+namespace clang {
+namespace format {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class QualifierFixerTest : public ::testing::Test {
+protected:
+  enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
+
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+
+  std::string format(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ StatusCheck CheckComplete = SC_ExpectComplete) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(0, Code.size()));
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, Ranges, "", &Status);
+if (CheckComplete != SC_DoNotCheck) {
+  bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
+  EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
+  << Code << "\n\n";
+}
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
+Style.ColumnLimit = ColumnLimit;
+return Style;
+  }
+
+  FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style));
+if (Style.Language == FormatStyle::LK_Cpp) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+_verifyFormat(File, Line, Code, test::messUp(Code), Style);
+  }
+
+  void _verifyIncompleteFormat(const char *File, int Line, llvm::StringRef Code,
+   const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Code.str(),
+  format(test::messUp(Code), St

[PATCH] D110273: [PowerPC] Fix lharx and lbarx builtin signatures

2021-09-22 Thread Albion Fung via Phabricator via cfe-commits
Conanap created this revision.
Conanap added reviewers: PowerPC, nemanjai, stefanp, saghir.
Conanap added projects: clang, LLVM, PowerPC.
Herald added subscribers: steven.zhang, kbarton.
Conanap requested review of this revision.

The signatures for the PowerPC builtins `lharx` and
`lbarx` are incorrect, and causes issues when in a function
that requiers the return of the builtin to be promoted.
This patch fixes these signatures.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110273

Files:
  clang/include/clang/Basic/BuiltinsPPC.def


Index: clang/include/clang/Basic/BuiltinsPPC.def
===
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -74,8 +74,8 @@
 BUILTIN(__builtin_ppc_fetch_and_swaplp, "ULiULiD*ULi", "")
 BUILTIN(__builtin_ppc_ldarx, "LiLiD*", "")
 BUILTIN(__builtin_ppc_lwarx, "iiD*", "")
-BUILTIN(__builtin_ppc_lharx, "isD*", "")
-BUILTIN(__builtin_ppc_lbarx, "UiUcD*", "")
+BUILTIN(__builtin_ppc_lharx, "ssD*", "")
+BUILTIN(__builtin_ppc_lbarx, "ccD*", "")
 BUILTIN(__builtin_ppc_stdcx, "iLiD*Li", "")
 BUILTIN(__builtin_ppc_stwcx, "iiD*i", "")
 BUILTIN(__builtin_ppc_sthcx, "isD*s", "")


Index: clang/include/clang/Basic/BuiltinsPPC.def
===
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -74,8 +74,8 @@
 BUILTIN(__builtin_ppc_fetch_and_swaplp, "ULiULiD*ULi", "")
 BUILTIN(__builtin_ppc_ldarx, "LiLiD*", "")
 BUILTIN(__builtin_ppc_lwarx, "iiD*", "")
-BUILTIN(__builtin_ppc_lharx, "isD*", "")
-BUILTIN(__builtin_ppc_lbarx, "UiUcD*", "")
+BUILTIN(__builtin_ppc_lharx, "ssD*", "")
+BUILTIN(__builtin_ppc_lbarx, "ccD*", "")
 BUILTIN(__builtin_ppc_stdcx, "iLiD*Li", "")
 BUILTIN(__builtin_ppc_stwcx, "iiD*i", "")
 BUILTIN(__builtin_ppc_sthcx, "isD*s", "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 38c09ea - DebugInfo: Add (initially no-op) -gsimple-template-names={simple,mangled}

2021-09-22 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-09-22T11:11:49-07:00
New Revision: 38c09ea2d279eabe3602e2002f8cdfcc5380

URL: 
https://github.com/llvm/llvm-project/commit/38c09ea2d279eabe3602e2002f8cdfcc5380
DIFF: 
https://github.com/llvm/llvm-project/commit/38c09ea2d279eabe3602e2002f8cdfcc5380.diff

LOG: DebugInfo: Add (initially no-op) -gsimple-template-names={simple,mangled}

This is to build the foundation of a new debug info feature to use only
the base name of template as its debug info name (eg: "t1" instead of
the full "t1"). The intent being that a consumer can still retrieve
all that information from the DW_TAG_template_*_parameters.

So gno-simple-template-names is business as usual/previously ("t1")
   =simple is the simplified name ("t1")
   =mangled is a special mode to communicate the full information, but
   also indicate that the name should be able to be simplified. The data
   is encoded as "_STNt1|" which will be matched with an
   llvm-dwarfdump --verify feature to deconstruct this name, rebuild the
   original name, and then try to rebuild the simple name via the DWARF
   tags - then compare the latter and the former to ensure that all the
   data necessary to fully rebuild the name is present.

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/DebugInfoOptions.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/debug-options.c

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 37900bf3ead1..5d1d4f9dc58e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -320,6 +320,12 @@ CODEGENOPT(DebugFwdTemplateParams, 1, 0) ///< Whether to 
emit complete
  ///< template parameter descriptions 
in
  ///< forward declarations (versus just
  ///< including them in the name).
+ENUM_CODEGENOPT(DebugSimpleTemplateNames, 
codegenoptions::DebugTemplateNamesKind, 2, 
codegenoptions::DebugTemplateNamesKind::Full) ///< Whether to emit template 
parameters
+   ///< in the textual names of 
template
+  ///< specializations.
+  ///< Implies DebugFwdTemplateNames to
+  ///< allow decorated names to be
+  ///< reconstructed when needed.
 CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists.
 
 CODEGENOPT(WholeProgramVTables, 1, 0) ///< Whether to apply whole-program

diff  --git a/clang/include/clang/Basic/DebugInfoOptions.h 
b/clang/include/clang/Basic/DebugInfoOptions.h
index c1259d7797db..a99a2b5903d7 100644
--- a/clang/include/clang/Basic/DebugInfoOptions.h
+++ b/clang/include/clang/Basic/DebugInfoOptions.h
@@ -54,6 +54,12 @@ enum DebugInfoKind {
   UnusedTypeInfo,
 };
 
+enum class DebugTemplateNamesKind {
+  Full,
+  Simple,
+  Mangled
+};
+
 } // end namespace codegenoptions
 } // end namespace clang
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f0932a0bd1de..13d740cdb0fb 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2967,6 +2967,15 @@ def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, 
Group,
   HelpText<"Set DWARF fission mode to either 'split' or 'single'">,
   Values<"split,single">;
 def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">, Group;
+def gsimple_template_names : Flag<["-"], "gsimple-template-names">, 
Group;
+def gsimple_template_names_EQ
+: Joined<["-"], "gsimple-template-names=">,
+  Group,
+  HelpText<"Use simple template names in DWARF, or include the full "
+   "template name with a modified prefix for validation">,
+  Values<"simple,mangled">, Flags<[CC1Option]>;
+def gno_simple_template_names : Flag<["-"], "gno-simple-template-names">,
+Group;
 def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, 
Flags<[CC1Option]>;
 def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group;
 def gpubnames : Flag<["-"], "gpubnames">, Group, 
Flags<[CC1Option]>;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index e6742c6575b9..6c7b8bbcaad7 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4128,6 +4128,29 @@ static void renderDebugOptions(const ToolChain &TC, 
const Driver &D,
options::OPT_gpubnames)
 ? "-gpubnames"
 : "-g

[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:102-106
+  auto *EBB = AllocaInsertPt->getParent();
+  auto Iter = AllocaInsertPt->getIterator();
+  if (Iter != EBB->end())
+++Iter;
+  Builder.SetInsertPoint(EBB, Iter);

hsmhsm wrote:
> arsenm wrote:
> > Where are the addrspacecasts inserted? Could you just adjust where those 
> > are inserted instead?
> The addressspace casts are inserted immediately after all static allocas (top 
> static alloca cluster).
> 
> An example:
> 
> Before this patch:
> 
> ```
> entry:
>   %N.addr = alloca i64, align 8, addrspace(5)
>   %N.addr.ascast = addrspacecast i64 addrspace(5)* %N.addr to i64*
>   %vla.addr = alloca i64, align 8, addrspace(5)
>   %vla.addr.ascast = addrspacecast i64 addrspace(5)* %vla.addr to i64*
>   %a.addr = alloca i32*, align 8, addrspace(5)
>   %a.addr.ascast = addrspacecast i32* addrspace(5)* %a.addr to i32**
>   %vla.addr2 = alloca i64, align 8, addrspace(5)
>   %vla.addr2.ascast = addrspacecast i64 addrspace(5)* %vla.addr2 to i64*
>   %b.addr = alloca i32*, align 8, addrspace(5)
>   %b.addr.ascast = addrspacecast i32* addrspace(5)* %b.addr to i32**
>   %N.casted = alloca i64, align 8, addrspace(5)
>   %N.casted.ascast = addrspacecast i64 addrspace(5)* %N.casted to i64*
>   %.zero.addr = alloca i32, align 4, addrspace(5)
>   %.zero.addr.ascast = addrspacecast i32 addrspace(5)* %.zero.addr to i32*
>   %.threadid_temp. = alloca i32, align 4, addrspace(5)
>   %.threadid_temp..ascast = addrspacecast i32 addrspace(5)* %.threadid_temp. 
> to i32*  
>   store i64 %N, i64* %N.addr.ascast, align 8
> ```
> 
> With this patch:
> 
> ```
> entry:
>   %N.addr = alloca i64, align 8, addrspace(5)
>   %vla.addr = alloca i64, align 8, addrspace(5)
>   %a.addr = alloca i32*, align 8, addrspace(5)
>   %vla.addr2 = alloca i64, align 8, addrspace(5)
>   %b.addr = alloca i32*, align 8, addrspace(5)
>   %N.casted = alloca i64, align 8, addrspace(5)
>   %.zero.addr = alloca i32, align 4, addrspace(5)
>   %.threadid_temp. = alloca i32, align 4, addrspace(5)
>   %.threadid_temp..ascast = addrspacecast i32 addrspace(5)* %.threadid_temp. 
> to i32*
>   %.zero.addr.ascast = addrspacecast i32 addrspace(5)* %.zero.addr to i32*
>   %N.casted.ascast = addrspacecast i64 addrspace(5)* %N.casted to i64*
>   %b.addr.ascast = addrspacecast i32* addrspace(5)* %b.addr to i32**
>   %vla.addr2.ascast = addrspacecast i64 addrspace(5)* %vla.addr2 to i64*
>   %a.addr.ascast = addrspacecast i32* addrspace(5)* %a.addr to i32**
>   %vla.addr.ascast = addrspacecast i64 addrspace(5)* %vla.addr to i64*
>   %N.addr.ascast = addrspacecast i64 addrspace(5)* %N.addr to i64*
>   store i64 %N, i64* %N.addr.ascast, align 8
> ```
I meant where in the clang code are these emitted, and how is that I set point 
found?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110257/new/

https://reviews.llvm.org/D110257

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110273: [PowerPC] Fix lharx and lbarx builtin signatures

2021-09-22 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

The description says it causes issues but there is no test case. Please add the 
test case that causes issues.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110273/new/

https://reviews.llvm.org/D110273

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a subscriber: rnk.
jdoerfert added a comment.

In D110257#3015712 , @jdoerfert wrote:

> In D110257#3015641 , @hsmhsm wrote:
>
>> In D110257#3015553 , @arsenm wrote:
>>
>>> I do think it's cleaner/more canonical IR to cluster these at the top of 
>>> the block, but I don't understand this comment:
>>>
 otherwise, inliner's attempt to move static allocas from callee to caller 
 will fail,
>>>
>>> The inliner successfully moves allocas to the caller's entry block, even 
>>> with addrspacecasts interspersed.
>>
>> The logic at 
>> https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/InlineFunction.cpp#L2093
>>  assumes that static allocas (within callee) are contiguous.
>
> True. Even worse. It will bail if a static alloca is used as an `inalloca` 
> argument.
> So, if you now interleave allocas that may be used in `inalloca` you also 
> break the "canonical form". 
> I assume this hits mostly windows but still.

@rnk This might be of interest to you. Any thoughts?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110257/new/

https://reviews.llvm.org/D110257

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110276: Clean up large copies of binaries copied into temp directories in tests

2021-09-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added reviewers: thakis, scott.linder.
tejohnson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In looking at the disk space used by a ninja check-all, I found that a
few of the largest files were copies of clang and lld made into temp
directories by a couple of tests. These tests were added in D53021 
 and
D74811 . Clean up these copies after usage.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110276

Files:
  clang/test/Driver/clang_f_opts.c
  lld/test/COFF/pdb-relative-source-lines.test


Index: lld/test/COFF/pdb-relative-source-lines.test
===
--- lld/test/COFF/pdb-relative-source-lines.test
+++ lld/test/COFF/pdb-relative-source-lines.test
@@ -41,6 +41,9 @@
 RUN: ./lld-link -debug -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb 
pdb_lines_1_relative.obj pdb_lines_2_relative.obj
 RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms 
-subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=ABSOLUTE %s
 
+Clean up copy of large binary copied into temp directory to avoid bloat.
+RUN: rm ./lld-link
+
 CHECK-LABEL:  - Module:  'c:\src\pdb_lines_1_relative.obj'
 CHECK-NEXT: ObjFile: 'c:\src\pdb_lines_1_relative.obj'
 CHECK:  SourceFiles:
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -565,6 +565,8 @@
 // RUN: cp %clang "%t.r/with spaces/clang"
 // RUN: "%t.r/with spaces/clang" -### -S -target x86_64-unknown-linux 
-frecord-gcc-switches %s 2>&1 | FileCheck 
-check-prefix=CHECK-RECORD-GCC-SWITCHES-ESCAPED %s
 // CHECK-RECORD-GCC-SWITCHES-ESCAPED: "-record-command-line" "{{.+}}with\\ 
spaces{{.+}}"
+// Clean up copy of large binary copied into temp directory to avoid bloat.
+// RUN: rm "%t.r/with spaces/clang"
 
 // RUN: %clang -### -S -ftrivial-auto-var-init=uninitialized %s 2>&1 | 
FileCheck -check-prefix=CHECK-TRIVIAL-UNINIT %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=pattern %s 2>&1 | FileCheck 
-check-prefix=CHECK-TRIVIAL-PATTERN %s


Index: lld/test/COFF/pdb-relative-source-lines.test
===
--- lld/test/COFF/pdb-relative-source-lines.test
+++ lld/test/COFF/pdb-relative-source-lines.test
@@ -41,6 +41,9 @@
 RUN: ./lld-link -debug -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj
 RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=ABSOLUTE %s
 
+Clean up copy of large binary copied into temp directory to avoid bloat.
+RUN: rm ./lld-link
+
 CHECK-LABEL:  - Module:  'c:\src\pdb_lines_1_relative.obj'
 CHECK-NEXT: ObjFile: 'c:\src\pdb_lines_1_relative.obj'
 CHECK:  SourceFiles:
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -565,6 +565,8 @@
 // RUN: cp %clang "%t.r/with spaces/clang"
 // RUN: "%t.r/with spaces/clang" -### -S -target x86_64-unknown-linux -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ESCAPED %s
 // CHECK-RECORD-GCC-SWITCHES-ESCAPED: "-record-command-line" "{{.+}}with\\ spaces{{.+}}"
+// Clean up copy of large binary copied into temp directory to avoid bloat.
+// RUN: rm "%t.r/with spaces/clang"
 
 // RUN: %clang -### -S -ftrivial-auto-var-init=uninitialized %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-UNINIT %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=pattern %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-PATTERN %s
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >