[llvm-branch-commits] [clang] release/20.x: [clang-format] Handle Java text blocks (#141334) (PR #141433)

2025-05-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (llvmbot)


Changes

Backport b7f5950bb3b97eac979925a3bbf015530c26962e

Requested by: @owenca

---
Full diff: https://github.com/llvm/llvm-project/pull/141433.diff


3 Files Affected:

- (modified) clang/lib/Format/FormatTokenLexer.cpp (+32) 
- (modified) clang/lib/Format/FormatTokenLexer.h (+2) 
- (modified) clang/unittests/Format/FormatTestJava.cpp (+57) 


``diff
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 16f0a76f3a954..d8ad3a1d52115 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -636,6 +636,36 @@ bool FormatTokenLexer::canPrecedeRegexLiteral(FormatToken 
*Prev) {
   return true;
 }
 
+void FormatTokenLexer::tryParseJavaTextBlock() {
+  if (FormatTok->TokenText != "\"\"")
+return;
+
+  const auto *S = Lex->getBufferLocation();
+  const auto *End = Lex->getBuffer().end();
+
+  if (S == End || *S != '\"')
+return;
+
+  ++S; // Skip the `"""` that begins a text block.
+
+  // Find the `"""` that ends the text block.
+  for (int Count = 0; Count < 3 && S < End; ++S) {
+switch (*S) {
+case '\\':
+  Count = -1;
+  break;
+case '\"':
+  ++Count;
+  break;
+default:
+  Count = 0;
+}
+  }
+
+  // Ignore the possibly invalid text block.
+  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(S)));
+}
+
 // Tries to parse a JavaScript Regex literal starting at the current token,
 // if that begins with a slash and is in a location where JavaScript allows
 // regex literals. Changes the current token to a regex literal and updates
@@ -1326,6 +1356,8 @@ FormatToken *FormatTokenLexer::getNextToken() {
 FormatTok->TokenText = FormatTok->TokenText.substr(0, 1);
 ++Column;
 StateStack.push(LexerState::TOKEN_STASHED);
+  } else if (Style.isJava() && FormatTok->is(tok::string_literal)) {
+tryParseJavaTextBlock();
   }
 
   if (Style.isVerilog() && Tokens.size() > 0 &&
diff --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 61474a3f9ada8..d9a25c8ef3538 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -71,6 +71,8 @@ class FormatTokenLexer {
 
   bool canPrecedeRegexLiteral(FormatToken *Prev);
 
+  void tryParseJavaTextBlock();
+
   // Tries to parse a JavaScript Regex literal starting at the current token,
   // if that begins with a slash and is in a location where JavaScript allows
   // regex literals. Changes the current token to a regex literal and updates
diff --git a/clang/unittests/Format/FormatTestJava.cpp 
b/clang/unittests/Format/FormatTestJava.cpp
index 33998bc7ff858..d0a3b4eb96d69 100644
--- a/clang/unittests/Format/FormatTestJava.cpp
+++ b/clang/unittests/Format/FormatTestJava.cpp
@@ -789,6 +789,63 @@ TEST_F(FormatTestJava, AlignCaseArrows) {
Style);
 }
 
+TEST_F(FormatTestJava, TextBlock) {
+  verifyNoChange("String myStr = \"\"\"\n"
+ "hello\n"
+ "there\n"
+ "\"\"\";");
+
+  verifyNoChange("String tb = \"\"\"\n"
+ "the new\"\"\";");
+
+  verifyNoChange("System.out.println(\"\"\"\n"
+ "This is the first line\n"
+ "This is the second line\n"
+ "\"\"\");");
+
+  verifyNoChange("void writeHTML() {\n"
+ "  String html = \"\"\" \n"
+ "\n"
+ "Hello World.\n"
+ "\n"
+ "\"\"\";\n"
+ "  writeOutput(html);\n"
+ "}");
+
+  verifyNoChange("String colors = \"\"\"\t\n"
+ "red\n"
+ "green\n"
+ "blue\"\"\".indent(4);");
+
+  verifyNoChange("String code = \"\"\"\n"
+ "String source = \\\"\"\"\n"
+ "String message = \"Hello, World!\";\n"
+ "System.out.println(message);\n"
+ "\\\"\"\";\n"
+ "\"\"\";");
+
+  verifyNoChange(
+  "class Outer {\n"
+  "  void printPoetry() {\n"
+  "String lilacs = \"\"\"\n"
+  "Passing the apple-tree blows of white and pink in the orchards\n"
+  "\"\"\";\n"
+  "System.out.println(lilacs);\n"
+  "  }\n"
+  "}");
+
+  verifyNoChange("String name = \"\"\"\r\n"
+ "red\n"
+ "green\n"
+ "blue\\\n"
+ "\"\"\";");
+
+  verifyFormat("String name = \"\"\"Pat Q. Smith\"\"\";");
+
+  verifyNoChange("String name = \"\"\"\n"
+ "  Pat Q. Smith");
+}
+
 } // namespace
 } // namespace test
 } // namespace format

``




https://github.com/llvm/llvm-project/pull/141433
___
llvm-branch-commits mailing lis

[llvm-branch-commits] [clang] release/20.x: [clang-format] Handle Java text blocks (#141334) (PR #141433)

2025-05-25 Thread Owen Pan via llvm-branch-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/141433

>From d32d17a56f6d53cebc6299c0474fc95abeb141ed Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 25 May 2025 15:40:45 -0700
Subject: [PATCH 1/2] [clang-format] Handle Java text blocks (#141334)

Fix #61954

(cherry picked from commit b7f5950bb3b97eac979925a3bbf015530c26962e)
---
 clang/lib/Format/FormatTokenLexer.cpp | 32 +
 clang/lib/Format/FormatTokenLexer.h   |  2 +
 clang/unittests/Format/FormatTestJava.cpp | 57 +++
 3 files changed, 91 insertions(+)

diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 16f0a76f3a954..d8ad3a1d52115 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -636,6 +636,36 @@ bool FormatTokenLexer::canPrecedeRegexLiteral(FormatToken 
*Prev) {
   return true;
 }
 
+void FormatTokenLexer::tryParseJavaTextBlock() {
+  if (FormatTok->TokenText != "\"\"")
+return;
+
+  const auto *S = Lex->getBufferLocation();
+  const auto *End = Lex->getBuffer().end();
+
+  if (S == End || *S != '\"')
+return;
+
+  ++S; // Skip the `"""` that begins a text block.
+
+  // Find the `"""` that ends the text block.
+  for (int Count = 0; Count < 3 && S < End; ++S) {
+switch (*S) {
+case '\\':
+  Count = -1;
+  break;
+case '\"':
+  ++Count;
+  break;
+default:
+  Count = 0;
+}
+  }
+
+  // Ignore the possibly invalid text block.
+  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(S)));
+}
+
 // Tries to parse a JavaScript Regex literal starting at the current token,
 // if that begins with a slash and is in a location where JavaScript allows
 // regex literals. Changes the current token to a regex literal and updates
