Polly 19.0.0git
Public Member Functions | Private Member Functions | Private Attributes | List of all members
polly::PerfMonitor Class Referencefinal

#include <PerfMonitor.h>

Public Member Functions

 PerfMonitor (const Scop &S, llvm::Module *M)
 Create a new performance monitor.
 
void initialize ()
 Initialize the performance monitor.
 
void insertRegionStart (llvm::Instruction *InsertBefore)
 Mark the beginning of a timing region.
 
void insertRegionEnd (llvm::Instruction *InsertBefore)
 Mark the end of a timing region.
 

Private Member Functions

llvm::Function * insertInitFunction (llvm::Function *FinalReporting)
 
void addToGlobalConstructors (llvm::Function *Fn)
 Add Function to list of global constructors.
 
void addGlobalVariables ()
 Add global variables to module.
 
void addScopCounter ()
 Add per-scop tracking to module.
 
llvm::Function * getRDTSCP ()
 Get a reference to the intrinsic "{ i64, i32 } @llvm.x86.rdtscp()".
 
llvm::Function * getAtExit ()
 Get a reference to "int atexit(void (*function)(void))" function.
 
llvm::Function * insertFinalReporting ()
 Create function "__polly_perf_final_reporting".
 
void AppendScopReporting ()
 Append Scop reporting data to "__polly_perf_final_reporting".
 

Private Attributes

llvm::Module * M
 
PollyIRBuilder Builder
 
const ScopS
 
bool Supported
 Indicates if performance profiling is supported on this architecture.
 
llvm::Value * CyclesTotalStartPtr
 The cycle counter at the beginning of the program execution.
 
llvm::Value * CyclesInCurrentScopPtr
 The total number of cycles spent in the current scop S.
 
llvm::Value * TripCountForCurrentScopPtr
 The total number of times the current scop S is executed.
 
llvm::Value * CyclesInScopsPtr
 The total number of cycles spent within scops.
 
llvm::Value * CyclesInScopStartPtr
 The value of the cycle counter at the beginning of the last scop.
 
llvm::Value * AlreadyInitializedPtr
 A global variable, that keeps track if the performance monitor initialization has already been run.
 

Detailed Description

Definition at line 16 of file PerfMonitor.h.

Constructor & Destructor Documentation

◆ PerfMonitor()

PerfMonitor::PerfMonitor ( const Scop S,
llvm::Module *  M 
)

Create a new performance monitor.

Parameters
SThe scop for which to generate fine-grained performance monitoring information.
MThe module for which to generate the performance monitor.

Definition at line 64 of file PerfMonitor.cpp.

References M, and Supported.

Member Function Documentation

◆ addGlobalVariables()

void PerfMonitor::addGlobalVariables ( )
private

Add global variables to module.

Insert a set of global variables that are used to track performance, into the module (or obtain references to them if they already exist).

Definition at line 102 of file PerfMonitor.cpp.

References AlreadyInitializedPtr, Builder, CyclesInScopsPtr, CyclesInScopStartPtr, CyclesTotalStartPtr, M, and TryRegisterGlobal().

Referenced by initialize().

◆ addScopCounter()

void PerfMonitor::addScopCounter ( )
private

Add per-scop tracking to module.

Insert the global variable which is used to track the number of cycles this scop runs.

Definition at line 93 of file PerfMonitor.cpp.

References Builder, CyclesInCurrentScopPtr, GetScopUniqueVarname(), M, TripCountForCurrentScopPtr, and TryRegisterGlobal().

Referenced by initialize().

◆ addToGlobalConstructors()

void PerfMonitor::addToGlobalConstructors ( llvm::Function *  Fn)
private

Add Function to list of global constructors.

If no global constructors are available in this current module, insert a new list of global constructors containing Fn as only global constructor. Otherwise, append Fn to the list of global constructors.

All functions listed as global constructors are executed before the main() function is called.

Parameters
FnFunction to add to global constructors

Definition at line 35 of file PerfMonitor.cpp.

References polly::Array, Builder, M, polly::Value, and X().

Referenced by initialize().

◆ AppendScopReporting()

void PerfMonitor::AppendScopReporting ( )
private

Append Scop reporting data to "__polly_perf_final_reporting".

This function appends the current scop (S)'s information to the final printing function.

Definition at line 167 of file PerfMonitor.cpp.

References assert, Builder, polly::RuntimeDebugBuilder::createCPUPrinter(), CyclesInCurrentScopPtr, FinalStartBB, ReturnFromFinal, Supported, TripCountForCurrentScopPtr, and polly::Value.

Referenced by initialize().

◆ getAtExit()

Function * PerfMonitor::getAtExit ( )
private

Get a reference to "int atexit(void (*function)(void))" function.

This function allows to register function pointers that must be executed when the program is terminated.

Returns
A reference to @atexit().

Definition at line 21 of file PerfMonitor.cpp.

References Builder, Function, and M.

Referenced by insertInitFunction().

◆ getRDTSCP()

Function * PerfMonitor::getRDTSCP ( )
private

Get a reference to the intrinsic "{ i64, i32 } @llvm.x86.rdtscp()".

The rdtscp function returns the current value of the processor's time-stamp counter as well as the current CPU identifier. On modern x86 systems, the returned value is independent of the dynamic clock frequency and consistent across multiple cores. It can consequently be used to get accurate and low-overhead timing information. Even though the counter is wrapping, it can be reliably used even for measuring longer time intervals, as on a 1 GHz processor the counter only wraps every 545 years.

