Merge pull request #6467 from briansull/multireg-return2
[platform/upstream/coreclr.git] / src / jit / phase.h
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 /*****************************************************************************/
6 #ifndef _PHASE_H_
7 #define _PHASE_H_
8
9 class Phase
10 {
11 public:
12     virtual void Run();
13
14 protected:
15     Phase(Compiler *_comp, 
16           const char *_name, 
17           Phases _phase=PHASE_NUMBER_OF) 
18         : comp(_comp), name(_name), phase(_phase) {}
19
20     virtual void PrePhase();
21     virtual void DoPhase() = 0;
22     virtual void PostPhase();
23
24     Compiler *comp;
25     const char *name;
26     Phases phase;
27 };
28
29 inline void Phase::Run()
30 {
31     PrePhase();
32     DoPhase();
33     PostPhase();
34 }
35
36 inline void Phase::PrePhase()
37 {
38 #ifdef DEBUG
39     if (VERBOSE)
40     {
41         printf("*************** In %s\n", name);
42         printf("Trees before %s\n", name);
43         comp->fgDispBasicBlocks(true);
44     }
45
46     if (comp->expensiveDebugCheckLevel >= 2)
47     {
48         // If everyone used the Phase class, this would duplicate the PostPhase() from the previous phase.
49         // But, not everyone does, so go ahead and do the check here, too.
50         comp->fgDebugCheckBBlist();
51         comp->fgDebugCheckLinks();
52     }
53 #endif // DEBUG
54 }
55
56 inline void Phase::PostPhase()
57 {
58 #ifdef DEBUG
59     if (VERBOSE)
60     {
61         printf("*************** Exiting %s\n", name);
62         printf("Trees after %s\n", name);
63         comp->fgDispBasicBlocks(true);
64     }
65 #endif // DEBUG
66
67     if (phase != PHASE_NUMBER_OF)
68     {
69         comp->EndPhase(phase);
70     }
71
72 #ifdef DEBUG
73     comp->fgDebugCheckBBlist();
74     comp->fgDebugCheckLinks();
75 #endif // DEBUG
76
77 }
78
79 #endif /* End of _PHASE_H_ */