forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphase.cpp
More file actions
180 lines (157 loc) · 5.32 KB
/
phase.cpp
File metadata and controls
180 lines (157 loc) · 5.32 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "jitpch.h"
#ifdef _MSC_VER
#pragma hdrstop
#endif
#include "phase.h"
//------------------------------------------------------------------------
// Observations ctor: snapshot key compiler variables before running a phase
//
// Arguments:
// compiler - current compiler instance
//
Phase::Observations::Observations(Compiler* compiler)
{
#ifdef DEBUG
m_compiler = compiler->impInlineRoot();
m_fgBBcount = m_compiler->fgBBcount;
m_fgBBNumMax = m_compiler->fgBBNumMax;
m_compHndBBtabCount = m_compiler->compHndBBtabCount;
m_lvaCount = m_compiler->lvaCount;
m_compGenTreeID = m_compiler->compGenTreeID;
m_compStatementID = m_compiler->compStatementID;
m_compBasicBlockID = m_compiler->compBasicBlockID;
#endif
}
//------------------------------------------------------------------------
// Observations Check: verify key compiler variables are unchanged
// if phase claims it made no modifications
//
// Arguments:
// status - status from the just-completed phase
//
void Phase::Observations::Check(PhaseStatus status)
{
#ifdef DEBUG
if (status == PhaseStatus::MODIFIED_NOTHING)
{
assert(m_fgBBcount == m_compiler->fgBBcount);
assert(m_fgBBNumMax == m_compiler->fgBBNumMax);
assert(m_compHndBBtabCount == m_compiler->compHndBBtabCount);
assert(m_lvaCount == m_compiler->lvaCount);
assert(m_compGenTreeID == m_compiler->compGenTreeID);
assert(m_compStatementID == m_compiler->compStatementID);
assert(m_compBasicBlockID == m_compiler->compBasicBlockID);
}
#endif
}
//------------------------------------------------------------------------
// Run: execute a phase and any before and after actions
//
void Phase::Run()
{
Observations observations(comp);
PrePhase();
PhaseStatus status = DoPhase();
PostPhase(status);
observations.Check(status);
}
//------------------------------------------------------------------------
// PrePhase: perform dumps and checks before a phase executes
//
void Phase::PrePhase()
{
comp->BeginPhase(m_phase);
#ifdef DEBUG
if (VERBOSE)
{
if (comp->compIsForInlining())
{
printf("\n*************** Inline @[%06u] Starting PHASE %s\n",
Compiler::dspTreeID(comp->impInlineInfo->iciCall), m_name);
}
else
{
printf("\n*************** Starting PHASE %s\n", m_name);
}
}
#endif // DEBUG
#if DUMP_FLOWGRAPHS
comp->fgDumpFlowGraph(m_phase, Compiler::PhasePosition::PrePhase);
#endif // DUMP_FLOWGRAPHS
}
//------------------------------------------------------------------------
// PostPhase: perform dumps and checks after a phase executes
//
// Arguments:
// status - status from the DoPhase call for this phase
//
void Phase::PostPhase(PhaseStatus status)
{
comp->EndPhase(m_phase);
#ifdef DEBUG
#if DUMP_FLOWGRAPHS
comp->fgDumpFlowGraph(m_phase, Compiler::PhasePosition::PostPhase);
#endif // DUMP_FLOWGRAPHS
// Don't dump or check post phase unless the phase made changes.
//
const bool madeChanges = (status != PhaseStatus::MODIFIED_NOTHING);
const bool doPostPhase = madeChanges;
const bool doPostPhaseChecks = (comp->activePhaseChecks != PhaseChecks::CHECK_NONE);
const bool doPostPhaseDumps = (comp->activePhaseDumps == PhaseDumps::DUMP_ALL);
const char* const statusMessage = madeChanges ? "" : " [no changes]";
if (VERBOSE)
{
if (comp->compIsForInlining())
{
printf("\n*************** Inline @[%06u] Finishing PHASE %s%s\n",
Compiler::dspTreeID(comp->impInlineInfo->iciCall), m_name, statusMessage);
}
else
{
printf("\n*************** Finishing PHASE %s%s\n", m_name, statusMessage);
}
if (doPostPhase && doPostPhaseDumps)
{
printf("Trees after %s\n", m_name);
comp->fgDispBasicBlocks(true);
}
}
if (doPostPhase && doPostPhaseChecks)
{
if ((comp->activePhaseChecks & PhaseChecks::CHECK_UNIQUE) == PhaseChecks::CHECK_UNIQUE)
{
comp->fgDebugCheckNodesUniqueness();
}
if ((comp->activePhaseChecks & PhaseChecks::CHECK_FG) == PhaseChecks::CHECK_FG)
{
comp->fgDebugCheckBBlist();
}
if ((comp->activePhaseChecks & PhaseChecks::CHECK_IR) == PhaseChecks::CHECK_IR)
{
comp->fgDebugCheckLinks();
}
if ((comp->activePhaseChecks & PhaseChecks::CHECK_EH) == PhaseChecks::CHECK_EH)
{
comp->fgVerifyHandlerTab();
}
if ((comp->activePhaseChecks & PhaseChecks::CHECK_LOOPS) == PhaseChecks::CHECK_LOOPS)
{
comp->fgDebugCheckLoops();
}
if ((comp->activePhaseChecks & PhaseChecks::CHECK_PROFILE) == PhaseChecks::CHECK_PROFILE)
{
comp->fgDebugCheckProfileWeights();
}
if ((comp->activePhaseChecks & PhaseChecks::CHECK_LINKED_LOCALS) == PhaseChecks::CHECK_LINKED_LOCALS)
{
comp->fgDebugCheckLinkedLocals();
}
if (comp->m_dfsTree != nullptr)
{
comp->fgDebugCheckDfsTree();
}
}
#endif // DEBUG
}