From 726c28f8c4951b5852c92afca329bb7b683c1ab3 Mon Sep 17 00:00:00 2001 From: Siddharth Bhat Date: Fri, 2 Jun 2017 11:36:52 +0000 Subject: [CodeGen] Track trip counts per-scop for performance measurement. - Add a counter that is incremented once on exit from a scop. - Test cases got split into two: one to test the cycles, and another one to test trip counts. - Sample output: ```name=sample-output.txt scop function, entry block name, exit block name, total time, trip count warmup, %entry.split, %polly.merge_new_and_old, 5180, 1 f, %entry.split, %polly.merge_new_and_old, 409944, 500 g, %entry.split, %polly.merge_new_and_old, 1226, 1 ``` Differential Revision: https://reviews.llvm.org/D33822 llvm-svn: 304543 --- polly/lib/CodeGen/PerfMonitor.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'polly/lib/CodeGen/PerfMonitor.cpp') diff --git a/polly/lib/CodeGen/PerfMonitor.cpp b/polly/lib/CodeGen/PerfMonitor.cpp index 5423d5a4fa6..0829934a07d 100644 --- a/polly/lib/CodeGen/PerfMonitor.cpp +++ b/polly/lib/CodeGen/PerfMonitor.cpp @@ -87,15 +87,18 @@ static std::string GetScopUniqueVarname(const Scop &S) { std::string EntryString, ExitString; std::tie(EntryString, ExitString) = S.getEntryExitStr(); - Name << "__polly_perf_cycles_in_" << std::string(S.getFunction().getName()) + Name << "__polly_perf_in_" << std::string(S.getFunction().getName()) << "_from__" << EntryString << "__to__" << ExitString; return Name.str(); } void PerfMonitor::addScopCounter() { const std::string varname = GetScopUniqueVarname(S); - TryRegisterGlobal(M, varname.c_str(), Builder.getInt64(0), + TryRegisterGlobal(M, (varname + "_cycles").c_str(), Builder.getInt64(0), &CyclesInCurrentScopPtr); + + TryRegisterGlobal(M, (varname + "_trip_count").c_str(), Builder.getInt64(0), + &TripCountForCurrentScopPtr); } void PerfMonitor::addGlobalVariables() { @@ -160,7 +163,7 @@ Function *PerfMonitor::insertFinalReporting() { RuntimeDebugBuilder::createCPUPrinter( Builder, "scop function, " - "entry block name, exit block name, total time\n"); + "entry block name, exit block name, total time, trip count\n"); ReturnFromFinal = Builder.CreateRetVoid(); return ExitFn; } @@ -179,13 +182,17 @@ void PerfMonitor::AppendScopReporting() { Value *CyclesInCurrentScop = Builder.CreateLoad(this->CyclesInCurrentScopPtr, true); + + Value *TripCountForCurrentScop = + Builder.CreateLoad(this->TripCountForCurrentScopPtr, true); + std::string EntryName, ExitName; std::tie(EntryName, ExitName) = S.getEntryExitStr(); // print in CSV for easy parsing with other tools. - RuntimeDebugBuilder::createCPUPrinter(Builder, S.getFunction().getName(), - ", ", EntryName, ", ", ExitName, ", ", - CyclesInCurrentScop, "\n"); + RuntimeDebugBuilder::createCPUPrinter( + Builder, S.getFunction().getName(), ", ", EntryName, ", ", ExitName, ", ", + CyclesInCurrentScop, ", ", TripCountForCurrentScop, "\n"); ReturnFromFinal = Builder.CreateRetVoid(); } @@ -288,4 +295,11 @@ void PerfMonitor::insertRegionEnd(Instruction *InsertBefore) { Value *CyclesInCurrentScop = Builder.CreateLoad(CyclesInCurrentScopPtr, true); CyclesInCurrentScop = Builder.CreateAdd(CyclesInCurrentScop, CyclesInScop); Builder.CreateStore(CyclesInCurrentScop, CyclesInCurrentScopPtr, true); + + Value *TripCountForCurrentScop = + Builder.CreateLoad(TripCountForCurrentScopPtr, true); + TripCountForCurrentScop = + Builder.CreateAdd(TripCountForCurrentScop, Builder.getInt64(1)); + Builder.CreateStore(TripCountForCurrentScop, TripCountForCurrentScopPtr, + true); } -- cgit v1.2.3