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

#include <loops.h>

Inheritance diagram for dart::InductionVar:
dart::ZoneAllocated

Classes

struct  Bound
 

Public Types

enum  Kind { kInvariant , kLinear , kWrapAround , kPeriodic }
 

Public Member Functions

 InductionVar (int64_t offset, int64_t mult, Definition *def)
 
 InductionVar (int64_t offset)
 
 InductionVar (Kind kind, InductionVar *initial, InductionVar *next)
 
bool IsEqual (const InductionVar *other) const
 
bool CanComputeDifferenceWith (const InductionVar *other, int64_t *diff) const
 
bool CanComputeBounds (LoopInfo *loop, Instruction *pos, InductionVar **min, InductionVar **max)
 
Kind kind () const
 
int64_t offset () const
 
int64_t mult () const
 
Definitiondef () const
 
InductionVarinitial () const
 
InductionVarnext () const
 
const GrowableArray< Bound > & bounds ()
 
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)
 

Static Public Member Functions

static bool IsInvariant (const InductionVar *x)
 
static bool IsConstant (const InductionVar *x)
 
static bool IsConstant (const InductionVar *x, int64_t *c)
 
static bool IsLinear (const InductionVar *x)
 
static bool IsLinear (const InductionVar *x, int64_t *s)
 
static bool IsWrapAround (const InductionVar *x)
 
static bool IsPeriodic (const InductionVar *x)
 
static bool IsInduction (const InductionVar *x)
 

Friends

class InductionVarAnalysis
 

Detailed Description

Definition at line 31 of file loops.h.

Member Enumeration Documentation

◆ Kind

Enumerator
kInvariant 
kLinear 
kWrapAround 
kPeriodic 

Definition at line 33 of file loops.h.

Constructor & Destructor Documentation

◆ InductionVar() [1/3]

dart::InductionVar::InductionVar ( int64_t  offset,
int64_t  mult,
Definition def 
)
inline

Definition at line 50 of file loops.h.

51 : kind_(kInvariant), offset_(offset), mult_(mult), def_(def), bounds_() {
52 ASSERT(mult_ == 0 || def != nullptr);
53 }
int64_t mult() const
Definition loops.h:112
int64_t offset() const
Definition loops.h:108
Definition * def() const
Definition loops.h:116
Definition * def_
Definition loops.h:190
int64_t offset_
Definition loops.h:188
int64_t mult_
Definition loops.h:189
#define ASSERT(E)

◆ InductionVar() [2/3]

dart::InductionVar::InductionVar ( int64_t  offset)
inlineexplicit

Definition at line 56 of file loops.h.

56: InductionVar(offset, 0, nullptr) {}
InductionVar(int64_t offset, int64_t mult, Definition *def)
Definition loops.h:50

◆ InductionVar() [3/3]

dart::InductionVar::InductionVar ( Kind  kind,
InductionVar initial,
InductionVar next 
)
inline

Definition at line 59 of file loops.h.

60 : kind_(kind), initial_(initial), next_(next), bounds_() {
62 switch (kind) {
63 case kLinear:
64 case kPeriodic:
66 break;
67 case kWrapAround:
68 ASSERT(next != nullptr);
69 break;
70 default:
72 }
73 }
#define UNREACHABLE()
Definition assert.h:248
static bool IsInvariant(const InductionVar *x)
Definition loops.h:135
InductionVar * next_
Definition loops.h:194
InductionVar * next() const
Definition loops.h:124
Kind kind() const
Definition loops.h:107
InductionVar * initial() const
Definition loops.h:120
InductionVar * initial_
Definition loops.h:193

Member Function Documentation

◆ bounds()

const GrowableArray< Bound > & dart::InductionVar::bounds ( )
inline

Definition at line 128 of file loops.h.

128{ return bounds_; }

◆ CanComputeBounds()

bool dart::InductionVar::CanComputeBounds ( LoopInfo loop,
Instruction pos,
InductionVar **  min,
InductionVar **  max 
)

Definition at line 920 of file loops.cc.

