Skip to content

Commit 18ec4ac

Browse files
author
Qiongsi Wu
committed
Refactoring tests, adding profile-use macro
1 parent a6c3b46 commit 18ec4ac

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,9 @@ static void InitializePGOProfileMacros(const CodeGenOptions &CodeGenOpts,
13681368
MacroBuilder &Builder) {
13691369
if (CodeGenOpts.hasProfileInstr())
13701370
Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE");
1371+
1372+
if (CodeGenOpts.hasProfileIRUse() || CodeGenOpts.hasProfileClangUse())
1373+
Builder.defineMacro("__LLVM_INSTR_PROFILE_USE");
13711374
}
13721375

13731376
/// InitializePreprocessor - Initialize the preprocessor getting it and the

clang/test/Preprocessor/pgo-init.c

Lines changed: 0 additions & 5 deletions
This file was deleted.

clang/test/Profile/c-general.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
// Also check compatibility with older profiles.
1010
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v1 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
1111

12+
// RUN: %clang -fprofile-generate -E -dM %s | FileCheck -match-full-lines -check-prefix=PROFGENMACRO %s
13+
// RUN: %clang -fprofile-instr-generate -E -dM %s | FileCheck -match-full-lines -check-prefix=PROFGENMACRO %s
14+
// RUN: %clang -fcs-profile-generate -E -dM %s | FileCheck -match-full-lines -check-prefix=PROFGENMACRO %s
15+
//
16+
// RUN: %clang -fprofile-use=%t.profdata -E -dM %s | FileCheck -match-full-lines -check-prefix=PROFUSEMACRO %s
17+
18+
// PROFGENMACRO:#define __LLVM_INSTR_PROFILE_GENERATE 1
19+
// PROFUSEMACRO:#define __LLVM_INSTR_PROFILE_USE 1
20+
1221
// PGOGEN: @[[SLC:__profc_simple_loops]] = private global [4 x i64] zeroinitializer
1322
// PGOGEN: @[[IFC:__profc_conditionals]] = private global [13 x i64] zeroinitializer
1423
// PGOGEN: @[[EEC:__profc_early_exits]] = private global [9 x i64] zeroinitializer
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %clang_profgen %s -S -emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN
2+
// RUN: %clang_profgen -o %t %s
3+
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
4+
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
5+
// RUN: %clang_profuse=%t.profdata %s -S -emit-llvm -o - | FileCheck %s --check-prefix=PROFUSE
6+
#include "profile/instr_profiling.h"
7+
8+
__attribute__((noinline)) int bar() { return 4; }
9+
10+
int foo() {
11+
__llvm_profile_reset_counters();
12+
// PROFGEN: call void @__llvm_profile_reset_counters()
13+
// PROFUSE-NOT: call void @__llvm_profile_reset_counters()
14+
return bar();
15+
}
16+
17+
int main() {
18+
int z = foo() + 3;
19+
__llvm_profile_dump();
20+
// PROFGEN: %call1 = call signext i32 @__llvm_profile_dump()
21+
// PROFUSE-NOT: %call1 = call signext i32 @__llvm_profile_dump()
22+
__llvm_orderfile_dump();
23+
// PROFGEN: %call2 = call signext i32 @__llvm_orderfile_dump()
24+
// PROFUSE-NOT: %call2 = call signext i32 @__llvm_orderfile_dump()
25+
return z + bar() - 11;
26+
}

0 commit comments

Comments
 (0)