@@ -1326,6 +1356,8 @@ FormatToken *FormatTokenLexer::getNextToken() {
 FormatTok->TokenText = FormatTok->TokenText.substr(0, 1);
 ++Column;
 StateStack.push(LexerState::TOKEN_STASHED);
+  } else if (Style.isJava() && FormatTok->is(tok::string_literal)) {
+tryParseJavaTextBlock();
   }
 
   if (Style.isVerilog() && Tokens.size() > 0 &&
diff --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 61474a3f9ada8..d9a25c8ef3538 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -71,6 +71,8 @@ class FormatTokenLexer {
 
   bool canPrecedeRegexLiteral(FormatToken *Prev);
 
+  void tryParseJavaTextBlock();
+
   // Tries to parse a JavaScript Regex literal starting at the current token,
   // if that begins with a slash and is in a location where JavaScript allows
   // regex literals. Changes the current token to a regex literal and updates
diff --git a/clang/unittests/Format/FormatTestJava.cpp 
b/clang/unittests/Format/FormatTestJava.cpp
index 33998bc7ff858..d0a3b4eb96d69 100644
--- a/clang/unittests/Format/FormatTestJava.cpp
+++ b/clang/unittests/Format/FormatTestJava.cpp
@@ -789,6 +789,63 @@ TEST_F(FormatTestJava, AlignCaseArrows) {
Style);
 }
 
+TEST_F(FormatTestJava, TextBlock) {
+  verifyNoChange("String myStr = \"\"\"\n"
+ "hello\n"
+ "there\n"
+ "\"\"\";");
+
+  verifyNoChange("String tb = \"\"\"\n"
+ "the new\"\"\";");
+
+  verifyNoChange("System.out.println(\"\"\"\n"
+ "This is the first line\n"
+ "This is the second line\n"
+ "\"\"\");");
+
+  verifyNoChange("void writeHTML() {\n"
+ "  String html = \"\"\" \n"
+ "\n"
+ "Hello World.\n"
+ "\n"
+ "\"\"\";\n"
+ "  writeOutput(html);\n"
+ "}");
+
+  verifyNoChange("String colors = \"\"\"\t\n"
+ "red\n"
+ "green\n"
+ "blue\"\"\".indent(4);");
+
+  verifyNoChange("String code = \"\"\"\n"
+ "String source = \\\"\"\"\n"
+ "String message = \"Hello, World!\";\n"
+ "System.out.println(message);\n"
+ "\\\"\"\";\n"
+ "\"\"\";");
+
+  verifyNoChange(
+  "class Outer {\n"
+  "  void printPoetry() {\n"
+  "String lilacs = \"\"\"\n"
+  "Passing the apple-tree blows of white and pink in the orchards\n"
+  "\"\"\";\n"
+  "System.out.println(lilacs);\n"
+  "  }\n"
+  "}");
+
+  verifyNoChange("String name = \"\"\"\r\n"
+ "red\n"
+ "green\n"
+ "blue\\\n"
+ "\"\"\";");
+
+  verifyFormat("String name = \"\"\"Pat Q. Smith\"\"\";");
+
+  verifyNoChange("String name = \"\"\"\n"
+ "  Pat Q. Smith");
+}
+
 } // namespace
 } // namespace test
 } // namespace format


[llvm-branch-commits] [clang] release/20.x: [clang-format] Handle Java text blocks (#141334) (PR #141433)

2025-05-25 Thread Owen Pan via llvm-branch-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/141433

>From d32d17a56f6d53cebc6299c0474fc95abeb141ed Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 25 May 2025 15:40:45 -0700
Subject: [PATCH 1/3] [clang-format] Handle Java text blocks (#141334)

Fix #61954

(cherry picked from commit b7f5950bb3b97eac979925a3bbf015530c26962e)
---
 clang/lib/Format/FormatTokenLexer.cpp | 32 +
 clang/lib/Format/FormatTokenLexer.h   |  2 +
 clang/unittests/Format/FormatTestJava.cpp | 57 +++
 3 files changed, 91 insertions(+)

diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 16f0a76f3a954..d8ad3a1d52115 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -636,6 +636,36 @@ bool FormatTokenLexer::canPrecedeRegexLiteral(FormatToken 
*Prev) {
   return true;
 }
 
+void FormatTokenLexer::tryParseJavaTextBlock() {
+  if (FormatTok->TokenText != "\"\"")
+return;
+
+  const auto *S = Lex->getBufferLocation();
+  const auto *End = Lex->getBuffer().end();
+
+  if (S == End || *S != '\"')
+return;
+
+  ++S; // Skip the `"""` that begins a text block.
+
+  // Find the `"""` that ends the text block.
+  for (int Count = 0; Count < 3 && S < End; ++S) {
+switch (*S) {
+case '\\':
+  Count = -1;
+  break;
+case '\"':
+  ++Count;
+  break;
+default:
+  Count = 0;
+}
+  }
+
+  // Ignore the possibly invalid text block.
+  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(S)));
+}
+
 // Tries to parse a JavaScript Regex literal starting at the current token,
 // if that begins with a slash and is in a location where JavaScript allows
 // regex literals. Changes the current token to a regex literal and updates