923 {
924 // Consult cache first.
925 LoopInfo::MemoKV::Pair* pair1 = loop->memo_cache_.Lookup(this);
926 if (pair1 != nullptr) {
927 LoopInfo::MemoVal::PosKV::Pair* pair2 = pair1->value->memo_.Lookup(pos);
928 if (pair2 != nullptr) {
929 *min = pair2->value.first;
930 *max = pair2->value.second;
931 return true;
932 }
933 }
934 // Compute and cache.
935 if (CanComputeBoundsImpl(loop, pos, min, max)) {
936 ASSERT(*min != nullptr && *max != nullptr);
937 LoopInfo::MemoVal* memo = nullptr;
938 if (pair1 != nullptr) {
939 memo = pair1->value;
940 } else {
941 memo = new LoopInfo::MemoVal();
942 loop->memo_cache_.Insert(LoopInfo::MemoKV::Pair(this, memo));
943 }
944 memo->memo_.Insert(
945 LoopInfo::MemoVal::PosKV::Pair(pos, std::make_pair(*min, *max)));
946 return true;
947 }
948 return false;
949}
SkPoint pos
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

◆ CanComputeDifferenceWith()

bool dart::InductionVar::CanComputeDifferenceWith ( const InductionVar other,
int64_t *  diff 
) const

Definition at line 841 of file loops.cc.

842 {
843 if (IsInvariant(this) && IsInvariant(other)) {
844 if (def_ == other->def_ && mult_ == other->mult_) {
845 *diff = other->offset_ - offset_;
846 return true;
847 }
848 } else if (IsLinear(this) && IsLinear(other)) {
849 return next_->IsEqual(other->next_) &&
850 initial_->CanComputeDifferenceWith(other->initial_, diff);
851 }
852 // TODO(ajcbik): examine other induction kinds too?
853 return false;
854}
bool CanComputeDifferenceWith(const InductionVar *other, int64_t *diff) const
Definition loops.cc:841
bool IsEqual(const InductionVar *other) const
Definition loops.h:76
static bool IsLinear(const InductionVar *x)
Definition loops.h:154

◆ def()

Definition * dart::InductionVar::def ( ) const
inline

Definition at line 116 of file loops.h.

116 {
117 ASSERT(kind_ == kInvariant);
118 return def_;
119 }

◆ initial()

InductionVar * dart::InductionVar::initial ( ) const
inline

Definition at line 120 of file loops.h.

120 {
121 ASSERT(kind_ != kInvariant);
122 return initial_;
123 }

◆ IsConstant() [1/2]

static bool dart::InductionVar::IsConstant ( const InductionVar x)
inlinestatic

Definition at line 140 of file loops.h.

140 {
141 return x != nullptr && x->kind_ == kInvariant && x->mult_ == 0;
142 }
double x

◆ IsConstant() [2/2]

static bool dart::InductionVar::IsConstant ( const InductionVar x,
int64_t *  c 
)
inlinestatic

Definition at line 145 of file loops.h.

145 {
146 if (IsConstant(x)) {
147 *c = x->offset_;
148 return true;
149 }
150 return false;
151 }
static bool IsConstant(const InductionVar *x)
Definition loops.h:140

◆ IsEqual()

bool dart::InductionVar::IsEqual ( const InductionVar other) const
inline

Definition at line 76 of file loops.h.

76 {
77 ASSERT(other != nullptr);
78 if (kind_ == other->kind_) {
79 switch (kind_) {
80 case kInvariant:
81 return offset_ == other->offset_ && mult_ == other->mult_ &&
82 (mult_ == 0 || def_ == other->def_);
83 case kLinear:
84 case kWrapAround:
85 case kPeriodic:
86 return initial_->IsEqual(other->initial_) &&
87 next_->IsEqual(other->next_);
88 }
89 }
90 return false;
91 }

◆ IsInduction()

static bool dart::InductionVar::IsInduction ( const InductionVar x)
inlinestatic

Definition at line 177 of file loops.h.

