mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-21 13:06:50 +00:00
[InstrProf] Remove -forder-file-instrumentation (#130192)
This commit is contained in:
parent
0ed5f9b22b
commit
2044dd07da
clang
docs
include/clang/Driver
lib/Driver
test/Driver
compiler-rt
include/profile
lib/profile
InstrProfiling.hInstrProfilingFile.cInstrProfilingPlatformAIX.cInstrProfilingPlatformDarwin.cInstrProfilingPlatformLinux.cInstrProfilingPlatformOther.cInstrProfilingPlatformWindows.c
test/profile
lld/test/MachO
llvm
include/llvm
lib
Passes
Transforms/Instrumentation
test/Instrumentation/InstrOrderFile
utils/gn/secondary/llvm/lib/Transforms/Instrumentation
@ -3195,7 +3195,6 @@ be collected.
|
||||
the profile file to ``Name``.
|
||||
* ``void __llvm_profile_reset_counters(void)``: resets all counters to zero.
|
||||
* ``int __llvm_profile_dump(void)``: write the profile data to disk.
|
||||
* ``int __llvm_orderfile_dump(void)``: write the order file to disk.
|
||||
|
||||
For example, the following pattern can be used to skip profiling program
|
||||
initialization, profile two specific hot regions, and skip profiling program
|
||||
|
@ -1811,15 +1811,13 @@ def fprofile_continuous : Flag<["-"], "fprofile-continuous">,
|
||||
HelpText<"Enable continuous instrumentation profiling mode">,
|
||||
MarshallingInfoFlag<CodeGenOpts<"ContinuousProfileSync">>;
|
||||
|
||||
defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
|
||||
CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
|
||||
PosFlag<SetTrue, [], [ClangOption], "Emit">,
|
||||
NegFlag<SetFalse, [], [ClangOption], "Do not emit">,
|
||||
BothFlags<[], [ClangOption, CC1Option],
|
||||
" pseudo probes for sample profiling">>;
|
||||
def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
|
||||
Group<f_Group>, Visibility<[ClangOption, CC1Option, CLOption]>,
|
||||
HelpText<"Generate instrumented code to collect order file into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var). Deprecated, please use -ftemporal-profile">;
|
||||
defm pseudo_probe_for_profiling
|
||||
: BoolFOption<"pseudo-probe-for-profiling",
|
||||
CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
|
||||
PosFlag<SetTrue, [], [ClangOption], "Emit">,
|
||||
NegFlag<SetFalse, [], [ClangOption], "Do not emit">,
|
||||
BothFlags<[], [ClangOption, CC1Option],
|
||||
" pseudo probes for sample profiling">>;
|
||||
def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
|
||||
Group<f_Group>, Visibility<[ClangOption, CC1Option, CLOption]>,
|
||||
HelpText<"Filename defining the list of functions/files to instrument. "
|
||||
|
@ -955,7 +955,6 @@ bool ToolChain::needsProfileRT(const ArgList &Args) {
|
||||
Args.hasArg(options::OPT_fprofile_instr_generate) ||
|
||||
Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
|
||||
Args.hasArg(options::OPT_fcreate_profile) ||
|
||||
Args.hasArg(options::OPT_forder_file_instrumentation) ||
|
||||
Args.hasArg(options::OPT_fprofile_generate_cold_function_coverage) ||
|
||||
Args.hasArg(options::OPT_fprofile_generate_cold_function_coverage_EQ);
|
||||
}
|
||||
|
@ -8030,21 +8030,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||
}
|
||||
}
|
||||
|
||||
if (const Arg *A =
|
||||
Args.getLastArg(options::OPT_forder_file_instrumentation)) {
|
||||
D.Diag(diag::warn_drv_deprecated_arg)
|
||||
<< A->getAsString(Args) << /*hasReplacement=*/true
|
||||
<< "-ftemporal-profile";
|
||||
CmdArgs.push_back("-forder-file-instrumentation");
|
||||
// Enable order file instrumentation when ThinLTO is not on. When ThinLTO is
|
||||
// on, we need to pass these flags as linker flags and that will be handled
|
||||
// outside of the compiler.
|
||||
if (!IsUsingLTO) {
|
||||
CmdArgs.push_back("-mllvm");
|
||||
CmdArgs.push_back("-enable-order-file-instrumentation");
|
||||
}
|
||||
}
|
||||
|
||||
if (Arg *A = Args.getLastArg(options::OPT_fforce_enable_int128,
|
||||
options::OPT_fno_force_enable_int128)) {
|
||||
if (A->getOption().matches(options::OPT_fforce_enable_int128))
|
||||
|
@ -49,9 +49,8 @@ static ArrayRef<options::ID> getUnsupportedOpts() {
|
||||
options::OPT_fno_profile_arcs, // -f[no-]profile-arcs
|
||||
options::OPT_fcreate_profile, // -fcreate-profile
|
||||
options::OPT_fprofile_instr_use,
|
||||
options::OPT_fprofile_instr_use_EQ, // -fprofile-instr-use
|
||||
options::OPT_forder_file_instrumentation, // -forder-file-instrumentation
|
||||
options::OPT_fcs_profile_generate, // -fcs-profile-generate
|
||||
options::OPT_fprofile_instr_use_EQ, // -fprofile-instr-use
|
||||
options::OPT_fcs_profile_generate, // -fcs-profile-generate
|
||||
options::OPT_fcs_profile_generate_EQ,
|
||||
};
|
||||
return UnsupportedOpts;
|
||||
|
@ -110,8 +110,6 @@
|
||||
// RUN: %clang -### -S -fcoverage-mapping -fno-coverage-mapping %s 2>&1 | FileCheck -check-prefix=CHECK-DISABLE-COVERAGE %s
|
||||
// RUN: %clang -### -S -fprofile-instr-generate -fcoverage-mapping -fno-coverage-mapping %s 2>&1 | FileCheck -check-prefix=CHECK-DISABLE-COVERAGE %s
|
||||
// RUN: %clang -### -S -fprofile-remapping-file=foo/bar.txt %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-REMAP %s
|
||||
// RUN: %clang -### -S -forder-file-instrumentation %s 2>&1 | FileCheck -check-prefix=CHECK-ORDERFILE-INSTR %s
|
||||
// RUN: %clang -### --target=x86_64-linux-gnu -flto -forder-file-instrumentation %s 2>&1 | FileCheck -check-prefix=CHECK-ORDERFILE-INSTR-LTO %s
|
||||
// CHECK-PROFILE-GENERATE: "-fprofile-instrument=clang"
|
||||
// CHECK-PROFILE-GENERATE-LLVM: "-fprofile-instrument=llvm"
|
||||
// CHECK-PROFILE-GENERATE-DIR: "-fprofile-instrument-path=/some/dir{{/|\\\\}}{{.*}}"
|
||||
@ -123,10 +121,6 @@
|
||||
// CHECK-COVERAGE-AND-GEN: '-fcoverage-mapping' only allowed with '-fprofile-instr-generate'
|
||||
// CHECK-DISABLE-COVERAGE-NOT: "-fcoverage-mapping"
|
||||
// CHECK-PROFILE-REMAP: "-fprofile-remapping-file=foo/bar.txt"
|
||||
// CHECK-ORDERFILE-INSTR: "-forder-file-instrumentation"
|
||||
// CHECK-ORDERFILE-INSTR: "-enable-order-file-instrumentation"
|
||||
// CHECK-ORDERFILE-INSTR-LTO: "-forder-file-instrumentation"
|
||||
// CHECK-ORDERFILE-INSTR-LTO-NOT: "-enable-order-file-instrumentation"
|
||||
|
||||
// RUN: %clang -### -S -fprofile-use %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE %s
|
||||
// RUN: %clang -### -S -fprofile-instr-use %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE %s
|
||||
@ -371,7 +365,6 @@
|
||||
// RUN: -fno-devirtualize-speculatively \
|
||||
// RUN: -fslp-vectorize-aggressive \
|
||||
// RUN: -fno-slp-vectorize-aggressive \
|
||||
// RUN: -forder-file-instrumentation \
|
||||
// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-WARNING %s
|
||||
// CHECK-WARNING-DAG: optimization flag '-finline-limit=1000' is not supported
|
||||
// CHECK-WARNING-DAG: optimization flag '-finline-limit' is not supported
|
||||
@ -431,7 +424,6 @@
|
||||
// CHECK-WARNING-DAG: optimization flag '-fno-devirtualize-speculatively' is not supported
|
||||
// CHECK-WARNING-DAG: the flag '-fslp-vectorize-aggressive' has been deprecated and will be ignored
|
||||
// CHECK-WARNING-DAG: the flag '-fno-slp-vectorize-aggressive' has been deprecated and will be ignored
|
||||
// CHECK-WARNING-DAG: argument '-forder-file-instrumentation' is deprecated, use '-ftemporal-profile' instead
|
||||
|
||||
// Test that we mute the warning on these
|
||||
// RUN: %clang -### -finline-limit=1000 -Wno-invalid-command-line-argument \
|
||||
|
@ -348,9 +348,6 @@ INSTR_PROF_SECT_ENTRY(IPSK_covmap, \
|
||||
INSTR_PROF_SECT_ENTRY(IPSK_covfun, \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON), \
|
||||
INSTR_PROF_COVFUN_COFF, "__LLVM_COV,")
|
||||
INSTR_PROF_SECT_ENTRY(IPSK_orderfile, \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON), \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COFF), "__DATA,")
|
||||
INSTR_PROF_SECT_ENTRY(IPSK_covdata, \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON), \
|
||||
INSTR_PROF_COVDATA_COFF, "__LLVM_COV,")
|
||||
@ -778,7 +775,6 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
|
||||
#define INSTR_PROF_COVFUN_COMMON __llvm_covfun
|
||||
#define INSTR_PROF_COVDATA_COMMON __llvm_covdata
|
||||
#define INSTR_PROF_COVNAME_COMMON __llvm_covnames
|
||||
#define INSTR_PROF_ORDERFILE_COMMON __llvm_orderfile
|
||||
#define INSTR_PROF_COVINIT_COMMON __llvm_covinit
|
||||
|
||||
/* Windows section names. Because these section names contain dollar characters,
|
||||
@ -799,7 +795,6 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
|
||||
*/
|
||||
#define INSTR_PROF_COVDATA_COFF ".lcovd"
|
||||
#define INSTR_PROF_COVNAME_COFF ".lcovn"
|
||||
#define INSTR_PROF_ORDERFILE_COFF ".lorderfile$M"
|
||||
|
||||
// FIXME: Placeholder for Windows. Windows currently does not initialize
|
||||
// the GCOV functions in the runtime.
|
||||
@ -823,7 +818,6 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
|
||||
#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_COVFUN_COFF
|
||||
#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_COVDATA_COFF
|
||||
#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_COVNAME_COFF
|
||||
#define INSTR_PROF_ORDERFILE_SECT_NAME INSTR_PROF_ORDERFILE_COFF
|
||||
#define INSTR_PROF_COVINIT_SECT_NAME INSTR_PROF_COVINIT_COFF
|
||||
#else
|
||||
/* Runtime section names and name strings. */
|
||||
@ -843,19 +837,9 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
|
||||
#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON)
|
||||
#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON)
|
||||
#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON)
|
||||
/* Order file instrumentation. */
|
||||
#define INSTR_PROF_ORDERFILE_SECT_NAME \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON)
|
||||
#define INSTR_PROF_COVINIT_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVINIT_COMMON)
|
||||
#endif
|
||||
|
||||
#define INSTR_PROF_ORDERFILE_BUFFER_NAME _llvm_order_file_buffer
|
||||
#define INSTR_PROF_ORDERFILE_BUFFER_NAME_STR \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_BUFFER_NAME)
|
||||
#define INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME _llvm_order_file_buffer_idx
|
||||
#define INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME_STR \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME)
|
||||
|
||||
/* Macros to define start/stop section symbol for a given
|
||||
* section on Linux. For instance
|
||||
* INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME) will
|
||||
@ -889,12 +873,6 @@ typedef struct InstrProfValueData {
|
||||
|
||||
#endif /* INSTR_PROF_DATA_INC */
|
||||
|
||||
#ifndef INSTR_ORDER_FILE_INC
|
||||
/* The maximal # of functions: 128*1024 (the buffer size will be 128*4 KB). */
|
||||
#define INSTR_ORDER_FILE_BUFFER_SIZE 131072
|
||||
#define INSTR_ORDER_FILE_BUFFER_BITS 17
|
||||
#define INSTR_ORDER_FILE_BUFFER_MASK 0x1ffff
|
||||
#endif /* INSTR_ORDER_FILE_INC */
|
||||
#else
|
||||
#undef INSTR_PROF_DATA_DEFINED
|
||||
#endif
|
||||
|
@ -73,15 +73,11 @@ void __llvm_profile_reset_counters(void);
|
||||
*/
|
||||
int __llvm_profile_dump(void);
|
||||
|
||||
// Interface to dump the current process' order file to disk.
|
||||
int __llvm_orderfile_dump(void);
|
||||
|
||||
#else
|
||||
|
||||
#define __llvm_profile_set_filename(Name)
|
||||
#define __llvm_profile_reset_counters()
|
||||
#define __llvm_profile_dump() (0)
|
||||
#define __llvm_orderfile_dump() (0)
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -124,7 +124,6 @@ ValueProfNode *__llvm_profile_begin_vnodes(void);
|
||||
ValueProfNode *__llvm_profile_end_vnodes(void);
|
||||
const VTableProfData *__llvm_profile_begin_vtables(void);
|
||||
const VTableProfData *__llvm_profile_end_vtables(void);
|
||||
uint32_t *__llvm_profile_begin_orderfile(void);
|
||||
|
||||
/*!
|
||||
* \brief Merge profile data from buffer.
|
||||
@ -175,8 +174,6 @@ void __llvm_profile_instrument_target_value(uint64_t TargetValue, void *Data,
|
||||
*/
|
||||
int __llvm_profile_write_file(void);
|
||||
|
||||
int __llvm_orderfile_write_file(void);
|
||||
|
||||
/*!
|
||||
* \brief Set the FILE object for writing instrumentation data. Return 0 if set
|
||||
* successfully or return 1 if failed.
|
||||
|
@ -357,15 +357,6 @@ static uint32_t fileWriter(ProfDataWriter *This, ProfDataIOVec *IOVecs,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TODO: make buffer size controllable by an internal option, and compiler can pass the size
|
||||
to runtime via a variable. */
|
||||
static uint32_t orderFileWriter(FILE *File, const uint32_t *DataStart) {
|
||||
if (fwrite(DataStart, sizeof(uint32_t), INSTR_ORDER_FILE_BUFFER_SIZE, File) !=
|
||||
INSTR_ORDER_FILE_BUFFER_SIZE)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void initFileWriter(ProfDataWriter *This, FILE *File) {
|
||||
This->Write = fileWriter;
|
||||
This->WriterCtx = File;
|
||||
@ -503,7 +494,7 @@ static void createProfileDir(const char *Filename) {
|
||||
* the original profile data is truncated and gets ready for the profile
|
||||
* dumper. With profile merging enabled, each executable as well as any of
|
||||
* its instrumented shared libraries dump profile data into their own data file.
|
||||
*/
|
||||
*/
|
||||
static FILE *openFileForMerging(const char *ProfileFileName, int *MergeDone) {
|
||||
FILE *ProfileFile = getProfileFile();
|
||||
int rc;
|
||||
@ -577,27 +568,6 @@ static int writeFile(const char *OutputName) {
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
/* Write order data to file \c OutputName. */
|
||||
static int writeOrderFile(const char *OutputName) {
|
||||
int RetVal;
|
||||
FILE *OutputFile;
|
||||
|
||||
OutputFile = fopen(OutputName, "w");
|
||||
|
||||
if (!OutputFile) {
|
||||
PROF_WARN("can't open file with mode ab: %s\n", OutputName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FreeHook = &free;
|
||||
setupIOBuffer();
|
||||
const uint32_t *DataBegin = __llvm_profile_begin_orderfile();
|
||||
RetVal = orderFileWriter(OutputFile, DataBegin);
|
||||
|
||||
fclose(OutputFile);
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
#define LPROF_INIT_ONCE_ENV "__LLVM_PROFILE_RT_INIT_ONCE"
|
||||
|
||||
static void truncateCurrentFile(void) {
|
||||
@ -1239,65 +1209,6 @@ int __llvm_profile_dump(void) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Order file data will be saved in a file with suffx .order. */
|
||||
static const char *OrderFileSuffix = ".order";
|
||||
|
||||
COMPILER_RT_VISIBILITY
|
||||
int __llvm_orderfile_write_file(void) {
|
||||
int rc, Length, LengthBeforeAppend, SuffixLength;
|
||||
const char *Filename;
|
||||
char *FilenameBuf;
|
||||
|
||||
// Temporarily suspend getting SIGKILL when the parent exits.
|
||||
int PDeathSig = lprofSuspendSigKill();
|
||||
|
||||
SuffixLength = strlen(OrderFileSuffix);
|
||||
Length = getCurFilenameLength() + SuffixLength;
|
||||
FilenameBuf = (char *)COMPILER_RT_ALLOCA(Length + 1);
|
||||
Filename = getCurFilename(FilenameBuf, 1);
|
||||
|
||||
/* Check the filename. */
|
||||
if (!Filename) {
|
||||
PROF_ERR("Failed to write file : %s\n", "Filename not set");
|
||||
if (PDeathSig == 1)
|
||||
lprofRestoreSigKill();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Append order file suffix */
|
||||
LengthBeforeAppend = strlen(Filename);
|
||||
memcpy(FilenameBuf + LengthBeforeAppend, OrderFileSuffix, SuffixLength);
|
||||
FilenameBuf[LengthBeforeAppend + SuffixLength] = '\0';
|
||||
|
||||
/* Check if there is llvm/runtime version mismatch. */
|
||||
if (GET_VERSION(__llvm_profile_get_version()) != INSTR_PROF_RAW_VERSION) {
|
||||
PROF_ERR("Runtime and instrumentation version mismatch : "
|
||||
"expected %d, but get %d\n",
|
||||
INSTR_PROF_RAW_VERSION,
|
||||
(int)GET_VERSION(__llvm_profile_get_version()));
|
||||
if (PDeathSig == 1)
|
||||
lprofRestoreSigKill();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Write order data to the file. */
|
||||
rc = writeOrderFile(Filename);
|
||||
if (rc)
|
||||
PROF_ERR("Failed to write file \"%s\": %s\n", Filename, strerror(errno));
|
||||
|
||||
// Restore SIGKILL.
|
||||
if (PDeathSig == 1)
|
||||
lprofRestoreSigKill();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
COMPILER_RT_VISIBILITY
|
||||
int __llvm_orderfile_dump(void) {
|
||||
int rc = __llvm_orderfile_write_file();
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void writeFileWithoutReturn(void) { __llvm_profile_write_file(); }
|
||||
|
||||
COMPILER_RT_VISIBILITY
|
||||
|
@ -196,8 +196,6 @@ static const int dummy_name[0] COMPILER_RT_SECTION(
|
||||
COMPILER_RT_SEG INSTR_PROF_NAME_SECT_NAME);
|
||||
static int dummy_vnds[0] COMPILER_RT_SECTION(
|
||||
COMPILER_RT_SEG INSTR_PROF_VNODES_SECT_NAME);
|
||||
static int dummy_orderfile[0] COMPILER_RT_SECTION(
|
||||
COMPILER_RT_SEG INSTR_PROF_ORDERFILE_SECT_NAME);
|
||||
static int dummy_vname[0] COMPILER_RT_SECTION(
|
||||
COMPILER_RT_SEG INSTR_PROF_VNAME_SECT_NAME);
|
||||
static int dummy_vtab[0] COMPILER_RT_SECTION(
|
||||
@ -213,11 +211,10 @@ static int dummy_covinit_funcs[0] COMPILER_RT_SECTION(
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||
#endif
|
||||
COMPILER_RT_VISIBILITY
|
||||
void *__llvm_profile_keep[] = {(void *)&dummy_cnts, (void *)&dummy_bits,
|
||||
(void *)&dummy_data, (void *)&dummy_name,
|
||||
(void *)&dummy_vnds, (void *)&dummy_orderfile,
|
||||
(void *)&dummy_vname, (void *)&dummy_vtab,
|
||||
(void *)&dummy_covinit_funcs};
|
||||
void *__llvm_profile_keep[] = {
|
||||
(void *)&dummy_cnts, (void *)&dummy_bits, (void *)&dummy_data,
|
||||
(void *)&dummy_name, (void *)&dummy_vnds, (void *)&dummy_vname,
|
||||
(void *)&dummy_vtab, (void *)&dummy_covinit_funcs};
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
@ -47,8 +47,6 @@ extern char
|
||||
COMPILER_RT_VISIBILITY
|
||||
extern char VNameEnd __asm("section$end$__DATA$" INSTR_PROF_VNAME_SECT_NAME);
|
||||
COMPILER_RT_VISIBILITY
|
||||
extern uint32_t
|
||||
OrderFileStart __asm("section$start$__DATA$" INSTR_PROF_ORDERFILE_SECT_NAME);
|
||||
|
||||
COMPILER_RT_VISIBILITY
|
||||
extern ValueProfNode
|
||||
@ -87,8 +85,6 @@ COMPILER_RT_VISIBILITY
|
||||
const char *__llvm_profile_begin_vtabnames(void) { return &VNameStart; }
|
||||
COMPILER_RT_VISIBILITY
|
||||
const char *__llvm_profile_end_vtabnames(void) { return &VNameEnd; }
|
||||
COMPILER_RT_VISIBILITY
|
||||
uint32_t *__llvm_profile_begin_orderfile(void) { return &OrderFileStart; }
|
||||
|
||||
COMPILER_RT_VISIBILITY
|
||||
ValueProfNode *__llvm_profile_begin_vnodes(void) {
|
||||
|
@ -32,7 +32,6 @@
|
||||
#define PROF_VTABLE_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_VTAB_COMMON)
|
||||
#define PROF_BITS_START INSTR_PROF_SECT_START(INSTR_PROF_BITS_COMMON)
|
||||
#define PROF_BITS_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_BITS_COMMON)
|
||||
#define PROF_ORDERFILE_START INSTR_PROF_SECT_START(INSTR_PROF_ORDERFILE_COMMON)
|
||||
#define PROF_VNODES_START INSTR_PROF_SECT_START(INSTR_PROF_VNODES_COMMON)
|
||||
#define PROF_VNODES_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_VNODES_COMMON)
|
||||
#define PROF_COVINIT_START INSTR_PROF_SECT_START(INSTR_PROF_COVINIT_COMMON)
|
||||
@ -53,7 +52,6 @@ extern char PROF_VNAME_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
|
||||
extern char PROF_VNAME_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
|
||||
extern char PROF_BITS_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
|
||||
extern char PROF_BITS_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
|
||||
extern uint32_t PROF_ORDERFILE_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
|
||||
extern char PROF_NAME_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
|
||||
extern char PROF_NAME_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
|
||||
extern ValueProfNode PROF_VNODES_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
|
||||
@ -102,9 +100,6 @@ COMPILER_RT_VISIBILITY char *__llvm_profile_begin_bitmap(void) {
|
||||
COMPILER_RT_VISIBILITY char *__llvm_profile_end_bitmap(void) {
|
||||
return &PROF_BITS_STOP;
|
||||
}
|
||||
COMPILER_RT_VISIBILITY uint32_t *__llvm_profile_begin_orderfile(void) {
|
||||
return &PROF_ORDERFILE_START;
|
||||
}
|
||||
|
||||
COMPILER_RT_VISIBILITY ValueProfNode *
|
||||
__llvm_profile_begin_vnodes(void) {
|
||||
|
@ -27,7 +27,6 @@ static const char *VNamesFirst = NULL;
|
||||
static const char *VNamesLast = NULL;
|
||||
static char *CountersFirst = NULL;
|
||||
static char *CountersLast = NULL;
|
||||
static uint32_t *OrderFileFirst = NULL;
|
||||
|
||||
static const void *getMinAddr(const void *A1, const void *A2) {
|
||||
return A1 < A2 ? A1 : A2;
|
||||
@ -108,9 +107,6 @@ COMPILER_RT_VISIBILITY
|
||||
char *__llvm_profile_begin_bitmap(void) { return BitmapFirst; }
|
||||
COMPILER_RT_VISIBILITY
|
||||
char *__llvm_profile_end_bitmap(void) { return BitmapLast; }
|
||||
/* TODO: correctly set up OrderFileFirst. */
|
||||
COMPILER_RT_VISIBILITY
|
||||
uint32_t *__llvm_profile_begin_orderfile(void) { return OrderFileFirst; }
|
||||
|
||||
COMPILER_RT_VISIBILITY
|
||||
ValueProfNode *__llvm_profile_begin_vnodes(void) {
|
||||
|
@ -36,7 +36,6 @@
|
||||
#pragma section(".lprfc$Z", read, write)
|
||||
#pragma section(".lprfb$A", read, write)
|
||||
#pragma section(".lprfb$Z", read, write)
|
||||
#pragma section(".lorderfile$A", read, write)
|
||||
#pragma section(".lprfnd$A", read, write)
|
||||
#pragma section(".lprfnd$Z", read, write)
|
||||
#endif
|
||||
@ -51,7 +50,6 @@ char COMPILER_RT_SECTION(".lprfc$A") CountersStart;
|
||||
char COMPILER_RT_SECTION(".lprfc$Z") CountersEnd;
|
||||
char COMPILER_RT_SECTION(".lprfb$A") BitmapStart;
|
||||
char COMPILER_RT_SECTION(".lprfb$Z") BitmapEnd;
|
||||
uint32_t COMPILER_RT_SECTION(".lorderfile$A") OrderFileStart;
|
||||
|
||||
ValueProfNode COMPILER_RT_SECTION(".lprfnd$A") VNodesStart;
|
||||
ValueProfNode COMPILER_RT_SECTION(".lprfnd$Z") VNodesEnd;
|
||||
@ -85,7 +83,6 @@ char *__llvm_profile_begin_counters(void) { return &CountersStart + 1; }
|
||||
char *__llvm_profile_end_counters(void) { return &CountersEnd; }
|
||||
char *__llvm_profile_begin_bitmap(void) { return &BitmapStart + 1; }
|
||||
char *__llvm_profile_end_bitmap(void) { return &BitmapEnd; }
|
||||
uint32_t *__llvm_profile_begin_orderfile(void) { return &OrderFileStart; }
|
||||
|
||||
ValueProfNode *__llvm_profile_begin_vnodes(void) { return &VNodesStart + 1; }
|
||||
ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
|
||||
|
@ -1,17 +0,0 @@
|
||||
void __llvm_profile_initialize_file(void);
|
||||
int __llvm_orderfile_dump(void);
|
||||
|
||||
__attribute__((noinline)) int f(int a);
|
||||
|
||||
__attribute__((noinline)) int g(int a);
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int a = f(argc);
|
||||
int t = 0;
|
||||
for (int i = 0; i < argc; i++)
|
||||
t += g(a);
|
||||
f(t);
|
||||
__llvm_profile_initialize_file();
|
||||
__llvm_orderfile_dump();
|
||||
return 0;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
// UNSUPPORTED: target={{.*windows.*}}
|
||||
// REQUIRES: darwin
|
||||
// RUN: rm -rf %t.dir && mkdir -p %t.dir
|
||||
// RUN: cd %t.dir
|
||||
//
|
||||
// RUN: %clang -forder-file-instrumentation -O1 -o %t.2 %S/Inputs/instrprof-order-file-2.c %S/Inputs/instrprof-order-file.c -mllvm -orderfile-write-mapping="mapping.txt"
|
||||
// RUN: %run %t.2 ANY
|
||||
// RUN: od -h default.profraw.order | FileCheck %s
|
||||
// RUN: cat mapping.txt | FileCheck %s --check-prefix=MAPPING
|
||||
|
||||
// Make sure we have MD5 for main, then f, then g.
|
||||
// CHECK: 0000000 d5fa e78d 6436 db95 a18f dd4c 4f75 cc91
|
||||
// CHECK: 0000020 f5b2 47ff 6643 b671 0000 0000 0000 0000
|
||||
|
||||
// MAPPING: MD5 cc914f75dd4ca18f f
|
||||
// MAPPING: MD5 b671664347fff5b2 g
|
||||
// MAPPING: MD5 db956436e78dd5fa main
|
@ -88,13 +88,12 @@
|
||||
# STRIP-NEXT: 0 __text {{[0-9a-f]*}} [[#%x, TEXTSTART:]] TEXT
|
||||
# STRIP-NEXT: 1 __cstring 00000000 [[#%x, CSTRINGSTART:]] DATA
|
||||
# STRIP-NEXT: 2 __data 00000000
|
||||
# STRIP-NEXT: 3 __llvm_orderfile 00000000
|
||||
# STRIP-NEXT: 4 __mybss 00000000
|
||||
# STRIP-NEXT: 5 __bar 00000000
|
||||
# STRIP-NEXT: 6 __ever 00000000
|
||||
# STRIP-NEXT: 7 __lookup 00000000
|
||||
# STRIP-NEXT: 8 symbol 00000000
|
||||
# STRIP-NEXT: 9 __quux 00000000
|
||||
# STRIP-NEXT: 3 __mybss 00000000
|
||||
# STRIP-NEXT: 4 __bar 00000000
|
||||
# STRIP-NEXT: 5 __ever 00000000
|
||||
# STRIP-NEXT: 6 __lookup 00000000
|
||||
# STRIP-NEXT: 7 symbol 00000000
|
||||
# STRIP-NEXT: 8 __quux 00000000
|
||||
|
||||
# STRIP-LABEL: SYMBOL TABLE:
|
||||
# STRIP-NOT: section$start$__FOO$__bar
|
||||
@ -110,14 +109,13 @@
|
||||
# STRIP2-NEXT: 0 __text {{[0-9a-f]*}} [[#%x, TEXTSTART:]] TEXT
|
||||
# STRIP2-NEXT: 1 __cstring 00000000 [[#%x, CSTRINGSTART:]] DATA
|
||||
# STRIP2-NEXT: 2 __data 00000000
|
||||
# STRIP2-NEXT: 3 __llvm_orderfile 00000000
|
||||
# STRIP2-NEXT: 4 __mybss 00000000
|
||||
# STRIP2-NEXT: 5 __bar 00000000
|
||||
# STRIP2-NEXT: 6 __notexist 00000000
|
||||
# STRIP2-NEXT: 7 __ever 00000000
|
||||
# STRIP2-NEXT: 8 __lookup 00000000
|
||||
# STRIP2-NEXT: 9 symbol 00000000
|
||||
# STRIP2-NEXT: 10 __quux 00000000
|
||||
# STRIP2-NEXT: 3 __mybss 00000000
|
||||
# STRIP2-NEXT: 4 __bar 00000000
|
||||
# STRIP2-NEXT: 5 __notexist 00000000
|
||||
# STRIP2-NEXT: 6 __ever 00000000
|
||||
# STRIP2-NEXT: 7 __lookup 00000000
|
||||
# STRIP2-NEXT: 8 symbol 00000000
|
||||
# STRIP2-NEXT: 9 __quux 00000000
|
||||
|
||||
# CHECK-LABEL: Sections:
|
||||
# CHECK-NEXT: Idx Name Size VMA Type
|
||||
@ -126,12 +124,11 @@
|
||||
# CHECK: 2 __cstring {{[0-9a-f]*}} [[#%x, CSTRINGSTART:]] DATA
|
||||
# CHECK: 3 __aftercstring {{[0-9a-f]*}} [[#%x, CSTRINGEND:]]
|
||||
# CHECK: 4 __data 00000008 [[#%x, DATASTART:]] DATA
|
||||
# CHECK: 5 __llvm_orderfile 00000000 [[#%x, LLVMORDERFILESTART:]] DATA
|
||||
# CHECK: 6 __mybss 00008000 [[#%x, MYBSSSTART:]] BSS
|
||||
# CHECK: 7 __quux 0000002a [[#%x, QUUXSTART:]]
|
||||
# CHECK: 8 __bar 00000059 [[#%x, BARSTART:]]
|
||||
# CHECK: 9 __uflag_sect 00000000
|
||||
# CHECK: 10 __lookup 00000000
|
||||
# CHECK: 5 __mybss 00008000 [[#%x, MYBSSSTART:]] BSS
|
||||
# CHECK: 6 __quux 0000002a [[#%x, QUUXSTART:]]
|
||||
# CHECK: 7 __bar 00000059 [[#%x, BARSTART:]]
|
||||
# CHECK: 8 __uflag_sect 00000000
|
||||
# CHECK: 9 __lookup 00000000
|
||||
# CHECK-NOT: symbol
|
||||
# CHECK-NOT: __unref
|
||||
|
||||
@ -142,8 +139,6 @@
|
||||
# CHECK-NOT: section$end$__TEXT$__cstring
|
||||
# CHECK-NOT: section$start$__DATA$__data
|
||||
# CHECK-NOT: section$end$__DATA$__data
|
||||
# CHECK-NOT: section$start$__DATA$__llvm_orderfile
|
||||
# CHECK-NOT: section$end$__DATA$__llvm_orderfile
|
||||
# CHECK-NOT: section$start$__DYNAMIC$__lookup
|
||||
# CHECK-NOT: section$start$__DYNAMIC$__unref
|
||||
# CHECK: section$end$ACTUAL$symbol
|
||||
@ -180,13 +175,6 @@
|
||||
# CHECK-NEXT: [[#%x, PC8:]]:
|
||||
# CHECK-SAME: leaq [[#%d, MYBSSSTART + 0x8000 - PC8 - 7]](%rip), %rbx
|
||||
|
||||
## section$start$__DATA$__llvm_orderfile / section$end$__DATA$__llvm_orderfile
|
||||
## This section has size 0.
|
||||
# CHECK: [[#%x, PC9:]]:
|
||||
# CHECK-SAME: leaq [[#%d, LLVMORDERFILESTART - PC9 - 7]](%rip), %rax
|
||||
# CHECK-NEXT: [[#%x, PC10:]]:
|
||||
# CHECK-SAME: leaq [[#%d, LLVMORDERFILESTART - PC10 - 7]](%rip), %rbx
|
||||
|
||||
## Section-rename tests.
|
||||
## Input section __FOO/__bar is renamed to output section
|
||||
## __BAZ/__quux by a -rename_section flag.
|
||||
@ -350,12 +338,6 @@ _main:
|
||||
movq section$start$__MYBSS$__mybss@GOTPCREL(%rip), %rax
|
||||
movq section$end$__MYBSS$__mybss@GOTPCREL(%rip), %rbx
|
||||
|
||||
# Referring to a non-existent section wills it into existence.
|
||||
# This is needed for e.g. __DATA/__llvm_orderfile in libclang_rt.profile.
|
||||
# This means `-u` can be used as a janky `-sectcreate`.
|
||||
movq section$start$__DATA$__llvm_orderfile@GOTPCREL(%rip), %rax
|
||||
movq section$end$__DATA$__llvm_orderfile@GOTPCREL(%rip), %rbx
|
||||
|
||||
# Section-rename tests.
|
||||
movq section$start$__FOO$__bar@GOTPCREL(%rip), %rax
|
||||
movq section$end$__FOO$__bar@GOTPCREL(%rip), %rbx
|
||||
|
@ -348,9 +348,6 @@ INSTR_PROF_SECT_ENTRY(IPSK_covmap, \
|
||||
INSTR_PROF_SECT_ENTRY(IPSK_covfun, \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON), \
|
||||
INSTR_PROF_COVFUN_COFF, "__LLVM_COV,")
|
||||
INSTR_PROF_SECT_ENTRY(IPSK_orderfile, \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON), \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COFF), "__DATA,")
|
||||
INSTR_PROF_SECT_ENTRY(IPSK_covdata, \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON), \
|
||||
INSTR_PROF_COVDATA_COFF, "__LLVM_COV,")
|
||||
@ -778,7 +775,6 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
|
||||
#define INSTR_PROF_COVFUN_COMMON __llvm_covfun
|
||||
#define INSTR_PROF_COVDATA_COMMON __llvm_covdata
|
||||
#define INSTR_PROF_COVNAME_COMMON __llvm_covnames
|
||||
#define INSTR_PROF_ORDERFILE_COMMON __llvm_orderfile
|
||||
#define INSTR_PROF_COVINIT_COMMON __llvm_covinit
|
||||
|
||||
/* Windows section names. Because these section names contain dollar characters,
|
||||
@ -799,7 +795,6 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
|
||||
*/
|
||||
#define INSTR_PROF_COVDATA_COFF ".lcovd"
|
||||
#define INSTR_PROF_COVNAME_COFF ".lcovn"
|
||||
#define INSTR_PROF_ORDERFILE_COFF ".lorderfile$M"
|
||||
|
||||
// FIXME: Placeholder for Windows. Windows currently does not initialize
|
||||
// the GCOV functions in the runtime.
|
||||
@ -823,7 +818,6 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
|
||||
#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_COVFUN_COFF
|
||||
#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_COVDATA_COFF
|
||||
#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_COVNAME_COFF
|
||||
#define INSTR_PROF_ORDERFILE_SECT_NAME INSTR_PROF_ORDERFILE_COFF
|
||||
#define INSTR_PROF_COVINIT_SECT_NAME INSTR_PROF_COVINIT_COFF
|
||||
#else
|
||||
/* Runtime section names and name strings. */
|
||||
@ -843,19 +837,9 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
|
||||
#define INSTR_PROF_COVFUN_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVFUN_COMMON)
|
||||
#define INSTR_PROF_COVDATA_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVDATA_COMMON)
|
||||
#define INSTR_PROF_COVNAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVNAME_COMMON)
|
||||
/* Order file instrumentation. */
|
||||
#define INSTR_PROF_ORDERFILE_SECT_NAME \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_COMMON)
|
||||
#define INSTR_PROF_COVINIT_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_COVINIT_COMMON)
|
||||
#endif
|
||||
|
||||
#define INSTR_PROF_ORDERFILE_BUFFER_NAME _llvm_order_file_buffer
|
||||
#define INSTR_PROF_ORDERFILE_BUFFER_NAME_STR \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_BUFFER_NAME)
|
||||
#define INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME _llvm_order_file_buffer_idx
|
||||
#define INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME_STR \
|
||||
INSTR_PROF_QUOTE(INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME)
|
||||
|
||||
/* Macros to define start/stop section symbol for a given
|
||||
* section on Linux. For instance
|
||||
* INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME) will
|
||||
@ -889,12 +873,6 @@ typedef struct InstrProfValueData {
|
||||
|
||||
#endif /* INSTR_PROF_DATA_INC */
|
||||
|
||||
#ifndef INSTR_ORDER_FILE_INC
|
||||
/* The maximal # of functions: 128*1024 (the buffer size will be 128*4 KB). */
|
||||
#define INSTR_ORDER_FILE_BUFFER_SIZE 131072
|
||||
#define INSTR_ORDER_FILE_BUFFER_BITS 17
|
||||
#define INSTR_ORDER_FILE_BUFFER_MASK 0x1ffff
|
||||
#endif /* INSTR_ORDER_FILE_INC */
|
||||
#else
|
||||
#undef INSTR_PROF_DATA_DEFINED
|
||||
#endif
|
||||
|
@ -1,27 +0,0 @@
|
||||
//===- InstrOrderFile.h ---- Late IR instrumentation for order file ----===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_INSTRORDERFILE_H
|
||||
#define LLVM_TRANSFORMS_INSTRUMENTATION_INSTRORDERFILE_H
|
||||
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
class Module;
|
||||
|
||||
/// The instrumentation pass for recording function order.
|
||||
class InstrOrderFilePass : public PassInfoMixin<InstrOrderFilePass> {
|
||||
public:
|
||||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_TRANSFORMS_INSTRUMENTATION_INSTRORDERFILE_H
|
@ -229,7 +229,6 @@
|
||||
#include "llvm/Transforms/Instrumentation/DataFlowSanitizer.h"
|
||||
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
|
||||
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
|
||||
#include "llvm/Transforms/Instrumentation/InstrOrderFile.h"
|
||||
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
|
||||
#include "llvm/Transforms/Instrumentation/KCFI.h"
|
||||
#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
|
||||
|
@ -76,7 +76,6 @@
|
||||
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
||||
#include "llvm/Transforms/Instrumentation/CGProfile.h"
|
||||
#include "llvm/Transforms/Instrumentation/ControlHeightReduction.h"
|
||||
#include "llvm/Transforms/Instrumentation/InstrOrderFile.h"
|
||||
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
|
||||
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
|
||||
#include "llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h"
|
||||
@ -267,10 +266,6 @@ static cl::opt<bool> FlattenedProfileUsed(
|
||||
cl::desc("Indicate the sample profile being used is flattened, i.e., "
|
||||
"no inline hierarchy exists in the profile"));
|
||||
|
||||
static cl::opt<bool> EnableOrderFileInstrumentation(
|
||||
"enable-order-file-instrumentation", cl::init(false), cl::Hidden,
|
||||
cl::desc("Enable order file instrumentation (default = off)"));
|
||||
|
||||
static cl::opt<bool>
|
||||
EnableMatrix("enable-matrix", cl::init(false), cl::Hidden,
|
||||
cl::desc("Enable lowering of the matrix intrinsics"));
|
||||
@ -1466,9 +1461,6 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
|
||||
if (!LTOPreLink)
|
||||
MPM.addPass(EliminateAvailableExternallyPass());
|
||||
|
||||
if (EnableOrderFileInstrumentation)
|
||||
MPM.addPass(InstrOrderFilePass());
|
||||
|
||||
// Do RPO function attribute inference across the module to forward-propagate
|
||||
// attributes where applicable.
|
||||
// FIXME: Is this really an optimization rather than a canonicalization?
|
||||
|
@ -88,7 +88,6 @@ MODULE_PASS("inliner-wrapper", ModuleInlinerWrapperPass())
|
||||
MODULE_PASS("inliner-wrapper-no-mandatory-first",
|
||||
ModuleInlinerWrapperPass(getInlineParams(), false))
|
||||
MODULE_PASS("insert-gcov-profiling", GCOVProfilerPass())
|
||||
MODULE_PASS("instrorderfile", InstrOrderFilePass())
|
||||
MODULE_PASS("instrprof", InstrProfilingLoweringPass())
|
||||
MODULE_PASS("ctx-instr-lower", PGOCtxProfLoweringPass())
|
||||
MODULE_PASS("print<ctx-prof-analysis>", CtxProfAnalysisPrinterPass(errs()))
|
||||
|
@ -10,7 +10,6 @@ add_llvm_component_library(LLVMInstrumentation
|
||||
MemorySanitizer.cpp
|
||||
NumericalStabilitySanitizer.cpp
|
||||
IndirectCallPromotion.cpp
|
||||
InstrOrderFile.cpp
|
||||
InstrProfiling.cpp
|
||||
KCFI.cpp
|
||||
LowerAllowCheckPass.cpp
|
||||
|
@ -1,169 +0,0 @@
|
||||
//===- InstrOrderFile.cpp ---- Late IR instrumentation for order file ----===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/Instrumentation/InstrOrderFile.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/GlobalValue.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/ProfileData/InstrProf.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Transforms/Utils/Instrumentation.h"
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
||||
using namespace llvm;
|
||||
#define DEBUG_TYPE "instrorderfile"
|
||||
|
||||
static cl::opt<std::string> ClOrderFileWriteMapping(
|
||||
"orderfile-write-mapping", cl::init(""),
|
||||
cl::desc(
|
||||
"Dump functions and their MD5 hash to deobfuscate profile data"),
|
||||
cl::Hidden);
|
||||
|
||||
namespace {
|
||||
|
||||
// We need a global bitmap to tell if a function is executed. We also
|
||||
// need a global variable to save the order of functions. We can use a
|
||||
// fixed-size buffer that saves the MD5 hash of the function. We need
|
||||
// a global variable to save the index into the buffer.
|
||||
|
||||
std::mutex MappingMutex;
|
||||
|
||||
struct InstrOrderFile {
|
||||
private:
|
||||
GlobalVariable *OrderFileBuffer;
|
||||
GlobalVariable *BufferIdx;
|
||||
GlobalVariable *BitMap;
|
||||
ArrayType *BufferTy;
|
||||
ArrayType *MapTy;
|
||||
|
||||
public:
|
||||
InstrOrderFile() = default;
|
||||
|
||||
void createOrderFileData(Module &M) {
|
||||
LLVMContext &Ctx = M.getContext();
|
||||
int NumFunctions = 0;
|
||||
for (Function &F : M) {
|
||||
if (!F.isDeclaration())
|
||||
NumFunctions++;
|
||||
}
|
||||
|
||||
BufferTy =
|
||||
ArrayType::get(Type::getInt64Ty(Ctx), INSTR_ORDER_FILE_BUFFER_SIZE);
|
||||
Type *IdxTy = Type::getInt32Ty(Ctx);
|
||||
MapTy = ArrayType::get(Type::getInt8Ty(Ctx), NumFunctions);
|
||||
|
||||
// Create the global variables.
|
||||
std::string SymbolName = INSTR_PROF_ORDERFILE_BUFFER_NAME_STR;
|
||||
OrderFileBuffer = new GlobalVariable(M, BufferTy, false, GlobalValue::LinkOnceODRLinkage,
|
||||
Constant::getNullValue(BufferTy), SymbolName);
|
||||
const Triple &TT = M.getTargetTriple();
|
||||
OrderFileBuffer->setSection(
|
||||
getInstrProfSectionName(IPSK_orderfile, TT.getObjectFormat()));
|
||||
|
||||
std::string IndexName = INSTR_PROF_ORDERFILE_BUFFER_IDX_NAME_STR;
|
||||
BufferIdx = new GlobalVariable(M, IdxTy, false, GlobalValue::LinkOnceODRLinkage,
|
||||
Constant::getNullValue(IdxTy), IndexName);
|
||||
|
||||
std::string BitMapName = "bitmap_0";
|
||||
BitMap = new GlobalVariable(M, MapTy, false, GlobalValue::PrivateLinkage,
|
||||
Constant::getNullValue(MapTy), BitMapName);
|
||||
}
|
||||
|
||||
// Generate the code sequence in the entry block of each function to
|
||||
// update the buffer.
|
||||
void generateCodeSequence(Module &M, Function &F, int FuncId) {
|
||||
if (!ClOrderFileWriteMapping.empty()) {
|
||||
std::lock_guard<std::mutex> LogLock(MappingMutex);
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream OS(ClOrderFileWriteMapping, EC,
|
||||
llvm::sys::fs::OF_Append);
|
||||
if (EC) {
|
||||
report_fatal_error(Twine("Failed to open ") + ClOrderFileWriteMapping +
|
||||
" to save mapping file for order file instrumentation\n");
|
||||
} else {
|
||||
std::stringstream stream;
|
||||
stream << std::hex << MD5Hash(F.getName());
|
||||
std::string singleLine = "MD5 " + stream.str() + " " +
|
||||
std::string(F.getName()) + '\n';
|
||||
OS << singleLine;
|
||||
}
|
||||
}
|
||||
|
||||
BasicBlock *OrigEntry = &F.getEntryBlock();
|
||||
|
||||
LLVMContext &Ctx = M.getContext();
|
||||
IntegerType *Int32Ty = Type::getInt32Ty(Ctx);
|
||||
IntegerType *Int8Ty = Type::getInt8Ty(Ctx);
|
||||
|
||||
// Create a new entry block for instrumentation. We will check the bitmap
|
||||
// in this basic block.
|
||||
BasicBlock *NewEntry =
|
||||
BasicBlock::Create(M.getContext(), "order_file_entry", &F, OrigEntry);
|
||||
IRBuilder<> entryB(NewEntry);
|
||||
// Create a basic block for updating the circular buffer.
|
||||
BasicBlock *UpdateOrderFileBB =
|
||||
BasicBlock::Create(M.getContext(), "order_file_set", &F, OrigEntry);
|
||||
IRBuilder<> updateB(UpdateOrderFileBB);
|
||||
|
||||
// Check the bitmap, if it is already 1, do nothing.
|
||||
// Otherwise, set the bit, grab the index, update the buffer.
|
||||
Value *IdxFlags[] = {ConstantInt::get(Int32Ty, 0),
|
||||
ConstantInt::get(Int32Ty, FuncId)};
|
||||
Value *MapAddr = entryB.CreateGEP(MapTy, BitMap, IdxFlags, "");
|
||||
LoadInst *loadBitMap = entryB.CreateLoad(Int8Ty, MapAddr, "");
|
||||
entryB.CreateStore(ConstantInt::get(Int8Ty, 1), MapAddr);
|
||||
Value *IsNotExecuted =
|
||||
entryB.CreateICmpEQ(loadBitMap, ConstantInt::get(Int8Ty, 0));
|
||||
entryB.CreateCondBr(IsNotExecuted, UpdateOrderFileBB, OrigEntry);
|
||||
|
||||
// Fill up UpdateOrderFileBB: grab the index, update the buffer!
|
||||
Value *IdxVal = updateB.CreateAtomicRMW(
|
||||
AtomicRMWInst::Add, BufferIdx, ConstantInt::get(Int32Ty, 1),
|
||||
MaybeAlign(), AtomicOrdering::SequentiallyConsistent);
|
||||
// We need to wrap around the index to fit it inside the buffer.
|
||||
Value *WrappedIdx = updateB.CreateAnd(
|
||||
IdxVal, ConstantInt::get(Int32Ty, INSTR_ORDER_FILE_BUFFER_MASK));
|
||||
Value *BufferGEPIdx[] = {ConstantInt::get(Int32Ty, 0), WrappedIdx};
|
||||
Value *BufferAddr =
|
||||
updateB.CreateGEP(BufferTy, OrderFileBuffer, BufferGEPIdx, "");
|
||||
updateB.CreateStore(ConstantInt::get(Type::getInt64Ty(Ctx), MD5Hash(F.getName())),
|
||||
BufferAddr);
|
||||
updateB.CreateBr(OrigEntry);
|
||||
}
|
||||
|
||||
bool run(Module &M) {
|
||||
createOrderFileData(M);
|
||||
|
||||
int FuncId = 0;
|
||||
for (Function &F : M) {
|
||||
if (F.isDeclaration())
|
||||
continue;
|
||||
generateCodeSequence(M, F, FuncId);
|
||||
++FuncId;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}; // End of InstrOrderFile struct
|
||||
} // End anonymous namespace
|
||||
|
||||
PreservedAnalyses
|
||||
InstrOrderFilePass::run(Module &M, ModuleAnalysisManager &AM) {
|
||||
if (InstrOrderFile().run(M))
|
||||
return PreservedAnalyses::none();
|
||||
return PreservedAnalyses::all();
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
; RUN: opt -passes=instrorderfile -S < %s | FileCheck %s
|
||||
|
||||
target triple = "x86_64-apple-macosx10.10.0"
|
||||
|
||||
; CHECK: @_llvm_order_file_buffer ={{.*}}global [131072 x i64] zeroinitializer
|
||||
; CHECK: @_llvm_order_file_buffer_idx = linkonce_odr global i32 0
|
||||
; CHECK: @bitmap_0 ={{.*}}global [1 x i8] zeroinitializer
|
||||
|
||||
define i32 @_Z1fv() {
|
||||
ret i32 0
|
||||
}
|
||||
; CHECK-LABEL: define i32 @_Z1fv
|
||||
; CHECK: order_file_entry
|
||||
; CHECK: %[[T1:.+]] = load i8, ptr @bitmap_0
|
||||
; CHECK: store i8 1, ptr @bitmap_0
|
||||
; CHECK: %[[T2:.+]] = icmp eq i8 %[[T1]], 0
|
||||
; CHECK: br i1 %[[T2]], label %order_file_set, label
|
||||
|
||||
; CHECK: order_file_set
|
||||
; CHECK: %[[T3:.+]] = atomicrmw add ptr @_llvm_order_file_buffer_idx, i32 1 seq_cst
|
||||
; CHECK: %[[T5:.+]] = and i32 %[[T3]], 131071
|
||||
; CHECK: %[[T4:.+]] = getelementptr [131072 x i64], ptr @_llvm_order_file_buffer, i32 0, i32 %[[T5]]
|
||||
; CHECK: store i64 {{.*}}, ptr %[[T4]]
|
@ -19,7 +19,6 @@ static_library("Instrumentation") {
|
||||
"GCOVProfiling.cpp",
|
||||
"HWAddressSanitizer.cpp",
|
||||
"IndirectCallPromotion.cpp",
|
||||
"InstrOrderFile.cpp",
|
||||
"InstrProfiling.cpp",
|
||||
"KCFI.cpp",
|
||||
"LowerAllowCheckPass.cpp",
|
||||
|
Loading…
x
Reference in New Issue
Block a user