Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
dart::LoopInfo Class Reference

#include <loops.h>

Inheritance diagram for dart::LoopInfo:
dart::ZoneAllocated

Public Member Functions

 LoopInfo (intptr_t id, BlockEntryInstr *header, BitVector *blocks)
 
void AddBlocks (BitVector *blocks)
 
void AddBackEdge (BlockEntryInstr *block)
 
bool IsBackEdge (BlockEntryInstr *block) const
 
bool IsAlwaysTaken (BlockEntryInstr *block) const
 
bool IsHeaderPhi (Definition *def) const
 
bool IsIn (LoopInfo *loop) const
 
bool Contains (BlockEntryInstr *block) const
 
intptr_t NestingDepth () const
 
void ResetInduction ()
 
void AddInduction (Definition *def, InductionVar *induc)
 
InductionVarLookupInduction (Definition *def) const
 
bool IsInRange (Instruction *pos, Value *index, Value *length)
 
intptr_t id () const
 
BlockEntryInstrheader () const
 
BitVectorblocks () const
 
const GrowableArray< BlockEntryInstr * > & back_edges ()
 
ConstraintInstrlimit () const
 
InductionVarcontrol () const
 
LoopInfoouter () const
 
LoopInfoinner () const
 
LoopInfonext () const
 
void PrintTo (BaseTextBuffer *f) const
 
const char * ToCString () const
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Friends

class InductionVar
 
class InductionVarAnalysis
 
class LoopHierarchy
 

Detailed Description

Definition at line 210 of file loops.h.

Constructor & Destructor Documentation

◆ LoopInfo()

dart::LoopInfo::LoopInfo ( intptr_t  id,
BlockEntryInstr header,
BitVector blocks 
)

Definition at line 980 of file loops.cc.

981 : id_(id),
982 header_(header),
983 blocks_(blocks),
984 back_edges_(),
985 induction_(),
986 memo_cache_(),
987 limit_(nullptr),
988 control_(nullptr),
989 outer_(nullptr),
990 inner_(nullptr),
991 next_(nullptr) {}
BitVector * blocks() const
Definition loops.h:253
BlockEntryInstr * header() const
Definition loops.h:252

Member Function Documentation

◆ AddBackEdge()

void dart::LoopInfo::AddBackEdge ( BlockEntryInstr block)

Definition at line 997 of file loops.cc.

997 {
998 back_edges_.Add(block);
999}

◆ AddBlocks()

void dart::LoopInfo::AddBlocks ( BitVector blocks)

Definition at line 993 of file loops.cc.

993 {
994 blocks_->AddAll(blocks);
995}
bool AddAll(const BitVector *from)
Definition bit_vector.cc:52

◆ AddInduction()

void dart::LoopInfo::AddInduction ( Definition def,
InductionVar induc 
)

Definition at line 1075 of file loops.cc.

1075 {
1076 ASSERT(def != nullptr);
1077 ASSERT(induc != nullptr);
1078 induction_.Insert(InductionKV::Pair(def, induc));
1079}
#define ASSERT(E)

◆ back_edges()

const GrowableArray< BlockEntryInstr * > & dart::LoopInfo::back_edges ( )
inline

Definition at line 254 of file loops.h.

254{ return back_edges_; }

◆ blocks()

BitVector * dart::LoopInfo::blocks ( ) const
inline

Definition at line 253 of file loops.h.

253{ return blocks_; }

◆ Contains()

bool dart::LoopInfo::Contains ( BlockEntryInstr block) const

Definition at line 1058 of file loops.cc.

1058 {
1059 return blocks_->Contains(block->preorder_number());
1060}
bool Contains(intptr_t i) const
Definition bit_vector.h:91

◆ control()

InductionVar * dart::LoopInfo::control ( ) const
inline

Definition at line 256 of file loops.h.

256{ return control_; }

◆ header()

BlockEntryInstr * dart::LoopInfo::header ( ) const
inline

Definition at line 252 of file loops.h.

252{ return header_; }

◆ id()

intptr_t dart::LoopInfo::id ( ) const
inline

Definition at line 251 of file loops.h.

251{ return id_; }

◆ inner()

LoopInfo * dart::LoopInfo::inner ( ) const
inline

Definition at line 258 of file loops.h.

258{ return inner_; }

◆ IsAlwaysTaken()

bool dart::LoopInfo::IsAlwaysTaken ( BlockEntryInstr block) const

Definition at line 1010 of file loops.cc.

1010 {
1011 // The loop header is always executed when executing a loop (including
1012 // loop body of a do-while). Reject any other loop body block that is
1013 // not directly controlled by header.
1014 if (block == header_) {
1015 return true;
1016 } else if (block->PredecessorCount() != 1 ||
1017 block->PredecessorAt(0) != header_) {
1018 return false;
1019 }
1020 // If the loop has a control induction, make sure the condition is such
1021 // that the loop body is entered at least once from the header.
1022 if (control_ != nullptr) {
1023 InductionVar* limit = nullptr;
1024 for (auto bound : control_->bounds()) {
1025 if (bound.branch_ == header_->last_instruction()) {
1026 limit = bound.limit_;
1027 break;
1028 }
1029 }
1030 // Control iterates at least once?
1031 if (limit != nullptr) {
1032 int64_t stride = 0;
1033 int64_t begin = 0;
1034 int64_t end = 0;
1035 if (InductionVar::IsLinear(control_, &stride) &&
1036 InductionVar::IsConstant(control_->initial(), &begin) &&
1038 ((stride == 1 && begin < end) || (stride == -1 && begin > end))) {
1039 return true;
1040 }
1041 }
1042 }
1043 return false;
1044}
Instruction * last_instruction() const
Definition il.h:1680
static bool IsConstant(const InductionVar *x)
Definition loops.h:140
InductionVar * initial() const
Definition loops.h:120
static bool IsLinear(const InductionVar *x)
Definition loops.h:154
ConstraintInstr * limit() const
Definition loops.h:255
friend class InductionVar
Definition loops.h:266
static const char * begin(const StringSlice &s)
Definition editor.cpp:252
glong glong end
Optional< SkRect > bounds
Definition SkRecords.h:189

◆ IsBackEdge()

bool dart::LoopInfo::IsBackEdge ( BlockEntryInstr block) const

Definition at line 1001 of file loops.cc.

1001 {
1002 for (intptr_t i = 0, n = back_edges_.length(); i < n; i++) {
1003 if (back_edges_[i] == block) {
1004 return true;
1005 }
1006 }
1007 return false;
1008}

◆ IsHeaderPhi()

bool dart::LoopInfo::IsHeaderPhi ( Definition def) const

Definition at line 1046 of file loops.cc.

1046 {
1047 return def != nullptr && def->IsPhi() && def->GetBlock() == header_ &&
1048 !def->AsPhi()->IsRedundant(); // phi(x,..,x) = x
1049}

◆ IsIn()

bool dart::LoopInfo::IsIn ( LoopInfo loop) const

Definition at line 1051 of file loops.cc.

1051 {
1052 if (loop != nullptr) {
1053 return loop->Contains(header_);
1054 }
1055 return false;
1056}

◆ IsInRange()

bool dart::LoopInfo::IsInRange ( Instruction pos,
Value index,
Value length 
)

Definition at line 1093 of file loops.cc.

1093 {
1095 index->definition()->OriginalDefinitionIgnoreBoxingAndConstraints());
1097 length->definition()->OriginalDefinitionIgnoreBoxingAndConstraints());
1098 if (induc != nullptr && len != nullptr) {
1099 // First, try the most common case. A simple induction directly
1100 // bounded by [c>=0,length-C>=0) for the length we are looking for.
1101 int64_t stride = 0;
1102 int64_t val = 0;
1103 int64_t diff = 0;
1104 if (InductionVar::IsLinear(induc, &stride) && stride == 1 &&
1105 InductionVar::IsConstant(induc->initial(), &val) && 0 <= val) {
1106 for (auto bound : induc->bounds()) {
1107 if (pos->IsDominatedBy(bound.branch_) &&
1108 len->CanComputeDifferenceWith(bound.limit_, &diff) && diff <= 0) {
1109 return true;
1110 }
1111 }
1112 }
1113 // If that fails, try to compute bounds using more outer loops.
1114 // Since array lengths >= 0, the conditions used during this
1115 // process avoid arithmetic wrap-around complications.
1116 InductionVar* min = nullptr;
1117 InductionVar* max = nullptr;
1118 if (induc->CanComputeBounds(this, pos, &min, &max)) {
1119 return InductionVar::IsConstant(min, &val) && 0 <= val &&
1120 len->CanComputeDifferenceWith(max, &diff) && diff < 0;
1121 }
1122 }
1123 return false;
1124}
SkPoint pos
InductionVar * LookupInduction(Definition *def) const
Definition loops.cc:1081
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48
size_t length

