Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
dart::TryCatchAnalyzer Class Reference
Inheritance diagram for dart::TryCatchAnalyzer:
dart::ValueObject

Public Member Functions

 TryCatchAnalyzer (FlowGraph *flow_graph, bool is_aot)
 
void Optimize ()
 
- Public Member Functions inherited from dart::ValueObject
 ValueObject ()
 
 ~ValueObject ()
 

Detailed Description

Definition at line 4052 of file redundancy_elimination.cc.

Constructor & Destructor Documentation

◆ TryCatchAnalyzer()

dart::TryCatchAnalyzer::TryCatchAnalyzer ( FlowGraph flow_graph,
bool  is_aot 
)
inlineexplicit

Definition at line 4054 of file redundancy_elimination.cc.

4055 : flow_graph_(flow_graph),
4056 is_aot_(is_aot),
4057 // Initial capacity is selected based on trivial examples.
4058 worklist_(flow_graph, /*initial_capacity=*/10) {}

Member Function Documentation

◆ Optimize()

void dart::TryCatchAnalyzer::Optimize ( )

Definition at line 4312 of file redundancy_elimination.cc.

4312 {
4313 // Analyze catch entries and remove "dead" Parameter instructions.
4314 if (is_aot_) {
4315 OptimizeDeadParameters();
4316 }
4317
4318 // For every catch-block: Iterate over all call instructions inside the
4319 // corresponding try-block and figure out for each environment value if it
4320 // is the same constant at all calls. If yes, replace the initial definition
4321 // at the catch-entry with this constant.
4322 const GrowableArray<CatchBlockEntryInstr*>& catch_entries =
4323 flow_graph_->graph_entry()->catch_entries();
4324
4325 for (auto catch_entry : catch_entries) {
4326 // Initialize cdefs with the original initial definitions (ParameterInstr).
4327 // The following representation is used:
4328 // ParameterInstr => unknown
4329 // ConstantInstr => known constant
4330 // nullptr => non-constant
4331 GrowableArray<Definition*>* idefs = catch_entry->initial_definitions();
4332 GrowableArray<Definition*> cdefs(idefs->length());
4333 cdefs.AddArray(*idefs);
4334
4335 // exception_var and stacktrace_var are never constant. In asynchronous or
4336 // generator functions they may be context-allocated in which case they are
4337 // not tracked in the environment anyway.
4338
4339 cdefs[flow_graph_->EnvIndex(catch_entry->raw_exception_var())] = nullptr;
4340 cdefs[flow_graph_->EnvIndex(catch_entry->raw_stacktrace_var())] = nullptr;
4341
4342 for (BlockIterator block_it = flow_graph_->reverse_postorder_iterator();
4343 !block_it.Done(); block_it.Advance()) {
4344 BlockEntryInstr* block = block_it.Current();
4345 if (block->try_index() == catch_entry->catch_try_index()) {
4346 for (ForwardInstructionIterator instr_it(block); !instr_it.Done();
4347 instr_it.Advance()) {
4348 Instruction* current = instr_it.Current();
4349 if (current->MayThrow()) {
4350 Environment* env = current->env()->Outermost();
4351 ASSERT(env != nullptr);
4352 for (intptr_t env_idx = 0; env_idx < cdefs.length(); ++env_idx) {
4353 if (cdefs[env_idx] != nullptr && !cdefs[env_idx]->IsConstant() &&
4354 env->ValueAt(env_idx)->BindsToConstant()) {
4355 // If the recorded definition is not a constant, record this
4356 // definition as the current constant definition.
4357 cdefs[env_idx] = env->ValueAt(env_idx)->definition();
4358 }
4359 if (cdefs[env_idx] != env->ValueAt(env_idx)->definition()) {
4360 // Non-constant definitions are reset to nullptr.
4361 cdefs[env_idx] = nullptr;
4362 }
4363 }
4364 }
4365 }
4366 }
4367 }
4368 for (intptr_t j = 0; j < idefs->length(); ++j) {
4369 if (cdefs[j] != nullptr && cdefs[j]->IsConstant()) {
4370 Definition* old = (*idefs)[j];
4371 ConstantInstr* orig = cdefs[j]->AsConstant();
4372 ConstantInstr* copy =
4373 new (flow_graph_->zone()) ConstantInstr(orig->value());
4374 flow_graph_->AllocateSSAIndex(copy);
4375 old->ReplaceUsesWith(copy);
4376 copy->set_previous(old->previous()); // partial link
4377 (*idefs)[j] = copy;
4378 }
4379 }
4380 }
4381}
GraphEntryInstr * graph_entry() const
Definition flow_graph.h:268
Zone * zone() const
Definition flow_graph.h:261
void AllocateSSAIndex(Definition *def)
Definition flow_graph.h:274
BlockIterator reverse_postorder_iterator() const
Definition flow_graph.h:219
intptr_t EnvIndex(const LocalVariable *variable) const
Definition flow_graph.h:189
const GrowableArray< CatchBlockEntryInstr * > & catch_entries() const
Definition il.h:1997
#define ASSERT(E)
Definition copy.py:1
static bool IsConstant(Definition *def, int64_t *val)
Definition loops.cc:123
Definition __init__.py:1

The documentation for this class was generated from the following file: