14#include "llvm/ADT/Twine.h"
15#include "llvm/IR/IntrinsicsX86.h"
16#include "llvm/IR/Module.h"
17#include "llvm/TargetParser/Triple.h"
23 const char *Name =
"atexit";
27 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
29 FunctionType::get(
Builder.getInt32Ty(), {Builder.getPtrTy()},
false);
30 F = Function::Create(Ty, Linkage, Name,
M);
37 const char *Name =
"llvm.global_ctors";
38 GlobalVariable *GV =
M->getGlobalVariable(Name);
39 std::vector<Constant *> V;
42 Constant *
Array = GV->getInitializer();
44 V.push_back(cast<Constant>(
X));
45 GV->eraseFromParent();
49 StructType::get(
Builder.getInt32Ty(), Fn->getType(),
Builder.getPtrTy());
52 ConstantStruct::get(ST,
Builder.getInt32(10), Fn,
53 ConstantPointerNull::get(
Builder.getPtrTy())));
54 ArrayType *Ty = ArrayType::get(ST, V.size());
56 GV =
new GlobalVariable(*
M, Ty,
true, GlobalValue::AppendingLinkage,
57 ConstantArray::get(Ty, V), Name,
nullptr,
58 GlobalVariable::NotThreadLocal);
62 return Intrinsic::getDeclaration(
M, Intrinsic::x86_rdtscp);
66 :
M(
M), Builder(
M->getContext()),
S(
S) {
67 if (Triple(
M->getTargetTriple()).getArch() == llvm::Triple::x86_64)
74 Constant *InitialValue, Value **Location) {
75 *Location =
M->getGlobalVariable(Name);
78 *Location =
new GlobalVariable(
79 *
M, InitialValue->getType(),
true, GlobalValue::WeakAnyLinkage,
80 InitialValue, Name,
nullptr, GlobalVariable::InitialExecTLSModel);
86 std::string EntryString, ExitString;
87 std::tie(EntryString, ExitString) =
S.getEntryExitStr();
89 return (Twine(
"__polly_perf_in_") +
S.getFunction().getName() +
"_from__" +
90 EntryString +
"__to__" + ExitString)
125 GlobalValue::LinkageTypes Linkage = Function::WeakODRLinkage;
126 FunctionType *Ty = FunctionType::get(
Builder.getVoidTy(), {},
false);
129 FinalStartBB = BasicBlock::Create(
M->getContext(),
"start", ExitFn);
134 Builder,
"Polly runtime information generation not supported\n");
142 Type *Int64Ty =
Builder.getInt64Ty();
143 Value *CurrentCycles =
146 Value *CyclesTotal =
Builder.CreateSub(CurrentCycles, CyclesStart);
163 "entry block name, exit block name, total time, trip count\n");
173 "PerfMonitor::insertFinalReporting.");
175 "PerfMonitor::insertFinalReporting.");
180 Type *Int64Ty =
Builder.getInt64Ty();
181 Value *CyclesInCurrentScop =
184 Value *TripCountForCurrentScop =
187 std::string EntryName, ExitName;
188 std::tie(EntryName, ExitName) =
S.getEntryExitStr();
192 Builder,
S.getFunction().getName(),
", ", EntryName,
", ", ExitName,
", ",
193 CyclesInCurrentScop,
", ", TripCountForCurrentScop,
"\n");
218 GlobalValue::LinkageTypes Linkage = Function::WeakODRLinkage;
219 FunctionType *Ty = FunctionType::get(
Builder.getVoidTy(), {},
false);
221 BasicBlock *Start = BasicBlock::Create(
M->getContext(),
"start", InitFn);
222 BasicBlock *EarlyReturn =
223 BasicBlock::Create(
M->getContext(),
"earlyreturn", InitFn);
224 BasicBlock *InitBB = BasicBlock::Create(
M->getContext(),
"initbb", InitFn);
237 Value *HasRunBefore =
239 Builder.CreateCondBr(HasRunBefore, EarlyReturn, InitBB);
240 Builder.SetInsertPoint(EarlyReturn);
244 Builder.SetInsertPoint(InitBB);
249 Value *FinalReportingPtr =
252 Builder.CreateCall(AtExitFn, {FinalReportingPtr});
257 Value *CurrentCycles =
270 Builder.SetInsertPoint(InsertBefore);
272 Value *CurrentCycles =
281 Builder.SetInsertPoint(InsertBefore);
283 Type *Int64Ty =
Builder.getInt64Ty();
284 LoadInst *CyclesStart =
286 Value *CurrentCycles =
288 Value *CyclesInScop =
Builder.CreateSub(CurrentCycles, CyclesStart);
290 CyclesInScops =
Builder.CreateAdd(CyclesInScops, CyclesInScop);
293 Value *CyclesInCurrentScop =
295 CyclesInCurrentScop =
Builder.CreateAdd(CyclesInCurrentScop, CyclesInScop);
298 Value *TripCountForCurrentScop =
300 TripCountForCurrentScop =
polly dump Polly Dump Function
static Function * FinalReporting
static ReturnInst * ReturnFromFinal
static const char * FinalReportingFunctionName
static void TryRegisterGlobal(Module *M, const char *Name, Constant *InitialValue, Value **Location)
static const char * InitFunctionName
static BasicBlock * FinalStartBB
static std::string GetScopUniqueVarname(const Scop &S)
static RegisterPass< ScopViewerWrapperPass > X("view-scops", "Polly - View Scops of function")
static RegisterPass< ScopPrinterWrapperPass > M("dot-scops", "Polly - Print Scops of function")
PerfMonitor(const Scop &S, llvm::Module *M)
Create a new performance monitor.
llvm::Value * AlreadyInitializedPtr
A global variable, that keeps track if the performance monitor initialization has already been run.
llvm::Function * insertFinalReporting()
Create function "__polly_perf_final_reporting".
llvm::Function * getRDTSCP()
Get a reference to the intrinsic "{ i64, i32 } @llvm.x86.rdtscp()".
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.
void AppendScopReporting()
Append Scop reporting data to "__polly_perf_final_reporting".
void initialize()
Initialize the performance monitor.
void insertRegionEnd(llvm::Instruction *InsertBefore)
Mark the end of a timing region.
llvm::Value * CyclesInScopsPtr
The total number of cycles spent within scops.
llvm::Value * TripCountForCurrentScopPtr
The total number of times the current scop S is executed.
void addToGlobalConstructors(llvm::Function *Fn)
Add Function to list of global constructors.
llvm::Value * CyclesInScopStartPtr
The value of the cycle counter at the beginning of the last scop.
bool Supported
Indicates if performance profiling is supported on this architecture.
void insertRegionStart(llvm::Instruction *InsertBefore)
Mark the beginning of a timing region.
llvm::Function * getAtExit()
Get a reference to "int atexit(void (*function)(void))" function.
void addGlobalVariables()
Add global variables to module.
llvm::Function * insertInitFunction(llvm::Function *FinalReporting)
void addScopCounter()
Add per-scop tracking to module.
This file contains the declaration of the PolyhedralInfo class, which will provide an interface to ex...
@ Array
MemoryKind::Array: Models a one or multi-dimensional array.
@ Value
MemoryKind::Value: Models an llvm::Value.
static void createCPUPrinter(PollyIRBuilder &Builder, Args... args)
Print a set of LLVM-IR Values or StringRefs via printf.