Flutter Engine
The Flutter Engine
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 4071 of file redundancy_elimination.cc.

Constructor & Destructor Documentation

◆ TryCatchAnalyzer()

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

Definition at line 4073 of file redundancy_elimination.cc.

4074 : flow_graph_(flow_graph),
4075 is_aot_(is_aot),
4076 // Initial capacity is selected based on trivial examples.
4077 worklist_(flow_graph, /*initial_capacity=*/10) {}

Member Function Documentation

◆ Optimize()

void dart::TryCatchAnalyzer::Optimize ( )

Definition at line 4331 of file redundancy_elimination.cc.

4331 {
4332 // Analyze catch entries and remove "dead" Parameter instructions.
4333 if (is_aot_) {
4334 OptimizeDeadParameters();
4335 }
4336
4337 // For every catch-block: Iterate over all call instructions inside the
4338 // corresponding try-block and figure out for each environment value if it
4339 // is the same constant at all calls. If yes, replace the initial definition
4340 // at the catch-entry with this constant.
4341 const GrowableArray<CatchBlockEntryInstr*>& catch_entries =
4342 flow_graph_->graph_entry()->catch_entries();
4343
4344 for (auto catch_entry : catch_entries) {
4345 // Initialize cdefs with the original initial definitions (ParameterInstr).
4346 // The following representation is used:
4347 // ParameterInstr => unknown
4348 // ConstantInstr => known constant
4349 // nullptr => non-constant
4350 GrowableArray<Definition*>* idefs = catch_entry->initial_definitions();
4351 GrowableArray<Definition*> cdefs(idefs->length());
4352 cdefs.AddArray(*idefs);
4353
4354 // exception_var and stacktrace_var are never constant. In asynchronous or
4355 // generator functions they may be context-allocated in which case they are
4356 // not tracked in the environment anyway.
4357
4358 cdefs[flow_graph_->EnvIndex(catch_entry->raw_exception_var())] = nullptr;
4359 cdefs[flow_graph_->EnvIndex(catch_entry->raw_stacktrace_var())] = nullptr;
4360
4361 for (BlockIterator block_it = flow_graph_->reverse_postorder_iterator();
4362 !block_it.Done(); block_it.Advance()) {
4363 BlockEntryInstr* block = block_it.Current();
4364 if (block->try_index() == catch_entry->catch_try_index()) {
4365 for (ForwardInstructionIterator instr_it(block); !instr_it.Done();
4366 instr_it.Advance()) {
4367 Instruction* current = instr_it.Current();
4368 if (current->MayThrow()) {
4369 Environment* env = current->env()->Outermost();
4370 ASSERT(env != nullptr);
4371 for (intptr_t env_idx = 0; env_idx < cdefs.length(); ++env_idx) {
4372 if (cdefs[env_idx] != nullptr && !cdefs[env_idx]->IsConstant() &&
4373 env->ValueAt(env_idx)->BindsToConstant()) {
4374 // If the recorded definition is not a constant, record this
4375 // definition as the current constant definition.
4376 cdefs[env_idx] = env->ValueAt(env_idx)->definition();
4377 }
4378 if (cdefs[env_idx] != env->ValueAt(env_idx)->definition()) {
4379 // Non-constant definitions are reset to nullptr.
4380 cdefs[env_idx] = nullptr;
4381 }
4382 }
4383 }
4384 }
4385 }
4386 }
4387 for (intptr_t j = 0; j < idefs->length(); ++j) {
4388 if (cdefs[j] != nullptr && cdefs[j]->IsConstant()) {
4389 Definition* old = (*idefs)[j];
4390 ConstantInstr* orig = cdefs[j]->AsConstant();
4391 ConstantInstr* copy =
4392 new (flow_graph_->zone()) ConstantInstr(orig->value());
4393 flow_graph_->AllocateSSAIndex(copy);
4394 old->ReplaceUsesWith(copy);
4395 copy->set_previous(old->previous()); // partial link
4396 (*idefs)[j] = copy;
4397 }
4398 }
4399 }
4400}
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
Definition: SkSwizzler.cpp:31
bool Done() const
Definition: flow_graph.h:46
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:2012
#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: