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 | #include "phase.h" |
7 | |
8 | class Rationalizer : public Phase |
9 | { |
10 | private: |
11 | BasicBlock* m_block; |
12 | GenTreeStmt* m_statement; |
13 | |
14 | public: |
15 | Rationalizer(Compiler* comp); |
16 | |
17 | #ifdef DEBUG |
18 | static void ValidateStatement(GenTree* tree, BasicBlock* block); |
19 | |
20 | // general purpose sanity checking of de facto standard GenTree |
21 | void SanityCheck(); |
22 | |
23 | // sanity checking of rationalized IR |
24 | void SanityCheckRational(); |
25 | |
26 | #endif // DEBUG |
27 | |
28 | virtual void DoPhase() override; |
29 | |
30 | static void RewriteAssignmentIntoStoreLcl(GenTreeOp* assignment); |
31 | |
32 | private: |
33 | inline LIR::Range& BlockRange() const |
34 | { |
35 | return LIR::AsRange(m_block); |
36 | } |
37 | |
38 | // SIMD related |
39 | void RewriteSIMDOperand(LIR::Use& use, bool keepBlk); |
40 | |
41 | // Intrinsic related transformations |
42 | void RewriteNodeAsCall(GenTree** use, |
43 | ArrayStack<GenTree*>& parents, |
44 | CORINFO_METHOD_HANDLE callHnd, |
45 | #ifdef FEATURE_READYTORUN_COMPILER |
46 | CORINFO_CONST_LOOKUP entryPoint, |
47 | #endif |
48 | GenTreeArgList* args); |
49 | |
50 | void RewriteIntrinsicAsUserCall(GenTree** use, ArrayStack<GenTree*>& parents); |
51 | |
52 | // Other transformations |
53 | void RewriteAssignment(LIR::Use& use); |
54 | void RewriteAddress(LIR::Use& use); |
55 | |
56 | // Root visitor |
57 | Compiler::fgWalkResult RewriteNode(GenTree** useEdge, ArrayStack<GenTree*>& parents); |
58 | }; |
59 | |
60 | inline Rationalizer::Rationalizer(Compiler* _comp) : Phase(_comp, "IR Rationalize" , PHASE_RATIONALIZE) |
61 | { |
62 | #ifdef DEBUG |
63 | comp->compNumStatementLinksTraversed = 0; |
64 | #endif |
65 | } |
66 | |