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