-
Notifications
You must be signed in to change notification settings - Fork 1
/
externis.h
100 lines (86 loc) · 2.59 KB
/
externis.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Copyright (C) 2022 Roy Jacobson
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <gcc-plugin.h>
#include <chrono>
#include <cpplib.h>
#include <cstdio>
#include <json.h>
#include <optional>
#include <pretty-print.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
namespace externis {
// Those are aliases so they're easily replacable with something else (like
// absl::flat_hash_map) if needed. Not doing it by default to keep minimal
// dependencies.
template <class Key, class Value> using map_t = std::unordered_map<Key, Value>;
template <class Value> using set_t = std::unordered_set<Value>;
using clock_t = std::chrono::high_resolution_clock;
using time_point_t = std::chrono::time_point<clock_t>;
extern time_point_t COMPILATION_START;
using TimeStamp = int64_t;
struct TimeSpan {
int64_t start;
int64_t end;
};
inline TimeStamp ns_from_start() {
return std::chrono::duration_cast<std::chrono::nanoseconds>(clock_t::now() -
COMPILATION_START)
.count();
}
enum EventCategory {
TU,
PREPROCESS,
FUNCTION,
STRUCT,
NAMESPACE,
// Pass categories
GIMPLE_PASS,
RTL_PASS,
SIMPLE_IPA_PASS,
IPA_PASS,
//
UNKNOWN
};
struct TraceEvent {
const char *name;
EventCategory category;
TimeSpan ts;
std::optional<map_t<std::string, std::string>> args;
};
void start_preprocess_file(const char *file_name, cpp_reader *pfile);
void end_preprocess_file();
void finish_preprocessing_stage();
void write_preprocessing_events();
void start_opt_pass(const opt_pass *pass);
void write_opt_pass_events();
void set_output_file(FILE *file);
void add_event(const TraceEvent &event);
void write_all_events();
void write_event(const TraceEvent &, bool);
struct FinishedFunction {
void *decl;
const char *name;
const char *file_name;
const char *scope_name;
EventCategory scope_type;
};
void end_parse_function(FinishedFunction);
void write_all_scopes();
void write_all_functions();
} // namespace externis