[Debugify] Add -debugify-each for testing each pass in a pipeline

This adds a -debugify-each mode to opt which, when enabled, wraps each
{Module,Function}Pass in a pipeline with logic to add, check, and strip
synthetic debug info for testing purposes.

This mode can be used to test complex pipelines for debug info bugs, or
to collect statistics about the number of debug values & locations lost
throughout various stages of a pipeline.

Patch by Son Tuan Vu!

Differential Revision: https://reviews.llvm.org/D46525

llvm-svn: 332312
diff --git a/llvm/test/DebugInfo/debugify-each.ll b/llvm/test/DebugInfo/debugify-each.ll
new file mode 100644
index 0000000..569c629
--- /dev/null
+++ b/llvm/test/DebugInfo/debugify-each.ll
@@ -0,0 +1,24 @@
+; RUN: opt -debugify-each -O3 -S -o - < %s | FileCheck %s
+; RUN: opt -debugify-each -instrprof -sroa -sccp -S -o - < %s | FileCheck %s
+
+define void @foo() {
+  ret void
+}
+
+define void @bar() {
+  ret void
+}
+
+; Verify that the module & function (check-)debugify passes run at least twice.
+
+; CHECK-DAG: CheckModuleDebugify: PASS
+; CHECK-DAG: CheckFunctionDebugify: PASS
+; CHECK-DAG: CheckFunctionDebugify: PASS
+; CHECK-DAG: CheckFunctionDebugify: PASS
+; CHECK-DAG: CheckFunctionDebugify: PASS
+
+; CHECK-DAG: CheckModuleDebugify: PASS
+; CHECK-DAG: CheckFunctionDebugify: PASS
+; CHECK-DAG: CheckFunctionDebugify: PASS
+; CHECK-DAG: CheckFunctionDebugify: PASS
+; CHECK-DAG: CheckFunctionDebugify: PASS