Add a LLVM_DUMP_METHOD macro.
authorNico Weber <nicolasweber@gmx.de>
Fri, 3 Jan 2014 22:53:37 +0000 (22:53 +0000)
committerNico Weber <nicolasweber@gmx.de>
Fri, 3 Jan 2014 22:53:37 +0000 (22:53 +0000)
The motivation is to mark dump methods as used in debug builds so that they can
be called from lldb, but to not do so in release builds so that they can be
dead-stripped.

There's lots of potential follow-up work suggested in the thread
"Should dump methods be LLVM_ATTRIBUTE_USED only in debug builds?" on cfe-dev,
but everyone seems to agreen on this subset.

Macro name chosen by fair coin toss.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198456 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/Compiler.h
lib/CodeGen/MachineBlockPlacement.cpp
lib/Transforms/Scalar/SROA.cpp

index d4f55e1a1b275d8ded36c2dcc586c6430eac5c8d..a6b5687d505e087a79b708220e3154bbe9a92bdd 100644 (file)
 #define LLVM_HAS_INITIALIZER_LISTS 0
 #endif
 
+/// \brief Mark debug helper function definitions like dump() that should not be
+/// stripped from debug builds.
+// FIXME: Move this to a private config.h as it's not usable in public headers.
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
+#else
+#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
+#endif
+
 #endif
index f297c5f67862f11bb0d72fc3812f09909e339dc7..760033fff13c7d476de4005a54d7713d6896c932 100644 (file)
@@ -152,7 +152,7 @@ public:
 
 #ifndef NDEBUG
   /// \brief Dump the blocks in this chain.
-  void dump() LLVM_ATTRIBUTE_USED {
+  LLVM_DUMP_METHOD void dump() {
     for (iterator I = begin(), E = end(); I != E; ++I)
       (*I)->dump();
   }
index 9f3fc83d129dfc8b8638523eb986d9aff4afc399..dc5dbbb84bbd78b053675992cf004ece55b2ae2f 100644 (file)
@@ -244,8 +244,8 @@ public:
   void printUse(raw_ostream &OS, const_iterator I,
                 StringRef Indent = "  ") const;
   void print(raw_ostream &OS) const;
-  void LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED dump(const_iterator I) const;
-  void LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED dump() const;
+  LLVM_DUMP_METHOD void dump(const_iterator I) const;
+  LLVM_DUMP_METHOD void dump() const;
 #endif
 
 private: