-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathfundepscan.cpp
More file actions
175 lines (143 loc) · 7.41 KB
/
fundepscan.cpp
File metadata and controls
175 lines (143 loc) · 7.41 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
#include "fundepscan.h"
namespace panda::bytecodeopt {
bool FunDepScan::HasBrokenCfgEdges() {
auto* graph = GetGraph();
const auto& rpo_blocks = graph->GetBlocksRPO();
std::set<uint32_t> reachable_ids;
for (auto* bb : rpo_blocks) {
reachable_ids.insert(bb->GetId());
}
for (auto* bb : graph->GetVectorBlocks()) {
if (bb == nullptr) continue;
if (reachable_ids.count(bb->GetId())) continue;
for (auto* succ : bb->GetSuccsBlocks()) {
if (reachable_ids.count(succ->GetId())) {
std::cout << "HasBrokenCfgEdges: unreachable block " << bb->GetId()
<< " has successor " << succ->GetId() << " in reachable set" << std::endl;
return true;
}
}
}
return false;
}
bool FunDepScan::RunImpl(){
if (GetGraph()->GetAliveBlocksCount() == 0 || HasBrokenCfgEdges()) {
return false;
}
for (auto *bb : GetGraph()->GetBlocksLinearOrder()) {
for (const auto &inst : bb->AllInsts()) {
VisitInstruction(inst);
}
}
return true;
}
void FunDepScan::VisitIntrinsic(GraphVisitor *visitor, Inst *inst_base)
{
ASSERT(inst_base->IsIntrinsic());
VisitEcma(visitor, inst_base);
}
void FunDepScan::VisitEcma(panda::compiler::GraphVisitor *visitor, Inst *inst_base){
ASSERT(inst_base->IsIntrinsic());
auto inst = inst_base->CastToIntrinsic();
auto enc = static_cast<FunDepScan *>(visitor);
switch(inst->GetIntrinsicId()){
case compiler::RuntimeInterface::IntrinsicId::CREATEOBJECTWITHBUFFER_IMM8_ID16:
case compiler::RuntimeInterface::IntrinsicId::CREATEOBJECTWITHBUFFER_IMM16_ID16:
{
auto literalarray_offset = static_cast<uint32_t>(inst->GetImms()[1]);
auto literalarray = FindLiteralArrayByOffset(enc->program_, literalarray_offset);
for (const auto& literal : literalarray->literals_) {
if(literal.tag_ == panda_file::LiteralTag::METHOD){
auto methodname = std::string(std::get<std::string>(literal.value_));
for (const auto& pair : *enc->methodname2offset_) {
if(pair.first.find(methodname) != std::string::npos){
uint32_t methodoffset = pair.second;
enc->depedges_->push_back(std::make_pair(enc->methodoffset_, methodoffset));
}
}
}
}
break;
}
case compiler::RuntimeInterface::IntrinsicId::DEFINEFUNC_IMM8_ID16_IMM8:
case compiler::RuntimeInterface::IntrinsicId::DEFINEFUNC_IMM16_ID16_IMM8:
{
uint32_t methodoffset = static_cast<uint32_t>(inst->GetImms()[1]);
enc->depedges_->push_back(std::make_pair(enc->methodoffset_, methodoffset));
if(contains(*enc->memberfuncs_, enc->methodoffset_)){
if(enc->current_constructor_offset){
(*enc->class2memberfuns_)[enc->current_constructor_offset].insert(methodoffset);
enc->depedges_->push_back(std::make_pair(enc->methodoffset_, methodoffset));
enc->memberfuncs_->insert(methodoffset);
}
}
break;
}
case compiler::RuntimeInterface::IntrinsicId::DEFINEMETHOD_IMM8_ID16_IMM8:
case compiler::RuntimeInterface::IntrinsicId::DEFINEMETHOD_IMM16_ID16_IMM8:
{
auto methodoffset = static_cast<uint32_t>(inst->GetImms()[1]);
auto method_name = enc->ir_interface_->GetMethodIdByOffset(methodoffset);
if(!enc->current_constructor_offset){
enc->depedges_->push_back(std::make_pair(enc->methodoffset_, methodoffset));
}else{
(*enc->class2memberfuns_)[enc->current_constructor_offset].insert(methodoffset);
if(method_name.find("instance_initializer") != std::string::npos){
std::cout << "set construct2initializer: " << enc->current_constructor_offset << " : " << methodoffset << std::endl;
(*enc->construct2initializer_)[enc->current_constructor_offset] = methodoffset;
enc->current_instance_initializer = methodoffset;
}else if(method_name.find("static_initializer") != std::string::npos){
std::cout << "set construct2staticinitializer: " << enc->current_constructor_offset << " : " << methodoffset << std::endl;
(*enc->construct2staticinitializer_)[enc->current_constructor_offset] = methodoffset;
enc->current_static_initializer = methodoffset;
}
}
break;
}
case compiler::RuntimeInterface::IntrinsicId::DEFINECLASSWITHBUFFER_IMM8_ID16_ID16_IMM16_V8:
case compiler::RuntimeInterface::IntrinsicId::DEFINECLASSWITHBUFFER_IMM16_ID16_ID16_IMM16_V8:
case compiler::RuntimeInterface::IntrinsicId::CALLRUNTIME_DEFINESENDABLECLASS_PREF_IMM16_ID16_ID16_IMM16_V8:
{
auto constructor_offset = static_cast<uint32_t>(inst->GetImms()[1]);
enc->current_constructor_offset = constructor_offset;
enc->inserted_construct_order_->push_back(enc->current_constructor_offset);
(*enc->class2memberfuns_)[constructor_offset].insert(constructor_offset);
(*enc->construct2definedmethod_)[constructor_offset] = enc->methodoffset_;
auto literalarray_offset = static_cast<uint32_t>(inst->GetImms()[2]);
auto member_functions = GetLiteralArrayByOffset(enc->program_, literalarray_offset);
if(member_functions){
for(auto const& member_function : *member_functions){
if (enc->methodname2offset_->find(member_function) != enc->methodname2offset_->end()) {
auto memeber_offset = (*enc->methodname2offset_)[member_function];
(*enc->class2memberfuns_)[constructor_offset].insert(memeber_offset);
}else{
HandleError("#function dep scan: DEFINECLASSWITHBUFFER");
}
}
}
break;
}
case compiler::RuntimeInterface::IntrinsicId::CALLRUNTIME_CREATEPRIVATEPROPERTY_PREF_IMM16_ID16:{
auto ir_id0 = static_cast<uint32_t>(inst->GetImms()[1]);
auto member_functions = GetLiteralArrayByOffset(enc->program_, ir_id0);
if(member_functions){
for(const auto& member_function : *member_functions){
auto memeber_offset = (*enc->methodname2offset_)[member_function];
(*enc->class2memberfuns_)[enc->current_constructor_offset].insert(memeber_offset);
}
}else{
HandleError("#function dep scan: CALLRUNTIME_CREATEPRIVATEPROPERTY");
}
break;
}
case compiler::RuntimeInterface::IntrinsicId::CALLRUNTIME_DEFINEPRIVATEPROPERTY_PREF_IMM8_IMM16_IMM16_V8:{
auto tier = static_cast<uint32_t>(inst->GetImms()[1]);
auto index = static_cast<uint32_t>(inst->GetImms()[2]);
//(*enc->method2lexicalmap_)[enc->methodoffset_][tier].insert(index);
(*enc->method2lexicalmap_)[enc->current_constructor_offset][tier].insert(index);
break;
}
default:;
}
}
};