mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 17:43:35 +03:00

Add the commandline options -fprofile-instr-generate[=filename] and -profile-instr-use=filename -fprofile-instr-generate -- Add instrumentation on branches, switches, and function entry; uses LLVM's InstrProf pass. -- Link to profile runtime that writes instrumentation counters to a file. -fprofile-instr-use -- Read profile data from a file and apply branch weights to branches and switches, and annotate functions with entrycount in LLVM IR. -- Functions with low or high entrycount are marked with 'cold' or 'inlinehint'. The only statement type without PGO yet is "try-finally". A new pragma, `pragma(LDC_profile_instr, [ true | false ])`, is added to selectively disable/enable instrumentation of functions (granularity = whole functions). The runtime library ldc-profile-rt is a copy of LLVM compiler-rt lib/profile. It has to be exactly in-sync with the LLVM version, and thus we need a copy for each PGO-supported LLVM (>=3.7). import ldc.profile for a D interface to ldc-profile-rt (for example to reset execution counts after a program startup phase). The instrumentation data is mainly passed on to LLVM: function-entry counts and branch counts/probabilities. LDC marks functions as hot when "execution count is 30% of the maximum function execution count", and marks functions as cold if their count is 1% of maximum function execution count. The source of LLVM's llvm-profdata tool is hereby included in LDCs repository (different source for each LLVM version), and the binary is included in the install bin folder. The executable is named "ldc-profdata" to avoid clashing with llvm-profdata on the same machine. This is needed because profdata executable has to be in-sync with the LLVM version used to build LDC. Maintenance burden: for trunk LLVM, we have to keep ldc-profile-rt and llvm-profdata in sync. There is no diff with upstream; but because of active development there are the occasional API changes.
54 lines
1.5 KiB
D
54 lines
1.5 KiB
D
//===-- gen/pragma.d - LDC-specific pragma handling ---------------*- D -*-===//
|
||
//
|
||
// LDC – the LLVM D compiler
|
||
//
|
||
// This file is distributed under the BSD-style LDC license. See the LICENSE
|
||
// file for details.
|
||
//
|
||
//===----------------------------------------------------------------------===//
|
||
//
|
||
// D bindings for pragma.h/.cpp
|
||
//
|
||
//===----------------------------------------------------------------------===//
|
||
|
||
module gen.dpragma;
|
||
|
||
import ddmd.attrib;
|
||
import ddmd.dscope;
|
||
import ddmd.dsymbol;
|
||
import ddmd.expression;
|
||
import ddmd.func;
|
||
|
||
extern (C++) enum LDCPragma : int {
|
||
LLVMnone = 0, // Not an LDC pragma.
|
||
LLVMignore, // Pragma has already been processed in DtoGetPragma, ignore.
|
||
LLVMintrinsic,
|
||
LLVMglobal_crt_ctor,
|
||
LLVMglobal_crt_dtor,
|
||
LLVMno_typeinfo,
|
||
LLVMalloca,
|
||
LLVMva_start,
|
||
LLVMva_copy,
|
||
LLVMva_end,
|
||
LLVMva_arg,
|
||
LLVMinline_asm,
|
||
LLVMinline_ir,
|
||
LLVMfence,
|
||
LLVMatomic_store,
|
||
LLVMatomic_load,
|
||
LLVMatomic_cmp_xchg,
|
||
LLVMatomic_rmw,
|
||
LLVMbitop_bt,
|
||
LLVMbitop_btc,
|
||
LLVMbitop_btr,
|
||
LLVMbitop_bts,
|
||
LLVMbitop_vld,
|
||
LLVMbitop_vst,
|
||
LLVMextern_weak
|
||
};
|
||
|
||
extern (C++) LDCPragma DtoGetPragma(Scope* sc, PragmaDeclaration decl, ref const(char)* arg1str);
|
||
extern (C++) void DtoCheckPragma(PragmaDeclaration decl, Dsymbol sym, LDCPragma llvm_internal, const char* arg1str);
|
||
extern (C++) bool DtoCheckProfileInstrPragma(Expression arg, ref bool value);
|
||
extern (C++) bool DtoIsIntrinsic(FuncDeclaration fd);
|
||
extern (C++) bool DtoIsVaIntrinsic(FuncDeclaration fd);
|