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