Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/test/CodeGen/attr-function-return.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-EXTERN
// RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
// RUN: -mfunction-return=thunk-extern -coverage-data-file=/dev/null \
// RUN: | FileCheck %s --check-prefixes=CHECK-GCOV
// RUN: | FileCheck %s --check-prefix=CHECK-GCOV
// RUN: %clang_cc1 -std=gnu2x -triple x86_64-linux-gnu %s -emit-llvm -o - \
// RUN: -mfunction-return=thunk-extern -fsanitize=address \
// RUN: | FileCheck %s --check-prefix=CHECK-ASAN
Expand Down
16 changes: 8 additions & 8 deletions clang/test/CodeGen/code-coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
/// 4.8 (default, compatible with gcov 7) emits the exit block the second.
// RUN: rm -rf %t && mkdir %t && cd %t
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='304*' %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-ELF,304 %s
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,304 %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='407*' %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-ELF,407 %s
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,407 %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone -coverage-data-file=/dev/null %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-ELF,408 %s
// RUN: FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,408 %s
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='304*' %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-XCOFF,304 %s
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,304 %s
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null -coverage-version='407*' %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-XCOFF,407 %s
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,407 %s
// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -disable-red-zone -coverage-data-file=/dev/null %s -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-XCOFF,408 %s
// RUN: FileCheck --check-prefixes=CHECK,CHECK-RT-INIT,408 %s

// RUN: %clang_cc1 -emit-llvm -disable-red-zone -coverage-notes-file=aaa.gcno -coverage-data-file=bbb.gcda -debug-info-kind=limited -dwarf-version=4 %s -o - | FileCheck %s --check-prefix GCOV_FILE_INFO

Expand Down Expand Up @@ -56,12 +56,12 @@ int test2(int b) {
// 408-SAME: i32 875575338

// Check for gcov initialization function pointers.
// CHECK-XCOFF: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"
// CHECK-RT-INIT: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"

// Check that the noredzone flag is set on the generated functions.

// CHECK: void @__llvm_gcov_writeout() unnamed_addr [[NRZ:#[0-9]+]]
// CHECK-ELF: void @__llvm_gcov_init() unnamed_addr [[NRZ]]
// CHECK-CTOR-INIT: void @__llvm_gcov_init() unnamed_addr [[NRZ]]

// CHECK: attributes [[NRZ]] = { {{.*}}noredzone{{.*}} }

Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/include/profile/InstrProfData.inc
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
#define INSTR_PROF_COVNAME_COFF ".lcovn"
#define INSTR_PROF_ORDERFILE_COFF ".lorderfile$M"

// TODO: Placeholder for Windows. We need to revise when we upstream this.
// FIXME: Placeholder for Windows. Windows currently does not initialize
// the GCOV functions in the runtime.
#define INSTR_PROF_COVINIT_COFF ".lcovd$M"

#ifdef _WIN32
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/ProfileData/InstrProfData.inc
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
#define INSTR_PROF_COVNAME_COFF ".lcovn"
#define INSTR_PROF_ORDERFILE_COFF ".lorderfile$M"

// TODO: Placeholder for Windows. We need to revise when we upstream this.
// FIXME: Placeholder for Windows. Windows currently does not initialize
// the GCOV functions in the runtime.
#define INSTR_PROF_COVINIT_COFF ".lcovd$M"

#ifdef _WIN32
Expand Down
9 changes: 7 additions & 2 deletions llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2976,10 +2976,15 @@ void PPCAIXAsmPrinter::emitGCOVRefs() {
/*MultiSymbolsAllowed*/ true);

OutStreamer->switchSection(CtrSection);
const XCOFF::StorageMappingClass MappingClass =
TM.Options.XCOFFReadOnlyPointers ? XCOFF::XMC_RO : XCOFF::XMC_RW;
if (OutContext.hasXCOFFSection(
"__llvm_covinit",
XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD))) {
MCSymbol *S = OutContext.getOrCreateSymbol("__llvm_covinit[RW]");
XCOFF::CsectProperties(MappingClass, XCOFF::XTY_SD))) {
const char *SymbolStr = TM.Options.XCOFFReadOnlyPointers
? "__llvm_covinit[RO]"
: "__llvm_covinit[RW]";
MCSymbol *S = OutContext.getOrCreateSymbol(SymbolStr);
OutStreamer->emitXCOFFRefDirective(S);
}
}
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,9 @@ bool GCOVProfiler::emitProfileNotes(
GlobalVariable *Counters = new GlobalVariable(
*M, CounterTy, false, GlobalValue::InternalLinkage,
Constant::getNullValue(CounterTy), "__llvm_gcov_ctr");
Counters->setSection("__llvm_gcov_ctr_section");
const llvm::Triple &Triple = llvm::Triple(M->getTargetTriple());
if (Triple.getObjectFormat() == llvm::Triple::XCOFF)
Counters->setSection("__llvm_gcov_ctr_section");
Copy link
Collaborator

@hubert-reinterpretcast hubert-reinterpretcast Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving the .ref generation to be from each GCOV-profiled function in the module instead of making this change. This change modifies the counters from being BSS in XCOFF to non-BSS (therefore increasing program load costs).

Not an impediment to landing this patch though.

CountersBySP.emplace_back(Counters, SP);

for (size_t I : llvm::seq<size_t>(0, Measured)) {
Expand Down
129 changes: 129 additions & 0 deletions llvm/test/CodeGen/PowerPC/gcov_ctr_ref_init.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
; Tests if the __llvm_gcov_ctr section contains a .ref pseudo-op
; referring to the __llvm_covinit section.
; RUN: llc < %s | FileCheck --check-prefixes=CHECK,CHECK-RW %s
; RUN: llc -mxcoff-roptr < %s | FileCheck --check-prefixes=CHECK,CHECK-RO %s

target datalayout = "E-m:a-p:32:32-Fi32-i64:64-n32"
target triple = "powerpc-ibm-aix"

; CHECK-RW: .csect __llvm_covinit[RW],3
; CHECK-RO: .csect __llvm_covinit[RO],3
; CHECK: .vbyte 4, __llvm_gcov_writeout[DS]
; CHECK-NEXT: .vbyte 4, __llvm_gcov_reset[DS]
; CHECK: __llvm_gcov_ctr.1:
; CHECK-NEXT: .extern .llvm_gcda_start_file[PR]
; CHECK-NEXT: .extern .llvm_gcda_emit_function[PR]
; CHECK-NEXT: .extern .llvm_gcda_emit_arcs[PR]
; CHECK-NEXT: .extern .llvm_gcda_summary_info[PR]
; CHECK-NEXT: .extern .llvm_gcda_end_file[PR]
; CHECK-RW-NEXT: .ref __llvm_covinit[RW]
; CHECK-RO-NEXT: .ref __llvm_covinit[RO]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems exceedingly weird. Why would we generate a label for __llvm_gcov_ctr.1: and not specify the space it needs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I think this is because of the global merge that happens in llc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I think this is because of the global merge that happens in llc.

Okay. We're seeing an existing bug here then. I'll see about getting an issue opened.


%emit_function_args_ty = type { i32, i32, i32 }
%emit_arcs_args_ty = type { i32, ptr }
%file_info = type { %start_file_args_ty, i32, ptr, ptr }
%start_file_args_ty = type { ptr, i32, i32 }

@__llvm_gcov_ctr = internal global [1 x i64] zeroinitializer, section "__llvm_gcov_ctr_section"
@__llvm_gcov_ctr.1 = internal global [1 x i64] zeroinitializer, section "__llvm_gcov_ctr_section"
@0 = private unnamed_addr constant [10 x i8] c"test.gcda\00", align 1
@__llvm_internal_gcov_emit_function_args.0 = internal unnamed_addr constant [2 x %emit_function_args_ty] [%emit_function_args_ty { i32 0, i32 1961870044, i32 -801444649 }, %emit_function_args_ty { i32 1, i32 1795396728, i32 -801444649 }]
@__llvm_internal_gcov_emit_arcs_args.0 = internal unnamed_addr constant [2 x %emit_arcs_args_ty] [%emit_arcs_args_ty { i32 1, ptr @__llvm_gcov_ctr }, %emit_arcs_args_ty { i32 1, ptr @__llvm_gcov_ctr.1 }]
@__llvm_internal_gcov_emit_file_info = internal unnamed_addr constant [1 x %file_info] [%file_info { %start_file_args_ty { ptr @0, i32 875575338, i32 -801444649 }, i32 2, ptr @__llvm_internal_gcov_emit_function_args.0, ptr @__llvm_internal_gcov_emit_arcs_args.0 }]
@__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit", align 8

define i32 @bar() {
entry:
%gcov_ctr = load i64, ptr @__llvm_gcov_ctr, align 8
%0 = add i64 %gcov_ctr, 1
store i64 %0, ptr @__llvm_gcov_ctr, align 8
ret i32 1
}

define i32 @main() {
entry:
%gcov_ctr = load i64, ptr @__llvm_gcov_ctr.1, align 8
%0 = add i64 %gcov_ctr, 1
store i64 %0, ptr @__llvm_gcov_ctr.1, align 8
%retval = alloca i32, align 4
store i32 0, ptr %retval, align 4
%call = call i32 @bar()
%sub = sub nsw i32 %call, 1
ret i32 %sub
}

define internal void @__llvm_gcov_writeout() unnamed_addr {
entry:
br label %file.loop.header

file.loop.header: ; preds = %file.loop.latch, %entry
%file_idx = phi i32 [ 0, %entry ], [ %next_file_idx, %file.loop.latch ]
%0 = getelementptr inbounds [1 x %file_info], ptr @__llvm_internal_gcov_emit_file_info, i32 0, i32 %file_idx
%start_file_args = getelementptr inbounds nuw %file_info, ptr %0, i32 0, i32 0
%1 = getelementptr inbounds nuw %start_file_args_ty, ptr %start_file_args, i32 0, i32 0
%filename = load ptr, ptr %1, align 4
%2 = getelementptr inbounds nuw %start_file_args_ty, ptr %start_file_args, i32 0, i32 1
%version = load i32, ptr %2, align 4
%3 = getelementptr inbounds nuw %start_file_args_ty, ptr %start_file_args, i32 0, i32 2
%stamp = load i32, ptr %3, align 4
call void @llvm_gcda_start_file(ptr %filename, i32 %version, i32 %stamp)
%4 = getelementptr inbounds nuw %file_info, ptr %0, i32 0, i32 1
%num_ctrs = load i32, ptr %4, align 4
%5 = getelementptr inbounds nuw %file_info, ptr %0, i32 0, i32 2
%emit_function_args = load ptr, ptr %5, align 4
%6 = getelementptr inbounds nuw %file_info, ptr %0, i32 0, i32 3
%emit_arcs_args = load ptr, ptr %6, align 4
%7 = icmp slt i32 0, %num_ctrs
br i1 %7, label %counter.loop.header, label %file.loop.latch

counter.loop.header: ; preds = %counter.loop.header, %file.loop.header
%ctr_idx = phi i32 [ 0, %file.loop.header ], [ %15, %counter.loop.header ]
%8 = getelementptr inbounds %emit_function_args_ty, ptr %emit_function_args, i32 %ctr_idx
%9 = getelementptr inbounds nuw %emit_function_args_ty, ptr %8, i32 0, i32 0
%ident = load i32, ptr %9, align 4
%10 = getelementptr inbounds nuw %emit_function_args_ty, ptr %8, i32 0, i32 1
%func_checkssum = load i32, ptr %10, align 4
%11 = getelementptr inbounds nuw %emit_function_args_ty, ptr %8, i32 0, i32 2
%cfg_checksum = load i32, ptr %11, align 4
call void @llvm_gcda_emit_function(i32 %ident, i32 %func_checkssum, i32 %cfg_checksum)
%12 = getelementptr inbounds %emit_arcs_args_ty, ptr %emit_arcs_args, i32 %ctr_idx
%13 = getelementptr inbounds nuw %emit_arcs_args_ty, ptr %12, i32 0, i32 0
%num_counters = load i32, ptr %13, align 4
%14 = getelementptr inbounds nuw %emit_arcs_args_ty, ptr %12, i32 0, i32 1
%counters = load ptr, ptr %14, align 4
call void @llvm_gcda_emit_arcs(i32 %num_counters, ptr %counters)
%15 = add i32 %ctr_idx, 1
%16 = icmp slt i32 %15, %num_ctrs
br i1 %16, label %counter.loop.header, label %file.loop.latch

file.loop.latch: ; preds = %counter.loop.header, %file.loop.header
call void @llvm_gcda_summary_info()
call void @llvm_gcda_end_file()
%next_file_idx = add i32 %file_idx, 1
%17 = icmp slt i32 %next_file_idx, 1
br i1 %17, label %file.loop.header, label %exit

exit: ; preds = %file.loop.latch
ret void
}

declare void @llvm_gcda_start_file(ptr, i32, i32)

declare void @llvm_gcda_emit_function(i32, i32, i32)

declare void @llvm_gcda_emit_arcs(i32, ptr)

declare void @llvm_gcda_summary_info()

declare void @llvm_gcda_end_file()

define internal void @__llvm_gcov_reset() unnamed_addr {
entry:
call void @llvm.memset.p0.i64(ptr @__llvm_gcov_ctr, i8 0, i64 8, i1 false)
call void @llvm.memset.p0.i64(ptr @__llvm_gcov_ctr.1, i8 0, i64 8, i1 false)
ret void
}

declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)


13 changes: 7 additions & 6 deletions llvm/test/Transforms/GCOVProfiling/kcfi-normalize.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
; RUN: mkdir -p %t && cd %t
; RUN: opt < %s -S -passes=insert-gcov-profiling \
; RUN: -mtriple=x86_64-unknown-linux-gnu | FileCheck \
; RUN: --check-prefixes=CHECK,CHECK-ELF %s
; RUN: --check-prefixes=CHECK,CHECK-CTOR-INIT %s
; RUN: opt < %s -S -passes=insert-gcov-profiling \
; RUN: -mtriple=powerpc64-ibm-aix | FileCheck \
; RUN: --check-prefixes=CHECK,CHECK-XCOFF %s
; RUN: --check-prefixes=CHECK,CHECK-RT-INIT %s

; Check for gcov initialization function pointers for XCOFF.
; CHECK-XCOFF: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"
; Check for gcov initialization function pointers when we initialize
; the writeout and reset functions in the runtime.
; CHECK-RT-INIT: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"

define dso_local void @empty() !dbg !5 {
entry:
Expand All @@ -35,7 +36,7 @@ entry:
; CHECK-SAME: !kcfi_type ![[#TYPE:]]
; CHECK: define internal void @__llvm_gcov_reset()
; CHECK-SAME: !kcfi_type ![[#TYPE]]
; CHECK-ELF: define internal void @__llvm_gcov_init()
; CHECK-ELF-SAME: !kcfi_type ![[#TYPE]]
; CHECK-CTOR-INIT: define internal void @__llvm_gcov_init()
; CHECK-CTOR-INIT-SAME: !kcfi_type ![[#TYPE]]

; CHECK: ![[#TYPE]] = !{i32 -440107680}
13 changes: 7 additions & 6 deletions llvm/test/Transforms/GCOVProfiling/kcfi.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
; RUN: mkdir -p %t && cd %t
; RUN: opt < %s -S -passes=insert-gcov-profiling \
; RUN: -mtriple=x86_64-unknown-linux-gnu | FileCheck \
; RUN: --check-prefixes=CHECK,CHECK-ELF %s
; RUN: --check-prefixes=CHECK,CHECK-CTOR-INIT %s
; RUN: opt < %s -S -passes=insert-gcov-profiling \
; RUN: -mtriple=powerpc64-ibm-aix | FileCheck \
; RUN: --check-prefixes=CHECK,CHECK-XCOFF %s
; RUN: --check-prefixes=CHECK,CHECK-RT-INIT %s

; Check for gcov initialization function pointers for XCOFF.
; CHECK-XCOFF: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"
; Check for gcov initialization function pointers when we initialize
; the writeout and reset functions in the runtime.
; CHECK-RT-INIT: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"

define dso_local void @empty() !dbg !5 {
entry:
Expand All @@ -33,7 +34,7 @@ entry:
; CHECK-SAME: !kcfi_type ![[#TYPE:]]
; CHECK: define internal void @__llvm_gcov_reset()
; CHECK-SAME: !kcfi_type ![[#TYPE]]
; CHECK-ELF: define internal void @__llvm_gcov_init()
; CHECK-ELF-SAME: !kcfi_type ![[#TYPE]]
; CHECK-CTOR-INIT: define internal void @__llvm_gcov_init()
; CHECK-CTOR-INIT-SAME: !kcfi_type ![[#TYPE]]

; CHECK: ![[#TYPE]] = !{i32 -1522505972}
11 changes: 6 additions & 5 deletions llvm/test/Transforms/GCOVProfiling/module-flags.ll
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
; RUN: mkdir -p %t && cd %t
; RUN: opt < %s -S -passes=insert-gcov-profiling \
; RUN: -mtriple=x86_64-unknown-linux-gnu | FileCheck \
; RUN: --check-prefixes=CHECK,CHECK-ELF %s
; RUN: --check-prefixes=CHECK,CHECK-CTOR-INIT %s
; RUN: opt < %s -S -passes=insert-gcov-profiling \
; RUN: -mtriple=powerpc64-ibm-aix | FileCheck \
; RUN: --check-prefixes=CHECK,CHECK-XCOFF %s
; RUN: --check-prefixes=CHECK,CHECK-RT-INIT %s

; Check for gcov initialization function pointers for XCOFF.
; CHECK-XCOFF: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"
; Check for gcov initialization function pointers when we initialize
; the writeout and reset functions in the runtime.
; CHECK-RT-INIT: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr @__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"

define dso_local void @empty() !dbg !5 {
entry:
Expand Down Expand Up @@ -36,5 +37,5 @@ entry:
;; Infer uwtable and "frame-pointer" from the module flags.
; CHECK: define internal void @__llvm_gcov_writeout() unnamed_addr #[[#ATTR:]]
; CHECK: define internal void @__llvm_gcov_reset() unnamed_addr #[[#ATTR]]
; CHECK-ELF: define internal void @__llvm_gcov_init() unnamed_addr #[[#ATTR]]
; CHECK-CTOR-INIT: define internal void @__llvm_gcov_init() unnamed_addr #[[#ATTR]]
; CHECK: attributes #[[#ATTR]] = { noinline nounwind uwtable "frame-pointer"="all" }
Loading