mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-24 08:18:33 +00:00
InstrProf: An intrinsic and lowering for instrumentation based profiling
Introduce the ``llvm.instrprof_increment`` intrinsic and the ``-instrprof`` pass. These provide the infrastructure for writing counters for profiling, as in clang's ``-fprofile-instr-generate``. The implementation of the instrprof pass is ported directly out of the CodeGenPGO classes in clang, and with the followup in clang that rips that code out to use these new intrinsics this ends up being NFC. Doing the instrumentation this way opens some doors in terms of improving the counter performance. For example, this will make it simple to experiment with alternate lowering strategies, and allows us to try handling profiling specially in some optimizations if we want to. Finally, this drastically simplifies the frontend and puts all of the lowering logic in one place. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223672 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -322,6 +322,33 @@ namespace llvm {
|
||||
Value *getSrc() const { return const_cast<Value*>(getArgOperand(1)); }
|
||||
};
|
||||
|
||||
/// This represents the llvm.instrprof_increment intrinsic.
|
||||
class InstrProfIncrementInst : public IntrinsicInst {
|
||||
public:
|
||||
static inline bool classof(const IntrinsicInst *I) {
|
||||
return I->getIntrinsicID() == Intrinsic::instrprof_increment;
|
||||
}
|
||||
static inline bool classof(const Value *V) {
|
||||
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
||||
}
|
||||
|
||||
GlobalVariable *getName() const {
|
||||
return cast<GlobalVariable>(
|
||||
const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
|
||||
}
|
||||
|
||||
ConstantInt *getHash() const {
|
||||
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
|
||||
}
|
||||
|
||||
ConstantInt *getNumCounters() const {
|
||||
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
|
||||
}
|
||||
|
||||
ConstantInt *getIndex() const {
|
||||
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -291,6 +291,12 @@ def int_stackprotector : Intrinsic<[], [llvm_ptr_ty, llvm_ptrptr_ty], []>;
|
||||
def int_stackprotectorcheck : Intrinsic<[], [llvm_ptrptr_ty],
|
||||
[IntrReadWriteArgMem]>;
|
||||
|
||||
// A counter increment for instrumentation based profiling.
|
||||
def int_instrprof_increment : Intrinsic<[],
|
||||
[llvm_ptr_ty, llvm_i64_ty,
|
||||
llvm_i32_ty, llvm_i32_ty],
|
||||
[]>;
|
||||
|
||||
//===------------------- Standard C Library Intrinsics --------------------===//
|
||||
//
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ void initializeEarlyIfConverterPass(PassRegistry&);
|
||||
void initializeEdgeBundlesPass(PassRegistry&);
|
||||
void initializeExpandPostRAPass(PassRegistry&);
|
||||
void initializeGCOVProfilerPass(PassRegistry&);
|
||||
void initializeInstrProfilingPass(PassRegistry&);
|
||||
void initializeAddressSanitizerPass(PassRegistry&);
|
||||
void initializeAddressSanitizerModulePass(PassRegistry&);
|
||||
void initializeMemorySanitizerPass(PassRegistry&);
|
||||
|
||||
@@ -78,6 +78,7 @@ namespace {
|
||||
(void) llvm::createDomOnlyViewerPass();
|
||||
(void) llvm::createDomViewerPass();
|
||||
(void) llvm::createGCOVProfilerPass();
|
||||
(void) llvm::createInstrProfilingPass();
|
||||
(void) llvm::createFunctionInliningPass();
|
||||
(void) llvm::createAlwaysInlinerPass();
|
||||
(void) llvm::createGlobalDCEPass();
|
||||
|
||||
@@ -63,6 +63,18 @@ struct GCOVOptions {
|
||||
ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
|
||||
GCOVOptions::getDefault());
|
||||
|
||||
/// Options for the frontend instrumentation based profiling pass.
|
||||
struct InstrProfOptions {
|
||||
InstrProfOptions() : NoRedZone(false) {}
|
||||
|
||||
// Add the 'noredzone' attribute to added runtime library calls.
|
||||
bool NoRedZone;
|
||||
};
|
||||
|
||||
/// Insert frontend instrumentation based profiling.
|
||||
ModulePass *createInstrProfilingPass(
|
||||
const InstrProfOptions &Options = InstrProfOptions());
|
||||
|
||||
// Insert AddressSanitizer (address sanity checking) instrumentation
|
||||
FunctionPass *createAddressSanitizerFunctionPass();
|
||||
ModulePass *createAddressSanitizerModulePass();
|
||||
|
||||
Reference in New Issue
Block a user