177 {
178 return x != nullptr && x->kind_ != kInvariant;
179 }

◆ IsInvariant()

static bool dart::InductionVar::IsInvariant ( const InductionVar x)
inlinestatic

Definition at line 135 of file loops.h.

135 {
136 return x != nullptr && x->kind_ == kInvariant;
137 }

◆ IsLinear() [1/2]

static bool dart::InductionVar::IsLinear ( const InductionVar x)
inlinestatic

Definition at line 154 of file loops.h.

154 {
155 return x != nullptr && x->kind_ == kLinear;
156 }

◆ IsLinear() [2/2]

static bool dart::InductionVar::IsLinear ( const InductionVar x,
int64_t *  s 
)
inlinestatic

Definition at line 159 of file loops.h.

159 {
160 if (IsLinear(x)) {
161 return IsConstant(x->next_, s);
162 }
163 return false;
164 }
struct MyStruct s

◆ IsPeriodic()

static bool dart::InductionVar::IsPeriodic ( const InductionVar x)
inlinestatic

Definition at line 172 of file loops.h.

172 {
173 return x != nullptr && x->kind_ == kPeriodic;
174 }

◆ IsWrapAround()

static bool dart::InductionVar::IsWrapAround ( const InductionVar x)
inlinestatic

Definition at line 167 of file loops.h.

167 {
168 return x != nullptr && x->kind_ == kWrapAround;
169 }

◆ kind()

Kind dart::InductionVar::kind ( ) const
inline

Definition at line 107 of file loops.h.

107{ return kind_; }

◆ mult()

int64_t dart::InductionVar::mult ( ) const
inline

Definition at line 112 of file loops.h.

112 {
113 ASSERT(kind_ == kInvariant);
114 return mult_;
115 }

◆ next()

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

Definition at line 124 of file loops.h.

124 {
125 ASSERT(kind_ != kInvariant);
126 return next_;
127 }

◆ offset()

int64_t dart::InductionVar::offset ( ) const
inline

Definition at line 108 of file loops.h.

108 {
109 ASSERT(kind_ == kInvariant);
110 return offset_;
111 }

◆ PrintTo()

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

Definition at line 951 of file loops.cc.

951 {
952 switch (kind_) {
953 case kInvariant:
954 if (mult_ != 0) {
955 f->Printf("(%" Pd64 " + %" Pd64 " x %.4s)", offset_, mult_,
956 def_->ToCString());
957 } else {
958 f->Printf("%" Pd64, offset_);
959 }
960 break;
961 case kLinear:
962 f->Printf("LIN(%s + %s * i)", initial_->ToCString(), next_->ToCString());
963 break;
964 case kWrapAround:
965 f->Printf("WRAP(%s, %s)", initial_->ToCString(), next_->ToCString());
966 break;
967 case kPeriodic:
968 f->Printf("PERIOD(%s, %s)", initial_->ToCString(), next_->ToCString());
969 break;
970 }
971}
const char * ToCString() const
Definition loops.cc:973
const char * ToCString() const
#define Pd64
Definition globals.h:416

◆ ToCString()

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

Definition at line 973 of file loops.cc.

973 {
974 char buffer[1024];
975 BufferFormatter f(buffer, sizeof(buffer));
976 PrintTo(&f);
978}
void PrintTo(BaseTextBuffer *f) const
Definition loops.cc:951
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

◆ InductionVarAnalysis

friend class InductionVarAnalysis
friend

Definition at line 182 of file loops.h.

Member Data Documentation

◆ def_

Definition* dart::InductionVar::def_

Definition at line 190 of file loops.h.

◆ initial_

InductionVar* dart::InductionVar::initial_

Definition at line 193 of file loops.h.

◆ mult_

int64_t dart::InductionVar::mult_

Definition at line 189 of file loops.h.

◆ next_

InductionVar* dart::InductionVar::next_

Definition at line 194 of file loops.h.

◆ offset_

int64_t dart::InductionVar::offset_

Definition at line 188 of file loops.h.


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