1// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_COMPILER_BACKEND_CODE_STATISTICS_H_
6#define RUNTIME_VM_COMPILER_BACKEND_CODE_STATISTICS_H_
7
8#if defined(DART_PRECOMPILED_RUNTIME)
9#error "AOT runtime should not use compiler sources (including header files)"
10#endif // defined(DART_PRECOMPILED_RUNTIME)
11
12#include "vm/compiler/assembler/assembler.h"
13#include "vm/compiler/backend/il.h"
14#include "vm/object.h"
15
16namespace dart {
17
18class CombinedCodeStatistics {
19 public:
20 // clang-format off
21 enum EntryCounter {
22#define DO(type, attrs) kTag##type,
23 FOR_EACH_INSTRUCTION(DO)
24#undef DO
25
26#define DO(type, attrs) kTag##type##SlowPath,
27 FOR_EACH_INSTRUCTION(DO)
28#undef DO
29
30 kTagAssertAssignableParameterCheck,
31 kTagAssertAssignableInsertedByFrontend,
32 kTagAssertAssignableFromSource,
33
34 kTagCheckedEntry,
35 kTagIntrinsics,
36
37 kNumEntries,
38 };
39 // clang-format on
40
41 CombinedCodeStatistics();
42
43 void Begin(Instruction* instruction);
44 void End(Instruction* instruction);
45
46 void DumpStatistics();
47
48 static EntryCounter SlowPathCounterFor(Instruction::Tag tag) {
49 return static_cast<CombinedCodeStatistics::EntryCounter>(
50 CombinedCodeStatistics::kTagGraphEntrySlowPath + tag);
51 }
52
53 private:
54 friend class CodeStatistics;
55
56 static int CompareEntries(const void* a, const void* b);
57
58 typedef struct {
59 const char* name;
60 intptr_t bytes;
61 intptr_t count;
62 } Entry;
63
64 Entry entries_[kNumEntries];
65 intptr_t unaccounted_bytes_;
66 intptr_t alignment_bytes_;
67 intptr_t object_header_bytes_;
68 intptr_t return_const_count_;
69 intptr_t return_const_with_load_field_count_;
70};
71
72class CodeStatistics {
73 public:
74 explicit CodeStatistics(compiler::Assembler* assembler);
75
76 void Begin(Instruction* instruction);
77 void End(Instruction* instruction);
78
79 void SpecialBegin(intptr_t tag);
80 void SpecialEnd(intptr_t tag);
81
82 void AppendTo(CombinedCodeStatistics* stat);
83
84 void Finalize();
85
86 private:
87 static const int kStackSize = 8;
88
89 compiler::Assembler* assembler_;
90
91 typedef struct {
92 intptr_t bytes;
93 intptr_t count;
94 } Entry;
95
96 Entry entries_[CombinedCodeStatistics::kNumEntries];
97 intptr_t instruction_bytes_;
98 intptr_t unaccounted_bytes_;
99 intptr_t alignment_bytes_;
100
101 intptr_t stack_[kStackSize];
102 intptr_t stack_index_;
103};
104
105} // namespace dart
106
107#endif // RUNTIME_VM_COMPILER_BACKEND_CODE_STATISTICS_H_
108