llvm.org GIT mirror llvm / 283b399
[Modules] Make Support/Debug.h modular. This requires it to not change behavior based on other files defining DEBUG_TYPE, which means it cannot define DEBUG_TYPE at all. This is actually better IMO as it forces folks to define relevant DEBUG_TYPEs for their files. However, it requires all files that currently use DEBUG(...) to define a DEBUG_TYPE if they don't already. I've updated all such files in LLVM and will do the same for other upstream projects. This still leaves one important change in how LLVM uses the DEBUG_TYPE macro going forward: we need to only define the macro *after* header files have been #include-ed. Previously, this wasn't possible because Debug.h required the macro to be pre-defined. This commit removes that. By defining DEBUG_TYPE after the includes two things are fixed: - Header files that need to provide a DEBUG_TYPE for some inline code can do so by defining the macro before their inline code and undef-ing it afterward so the macro does not escape. - We no longer have rampant ODR violations due to including headers with different DEBUG_TYPE definitions. This may be mostly an academic violation today, but with modules these types of violations are easy to check for and potentially very relevant. Where necessary to suppor headers with DEBUG_TYPE, I have moved the definitions below the includes in this commit. I plan to move the rest of the DEBUG_TYPE macros in LLVM in subsequent commits; this one is big enough. The comments in Debug.h, which were hilariously out of date already, have been updated to reflect the recommended practice going forward. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206822 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
59 changed file(s) with 126 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
1212 //
1313 // In particular, just wrap your code with the DEBUG() macro, and it will be
1414 // enabled automatically if you specify '-debug' on the command-line.
15 // Alternatively, you can also use the SET_DEBUG_TYPE("foo") macro to specify
16 // that your debug code belongs to class "foo". Then, on the command line, you
17 // can specify '-debug-only=foo' to enable JUST the debug information for the
18 // foo class.
15 // Alternatively, you can also define the DEBUG_TYPE macro to "foo" specify
16 // that your debug code belongs to class "foo". Be careful that you only do
17 // this after including Debug.h and not around any #include of headers. Headers
18 // should define and undef the macro acround the code that needs to use the
19 // DEBUG() macro. Then, on the command line, you can specify '-debug-only=foo'
20 // to enable JUST the debug information for the foo class.
1921 //
2022 // When compiling without assertions, the -debug-* options and all code in
2123 // DEBUG() statements disappears, so it does not affect the runtime of the code.
2830 #include "llvm/Support/raw_ostream.h"
2931
3032 namespace llvm {
31
32 /// DEBUG_TYPE macro - Files can specify a DEBUG_TYPE as a string, which causes
33 /// all of their DEBUG statements to be activatable with -debug-only=thatstring.
34 #ifndef DEBUG_TYPE
35 #define DEBUG_TYPE ""
36 #endif
3733
3834 #ifndef NDEBUG
3935 /// DebugFlag - This boolean is set to true if the '-debug' command line option
1919
2020 namespace llvm {
2121 namespace sys {
22
23 #define DEBUG_TYPE "unicode"
2224
2325 /// \brief Represents a closed range of Unicode code points [Lower, Upper].
2426 struct UnicodeCharRange {
8789 const CharRanges Ranges;
8890 };
8991
92 #undef DEBUG_TYPE // "unicode"
93
9094 } // namespace sys
9195 } // namespace llvm
9296
2121 #include "llvm/Support/Debug.h"
2222
2323 namespace llvm {
24
25 #define DEBUG_TYPE "ssaupdater"
2426
2527 class CastInst;
2628 class PHINode;
450452 }
451453 };
452454
455 #undef DEBUG_TYPE // "ssaupdater"
456
453457 } // End llvm namespace
454458
455459 #endif
1717 #include "llvm/Support/Debug.h"
1818 #include "llvm/Support/Timer.h"
1919 using namespace llvm;
20
21 #define DEBUG_TYPE "loop-pass-manager"
2022
2123 namespace {
2224
3333 #include "llvm/Target/TargetRegisterInfo.h"
3434 #include
3535 using namespace llvm;
36
37 #define DEBUG_TYPE "codegen"
3638
3739 MachineBasicBlock::MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb)
3840 : BB(bb), Number(-1), xParent(&mf), Alignment(0), IsLandingPad(false),
3737 #include "llvm/Target/TargetMachine.h"
3838 using namespace llvm;
3939
40 #define DEBUG_TYPE "codegen"
41
4042 //===----------------------------------------------------------------------===//
4143 // MachineFunction implementation
4244 //===----------------------------------------------------------------------===//
2727 #include "llvm/Target/TargetRegisterInfo.h"
2828 #include "llvm/Transforms/Utils/SSAUpdaterImpl.h"
2929 using namespace llvm;
30
31 #define DEBUG_TYPE "machine-ssaupdater"
3032
3133 typedef DenseMap AvailableValsTy;
3234 static AvailableValsTy &getAvailableVals(void *AV) {
2626 #include "llvm/Target/TargetRegisterInfo.h"
2727 using namespace llvm;
2828
29 #define DEBUG_TYPE "dag-printer"
30
2931 namespace llvm {
3032 template<>
3133 struct DOTGraphTraits : public DefaultDOTGraphTraits {
1818 using namespace llvm;
1919 using namespace dwarf;
2020 using namespace object;
21
22 #define DEBUG_TYPE "dwarf"
2123
2224 typedef DWARFDebugLine::LineTable DWARFLineTable;
2325
2323 #include "llvm/Support/ErrorHandling.h"
2424 #include "llvm/Support/raw_ostream.h"
2525 #include
26
27 #define DEBUG_TYPE "ir"
2628
2729 namespace llvm {
2830 template
3939 #include
4040
4141 using namespace llvm;
42
43 #define DEBUG_TYPE "ir"
4244
4345 void llvm::initializeCore(PassRegistry &Registry) {
4446 initializeDominatorTreeWrapperPassPass(Registry);
2020 #include "llvm/Support/Debug.h"
2121 #include "llvm/Support/raw_ostream.h"
2222 using namespace llvm;
23
24 #define DEBUG_TYPE "ir"
2325
2426 //===----------------------------------------------------------------------===//
2527 // Pass Implementation
2929
3030 using namespace llvm;
3131 using namespace object;
32
33 #define DEBUG_TYPE "mc"
3234
3335 MCObjectDisassembler::MCObjectDisassembler(const ObjectFile &Obj,
3436 const MCDisassembler &Dis,
2424 #include "llvm/Support/MachO.h"
2525 #include
2626 using namespace llvm;
27
28 #define DEBUG_TYPE "mc"
2729
2830 void MachObjectWriter::reset() {
2931 Relocations.clear();
3636 #include
3737 using namespace llvm;
3838 using namespace cl;
39
40 #define DEBUG_TYPE "commandline"
3941
4042 //===----------------------------------------------------------------------===//
4143 // Template instantiations and anchors.
4040 #include
4141 #include
4242 using namespace llvm;
43
44 #define DEBUG_TYPE "dag-delta"
4345
4446 namespace {
4547
1717 #include "llvm/IR/GlobalValue.h"
1818 #include "llvm/Support/CommandLine.h"
1919 #include "llvm/Target/TargetSubtargetInfo.h"
20
21 #define DEBUG_TYPE "aarch64-subtarget"
2022
2123 #define GET_SUBTARGETINFO_TARGET_DESC
2224 #define GET_SUBTARGETINFO_CTOR
4040 #include "ARMGenInstrInfo.inc"
4141
4242 using namespace llvm;
43
44 #define DEBUG_TYPE "arm-instrinfo"
4345
4446 static cl::opt
4547 EnableARM3Addr("enable-arm-3-addr-conv", cl::Hidden,
1919 #include "llvm/Support/CommandLine.h"
2020 #include "llvm/Target/TargetInstrInfo.h"
2121 #include "llvm/Target/TargetOptions.h"
22
23 #define DEBUG_TYPE "arm-subtarget"
2224
2325 #define GET_SUBTARGETINFO_TARGET_DESC
2426 #define GET_SUBTARGETINFO_CTOR
1616 #include "llvm/CodeGen/MachineScheduler.h"
1717 #include "llvm/IR/GlobalValue.h"
1818 #include "llvm/Support/TargetRegistry.h"
19
20 #define DEBUG_TYPE "arm64-subtarget"
1921
2022 #define GET_SUBTARGETINFO_CTOR
2123 #define GET_SUBTARGETINFO_TARGET_DESC
3737 #include "llvm/Support/raw_ostream.h"
3838
3939 using namespace llvm;
40
41 #define DEBUG_TYPE "hexagon-lowering"
4042
4143 static cl::opt
4244 EmitJumpTables("hexagon-emit-jump-tables", cl::init(true), cl::Hidden,
3131 #include "HexagonGenDFAPacketizer.inc"
3232
3333 using namespace llvm;
34
35 #define DEBUG_TYPE "hexagon-instrinfo"
3436
3537 ///
3638 /// Constants for Hexagon instructions.
1616 #include "llvm/Support/CommandLine.h"
1717 #include "llvm/Support/ErrorHandling.h"
1818 using namespace llvm;
19
20 #define DEBUG_TYPE "hexagon-subtarget"
1921
2022 #define GET_SUBTARGETINFO_CTOR
2123 #define GET_SUBTARGETINFO_TARGET_DESC
2929 #include "llvm/Support/raw_ostream.h"
3030 #include "llvm/Target/TargetLowering.h"
3131 using namespace llvm;
32
33 #define DEBUG_TYPE "msp430-isel"
3234
3335 namespace {
3436 struct MSP430ISelAddressMode {
1313 #include "MSP430Subtarget.h"
1414 #include "MSP430.h"
1515 #include "llvm/Support/TargetRegistry.h"
16
17 #define DEBUG_TYPE "msp430-subtarget"
1618
1719 #define GET_SUBTARGETINFO_TARGET_DESC
1820 #define GET_SUBTARGETINFO_CTOR
2727 #include "llvm/Support/TargetRegistry.h"
2828
2929 using namespace llvm;
30
31 #define DEBUG_TYPE "mips-asm-parser"
3032
3133 namespace llvm {
3234 class MCInstrInfo;
2323 #include "llvm/Support/TargetRegistry.h"
2424
2525 using namespace llvm;
26
27 #define DEBUG_TYPE "mips-disassembler"
2628
2729 typedef MCDisassembler::DecodeStatus DecodeStatus;
2830
2828
2929 using namespace llvm;
3030
31 #define DEBUG_TYPE "mips16-instrinfo"
3132
3233 Mips16InstrInfo::Mips16InstrInfo(MipsTargetMachine &tm)
3334 : MipsInstrInfo(tm, Mips::Bimm16),
3737 #include "llvm/Target/TargetOptions.h"
3838
3939 using namespace llvm;
40
41 #define DEBUG_TYPE "mips16-registerinfo"
4042
4143 Mips16RegisterInfo::Mips16RegisterInfo(const MipsSubtarget &ST)
4244 : MipsRegisterInfo(ST) {}
1212 #include "llvm/Support/Casting.h"
1313 #include "llvm/Support/Debug.h"
1414 #include "llvm/Support/raw_ostream.h"
15
16 #define DEBUG_TYPE "mips-isel"
1517
1618 namespace llvm {
1719
3838
3939 using namespace llvm;
4040
41 #define DEBUG_TYPE "mips-reg-info"
42
4143 MipsSERegisterInfo::MipsSERegisterInfo(const MipsSubtarget &ST)
4244 : MipsRegisterInfo(ST) {}
4345
3434 #include "llvm/Transforms/Scalar.h"
3535 using namespace llvm;
3636
37 #define DEBUG_TYPE "mips"
38
3739
3840
3941 extern "C" void LLVMInitializeMipsTarget() {
2323 #include "llvm/Target/TargetRegisterInfo.h"
2424
2525 using namespace llvm;
26
27 #define DEBUG_TYPE "nvptx-prolog-epilog"
2628
2729 namespace {
2830 class NVPTXPrologEpilogPass : public MachineFunctionPass {
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "NVPTXSubtarget.h"
14
15 #define DEBUG_TYPE "nvptx-subtarget"
16
1417 #define GET_SUBTARGETINFO_ENUM
1518 #define GET_SUBTARGETINFO_TARGET_DESC
1619 #define GET_SUBTARGETINFO_CTOR
1720 #include "NVPTXGenSubtargetInfo.inc"
1821
1922 using namespace llvm;
20
2123
2224 // Pin the vtable to this file.
2325 void NVPTXSubtarget::anchor() {}
3636 #define NVVM_REFLECT_FUNCTION "__nvvm_reflect"
3737
3838 using namespace llvm;
39
40 #define DEBUG_TYPE "nvptx-reflect"
3941
4042 namespace llvm { void initializeNVVMReflectPass(PassRegistry &); }
4143
1515 #include "llvm/Support/TargetRegistry.h"
1616
1717 using namespace llvm;
18
19 #define DEBUG_TYPE "ppc-disassembler"
1820
1921 typedef MCDisassembler::DecodeStatus DecodeStatus;
2022
3939 #include "PPCGenInstrInfo.inc"
4040
4141 using namespace llvm;
42
43 #define DEBUG_TYPE "ppc-instr-info"
4244
4345 static cl::
4446 opt DisableCTRLoopAnal("disable-ppc-ctrloop-analysis", cl::Hidden,
2222 #include "llvm/Support/TargetRegistry.h"
2323 #include "llvm/Target/TargetMachine.h"
2424 #include
25
26 #define DEBUG_TYPE "ppc-subtarget"
2527
2628 #define GET_SUBTARGETINFO_TARGET_DESC
2729 #define GET_SUBTARGETINFO_CTOR
1414 #include "AMDGPUSubtarget.h"
1515
1616 using namespace llvm;
17
18 #define DEBUG_TYPE "amdgpu-subtarget"
1719
1820 #define GET_SUBTARGETINFO_ENUM
1921 #define GET_SUBTARGETINFO_TARGET_DESC
1414 #include "Sparc.h"
1515 #include "llvm/Support/MathExtras.h"
1616 #include "llvm/Support/TargetRegistry.h"
17
18 #define DEBUG_TYPE "sparc-subtarget"
1719
1820 #define GET_SUBTARGETINFO_TARGET_DESC
1921 #define GET_SUBTARGETINFO_CTOR
1515 #include "llvm/Support/TargetRegistry.h"
1616
1717 using namespace llvm;
18
19 #define DEBUG_TYPE "systemz-disassembler"
1820
1921 typedef MCDisassembler::DecodeStatus DecodeStatus;
2022
1717 #include "llvm/Support/raw_ostream.h"
1818
1919 using namespace llvm;
20
21 #define DEBUG_TYPE "systemz-isel"
2022
2123 namespace {
2224 // Used to build addressing modes.
1010 #include "MCTargetDesc/SystemZMCTargetDesc.h"
1111 #include "llvm/IR/GlobalValue.h"
1212 #include "llvm/Support/Host.h"
13
14 #define DEBUG_TYPE "systemz-subtarget"
1315
1416 #define GET_SUBTARGETINFO_TARGET_DESC
1517 #define GET_SUBTARGETINFO_CTOR
3535
3636 using namespace llvm;
3737 using namespace llvm::X86Disassembler;
38
39 #define DEBUG_TYPE "x86-disassembler"
3840
3941 void llvm::X86Disassembler::Debug(const char *file, unsigned line,
4042 const char *s) {
3434 #include "llvm/Support/raw_ostream.h"
3535 #include "llvm/Target/TargetOptions.h"
3636 #include
37
38 #define DEBUG_TYPE "x86-instr-info"
3739
3840 #define GET_INSTRINFO_CTOR_DTOR
3941 #include "X86GenInstrInfo.inc"
2222 #include "llvm/Support/TargetRegistry.h"
2323
2424 using namespace llvm;
25
26 #define DEBUG_TYPE "xcore-disassembler"
2527
2628 typedef MCDisassembler::DecodeStatus DecodeStatus;
2729
3737
3838 using namespace llvm;
3939
40 #define DEBUG_TYPE "xcore-reg-info"
41
4042 XCoreRegisterInfo::XCoreRegisterInfo()
4143 : XCoreGenRegisterInfo(XCore::LR) {
4244 }
1414 #include "XCore.h"
1515 #include "llvm/Support/TargetRegistry.h"
1616
17 #define DEBUG_TYPE "xcore-subtarget"
18
1719 #define GET_SUBTARGETINFO_TARGET_DESC
1820 #define GET_SUBTARGETINFO_CTOR
1921 #include "XCoreGenSubtargetInfo.inc"
3737 #include
3838 using namespace llvm;
3939
40 #define DEBUG_TYPE "code-extractor"
41
4042 // Provide a command-line option to aggregate function arguments into a struct
4143 // for functions produced by the code extractor. This is useful when converting
4244 // extracted functions to pthread-based code, as only one argument (void*) can
4141 #include "llvm/Support/MathExtras.h"
4242 #include "llvm/Support/raw_ostream.h"
4343 using namespace llvm;
44
45 #define DEBUG_TYPE "local"
4446
4547 STATISTIC(NumRemoved, "Number of unreachable basic blocks removed");
4648
2525 #include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
2626 #include
2727 using namespace llvm;
28
29 #define DEBUG_TYPE "lower-switch"
2830
2931 namespace {
3032 /// LowerSwitch Pass - Replace all SwitchInst instructions with chained branch
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #define DEBUG_TYPE "ssaupdater"
1413 #include "llvm/Transforms/Utils/SSAUpdater.h"
1514 #include "llvm/ADT/DenseMap.h"
1615 #include "llvm/ADT/TinyPtrVector.h"
2625 #include "llvm/Transforms/Utils/SSAUpdaterImpl.h"
2726
2827 using namespace llvm;
28
29 #define DEBUG_TYPE "ssaupdater"
2930
3031 typedef DenseMap AvailableValsTy;
3132 static AvailableValsTy &getAvailableVals(void *AV) {
3232 #include "llvm/Transforms/Utils/CodeExtractor.h"
3333 #include
3434 using namespace llvm;
35
36 #define DEBUG_TYPE "bugpoint"
3537
3638 namespace llvm {
3739 bool DisableSimplifyCFG = false;
3434 #include
3535
3636 using namespace llvm;
37
38 #define DEBUG_TYPE "bugpoint"
3739
3840 namespace llvm {
3941 extern cl::opt OutputPrefix;
2525
2626 using namespace llvm;
2727
28 #define DEBUG_TYPE "lli"
29
2830 bool RemoteTargetExternal::allocateSpace(size_t Size, unsigned Alignment,
2931 uint64_t &Address) {
3032 DEBUG(dbgs() << "Message [allocate space] size: " << Size <<
116116 #include
117117 using namespace llvm;
118118
119 #define DEBUG_TYPE "asm-matcher-emitter"
120
119121 static cl::opt
120122 MatchPrefix("match-prefix", cl::init(""),
121123 cl::desc("Only match instructions with the given prefix"));
2727 #include
2828 #include
2929 using namespace llvm;
30
31 #define DEBUG_TYPE "asm-writer-emitter"
3032
3133 namespace {
3234 class AsmWriterEmitter {
2323 #include
2424 #include
2525 using namespace llvm;
26
27 #define DEBUG_TYPE "dag-patterns"
2628
2729 //===----------------------------------------------------------------------===//
2830 // EEVT::TypeSet Implementation
1616 #include "llvm/TableGen/Record.h"
1717 #include "llvm/TableGen/TableGenBackend.h"
1818 using namespace llvm;
19
20 #define DEBUG_TYPE "dag-isel-emitter"
1921
2022 namespace {
2123 /// DAGISelEmitter - The top-level class which coordinates construction