Skip to content

[NFC] Eliminate top-level "using namespace" from some headers. #102751

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

Merged
merged 1 commit into from
Aug 11, 2024

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented Aug 10, 2024

  • Eliminate top-level "using namespace" from some headers.

@jurahul jurahul requested a review from nikic as a code owner August 10, 2024 13:41
@jurahul jurahul marked this pull request as draft August 10, 2024 13:41
@jurahul jurahul removed the request for review from nikic August 10, 2024 13:42
@@ -15,10 +15,6 @@

#include "RuntimeDyldImpl.h"

#define DEBUG_TYPE "dyld"
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 header code does not seems to use anything like LLVM_DEBUG which needs the DEBUG_TYPE to be set.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Taking a cursory look, it seems it's not yet decided when the code will be removed. As such, might to ok to commit it. But if there is a push-back, I can undo the changes in some files.

@@ -17,11 +17,6 @@
#include "llvm/Object/MachO.h"
#include "llvm/Support/Format.h"

#define DEBUG_TYPE "dyld"
Copy link
Contributor Author

@jurahul jurahul Aug 10, 2024

Choose a reason for hiding this comment

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

Same observation here as well, this DEBUG_TYPE define is unused.

@@ -22,8 +21,6 @@

#define DEBUG_TYPE "dyld"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added undef for this one (which seems to be used) at the end of the header.

@@ -46,12 +46,8 @@
#include <type_traits>
#include <utility>

