1*d883ef10SRahul Joshi //===- TGTimer.cpp - TableGen Timer implementation --------------*- C++ -*-===// 2*d883ef10SRahul Joshi // 3*d883ef10SRahul Joshi // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*d883ef10SRahul Joshi // See https://llvm.org/LICENSE.txt for license information. 5*d883ef10SRahul Joshi // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*d883ef10SRahul Joshi // 7*d883ef10SRahul Joshi //===----------------------------------------------------------------------===// 8*d883ef10SRahul Joshi // 9*d883ef10SRahul Joshi // Implement the tablegen timer class. 10*d883ef10SRahul Joshi // 11*d883ef10SRahul Joshi //===----------------------------------------------------------------------===// 12*d883ef10SRahul Joshi 13*d883ef10SRahul Joshi #include "llvm/TableGen/TGTimer.h" 14*d883ef10SRahul Joshi using namespace llvm; 15*d883ef10SRahul Joshi 16*d883ef10SRahul Joshi // These functions implement the phase timing facility. Starting a timer 17*d883ef10SRahul Joshi // when one is already running stops the running one. 18*d883ef10SRahul Joshi void TGTimer::startTimer(StringRef Name) { 19*d883ef10SRahul Joshi if (!TimingGroup) 20*d883ef10SRahul Joshi return; 21*d883ef10SRahul Joshi if (LastTimer && LastTimer->isRunning()) { 22*d883ef10SRahul Joshi LastTimer->stopTimer(); 23*d883ef10SRahul Joshi if (BackendTimer) { 24*d883ef10SRahul Joshi LastTimer->clear(); 25*d883ef10SRahul Joshi BackendTimer = false; 26*d883ef10SRahul Joshi } 27*d883ef10SRahul Joshi } 28*d883ef10SRahul Joshi 29*d883ef10SRahul Joshi LastTimer = std::make_unique<Timer>("", Name, *TimingGroup); 30*d883ef10SRahul Joshi LastTimer->startTimer(); 31*d883ef10SRahul Joshi } 32*d883ef10SRahul Joshi 33*d883ef10SRahul Joshi void TGTimer::stopTimer() { 34*d883ef10SRahul Joshi if (!TimingGroup) 35*d883ef10SRahul Joshi return; 36*d883ef10SRahul Joshi 37*d883ef10SRahul Joshi assert(LastTimer && "No phase timer was started"); 38*d883ef10SRahul Joshi LastTimer->stopTimer(); 39*d883ef10SRahul Joshi } 40*d883ef10SRahul Joshi 41*d883ef10SRahul Joshi void TGTimer::startBackendTimer(StringRef Name) { 42*d883ef10SRahul Joshi if (!TimingGroup) 43*d883ef10SRahul Joshi return; 44*d883ef10SRahul Joshi 45*d883ef10SRahul Joshi startTimer(Name); 46*d883ef10SRahul Joshi BackendTimer = true; 47*d883ef10SRahul Joshi } 48*d883ef10SRahul Joshi 49*d883ef10SRahul Joshi void TGTimer::stopBackendTimer() { 50*d883ef10SRahul Joshi if (!TimingGroup || !BackendTimer) 51*d883ef10SRahul Joshi return; 52*d883ef10SRahul Joshi stopTimer(); 53*d883ef10SRahul Joshi BackendTimer = false; 54*d883ef10SRahul Joshi } 55