Skip to content

Conversation

@jurahul
Copy link
Contributor

@jurahul jurahul commented Nov 5, 2025

No description provided.

@jurahul jurahul force-pushed the nfc_ns_cleanup_scalar_evolution branch from 6e68a98 to 941a0de Compare November 5, 2025 21:58
@jurahul jurahul marked this pull request as ready for review November 5, 2025 23:33
@jurahul jurahul requested a review from nikic as a code owner November 5, 2025 23:33
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Nov 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Rahul Joshi (jurahul)

Changes

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

2 Files Affected:

  • (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+11-2)
  • (modified) llvm/lib/Analysis/ScalarEvolutionDivision.cpp (-4)
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index a31f17b1936d6..63f75ef8adbb6 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -13990,7 +13990,15 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
 }
 
 namespace llvm {
-raw_ostream &operator<<(raw_ostream &OS, ScalarEvolution::LoopDisposition LD) {
+// Note: these overloaded operators need to be in the llvm namespace for them
+// to be resolved correctly. If we put them outside the llvm namespace, the
+//
+// OS << ": " << SE.getLoopDisposition(SV, InnerL);
+//
+// code below "breaks" and start printing raw enum values as opposed to the
+// string values.
+static raw_ostream &operator<<(raw_ostream &OS,
+                               ScalarEvolution::LoopDisposition LD) {
   switch (LD) {
   case ScalarEvolution::LoopVariant:
     OS << "Variant";
@@ -14005,7 +14013,8 @@ raw_ostream &operator<<(raw_ostream &OS, ScalarEvolution::LoopDisposition LD) {
   return OS;
 }
 
-raw_ostream &operator<<(raw_ostream &OS, ScalarEvolution::BlockDisposition BD) {
+static raw_ostream &operator<<(raw_ostream &OS,
+                               llvm::ScalarEvolution::BlockDisposition BD) {
   switch (BD) {
   case ScalarEvolution::DoesNotDominateBlock:
     OS << "DoesNotDominate";
diff --git a/llvm/lib/Analysis/ScalarEvolutionDivision.cpp b/llvm/lib/Analysis/ScalarEvolutionDivision.cpp
index bce41f9f5329e..4e422539ff9f6 100644
--- a/llvm/lib/Analysis/ScalarEvolutionDivision.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionDivision.cpp
@@ -29,8 +29,6 @@ class Type;
 
 using namespace llvm;
 
-namespace {
-
 static inline int sizeOfSCEV(const SCEV *S) {
   struct FindSCEVSize {
     int Size = 0;
@@ -52,8 +50,6 @@ static inline int sizeOfSCEV(const SCEV *S) {
   return F.Size;
 }
 
-} // namespace
-
 // Computes the Quotient and Remainder of the division of Numerator by
 // Denominator.
 void SCEVDivision::divide(ScalarEvolution &SE, const SCEV *Numerator,

@jurahul
Copy link
Contributor Author

jurahul commented Nov 18, 2025

ping @kazutakahirata (I know nikic is OOO)

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ScalarEvolutionDivision.cpp bits look good. I'm not sure about the ScalarEvolution.cpp bits. I generally like clean code, but if we have to add a comment to accomplish the cleanup task, we might be increasing cognitive load. The reader would have to understand the code itself and why the code is written in a particular manner.

@jurahul
Copy link
Contributor Author

jurahul commented Nov 18, 2025

The added comment in ScalarEvolution.cpp is actually explaining the existing code (why are the << operators required to be llvm namespace, to make ADL work correctly to print the enum values in string form). The static then is just making sure these don't escape outside the file. When I initially just make them static (without llvm namespace) code broken in non-intuitive ways and I had to hunt around for why, so thought a comment here would make sense. I can add this comment as a separate PR as well since its unrelated to these being made static.

We can also wait for @nikic to weigh in as there is no rush to get this in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants