summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Transforms/GCOVProfiler.h31
-rw-r--r--llvm/lib/Passes/PassBuilder.cpp1
-rw-r--r--llvm/lib/Passes/PassRegistry.def1
-rw-r--r--llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp14
-rw-r--r--llvm/test/Transforms/GCOVProfiling/function-numbering.ll4
-rw-r--r--llvm/test/Transforms/GCOVProfiling/global-ctor.ll4
-rw-r--r--llvm/test/Transforms/GCOVProfiling/linezero.ll3
-rw-r--r--llvm/test/Transforms/GCOVProfiling/linkagename.ll4
-rw-r--r--llvm/test/Transforms/GCOVProfiling/modules.ll1
-rw-r--r--llvm/test/Transforms/GCOVProfiling/return-block.ll9
-rw-r--r--llvm/test/Transforms/GCOVProfiling/version.ll8
11 files changed, 79 insertions, 1 deletions
diff --git a/llvm/include/llvm/Transforms/GCOVProfiler.h b/llvm/include/llvm/Transforms/GCOVProfiler.h
new file mode 100644
index 00000000000..f6521901a33
--- /dev/null
+++ b/llvm/include/llvm/Transforms/GCOVProfiler.h
@@ -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
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 7ca5c7b7b3f..fca3e2534ed 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -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"
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index fcc00bafcae..398da320171 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -43,6 +43,7 @@ MODULE_PASS("forceattrs", ForceFunctionAttrsPass())
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())
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index f7ace857a37..9b19833cb75 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -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.
diff --git a/llvm/test/Transforms/GCOVProfiling/function-numbering.ll b/llvm/test/Transforms/GCOVProfiling/function-numbering.ll
index f66ce243ac3..6f10fd23cb0 100644
--- a/llvm/test/Transforms/GCOVProfiling/function-numbering.ll
+++ b/llvm/test/Transforms/GCOVProfiling/function-numbering.ll
@@ -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"
diff --git a/llvm/test/Transforms/GCOVProfiling/global-ctor.ll b/llvm/test/Transforms/GCOVProfiling/global-ctor.ll
index 1275933850f..e20da85eb58 100644
--- a/llvm/test/Transforms/GCOVProfiling/global-ctor.ll
+++ b/llvm/test/Transforms/GCOVProfiling/global-ctor.ll
@@ -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 }]
diff --git a/llvm/test/Transforms/GCOVProfiling/linezero.ll b/llvm/test/Transforms/GCOVProfiling/linezero.ll
index 2298f125440..a2e5381e4db 100644
--- a/llvm/test/Transforms/GCOVProfiling/linezero.ll
+++ b/llvm/test/Transforms/GCOVProfiling/linezero.ll
@@ -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"
diff --git a/llvm/test/Transforms/GCOVProfiling/linkagename.ll b/llvm/test/Transforms/GCOVProfiling/linkagename.ll
index b076d932ea8..dc46a35a185 100644
--- a/llvm/test/Transforms/GCOVProfiling/linkagename.ll
+++ b/llvm/test/Transforms/GCOVProfiling/linkagename.ll
@@ -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
diff --git a/llvm/test/Transforms/GCOVProfiling/modules.ll b/llvm/test/Transforms/GCOVProfiling/modules.ll
index fa51d2943b8..460d4dfdfa1 100644
--- a/llvm/test/Transforms/GCOVProfiling/modules.ll
+++ b/llvm/test/Transforms/GCOVProfiling/modules.ll
@@ -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
diff --git a/llvm/test/Transforms/GCOVProfiling/return-block.ll b/llvm/test/Transforms/GCOVProfiling/return-block.ll
index ee9ca1da23a..424e0b581f0 100644
--- a/llvm/test/Transforms/GCOVProfiling/return-block.ll
+++ b/llvm/test/Transforms/GCOVProfiling/return-block.ll
@@ -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"
diff --git a/llvm/test/Transforms/GCOVProfiling/version.ll b/llvm/test/Transforms/GCOVProfiling/version.ll
index e5ffa33c648..da70ac46357 100644
--- a/llvm/test/Transforms/GCOVProfiling/version.ll
+++ b/llvm/test/Transforms/GCOVProfiling/version.ll
@@ -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
}
OpenPOWER on IntegriCloud