namespace llvm {
Copy link
Contributor Author

@jurahul jurahul Aug 10, 2024

Choose a reason for hiding this comment

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

These declarations are unnecessary as they are already provided by the included headers.

@llvmbot
Copy link
Member

llvmbot commented Aug 10, 2024

@llvm/pr-subscribers-backend-risc-v
@llvm/pr-subscribers-backend-systemz
@llvm/pr-subscribers-llvm-selectiondag
@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-backend-arm

@llvm/pr-subscribers-mlgo

Author: Rahul Joshi (jurahul)

Changes
  • Eliminate top-level "using namespace" from some headers.

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

19 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h (-2)
  • (modified) llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp (+7-8)
  • (modified) llvm/lib/CodeGen/MLRegAllocEvictAdvisor.h (+3-1)
  • (modified) llvm/lib/CodeGen/SelectionDAG/MatchContext.h (+5-4)
  • (modified) llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h (+1-7)
  • (modified) llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h (+1-3)
  • (modified) llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h (+1-8)
  • (modified) llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h (+23-7)
  • (modified) llvm/lib/Target/AMDGPU/AMDGPUCombinerHelper.h (+3-2)
  • (modified) llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.h (+3-5)
  • (modified) llvm/lib/Target/AMDGPU/R600ISelDAGToDAG.cpp (+2)
  • (modified) llvm/lib/Target/AMDGPU/R600MachineScheduler.h (-2)
  • (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h (+5-7)
  • (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendWinCOFF.h (+5-6)
  • (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h (+4-5)
  • (modified) llvm/lib/Target/SystemZ/SystemZMachineScheduler.h (-2)
  • (modified) llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombineInternal.h (+1-3)
  • (modified) llvm/lib/Transforms/InstCombine/InstCombineInternal.h (-2)
  • (modified) llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp (+1-5)
diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
index bba675f1d3eb7d..08e6a0e3ef6295 100644
--- a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
+++ b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
@@ -29,8 +29,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Target/TargetMachine.h"
 
-using namespace llvm;
-
 namespace llvm {
 
 // This struct represents the cluster information for a machine basic block,
diff --git a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
index 4f0fab8e58bf83..0a124ac3fd1b68 100644
--- a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
@@ -943,7 +943,7 @@ void MLEvictAdvisor::extractFeatures(
 #undef SET
 }
 
-void extractInstructionFeatures(
+void llvm::extractInstructionFeatures(
     SmallVectorImpl<LRStartEndInfo> &LRPosInfo, MLModelRunner *RegallocRunner,
     function_ref<int(SlotIndex)> GetOpcode,
     function_ref<float(SlotIndex)> GetMBBFreq,
@@ -1060,13 +1060,12 @@ void extractInstructionFeatures(
   }
 }
 
-void extractMBBFrequency(const SlotIndex CurrentIndex,
-                         const size_t CurrentInstructionIndex,
-                         std::map<MachineBasicBlock *, size_t> &VisitedMBBs,
-                         function_ref<float(SlotIndex)> GetMBBFreq,
-                         MachineBasicBlock *CurrentMBBReference,
-                         MLModelRunner *RegallocRunner, const int MBBFreqIndex,
-                         const int MBBMappingIndex) {
+void llvm::extractMBBFrequency(
+    const SlotIndex CurrentIndex, const size_t CurrentInstructionIndex,
+    std::map<MachineBasicBlock *, size_t> &VisitedMBBs,
+    function_ref<float(SlotIndex)> GetMBBFreq,
+    MachineBasicBlock *CurrentMBBReference, MLModelRunner *RegallocRunner,
+    const int MBBFreqIndex, const int MBBMappingIndex) {
   size_t CurrentMBBIndex = VisitedMBBs[CurrentMBBReference];
   float CurrentMBBFreq = GetMBBFreq(CurrentIndex);
   if (CurrentMBBIndex < ModelMaxSupportedMBBCount) {
diff --git a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.h b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.h
index 0213801cd61b4d..27dd2b9aee9af4 100644
--- a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.h
+++ b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.h
@@ -19,7 +19,7 @@
 #include "llvm/CodeGen/SlotIndexes.h"
 #include <map>
 
-using namespace llvm;
+namespace llvm {
 
 // LRStartEndInfo contains the start and end of a specific live range as
 // slot indices as well as storing the index of the physical register it
@@ -91,4 +91,6 @@ static const int64_t ModelMaxSupportedMBBCount = 100;
 static const std::vector<int64_t> MBBFrequencyShape{1,
                                                     ModelMaxSupportedMBBCount};
 
+} // namespace llvm
+
 #endif // LLVM_CODEGEN_MLREGALLOCEVICTIONADVISOR_H
diff --git a/llvm/lib/CodeGen/SelectionDAG/MatchContext.h b/llvm/lib/CodeGen/SelectionDAG/MatchContext.h
index f965cb952f97a2..d81a0c2e87e7d2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/MatchContext.h
+++ b/llvm/lib/CodeGen/SelectionDAG/MatchContext.h
@@ -16,9 +16,8 @@
 #include "llvm/CodeGen/SelectionDAG.h"
 #include "llvm/CodeGen/TargetLowering.h"
 
-using namespace llvm;
+namespace llvm {
 
-namespace {
 class EmptyMatchContext {
   SelectionDAG &DAG;
   const TargetLowering &TLI;
@@ -171,5 +170,7 @@ class VPMatchContext {
     return TLI.isOperationLegalOrCustom(VPOp, VT, LegalOnly);
   }
 };
-} // end anonymous namespace
-#endif
+
+} // namespace llvm
+
+#endif // LLVM_LIB_CODEGEN_SELECTIONDAG_MATCHCONTEXT_H
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h
index 41ee06c15448fd..25e3783cf160b2 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.h
@@ -15,10 +15,6 @@
 
 #include "RuntimeDyldImpl.h"
 
-#define DEBUG_TYPE "dyld"
-
-using namespace llvm;
-
 namespace llvm {
 
 // Common base class for COFF dynamic linker support.
@@ -56,6 +52,4 @@ class RuntimeDyldCOFF : public RuntimeDyldImpl {
 
 } // end namespace llvm
 
-#undef DEBUG_TYPE
-
-#endif
+#endif // LLVM_RUNTIME_DYLD_COFF_H
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
index b73d2af8c0c490..1b90013dfe2df9 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
@@ -16,8 +16,6 @@
 #include "RuntimeDyldImpl.h"
 #include "llvm/ADT/DenseMap.h"
 
-using namespace llvm;
-
 namespace llvm {
 namespace object {
 class ELFObjectFileBase;
@@ -233,4 +231,4 @@ class RuntimeDyldELF : public RuntimeDyldImpl {
 
 } // end namespace llvm
 
-#endif
+#endif // LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDELF_H
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
index 650e7b79fbb8e1..061d0e8cbe9432 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
@@ -17,11 +17,6 @@
 #include "llvm/Object/MachO.h"
 #include "llvm/Support/Format.h"
 
-#define DEBUG_TYPE "dyld"
-
-using namespace llvm;
-using namespace llvm::object;
-
 namespace llvm {
 class RuntimeDyldMachO : public RuntimeDyldImpl {
 protected:
@@ -162,6 +157,4 @@ class RuntimeDyldMachOCRTPBase : public RuntimeDyldMachO {
 
 } // end namespace llvm
 
-#undef DEBUG_TYPE
-
-#endif
+#endif // LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDMACHO_H
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h
index 66c9753a72fda7..f54ed0eae00760 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h
@@ -1,5 +1,4 @@
-//===-- RuntimeDyldCOFFAArch64.h --- COFF/AArch64 specific code ---*- C++
-//-*-===//
+//===-- RuntimeDyldCOFFAArch64.h --- COFF/AArch64 specific code ---*- C++*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -22,8 +21,6 @@
 
 #define DEBUG_TYPE "dyld"
 
-using namespace llvm::support::endian;
-
 namespace llvm {
 
 // This relocation type is used for handling long branch instruction
@@ -32,16 +29,28 @@ enum InternalRelocationType : unsigned {
   INTERNAL_REL_ARM64_LONG_BRANCH26 = 0x111,
 };
 
-static void add16(uint8_t *p, int16_t v) { write16le(p, read16le(p) + v); }
-static void or32le(void *P, int32_t V) { write32le(P, read32le(P) | V); }
+static void add16(uint8_t *p, int16_t v) {
+  using namespace llvm::support::endian;
+  write16le(p, read16le(p) + v);
+}
+
+static void or32le(void *P, int32_t V) {
+  using namespace llvm::support::endian;
+
+  write32le(P, read32le(P) | V);
+}
 
 static void write32AArch64Imm(uint8_t *T, uint64_t imm, uint32_t rangeLimit) {
+  using namespace llvm::support::endian;
+
   uint32_t orig = read32le(T);
   orig &= ~(0xFFF << 10);
   write32le(T, orig | ((imm & (0xFFF >> rangeLimit)) << 10));
 }
 
 static void write32AArch64Ldr(uint8_t *T, uint64_t imm) {
+  using namespace llvm::support::endian;
+
   uint32_t orig = read32le(T);
   uint32_t size = orig >> 30;
   // 0x04000000 indicates SIMD/FP registers
@@ -54,6 +63,8 @@ static void write32AArch64Ldr(uint8_t *T, uint64_t imm) {
 }
 
 static void write32AArch64Addr(void *T, uint64_t s, uint64_t p, int shift) {
+  using namespace llvm::support::endian;
+
   uint64_t Imm = (s >> shift) - (p >> shift);
   uint32_t ImmLo = (Imm & 0x3) << 29;
   uint32_t ImmHi = (Imm & 0x1FFFFC) << 3;
@@ -144,6 +155,7 @@ class RuntimeDyldCOFFAArch64 : public RuntimeDyldCOFF {
                        const object::ObjectFile &Obj,
                        ObjSectionToIDMap &ObjSectionToID,
                        StubMap &Stubs) override {
+    using namespace llvm::support::endian;
 
     auto Symbol = RelI->getSymbol();
     if (Symbol == Obj.symbol_end())
@@ -255,6 +267,8 @@ class RuntimeDyldCOFFAArch64 : public RuntimeDyldCOFF {
   }
 
   void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override {
+    using namespace llvm::support::endian;
+
     const auto Section = Sections[RE.SectionID];
     uint8_t *Target = Section.getAddressWithOffset(RE.Offset);
     uint64_t FinalAddress = Section.getLoadAddressWithOffset(RE.Offset);
@@ -374,4 +388,6 @@ class RuntimeDyldCOFFAArch64 : public RuntimeDyldCOFF {
 
 } // End namespace llvm
 
-#endif
+#undef DEBUG_TYPE
+
+#endif // LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFAARCH64_H
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCombinerHelper.h b/llvm/lib/Target/AMDGPU/AMDGPUCombinerHelper.h
index a933e85ce3ca24..6510abe9d23218 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCombinerHelper.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCombinerHelper.h
@@ -18,8 +18,7 @@
 #include "llvm/CodeGen/GlobalISel/Combiner.h"
 #include "llvm/CodeGen/GlobalISel/CombinerHelper.h"
 
-using namespace llvm;
-
+namespace llvm {
 class AMDGPUCombinerHelper : public CombinerHelper {
 public:
   using CombinerHelper::CombinerHelper;
@@ -33,4 +32,6 @@ class AMDGPUCombinerHelper : public CombinerHelper {
                                    Register Src1, Register Src2);
 };
 
+} // namespace llvm
+
 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUCOMBINERHELPER_H
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.h b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.h
index e7911bc1793dfe..45a951352c1eb1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.h
@@ -20,9 +20,7 @@
 #include "llvm/CodeGen/SelectionDAGISel.h"
 #include "llvm/Target/TargetMachine.h"
 
-using namespace llvm;
-
-namespace {
+namespace llvm {
 
 static inline bool getConstantValue(SDValue N, uint32_t &Out) {
   // This is only used for packed vectors, where using 0 for undef should
@@ -60,8 +58,6 @@ static inline SDNode *packConstantV2I16(const SDNode *N, SelectionDAG &DAG) {
   return nullptr;
 }
 
-} // namespace
-
 /// AMDGPU specific code to select AMDGPU machine instructions for
 /// SelectionDAG operations.
 class AMDGPUDAGToDAGISel : public SelectionDAGISel {
@@ -301,4 +297,6 @@ class AMDGPUDAGToDAGISelLegacy : public SelectionDAGISelLegacy {
   StringRef getPassName() const override;
 };
 
+} // namespace llvm
+
 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUISELDAGTODAG_H
diff --git a/llvm/lib/Target/AMDGPU/R600ISelDAGToDAG.cpp b/llvm/lib/Target/AMDGPU/R600ISelDAGToDAG.cpp
index 6b4f5a88c6476b..a975ab17e962f5 100644
--- a/llvm/lib/Target/AMDGPU/R600ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AMDGPU/R600ISelDAGToDAG.cpp
@@ -18,6 +18,8 @@
 #include "R600Subtarget.h"
 #include "llvm/Analysis/ValueTracking.h"
 
+using namespace llvm;
+
 namespace {
 class R600DAGToDAGISel : public AMDGPUDAGToDAGISel {
   const R600Subtarget *Subtarget = nullptr;
diff --git a/llvm/lib/Target/AMDGPU/R600MachineScheduler.h b/llvm/lib/Target/AMDGPU/R600MachineScheduler.h
index f3fd71d470baca..ddc047401aa18d 100644
--- a/llvm/lib/Target/AMDGPU/R600MachineScheduler.h
+++ b/llvm/lib/Target/AMDGPU/R600MachineScheduler.h
@@ -17,8 +17,6 @@
 #include "llvm/CodeGen/MachineScheduler.h"
 #include <vector>
 
-using namespace llvm;
-
 namespace llvm {
 
 class R600InstrInfo;
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h
index abbe73e336f505..17ae262c0826a4 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendELF.h
@@ -6,16 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_TARGET_ARM_ELFARMASMBACKEND_H
-#define LLVM_LIB_TARGET_ARM_ELFARMASMBACKEND_H
+#ifndef LLVM_LIB_TARGET_ARM_MCTARGETDESC_ELFARMASMBACKEND_H
+#define LLVM_LIB_TARGET_ARM_MCTARGETDESC_ELFARMASMBACKEND_H
 
 #include "ARMAsmBackend.h"
 #include "MCTargetDesc/ARMMCTargetDesc.h"
 #include "llvm/MC/MCObjectWriter.h"
 
-using namespace llvm;
-
-namespace {
+namespace llvm {
 class ARMAsmBackendELF : public ARMAsmBackend {
 public:
   uint8_t OSABI;
@@ -30,6 +28,6 @@ class ARMAsmBackendELF : public ARMAsmBackend {
 
   std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
 };
-}
+} // namespace llvm
 
-#endif
+#endif // LLVM_LIB_TARGET_ARM_MCTARGETDESC_ELFARMASMBACKEND_H
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendWinCOFF.h b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendWinCOFF.h
index 86ce6efe662a27..9b50fb7f075821 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendWinCOFF.h
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendWinCOFF.h
@@ -6,14 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIB_TARGET_ARM_ARMASMBACKENDWINCOFF_H
-#define LLVM_LIB_TARGET_ARM_ARMASMBACKENDWINCOFF_H
+#ifndef LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMASMBACKENDWINCOFF_H
+#define LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMASMBACKENDWINCOFF_H
 
 #include "ARMAsmBackend.h"
 #include "llvm/MC/MCObjectWriter.h"
-using namespace llvm;
 
-namespace {
+namespace llvm {
 class ARMAsmBackendWinCOFF : public ARMAsmBackend {
 public:
   ARMAsmBackendWinCOFF(const Target &T, bool isThumb)
@@ -23,6 +22,6 @@ class ARMAsmBackendWinCOFF : public ARMAsmBackend {
     return createARMWinCOFFObjectWriter();
   }
 };
-}
+} // namespace llvm
 
-#endif
+#endif // LLVM_LIB_TARGET_ARM_MCTARGETDESC_ARMASMBACKENDWINCOFF_H
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h
index b06760859483df..47df31af3057d7 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h
@@ -12,7 +12,7 @@
 #include "RISCVTargetStreamer.h"
 #include "llvm/MC/MCELFStreamer.h"
 
-using namespace llvm;
+namespace llvm {
 
 class RISCVELFStreamer : public MCELFStreamer {
   void reset() override;
@@ -38,8 +38,6 @@ class RISCVELFStreamer : public MCELFStreamer {
   void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
 };
 
-namespace llvm {
-
 class RISCVTargetELFStreamer : public RISCVTargetStreamer {
 private:
   StringRef CurrentVendor;
@@ -75,5 +73,6 @@ MCELFStreamer *createRISCVELFStreamer(MCContext &C,
                                       std::unique_ptr<MCAsmBackend> MAB,
                                       std::unique_ptr<MCObjectWriter> MOW,
                                       std::unique_ptr<MCCodeEmitter> MCE);
-}
-#endif
+} // namespace llvm
+
+#endif // LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVELFSTREAMER_H
diff --git a/llvm/lib/Target/SystemZ/SystemZMachineScheduler.h b/llvm/lib/Target/SystemZ/SystemZMachineScheduler.h
index e97092409ce962..1ff6cc81503ce7 100644
--- a/llvm/lib/Target/SystemZ/SystemZMachineScheduler.h
+++ b/llvm/lib/Target/SystemZ/SystemZMachineScheduler.h
@@ -22,8 +22,6 @@
 #include "llvm/CodeGen/ScheduleDAG.h"
 #include <set>
 
-using namespace llvm;
-
 namespace llvm {
 
 /// A MachineSchedStrategy implementation for SystemZ post RA scheduling.
diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombineInternal.h b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombineInternal.h
index 9fc103d45d9858..28a0181392ef3e 100644
--- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombineInternal.h
+++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombineInternal.h
@@ -20,8 +20,6 @@
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/Support/KnownBits.h"
 
-using namespace llvm;
-
 //===----------------------------------------------------------------------===//
 // TruncInstCombine - looks for expression graphs dominated by trunc
 // instructions and for each eligible graph, it will create a reduced bit-width
@@ -137,4 +135,4 @@ class TruncInstCombine {
 };
 } // end namespace llvm.
 
-#endif
+#endif // LLVM_LIB_TRANSFORMS_AGGRESSIVEINSTCOMBINE_COMBINEINTERNAL_H
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 64fbcc80e0edf4..16f1c3ba15eba2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -33,8 +33,6 @@
 #define DEBUG_TYPE "instcombine"
 #include "llvm/Transforms/Utils/InstructionWorklist.h"
 
-using namespace llvm::PatternMatch;
-
 // As a default, let's assume that we want to be aggressive,
 // and attempt to traverse with no limits in attempt to sink negation.
 static constexpr unsigned NegatorDefaultMaxDepth = ~0U;
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
index e4895b59f4b4a9..2dd1db6a4a757b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
@@ -46,12 +46,8 @@
 #include <type_traits>
 #include <utility>
 
-namespace llvm {
-class DataLayout;
-class LLVMContext;
-} // namespace llvm
-
 using namespace llvm;
+using namespace llvm::PatternMatch;
 
 #define DEBUG_TYPE "instcombine"
 

- Eliminate top-level "using namespace" from some headers.
@jurahul
Copy link
Contributor Author

jurahul commented Aug 10, 2024

All checks are clean now. @nikic and @s-barannikov can you please review?

@jurahul jurahul marked this pull request as ready for review August 10, 2024 23:57
@jurahul
Copy link
Contributor Author

jurahul commented Aug 11, 2024

Also, I wonder if there is a clang-tidy warning for this. I'll try to find.

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

LGTM

@jurahul
Copy link
Contributor Author

jurahul commented Aug 11, 2024

Thanks. Can one of you please merge the PR?

@kazutakahirata kazutakahirata merged commit 1753008 into llvm:main Aug 11, 2024
10 checks passed
@firewave
Copy link

Also, I wonder if there is a clang-tidy warning for this. I'll try to find.

There is google-build-using-namespace: https://clang.llvm.org/extra/clang-tidy/checks/google/build-using-namespace.html. That flags all usages though. It (or an alias) should probably get an option to limit it to headers only.

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.

6 participants