[llvm] r271823 - [PM] Port GCOVProfiler pass to the new pass manager

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 4 22:12:24 PDT 2016


Author: davidxl
Date: Sun Jun  5 00:12:23 2016
New Revision: 271823

URL: http://llvm.org/viewvc/llvm-project?rev=271823&view=rev
Log:
[PM] Port GCOVProfiler pass to the new pass manager



Added:
    llvm/trunk/include/llvm/Transforms/GCOVProfiler.h
Modified:
    llvm/trunk/lib/Passes/PassBuilder.cpp
    llvm/trunk/lib/Passes/PassRegistry.def
    llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
    llvm/trunk/test/Transforms/GCOVProfiling/function-numbering.ll
    llvm/trunk/test/Transforms/GCOVProfiling/global-ctor.ll
    llvm/trunk/test/Transforms/GCOVProfiling/linezero.ll
    llvm/trunk/test/Transforms/GCOVProfiling/linkagename.ll
    llvm/trunk/test/Transforms/GCOVProfiling/modules.ll
    llvm/trunk/test/Transforms/GCOVProfiling/return-block.ll
    llvm/trunk/test/Transforms/GCOVProfiling/version.ll

Added: llvm/trunk/include/llvm/Transforms/GCOVProfiler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/GCOVProfiler.h?rev=271823&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Transforms/GCOVProfiler.h (added)
+++ llvm/trunk/include/llvm/Transforms/GCOVProfiler.h Sun Jun  5 00:12:23 2016
@@ -0,0 +1,31 @@
+//===- Transforms/GCOVProfiler.h - GCOVProfiler pass  ----------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+/// \file
+/// This file provides the interface for the GCOV style profiler  pass.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_GCOVPROFILER_H
+#define LLVM_TRANSFORMS_GCOVPROFILER_H
+
+#include "llvm/IR/PassManager.h"
+#include "llvm/Transforms/Instrumentation.h"
+
+namespace llvm {
+/// The gcov-style instrumentation pass
+class GCOVProfilerPass : public PassInfoMixin<GCOVProfilerPass> {
+public:
+  GCOVProfilerPass(const GCOVOptions &Options = GCOVOptions::getDefault()) : GCOVOpts(Options) { }
+  PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);
+
+private:
+  GCOVOptions GCOVOpts;
+};
+
+} // End llvm namespace
+#endif

Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=271823&r1=271822&r2=271823&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Sun Jun  5 00:12:23 2016
@@ -50,6 +50,7 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/GCOVProfiler.h"
 #include "llvm/Transforms/IPO/ConstantMerge.h"
 #include "llvm/Transforms/IPO/ElimAvailExtern.h"
 #include "llvm/Transforms/IPO/ForceFunctionAttrs.h"

Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=271823&r1=271822&r2=271823&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Sun Jun  5 00:12:23 2016
@@ -43,6 +43,7 @@ MODULE_PASS("forceattrs", ForceFunctionA
 MODULE_PASS("globaldce", GlobalDCEPass())
 MODULE_PASS("globalopt", GlobalOptPass())
 MODULE_PASS("inferattrs", InferFunctionAttrsPass())
+MODULE_PASS("insert-gcov-profiling", GCOVProfilerPass())
 MODULE_PASS("internalize", InternalizePass())
 MODULE_PASS("instrprof", InstrProfiling())
 MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())

Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=271823&r1=271822&r2=271823&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Sun Jun  5 00:12:23 2016
@@ -14,7 +14,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Transforms/Instrumentation.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/STLExtras.h"
@@ -35,6 +34,8 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/GCOVProfiler.h"
+#include "llvm/Transforms/Instrumentation.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 #include <algorithm>
 #include <memory>
@@ -464,6 +465,17 @@ bool GCOVProfiler::runOnModule(Module &M
   return false;
 }
 
+PreservedAnalyses GCOVProfilerPass::run(Module &M,
+                                        AnalysisManager<Module> &AM) {
+
+  GCOVProfiler Profiler(GCOVOpts);
+
+  if (!Profiler.runOnModule(M))
+    return PreservedAnalyses::all();
+
+  return PreservedAnalyses::none();
+}
+
 static bool functionHasLines(Function &F) {
   // Check whether this function actually has any source lines. Not only
   // do these waste space, they also can crash gcov.

Modified: llvm/trunk/test/Transforms/GCOVProfiling/function-numbering.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GCOVProfiling/function-numbering.ll?rev=271823&r1=271822&r2=271823&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GCOVProfiling/function-numbering.ll (original)
+++ llvm/trunk/test/Transforms/GCOVProfiling/function-numbering.ll Sun Jun  5 00:12:23 2016
@@ -7,6 +7,10 @@
 
 ; RUN: opt -insert-gcov-profiling -S < %t2 | FileCheck --check-prefix GCDA %s
 ; RUN: llvm-cov gcov -n -dump %T/function-numbering.gcno 2>&1 | FileCheck --check-prefix GCNO %s
+; RUNN: rm %T/function-numbering.gcno
+
+; RUN: opt -passes=insert-gcov-profiling -S < %t2 | FileCheck --check-prefix GCDA %s
+; RUN: llvm-cov gcov -n -dump %T/function-numbering.gcno 2>&1 | FileCheck --check-prefix GCNO %s
 
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.10.0"

Modified: llvm/trunk/test/Transforms/GCOVProfiling/global-ctor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GCOVProfiling/global-ctor.ll?rev=271823&r1=271822&r2=271823&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GCOVProfiling/global-ctor.ll (original)
+++ llvm/trunk/test/Transforms/GCOVProfiling/global-ctor.ll Sun Jun  5 00:12:23 2016
@@ -4,6 +4,10 @@
 ; RUN: not grep '_GLOBAL__sub_I_global-ctor' %T/global-ctor.gcno
 ; RUN: rm %T/global-ctor.gcno
 
+; RUN: opt -passes=insert-gcov-profiling -disable-output < %t2
+; RUN: not grep '_GLOBAL__sub_I_global-ctor' %T/global-ctor.gcno
+; RUN: rm %T/global-ctor.gcno
+
 @x = global i32 0, align 4
 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_global-ctor.ll, i8* null }]
 

Modified: llvm/trunk/test/Transforms/GCOVProfiling/linezero.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GCOVProfiling/linezero.ll?rev=271823&r1=271822&r2=271823&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GCOVProfiling/linezero.ll (original)
+++ llvm/trunk/test/Transforms/GCOVProfiling/linezero.ll Sun Jun  5 00:12:23 2016
@@ -1,6 +1,9 @@
 ; RUN: sed -e 's|PATTERN|%/T|g' %s | opt -insert-gcov-profiling -disable-output
 ; RUN: rm %T/linezero.gcno
 
+; RUN: sed -e 's|PATTERN|%/T|g' %s | opt -passes=insert-gcov-profiling -disable-output
+; RUN: rm %T/linezero.gcno
+
 ; This is a crash test.
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

Modified: llvm/trunk/test/Transforms/GCOVProfiling/linkagename.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GCOVProfiling/linkagename.ll?rev=271823&r1=271822&r2=271823&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GCOVProfiling/linkagename.ll (original)
+++ llvm/trunk/test/Transforms/GCOVProfiling/linkagename.ll Sun Jun  5 00:12:23 2016
@@ -4,6 +4,10 @@
 ; RUN: grep _Z3foov %T/linkagename.gcno
 ; RUN: rm %T/linkagename.gcno
 
+; RUN: opt -passes=insert-gcov-profiling -disable-output < %t2
+; RUN: grep _Z3foov %T/linkagename.gcno
+; RUN: rm %T/linkagename.gcno
+
 define void @_Z3foov() !dbg !5 {
 entry:
   ret void, !dbg !8

Modified: llvm/trunk/test/Transforms/GCOVProfiling/modules.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GCOVProfiling/modules.ll?rev=271823&r1=271822&r2=271823&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GCOVProfiling/modules.ll (original)
+++ llvm/trunk/test/Transforms/GCOVProfiling/modules.ll Sun Jun  5 00:12:23 2016
@@ -1,4 +1,5 @@
 ; RUN: opt -insert-gcov-profiling -o - < %s | llvm-dis | FileCheck -check-prefix=EMIT-ARCS %s
+; RUN: opt -passes=insert-gcov-profiling -o - < %s | llvm-dis | FileCheck -check-prefix=EMIT-ARCS %s
 
 ; EMIT-ARCS-NOT: call void @llvm_gcda_start_file
 

Modified: llvm/trunk/test/Transforms/GCOVProfiling/return-block.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GCOVProfiling/return-block.ll?rev=271823&r1=271822&r2=271823&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GCOVProfiling/return-block.ll (original)
+++ llvm/trunk/test/Transforms/GCOVProfiling/return-block.ll Sun Jun  5 00:12:23 2016
@@ -9,6 +9,15 @@
 ; But we can optionally emit it second, to match newer gcc versions.
 ; RUN: opt -insert-gcov-profiling -gcov-exit-block-before-body -disable-output %t2
 ; RUN: llvm-cov gcov -n -dump %T/return-block.gcno 2>&1 | FileCheck -check-prefix=CHECK -check-prefix=RETURN-SECOND %s
+; RUN: rm  %T/return-block.gcno
+
+; By default, the return block is last.
+; RUN: opt -passes=insert-gcov-profiling -disable-output %t2
+; RUN: llvm-cov gcov -n -dump %T/return-block.gcno 2>&1 | FileCheck -check-prefix=CHECK -check-prefix=RETURN-LAST %s
+
+; But we can optionally emit it second, to match newer gcc versions.
+; RUN: opt -passes=insert-gcov-profiling -gcov-exit-block-before-body -disable-output %t2
+; RUN: llvm-cov gcov -n -dump %T/return-block.gcno 2>&1 | FileCheck -check-prefix=CHECK -check-prefix=RETURN-SECOND %s
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"

Modified: llvm/trunk/test/Transforms/GCOVProfiling/version.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GCOVProfiling/version.ll?rev=271823&r1=271822&r2=271823&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GCOVProfiling/version.ll (original)
+++ llvm/trunk/test/Transforms/GCOVProfiling/version.ll Sun Jun  5 00:12:23 2016
@@ -8,6 +8,14 @@
 ; RUN: head -c8 %T/version.gcno | grep '^oncg.704'
 ; RUN: rm %T/version.gcno
 
+; RUN: opt -passes=insert-gcov-profiling -disable-output < %t2
+; RUN: head -c8 %T/version.gcno | grep '^oncg.204'
+; RUN: rm %T/version.gcno
+; RUN: not opt -passes=insert-gcov-profiling -default-gcov-version=asdfasdf -disable-output < %t2
+; RUN: opt -passes=insert-gcov-profiling -default-gcov-version=407* -disable-output < %t2
+; RUN: head -c8 %T/version.gcno | grep '^oncg.704'
+; RUN: rm %T/version.gcno
+
 define void @test() !dbg !5 {
   ret void, !dbg !8
 }




More information about the llvm-commits mailing list