◆ limit()

ConstraintInstr * dart::LoopInfo::limit ( ) const
inline

Definition at line 255 of file loops.h.

255{ return limit_; }

◆ LookupInduction()

InductionVar * dart::LoopInfo::LookupInduction ( Definition def) const

Definition at line 1081 of file loops.cc.

1081 {
1082 InductionKV::Pair* pair = induction_.Lookup(def);
1083 if (pair != nullptr) {
1084 return pair->value;
1085 }
1086 return nullptr;
1087}

◆ NestingDepth()

intptr_t dart::LoopInfo::NestingDepth ( ) const

Definition at line 1062 of file loops.cc.

1062 {
1063 intptr_t nesting_depth = 1;
1064 for (LoopInfo* o = outer_; o != nullptr; o = o->outer()) {
1065 nesting_depth++;
1066 }
1067 return nesting_depth;
1068}

◆ next()

LoopInfo * dart::LoopInfo::next ( ) const
inline

Definition at line 259 of file loops.h.

259{ return next_; }

◆ outer()

LoopInfo * dart::LoopInfo::outer ( ) const
inline

Definition at line 257 of file loops.h.

257{ return outer_; }

◆ PrintTo()

void dart::LoopInfo::PrintTo ( BaseTextBuffer f) const

Definition at line 1126 of file loops.cc.

1126 {
1127 f->Printf("%*c", static_cast<int>(2 * NestingDepth()), ' ');
1128 f->Printf("loop%" Pd " B%" Pd " ", id_, header_->block_id());
1129 intptr_t num_blocks = 0;
1130 for (BitVector::Iterator it(blocks_); !it.Done(); it.Advance()) {
1131 num_blocks++;
1132 }
1133 f->Printf("#blocks=%" Pd, num_blocks);
1134 if (outer_ != nullptr) f->Printf(" outer=%" Pd, outer_->id_);
1135 if (inner_ != nullptr) f->Printf(" inner=%" Pd, inner_->id_);
1136 if (next_ != nullptr) f->Printf(" next=%" Pd, next_->id_);
1137 f->AddString(" [");
1138 for (intptr_t i = 0, n = back_edges_.length(); i < n; i++) {
1139 f->Printf(" B%" Pd, back_edges_[i]->block_id());
1140 }
1141 f->AddString(" ]");
1142}
intptr_t block_id() const
Definition il.h:1655
intptr_t NestingDepth() const
Definition loops.cc:1062
#define Pd
Definition globals.h:408

◆ ResetInduction()

void dart::LoopInfo::ResetInduction ( )

Definition at line 1070 of file loops.cc.

1070 {
1071 induction_.Clear();
1072 memo_cache_.Clear();
1073}

◆ ToCString()

const char * dart::LoopInfo::ToCString ( ) const

Definition at line 1144 of file loops.cc.

1144 {
1145 char buffer[1024];
1146 BufferFormatter f(buffer, sizeof(buffer));
1147 PrintTo(&f);
1149}
void PrintTo(BaseTextBuffer *f) const
Definition loops.cc:1126
Zone * zone() const
static Thread * Current()
Definition thread.h:361
char * MakeCopyOfString(const char *str)
Definition zone.cc:270
static const uint8_t buffer[]

Friends And Related Symbol Documentation

◆ InductionVar

friend class InductionVar
friend

Definition at line 266 of file loops.h.

◆ InductionVarAnalysis

friend class InductionVarAnalysis
friend

Definition at line 267 of file loops.h.

◆ LoopHierarchy

friend class LoopHierarchy
friend

Definition at line 268 of file loops.h.


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