The RDTSCP instruction is "pseudo" serializing:

"“The RDTSCP instruction waits until all previous instructions have been executed before reading the counter. However, subsequent instructions may begin execution before the read operation is performed.”

To ensure that no later instructions are scheduled before the RDTSCP instruction it is often recommended to schedule a cpuid call after the RDTSCP instruction. We do not do this yet, trading some imprecision in our timing for a reduced overhead in our timing.

Returns
A reference to the declaration of @llvm.x86.rdtscp.

Definition at line 60 of file PerfMonitor.cpp.

References Function, and M.

Referenced by insertFinalReporting(), insertInitFunction(), insertRegionEnd(), and insertRegionStart().

◆ initialize()

void PerfMonitor::initialize ( )

Initialize the performance monitor.

Ensure that all global variables, functions, and callbacks needed to manage the performance monitor are initialized and registered.

Definition at line 199 of file PerfMonitor.cpp.

References addGlobalVariables(), addScopCounter(), addToGlobalConstructors(), AppendScopReporting(), FinalReporting, Function, insertFinalReporting(), and insertInitFunction().

Referenced by generateCode().

◆ insertFinalReporting()

Function * PerfMonitor::insertFinalReporting ( )
private

Create function "__polly_perf_final_reporting".

This function finalizes the performance measurements and prints the results to stdout. It is expected to be registered with 'atexit()'.

Definition at line 122 of file PerfMonitor.cpp.

References Builder, polly::RuntimeDebugBuilder::createCPUPrinter(), CyclesInScopsPtr, CyclesTotalStartPtr, FinalReportingFunctionName, FinalStartBB, Function, getRDTSCP(), M, ReturnFromFinal, Supported, and polly::Value.

Referenced by initialize().

◆ insertInitFunction()

Function * PerfMonitor::insertInitFunction ( llvm::Function *  FinalReporting)
private

◆ insertRegionEnd()

void PerfMonitor::insertRegionEnd ( llvm::Instruction *  InsertBefore)

Mark the end of a timing region.

Parameters
InsertBeforeThe instruction before which the timing region starts.

Definition at line 276 of file PerfMonitor.cpp.

References Builder, CyclesInCurrentScopPtr, CyclesInScopsPtr, CyclesInScopStartPtr, Function, getRDTSCP(), Supported, TripCountForCurrentScopPtr, and polly::Value.

Referenced by generateCode().

◆ insertRegionStart()

void PerfMonitor::insertRegionStart ( llvm::Instruction *  InsertBefore)

Mark the beginning of a timing region.

Parameters
InsertBeforeThe instruction before which the timing region starts.

Definition at line 265 of file PerfMonitor.cpp.

References Builder, CyclesInScopStartPtr, Function, getRDTSCP(), Supported, and polly::Value.

Referenced by generateCode().

Member Data Documentation

◆ AlreadyInitializedPtr

llvm::Value* polly::PerfMonitor::AlreadyInitializedPtr
private

A global variable, that keeps track if the performance monitor initialization has already been run.

Definition at line 68 of file PerfMonitor.h.

Referenced by addGlobalVariables(), and insertInitFunction().

◆ Builder

PollyIRBuilder polly::PerfMonitor::Builder
private

◆ CyclesInCurrentScopPtr

llvm::Value* polly::PerfMonitor::CyclesInCurrentScopPtr
private

The total number of cycles spent in the current scop S.

Definition at line 55 of file PerfMonitor.h.

Referenced by addScopCounter(), AppendScopReporting(), and insertRegionEnd().

◆ CyclesInScopsPtr

llvm::Value* polly::PerfMonitor::CyclesInScopsPtr
private

The total number of cycles spent within scops.

Definition at line 61 of file PerfMonitor.h.

Referenced by addGlobalVariables(), insertFinalReporting(), and insertRegionEnd().

◆ CyclesInScopStartPtr

llvm::Value* polly::PerfMonitor::CyclesInScopStartPtr
private

The value of the cycle counter at the beginning of the last scop.

Definition at line 64 of file PerfMonitor.h.

Referenced by addGlobalVariables(), insertRegionEnd(), and insertRegionStart().

◆ CyclesTotalStartPtr

llvm::Value* polly::PerfMonitor::CyclesTotalStartPtr
private

The cycle counter at the beginning of the program execution.

Definition at line 52 of file PerfMonitor.h.

Referenced by addGlobalVariables(), insertFinalReporting(), and insertInitFunction().

◆ M

llvm::Module* polly::PerfMonitor::M
private

◆ S

const Scop& polly::PerfMonitor::S
private

Definition at line 46 of file PerfMonitor.h.

◆ Supported

bool polly::PerfMonitor::Supported
private

Indicates if performance profiling is supported on this architecture.

Definition at line 49 of file PerfMonitor.h.

Referenced by AppendScopReporting(), insertFinalReporting(), insertInitFunction(), insertRegionEnd(), insertRegionStart(), and PerfMonitor().

◆ TripCountForCurrentScopPtr

llvm::Value* polly::PerfMonitor::TripCountForCurrentScopPtr
private

The total number of times the current scop S is executed.

Definition at line 58 of file PerfMonitor.h.

Referenced by addScopCounter(), AppendScopReporting(), and insertRegionEnd().


The documentation for this class was generated from the following files: