forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssabuilder.h
More file actions
90 lines (70 loc) · 3.86 KB
/
ssabuilder.h
File metadata and controls
90 lines (70 loc) · 3.86 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#pragma once
#pragma warning(disable : 4503) // 'identifier' : decorated name length exceeded, name was truncated
#include "compiler.h"
#include "ssarenamestate.h"
typedef int LclVarNum;
// Pair of a local var name eg: V01 and Ssa number; eg: V01_01
typedef std::pair<LclVarNum, int> SsaVarName;
class SsaBuilder
{
private:
inline void EndPhase(Phases phase)
{
m_pCompiler->EndPhase(phase);
}
public:
// Constructor
SsaBuilder(Compiler* pCompiler);
// Requires stmt nodes to be already sequenced in evaluation order. Analyzes the graph
// for introduction of phi-nodes as GT_PHI tree nodes at the beginning of each block.
// Each GT_LCL_VAR is given its ssa number through its GetSsaNum() field in the node.
// Each GT_PHI node will be under a STORE_LCL_VAR node as the store's value operand.
// The inputs to the PHI are represented as a linked list of GT_PHI_ARG nodes. Each
// use or def is denoted by the corresponding local nodes. All defs of a particular
// variable are stored in the "per SSA data" on the local descriptor.
void Build();
private:
// Compute flow graph dominance frontiers.
void ComputeDominanceFrontiers(BasicBlock** postOrder, int count, BlkToBlkVectorMap* mapDF);
// Compute the iterated dominance frontier for the specified block.
void ComputeIteratedDominanceFrontier(BasicBlock* b, const BlkToBlkVectorMap* mapDF, BlkVector* bIDF);
// Insert a new GT_PHI statement.
void InsertPhi(BasicBlock* block, unsigned lclNum);
// Add a new GT_PHI_ARG node to an existing GT_PHI node
void AddPhiArg(
BasicBlock* block, Statement* stmt, GenTreePhi* phi, unsigned lclNum, unsigned ssaNum, BasicBlock* pred);
// Requires "postOrder" to hold the blocks of the flowgraph in topologically sorted order. Requires
// count to be the valid entries in the "postOrder" array. Inserts GT_PHI nodes at the beginning
// of basic blocks that require them.
void InsertPhiFunctions();
// Rename all definitions and uses within the compiled method.
void RenameVariables();
// Rename all definitions and uses within a block.
void BlockRenameVariables(BasicBlock* block);
// Rename a local or memory definition generated by a local store/GT_CALL node.
void RenameDef(GenTree* defNode, BasicBlock* block);
unsigned RenamePushDef(GenTree* defNode, BasicBlock* block, unsigned lclNum, bool isFullDef);
// Rename a use of a local variable.
void RenameLclUse(GenTreeLclVarCommon* lclNode, BasicBlock* block);
// Assumes that "block" contains a definition for local var "lclNum", with SSA number "ssaNum".
// IF "block" is within one or more blocks with EH successors,
// and the local variable is live at the start of the corresponding successors,
// add this SSA number "ssaNum" to the argument list of the phi for the variable in the start
// block of those handlers.
void AddDefToEHSuccessorPhis(BasicBlock* block, unsigned lclNum, unsigned ssaNum);
// Same as above, for memory.
void AddMemoryDefToEHSuccessorPhis(MemoryKind memoryKind, BasicBlock* block, unsigned ssaNum);
// Add GT_PHI_ARG nodes to the GT_PHI nodes within block's successors.
void AddPhiArgsToSuccessors(BasicBlock* block);
// Similar to Add[Memory]DefToEHSuccessorPhis, but adds initial values to
// the handlers of a newly entered block based on one entering block.
void AddPhiArgsToNewlyEnteredHandler(BasicBlock* predEnterBlock, BasicBlock* enterBlock, BasicBlock* handlerStart);
Compiler* m_pCompiler;
CompAllocator m_allocator;
// Bit vector used by ComputeImmediateDom to track already visited blocks.
BitVecTraits m_visitedTraits;
BitVec m_visited;
SsaRenameState m_renameStack;
};