Skip to content

[NFC][LLVM] Fix some llvm namespace usage in Bitcode writer #141709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented May 28, 2025

  • Add declaration of ForceSummaryEdgesCold to ModuleSummaryAnalysis.h and do not use namespace scope for its definition in ModuleSummaryAnalysis.cpp
  • No need of forward declaration of Argument.
  • include ModuleSummaryAnalysis.h in BitcodeWriter.cpp to get declaration of ForceSummaryEdgesCold

@jurahul jurahul marked this pull request as ready for review May 28, 2025 14:28
@jurahul jurahul requested review from snehasish and MaskRay May 28, 2025 14:28
@jurahul jurahul requested a review from teresajohnson May 28, 2025 14:28
@llvmbot
Copy link
Member

llvmbot commented May 28, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Rahul Joshi (jurahul)

Changes
  • Add declaration of ForceSummaryEdgesCold to ModuleSummaryAnalysis.h and do not use namespace scope for its definition in ModuleSummaryAnalysis.cpp
  • No need of forward declaration of Argument.
  • include ModuleSummaryAnalysis.h in BitcodeWriter.cpp to get declaration of ForceSummaryEdgesCold

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

4 Files Affected:

  • (modified) llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h (+2)
  • (modified) llvm/lib/Analysis/ModuleSummaryAnalysis.cpp (+1-3)
  • (modified) llvm/lib/Bitcode/Reader/MetadataLoader.cpp (-3)
  • (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+1-4)
diff --git a/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h b/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
index e36dea58cec45..44b5b7ebea935 100644
--- a/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
+++ b/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
@@ -103,6 +103,8 @@ createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index);
 /// consistency between summary analysis and the ThinLTO backend processing.
 bool mayHaveMemprofSummary(const CallBase *CB);
 
+extern FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold;
+
 } // end namespace llvm
 
 #endif // LLVM_ANALYSIS_MODULESUMMARYANALYSIS_H
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index d7e12dc80d7c2..571212c442689 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -63,10 +63,8 @@ using namespace llvm::memprof;
 
 // Option to force edges cold which will block importing when the
 // -import-cold-multiplier is set to 0. Useful for debugging.
-namespace llvm {
-FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold =
+FunctionSummary::ForceSummaryHotnessType llvm::ForceSummaryEdgesCold =
     FunctionSummary::FSHT_None;
-} // namespace llvm
 
 static cl::opt<FunctionSummary::ForceSummaryHotnessType, true> FSEC(
     "force-summary-edges-cold", cl::Hidden, cl::location(ForceSummaryEdgesCold),
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index c724488b45d48..8f67f00232fcd 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -60,9 +60,6 @@
 #include <type_traits>
 #include <utility>
 #include <vector>
-namespace llvm {
-class Argument;
-}
 
 using namespace llvm;
 
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index f8d80c1fc7798..5b3cd59f40821 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -23,6 +23,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Analysis/ModuleSummaryAnalysis.h"
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Bitcode/BitcodeCommon.h"
 #include "llvm/Bitcode/BitcodeReader.h"
@@ -117,10 +118,6 @@ static cl::opt<bool>
 #endif
                                 cl::desc(""));
 
-namespace llvm {
-extern FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold;
-}
-
 extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
 
 namespace {

@@ -23,6 +23,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure including an additional header is superior to just including the extern here below - why make this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an attempt to apply https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions to variables as well. I have another PR for the coding standard change (not yet approved).

Also, the idea that there is just one declaration in a header shared by all who access that variables.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the background. I'm not sure how I feel about going through and changing all of these as I think it will cause a lot of churn and add compile time. Let's wait to see if the coding standard change is accepted.

@@ -117,10 +118,6 @@ static cl::opt<bool>
#endif
cl::desc(""));

namespace llvm {
extern FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this could be simplified to "extern llvm::FunctionSummary::..." like the extern llvm::cl::opt below, if we decide to keep it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, that does not work. Note in the case below, llvm:: is for the type. Here we want to declare an extern variable in the llvm namespace, and extern type llvm::VarName does not work (I did try that first).

@jurahul jurahul requested a review from teresajohnson May 28, 2025 14:56
@@ -23,6 +23,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the background. I'm not sure how I feel about going through and changing all of these as I think it will cause a lot of churn and add compile time. Let's wait to see if the coding standard change is accepted.

@@ -60,9 +60,6 @@
#include <type_traits>
#include <utility>
#include <vector>
namespace llvm {
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is unrelated to the other changes and can be split into a separate PR and committed. There is a use of Argument in this file, but presumably it is being pulled in via other headers, so no need for this forward def.

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

Successfully merging this pull request may close these issues.

3 participants