@@ -1326,6 +1356,8 @@ FormatToken *FormatTokenLexer::getNextToken() {
 FormatTok->TokenText = FormatTok->TokenText.substr(0, 1);
 ++Column;
 StateStack.push(LexerState::TOKEN_STASHED);
+  } else if (Style.isJava() && FormatTok->is(tok::string_literal)) {
+tryParseJavaTextBlock();
   }
 
   if (Style.isVerilog() && Tokens.size() > 0 &&
diff --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 61474a3f9ada8..d9a25c8ef3538 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -71,6 +71,8 @@ class FormatTokenLexer {
 
   bool canPrecedeRegexLiteral(FormatToken *Prev);
 
+  void tryParseJavaTextBlock();
+
   // Tries to parse a JavaScript Regex literal starting at the current token,
   // if that begins with a slash and is in a location where JavaScript allows
   // regex literals. Changes the current token to a regex literal and updates
diff --git a/clang/unittests/Format/FormatTestJava.cpp 
b/clang/unittests/Format/FormatTestJava.cpp
index 33998bc7ff858..d0a3b4eb96d69 100644
--- a/clang/unittests/Format/FormatTestJava.cpp
+++ b/clang/unittests/Format/FormatTestJava.cpp
@@ -789,6 +789,63 @@ TEST_F(FormatTestJava, AlignCaseArrows) {
Style);
 }
 
+TEST_F(FormatTestJava, TextBlock) {
+  verifyNoChange("String myStr = \"\"\"\n"
+ "hello\n"
+ "there\n"
+ "\"\"\";");
+
+  verifyNoChange("String tb = \"\"\"\n"
+ "the new\"\"\";");
+
+  verifyNoChange("System.out.println(\"\"\"\n"
+ "This is the first line\n"
+ "This is the second line\n"
+ "\"\"\");");
+
+  verifyNoChange("void writeHTML() {\n"
+ "  String html = \"\"\" \n"
+ "\n"
+ "Hello World.\n"
+ "\n"
+ "\"\"\";\n"
+ "  writeOutput(html);\n"
+ "}");
+
+  verifyNoChange("String colors = \"\"\"\t\n"
+ "red\n"
+ "green\n"
+ "blue\"\"\".indent(4);");
+
+  verifyNoChange("String code = \"\"\"\n"
+ "String source = \\\"\"\"\n"
+ "String message = \"Hello, World!\";\n"
+ "System.out.println(message);\n"
+ "\\\"\"\";\n"
+ "\"\"\";");
+
+  verifyNoChange(
+  "class Outer {\n"
+  "  void printPoetry() {\n"
+  "String lilacs = \"\"\"\n"
+  "Passing the apple-tree blows of white and pink in the orchards\n"
+  "\"\"\";\n"
+  "System.out.println(lilacs);\n"
+  "  }\n"
+  "}");
+
+  verifyNoChange("String name = \"\"\"\r\n"
+ "red\n"
+ "green\n"
+ "blue\\\n"
+ "\"\"\";");
+
+  verifyFormat("String name = \"\"\"Pat Q. Smith\"\"\";");
+
+  verifyNoChange("String name = \"\"\"\n"
+ "  Pat Q. Smith");
+}
+
 } // namespace
 } // namespace test
 } // namespace format


[llvm-branch-commits] [clang] release/20.x: [clang-format] Handle Java text blocks (#141334) (PR #141433)

2025-05-25 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/141433

Backport b7f5950bb3b97eac979925a3bbf015530c26962e

Requested by: @owenca

>From d32d17a56f6d53cebc6299c0474fc95abeb141ed Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 25 May 2025 15:40:45 -0700
Subject: [PATCH] [clang-format] Handle Java text blocks (#141334)

Fix #61954

(cherry picked from commit b7f5950bb3b97eac979925a3bbf015530c26962e)
---
 clang/lib/Format/FormatTokenLexer.cpp | 32 +
 clang/lib/Format/FormatTokenLexer.h   |  2 +
 clang/unittests/Format/FormatTestJava.cpp | 57 +++
 3 files changed, 91 insertions(+)

diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 16f0a76f3a954..d8ad3a1d52115 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -636,6 +636,36 @@ bool FormatTokenLexer::canPrecedeRegexLiteral(FormatToken 
*Prev) {
   return true;
 }
 
+void FormatTokenLexer::tryParseJavaTextBlock() {
+  if (FormatTok->TokenText != "\"\"")
+return;
+
+  const auto *S = Lex->getBufferLocation();
+  const auto *End = Lex->getBuffer().end();
+
+  if (S == End || *S != '\"')
+return;
+
+  ++S; // Skip the `"""` that begins a text block.
+
+  // Find the `"""` that ends the text block.
+  for (int Count = 0; Count < 3 && S < End; ++S) {
+switch (*S) {
+case '\\':
+  Count = -1;
+  break;
+case '\"':
+  ++Count;
+  break;
+default:
+  Count = 0;
+}
+  }
+
+  // Ignore the possibly invalid text block.
+  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(S)));
+}
+
 // Tries to parse a JavaScript Regex literal starting at the current token,
 // if that begins with a slash and is in a location where JavaScript allows
 // regex literals. Changes the current token to a regex literal and updates
@@ -1326,6 +1356,8 @@ FormatToken *FormatTokenLexer::getNextToken() {
 FormatTok->TokenText = FormatTok->TokenText.substr(0, 1);
 ++Column;
 StateStack.push(LexerState::TOKEN_STASHED);
+  } else if (Style.isJava() && FormatTok->is(tok::string_literal)) {
+tryParseJavaTextBlock();
   }
 
   if (Style.isVerilog() && Tokens.size() > 0 &&
diff --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 61474a3f9ada8..d9a25c8ef3538 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -71,6 +71,8 @@ class FormatTokenLexer {
 
   bool canPrecedeRegexLiteral(FormatToken *Prev);
 
+  void tryParseJavaTextBlock();
+
   // Tries to parse a JavaScript Regex literal starting at the current token,
   // if that begins with a slash and is in a location where JavaScript allows
   // regex literals. Changes the current token to a regex literal and updates
diff --git a/clang/unittests/Format/FormatTestJava.cpp 
b/clang/unittests/Format/FormatTestJava.cpp
index 33998bc7ff858..d0a3b4eb96d69 100644
--- a/clang/unittests/Format/FormatTestJava.cpp
+++ b/clang/unittests/Format/FormatTestJava.cpp
@@ -789,6 +789,63 @@ TEST_F(FormatTestJava, AlignCaseArrows) {
Style);
 }
 
+TEST_F(FormatTestJava, TextBlock) {
+  verifyNoChange("String myStr = \"\"\"\n"
+ "hello\n"
+ "there\n"
+ "\"\"\";");
+
+  verifyNoChange("String tb = \"\"\"\n"
+ "the new\"\"\";");
+
+  verifyNoChange("System.out.println(\"\"\"\n"
+ "This is the first line\n"
+ "This is the second line\n"
+ "\"\"\");");
+
+  verifyNoChange("void writeHTML() {\n"
+ "  String html = \"\"\" \n"
+ "\n"
+ "Hello World.\n"
+ "\n"
+ "\"\"\";\n"
+ "  writeOutput(html);\n"
+ "}");
+
+  verifyNoChange("String colors = \"\"\"\t\n"
+ "red\n"
+ "green\n"
+ "blue\"\"\".indent(4);");
+
+  verifyNoChange("String code = \"\"\"\n"
+ "String source = \\\"\"\"\n"
+ "String message = \"Hello, World!\";\n"
+ "System.out.println(message);\n"
+ "\\\"\"\";\n"
+ "\"\"\";");
+
+  verifyNoChange(
+  "class Outer {\n"
+  "  void printPoetry() {\n"
+  "String lilacs = \"\"\"\n"
+  "Passing the apple-tree blows of white and pink in the orchards\n"
+  "\"\"\";\n"
+  "System.out.println(lilacs);\n"
+  "  }\n"
+  "}");
+
+  verifyNoChange("String name = \"\"\"\r\n"
+ "red\n"
+ "green\n"
+ "blue\\\n"
+ "\"\"\";");
+
+  verifyFormat("String name = \"\"\"Pat Q. Smith\"\"\";");
+
+  verifyNoChange("String name = \"\"\"\n"
+ "  Pat Q. Smit

[llvm-branch-commits] [clang] release/20.x: [clang-format] Handle Java text blocks (#141334) (PR #141433)

2025-05-25 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/141433
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/20.x: [clang-format] Handle Java text blocks (#141334) (PR #141433)

2025-05-25 Thread via llvm-branch-commits

llvmbot wrote:

@HazardyKnusperkeks What do you think about merging this PR to the release 
branch?

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


[llvm-branch-commits] [polly] [Polly] Introduce PhaseManager and remove LPM support (PR #125442)

2025-05-25 Thread Karthika Devi C via llvm-branch-commits


@@ -0,0 +1,419 @@
+//===-- PhaseManager.cpp *- C++ 
-*-===//
+//
+// 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 "polly/Pass/PhaseManager.h"
+#include "polly/CodeGen/CodeGeneration.h"
+#include "polly/CodeGen/IslAst.h"
+#include "polly/CodePreparation.h"
+#include "polly/DeLICM.h"
+#include "polly/DeadCodeElimination.h"
+#include "polly/DependenceInfo.h"
+#include "polly/FlattenSchedule.h"
+#include "polly/ForwardOpTree.h"
+#include "polly/JSONExporter.h"
+#include "polly/MaximalStaticExpansion.h"
+#include "polly/PruneUnprofitable.h"
+#include "polly/ScheduleOptimizer.h"
+#include "polly/ScopDetection.h"
+#include "polly/ScopDetectionDiagnostic.h"
+#include "polly/ScopGraphPrinter.h"
+#include "polly/ScopInfo.h"
+#include "polly/Simplify.h"
+#include "llvm/Analysis/AssumptionCache.h"
+#include "llvm/Analysis/OptimizationRemarkEmitter.h"
+#include "llvm/IR/Module.h"
+
+#define DEBUG_TYPE "polly-pass"
+
+using namespace polly;
+using namespace llvm;
+
+namespace {
+
+/// Recurse through all subregions and all regions and add them to RQ.
+static void addRegionIntoQueue(Region &R, SmallVector &RQ) {
+  RQ.push_back(&R);
+  for (const auto &E : R)
+addRegionIntoQueue(*E, RQ);
+}
+
+/// The phase pipeline of Polly to be embedded into another pass manager than
+/// runs passes on functions.
+///
+/// Polly holds state besides LLVM-IR (RegionInfo and ScopInfo) between phases
+/// that LLVM pass managers do not consider when scheduling analyses and 
passes.
+/// That is, the ScopInfo must persist between phases that a pass manager must
+/// not invalidate to recompute later.
+class PhaseManager {
+private:
+  Function &F;
+  FunctionAnalysisManager &FAM;
+  PollyPassOptions Opts;
+
+public:
+  PhaseManager(Function &F, FunctionAnalysisManager &FAM, PollyPassOptions 
Opts)
+  : F(F), FAM(FAM), Opts(std::move(Opts)) {}
+
+  /// Execute Polly's phases as indicated by the options.
+  bool run() {
+// Get analyses from the function pass manager.
+// These must be preserved during all phases so that if processing one SCoP
+// has finished, the next SCoP can still use them. Recomputing is not an
+// option because ScopDetection stores references to the old results.
+// TODO: CodePreparation doesn't actually need these analysis, it just 
keeps
+// them up-to-date. If they are not computed yet, can also compute after 
the
+// prepare phase.
+auto &LI = FAM.getResult(F);
+auto &DT = FAM.getResult(F);
+bool ModifiedIR = false;
+
+// Phase: prepare
+// TODO: Setting ModifiedIR will invalidate any anlysis, even if DT, LI are
+// preserved.
+if (Opts.isPhaseEnabled(PassPhase::Prepare))
+  ModifiedIR |= runCodePreparation(F, &DT, &LI, nullptr);
+
+// Can't do anything without detection
+if (!Opts.isPhaseEnabled(PassPhase::Detection))
+  return false;
+
+auto &AA = FAM.getResult(F);
+auto &SE = FAM.getResult(F);
+auto &ORE = FAM.getResult(F);
+
+// ScopDetection is modifying RegionInfo, do not cache it, nor use a cached
+// version.
+RegionInfo RI = RegionInfoAnalysis().run(F, FAM);
+
+// Phase: detection
+ScopDetection SD(DT, SE, LI, RI, AA, ORE);
+SD.detect(F);
+if (Opts.isPhaseEnabled(PassPhase::PrintDetect)) {
+  outs() << "Detected Scops in Function " << F.getName() << "\n";
+  for (const Region *R : SD.ValidRegions)
+outs() << "Valid Region for Scop: " << R->getNameStr() << '\n';
+  outs() << "\n";
+}
+
+if (Opts.isPhaseEnabled(PassPhase::DotScops))
+  printGraphForFunction(F, &SD, "scops", false);
+if (Opts.isPhaseEnabled(PassPhase::DotScopsOnly))
+  printGraphForFunction(F, &SD, "scopsonly", true);
+
+auto ViewScops = [&](const char *Name, bool IsSimply) {
+  if (Opts.ViewFilter.empty() && !F.getName().count(Opts.ViewFilter))
+return;
+
+  if (Opts.ViewAll || std::distance(SD.begin(), SD.end()) > 0)
+viewGraphForFunction(F, &SD, Name, IsSimply);
+};
+if (Opts.isPhaseEnabled(PassPhase::ViewScops))
+  ViewScops("scops", false);
+if (Opts.isPhaseEnabled(PassPhase::ViewScopsOnly))
+  ViewScops("scopsonly", true);
+
+// Phase: scops
+auto &AC = FAM.getResult(F);
+const DataLayout &DL = F.getParent()->getDataLayout();
+ScopInfo Info(DL, SD, SE, LI, AA, DT, AC, ORE);

kartcq wrote:

It's in second case for pass pipeline, the order is changed.

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


[llvm-branch-commits] [llvm] release/20.x: Fix test pfalse-v4i1.ll added in #138712 to require asserts. (PR #140176)

2025-05-25 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/140176
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] aa804fd - [sanitizer_common] Remove interceptors for deprecated struct termio (#137403)

2025-05-25 Thread Tom Stellard via llvm-branch-commits

Author: Tom Stellard
Date: 2025-05-25T03:13:33-07:00
New Revision: aa804fd3e624cb92c6e7665182504c6049387f35

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

LOG: [sanitizer_common] Remove interceptors for deprecated struct termio 
(#137403)

This struct will be removed from glibc-2.42 and has been deprecated for
a very long time.

Fixes #137321

(cherry picked from commit 59978b21ad9c65276ee8e14f26759691b8a65763)

Added: 


Modified: 
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h

Removed: 




diff  --git 
a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc 
b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
index 49ec4097c900b..dda11daa77f49 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
@@ -338,17 +338,9 @@ static void ioctl_table_fill() {
   _(SOUND_PCM_WRITE_CHANNELS, WRITE, sizeof(int));
   _(SOUND_PCM_WRITE_FILTER, WRITE, sizeof(int));
   _(TCFLSH, NONE, 0);
-#if SANITIZER_GLIBC
-  _(TCGETA, WRITE, struct_termio_sz);
-#endif
   _(TCGETS, WRITE, struct_termios_sz);
   _(TCSBRK, NONE, 0);
   _(TCSBRKP, NONE, 0);
-#if SANITIZER_GLIBC
-  _(TCSETA, READ, struct_termio_sz);
-  _(TCSETAF, READ, struct_termio_sz);
-  _(TCSETAW, READ, struct_termio_sz);
-#endif
   _(TCSETS, READ, struct_termios_sz);
   _(TCSETSF, READ, struct_termios_sz);
   _(TCSETSW, READ, struct_termios_sz);

diff  --git 
a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
index ec5f2edab6a64..b3e717591d6c7 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -485,9 +485,6 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
   unsigned struct_input_id_sz = sizeof(struct input_id);
   unsigned struct_mtpos_sz = sizeof(struct mtpos);
   unsigned struct_rtentry_sz = sizeof(struct rtentry);
-#if SANITIZER_GLIBC || SANITIZER_ANDROID
-  unsigned struct_termio_sz = sizeof(struct termio);
-#endif
   unsigned struct_vt_consize_sz = sizeof(struct vt_consize);
   unsigned struct_vt_sizes_sz = sizeof(struct vt_sizes);
   unsigned struct_vt_stat_sz = sizeof(struct vt_stat);

diff  --git 
a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 1a7d9e64048eb..005ff27624629 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -1043,7 +1043,6 @@ extern unsigned struct_hd_geometry_sz;
 extern unsigned struct_input_absinfo_sz;
 extern unsigned struct_input_id_sz;
 extern unsigned struct_mtpos_sz;
-extern unsigned struct_termio_sz;
 extern unsigned struct_vt_consize_sz;
 extern unsigned struct_vt_sizes_sz;
 extern unsigned struct_vt_stat_sz;



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


[llvm-branch-commits] [compiler-rt] release/20.x: [sanitizer_common] Remove interceptors for deprecated struct termio (#137403) (PR #137707)

2025-05-25 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/137707

>From aa804fd3e624cb92c6e7665182504c6049387f35 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Mon, 28 Apr 2025 13:45:11 -0700
Subject: [PATCH] [sanitizer_common] Remove interceptors for deprecated struct
 termio (#137403)

This struct will be removed from glibc-2.42 and has been deprecated for
a very long time.

Fixes #137321

(cherry picked from commit 59978b21ad9c65276ee8e14f26759691b8a65763)
---
 .../sanitizer_common_interceptors_ioctl.inc   | 8 
 .../sanitizer_common/sanitizer_platform_limits_posix.cpp  | 3 ---
 .../sanitizer_common/sanitizer_platform_limits_posix.h| 1 -
 3 files changed, 12 deletions(-)

diff --git 
a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc 
b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
index 49ec4097c900b..dda11daa77f49 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
@@ -338,17 +338,9 @@ static void ioctl_table_fill() {
   _(SOUND_PCM_WRITE_CHANNELS, WRITE, sizeof(int));
   _(SOUND_PCM_WRITE_FILTER, WRITE, sizeof(int));
   _(TCFLSH, NONE, 0);
-#if SANITIZER_GLIBC
-  _(TCGETA, WRITE, struct_termio_sz);
-#endif
   _(TCGETS, WRITE, struct_termios_sz);
   _(TCSBRK, NONE, 0);
   _(TCSBRKP, NONE, 0);
-#if SANITIZER_GLIBC
-  _(TCSETA, READ, struct_termio_sz);
-  _(TCSETAF, READ, struct_termio_sz);
-  _(TCSETAW, READ, struct_termio_sz);
-#endif
   _(TCSETS, READ, struct_termios_sz);
   _(TCSETSF, READ, struct_termios_sz);
   _(TCSETSW, READ, struct_termios_sz);
diff --git 
a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
index ec5f2edab6a64..b3e717591d6c7 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -485,9 +485,6 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
   unsigned struct_input_id_sz = sizeof(struct input_id);
   unsigned struct_mtpos_sz = sizeof(struct mtpos);
   unsigned struct_rtentry_sz = sizeof(struct rtentry);
-#if SANITIZER_GLIBC || SANITIZER_ANDROID
-  unsigned struct_termio_sz = sizeof(struct termio);
-#endif
   unsigned struct_vt_consize_sz = sizeof(struct vt_consize);
   unsigned struct_vt_sizes_sz = sizeof(struct vt_sizes);
   unsigned struct_vt_stat_sz = sizeof(struct vt_stat);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 1a7d9e64048eb..005ff27624629 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -1043,7 +1043,6 @@ extern unsigned struct_hd_geometry_sz;
 extern unsigned struct_input_absinfo_sz;
 extern unsigned struct_input_id_sz;
 extern unsigned struct_mtpos_sz;
-extern unsigned struct_termio_sz;
 extern unsigned struct_vt_consize_sz;
 extern unsigned struct_vt_sizes_sz;
 extern unsigned struct_vt_stat_sz;

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


[llvm-branch-commits] [compiler-rt] release/20.x: [sanitizer_common] Remove interceptors for deprecated struct termio (#137403) (PR #137707)

2025-05-25 Thread via llvm-branch-commits

github-actions[bot] wrote:

@tstellar (or anyone else). If you would like to add a note about this fix in 
the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.  When you are done, please add the 
release:note label to this PR. 

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


[llvm-branch-commits] [compiler-rt] release/20.x: [sanitizer_common] Remove interceptors for deprecated struct termio (#137403) (PR #137707)

2025-05-25 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/137707
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits