Skip to content

Commit 6c9381e

Browse files
author
Qiongsi Wu
committed
Initial commit
1 parent 74a09bd commit 6c9381e

File tree

7 files changed

+83
-36
lines changed

7 files changed

+83
-36
lines changed

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
100100
/*OwnsHeaderSearch=*/false);
101101
PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
102102
InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
103-
Compiler.getFrontendOpts());
103+
Compiler.getFrontendOpts(), Compiler.getCodeGenOpts());
104104
ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts,
105105
Compiler.getTarget().getTriple());
106106
}

clang/include/clang/Frontend/Utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ class PCHContainerReader;
4343
class Preprocessor;
4444
class PreprocessorOptions;
4545
class PreprocessorOutputOptions;
46+
class CodeGenOptions;
4647

4748
/// InitializePreprocessor - Initialize the preprocessor getting it and the
4849
/// environment ready to process a single file.
4950
void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts,
5051
const PCHContainerReader &PCHContainerRdr,
51-
const FrontendOptions &FEOpts);
52+
const FrontendOptions &FEOpts,
53+
const CodeGenOptions &CodeGenOpts);
5254

5355
/// DoPrintPreprocessedInput - Implement -E mode.
5456
void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
470470

471471
// Predefine macros and configure the preprocessor.
472472
InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
473-
getFrontendOpts());
473+
getFrontendOpts(), getCodeGenOpts());
474474

475475
// Initialize the header search object. In CUDA compilations, we use the aux
476476
// triple (the host triple) to initialize our header search, since we need to

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
13661366

13671367
/// InitializePreprocessor - Initialize the preprocessor getting it and the
13681368
/// environment ready to process a single file.
1369-
void clang::InitializePreprocessor(
1370-
Preprocessor &PP, const PreprocessorOptions &InitOpts,
1371-
const PCHContainerReader &PCHContainerRdr,
1372-
const FrontendOptions &FEOpts) {
1369+
void clang::InitializePreprocessor(Preprocessor &PP,
1370+
const PreprocessorOptions &InitOpts,
1371+
const PCHContainerReader &PCHContainerRdr,
1372+
const FrontendOptions &FEOpts,
1373+
const CodeGenOptions &CodeGenOpts) {
13731374
const LangOptions &LangOpts = PP.getLangOpts();
13741375
std::string PredefineBuffer;
13751376
PredefineBuffer.reserve(4080);
@@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor(
14161417
InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
14171418
FEOpts, Builder);
14181419

1420+
if (CodeGenOpts.hasProfileIRInstr())
1421+
Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE");
1422+
14191423
// Add on the predefines from the driver. Wrap in a #line directive to report
14201424
// that they come from the command line.
14211425
Builder.append("# 1 \"<command line>\" 1");

compiler-rt/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ endif(COMPILER_RT_BUILD_ORC)
4444
if (COMPILER_RT_BUILD_PROFILE)
4545
set(PROFILE_HEADERS
4646
profile/InstrProfData.inc
47+
profile/instr_prof_interface.h
4748
)
4849
endif(COMPILER_RT_BUILD_PROFILE)
4950

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*===---- instr_profiling.h - Instrumentation PGO User Program API ----------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*
9+
* This header provides a public interface for user programs to provide
10+
* fine-grained control of profile dumping.
11+
*
12+
\*===---------------------------------------------------------------------===*/
13+
14+
#ifndef COMPILER_RT_INSTR_PROFILING
15+
#define COMPILER_RT_INSTR_PROFILING
16+
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
#ifdef __LLVM_INSTR_PROFILE_GENERATE
22+
// Profile file reset and dump interfaces.
23+
// Only defined when `-fprofile-generate` is in effect.
24+
25+
/*!
26+
* \brief Interface to set all PGO counters to zero for the current process.
27+
*
28+
*/
29+
void __llvm_profile_reset_counters(void);
30+
31+
/*!
32+
* \brief this is a wrapper interface to \c __llvm_profile_write_file.
33+
* After this interface is invoked, an already dumped flag will be set
34+
* so that profile won't be dumped again during program exit.
35+
* Invocation of interface __llvm_profile_reset_counters will clear
36+
* the flag. This interface is designed to be used to collect profile
37+
* data from user selected hot regions. The use model is
38+
* __llvm_profile_reset_counters();
39+
* ... hot region 1
40+
* __llvm_profile_dump();
41+
* .. some other code
42+
* __llvm_profile_reset_counters();
43+
* ... hot region 2
44+
* __llvm_profile_dump();
45+
*
46+
* It is expected that on-line profile merging is on with \c %m specifier
47+
* used in profile filename . If merging is not turned on, user is expected
48+
* to invoke __llvm_profile_set_filename to specify different profile names
49+
* for different regions before dumping to avoid profile write clobbering.
50+
*/
51+
int __llvm_profile_dump(void);
52+
53+
// Interface to dump the current process' order file to disk.
54+
int __llvm_orderfile_dump(void);
55+
56+
#else
57+
#define __llvm_profile_reset_counters()
58+
#define __llvm_profile_dump()
59+
#define __llvm_orderfile_dump()
60+
#endif
61+
62+
#ifdef __cplusplus
63+
} // extern "C"
64+
#endif
65+
66+
#endif

compiler-rt/lib/profile/InstrProfiling.h

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include "InstrProfilingPort.h"
1313
#include <stdio.h>
1414

15+
#define __LLVM_INSTR_PROFILE_GENERATE
16+
#include "profile/instr_prof_interface.h"
17+
1518
#define INSTR_PROF_VISIBILITY COMPILER_RT_VISIBILITY
1619
#include "profile/InstrProfData.inc"
1720

@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes();
100103
ValueProfNode *__llvm_profile_end_vnodes();
101104
uint32_t *__llvm_profile_begin_orderfile();
102105

103-
/*!
104-
* \brief Clear profile counters to zero.
105-
*
106-
*/
107-
void __llvm_profile_reset_counters(void);
108-
109106
/*!
110107
* \brief Merge profile data from buffer.
111108
*
@@ -156,29 +153,6 @@ void __llvm_profile_instrument_target_value(uint64_t TargetValue, void *Data,
156153
int __llvm_profile_write_file(void);
157154

158155
int __llvm_orderfile_write_file(void);
159-
/*!
160-
* \brief this is a wrapper interface to \c __llvm_profile_write_file.
161-
* After this interface is invoked, an already dumped flag will be set
162-
* so that profile won't be dumped again during program exit.
163-
* Invocation of interface __llvm_profile_reset_counters will clear
164-
* the flag. This interface is designed to be used to collect profile
165-
* data from user selected hot regions. The use model is
166-
* __llvm_profile_reset_counters();
167-
* ... hot region 1
168-
* __llvm_profile_dump();
169-
* .. some other code
170-
* __llvm_profile_reset_counters();
171-
* ... hot region 2
172-
* __llvm_profile_dump();
173-
*
174-
* It is expected that on-line profile merging is on with \c %m specifier
175-
* used in profile filename . If merging is not turned on, user is expected
176-
* to invoke __llvm_profile_set_filename to specify different profile names
177-
* for different regions before dumping to avoid profile write clobbering.
178-
*/
179-
int __llvm_profile_dump(void);
180-
181-
int __llvm_orderfile_dump(void);
182156

183157
/*!
184158
* \brief Set the filename for writing instrumentation data.

0 commit comments

Comments
 (0)