xref: /freebsd/contrib/llvm-project/llvm/include/llvm/TableGen/TGTimer.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- llvm/TableGen/TGTimer.h - Class for TableGen Timer -------*- 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 // This file defines the TableGen timer class. It's a thin wrapper around timer
10 // support in llvm/Support/Timer.h.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TABLEGEN_TGTIMER_H
15 #define LLVM_TABLEGEN_TGTIMER_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Timer.h"
19 #include <memory>
20 
21 namespace llvm {
22 
23 // Timer related functionality f or TableGen backends.
24 class TGTimer {
25 private:
26   std::unique_ptr<TimerGroup> TimingGroup;
27   std::unique_ptr<Timer> LastTimer;
28   bool BackendTimer = false; // Is last timer special backend overall timer?
29 
30 public:
31   TGTimer() = default;
32   ~TGTimer() = default;
33 
34   /// Start phase timing; called if the --time-phases option is specified.
startPhaseTiming()35   void startPhaseTiming() {
36     TimingGroup =
37         std::make_unique<TimerGroup>("TableGen", "TableGen Phase Timing");
38   }
39 
40   /// Start timing a phase. Automatically stops any previous phase timer.
41   void startTimer(StringRef Name);
42 
43   /// Stop timing a phase.
44   void stopTimer();
45 
46   /// Start timing the overall backend. If the backend itself starts a timer,
47   /// then this timer is cleared.
48   void startBackendTimer(StringRef Name);
49 
50   /// Stop timing the overall backend.
51   void stopBackendTimer();
52 
53   /// Stop phase timing and print the report.
stopPhaseTiming()54   void stopPhaseTiming() { TimingGroup.reset(); }
55 };
56 
57 } // end namespace llvm
58 
59 #endif // LLVM_TABLEGEN_TGTIMER_H
60