14#include "llvm/ADT/Twine.h"
15#include "llvm/IR/IntrinsicsX86.h"
16#include "llvm/TargetParser/Triple.h"
22 const char *Name =
"atexit";
26 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
28 FunctionType::get(
Builder.getInt32Ty(), {Builder.getPtrTy()},
false);
29 F = Function::Create(Ty, Linkage, Name,
M);
36 const char *Name =
"llvm.global_ctors";
37 GlobalVariable *GV =
M->getGlobalVariable(Name);
38 std::vector<Constant *> V;
41 Constant *
Array = GV->getInitializer();
43 V.push_back(cast<Constant>(
X));
44 GV->eraseFromParent();
48 StructType::get(
Builder.getInt32Ty(), Fn->getType(),
Builder.getPtrTy());
51 ConstantStruct::get(ST,
Builder.getInt32(10), Fn,
52 ConstantPointerNull::get(
Builder.getPtrTy())));
53 ArrayType *Ty = ArrayType::get(ST, V.size());
55 GV =
new GlobalVariable(*
M, Ty,
true, GlobalValue::AppendingLinkage,
56 ConstantArray::get(Ty, V), Name,
nullptr,
57 GlobalVariable::NotThreadLocal);
61 return Intrinsic::getDeclaration(
M, Intrinsic::x86_rdtscp);
65 :
M(
M), Builder(
M->getContext()),
S(
S) {
66 if (Triple(
M->getTargetTriple()).getArch() == llvm::Triple::x86_64)
73 Constant *InitialValue, Value **Location) {
74 *Location =
M->getGlobalVariable(Name);
77 *Location =
new GlobalVariable(
78 *
M, InitialValue->getType(),
true, GlobalValue::WeakAnyLinkage,
79 InitialValue, Name,
nullptr, GlobalVariable::InitialExecTLSModel);
85 std::string EntryString, ExitString;
86 std::tie(EntryString, ExitString) =
S.getEntryExitStr();
88 return (Twine(
"__polly_perf_in_") +
S.getFunction().getName() +
"_from__" +
89 EntryString +
"__to__" + ExitString)
124 GlobalValue::LinkageTypes Linkage = Function::WeakODRLinkage;
125 FunctionType *Ty = FunctionType::get(
Builder.getVoidTy(), {},
false);
128 FinalStartBB = BasicBlock::Create(
M->getContext(),
"start", ExitFn);
133 Builder,
"Polly runtime information generation not supported\n");
141 Type *Int64Ty =
Builder.getInt64Ty();
142 Value *CurrentCycles =
145 Value *CyclesTotal =
Builder.CreateSub(CurrentCycles, CyclesStart);
162 "entry block name, exit block name, total time, trip count\n");
172 "PerfMonitor::insertFinalReporting.");
174 "PerfMonitor::insertFinalReporting.");
179 Type *Int64Ty =
Builder.getInt64Ty();
180 Value *CyclesInCurrentScop =
183 Value *TripCountForCurrentScop =
186 std::string EntryName, ExitName;
187 std::tie(EntryName, ExitName) =
S.getEntryExitStr();
191 Builder,
S.getFunction().getName(),
", ", EntryName,
", ", ExitName,
", ",
192 CyclesInCurrentScop,
", ", TripCountForCurrentScop,
"\n");
217 GlobalValue::LinkageTypes Linkage = Function::WeakODRLinkage;
218 FunctionType *Ty = FunctionType::get(
Builder.getVoidTy(), {},
false);
220 BasicBlock *Start = BasicBlock::Create(
M->getContext(),
"start", InitFn);
221 BasicBlock *EarlyReturn =
222 BasicBlock::Create(
M->getContext(),
"earlyreturn", InitFn);
223 BasicBlock *InitBB = BasicBlock::Create(
M->getContext(),
"initbb", InitFn);
236 Value *HasRunBefore =
238 Builder.CreateCondBr(HasRunBefore, EarlyReturn, InitBB);
239 Builder.SetInsertPoint(EarlyReturn);
243 Builder.SetInsertPoint(InitBB);
248 Value *FinalReportingPtr =
251 Builder.CreateCall(AtExitFn, {FinalReportingPtr});
256 Value *CurrentCycles =
269 Builder.SetInsertPoint(InsertBefore);
271 Value *CurrentCycles =
280 Builder.SetInsertPoint(InsertBefore);
282 Type *Int64Ty =
Builder.getInt64Ty();
283 LoadInst *CyclesStart =
285 Value *CurrentCycles =
287 Value *CyclesInScop =
Builder.CreateSub(CurrentCycles, CyclesStart);
289 CyclesInScops =
Builder.CreateAdd(CyclesInScops, CyclesInScop);
292 Value *CyclesInCurrentScop =
294 CyclesInCurrentScop =
Builder.CreateAdd(CyclesInCurrentScop, CyclesInScop);
297 Value *TripCountForCurrentScop =
299 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.