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

#include <il.h>

Inheritance diagram for dart::CallTargets:
dart::Cids dart::ZoneAllocated

Public Member Functions

 CallTargets (Zone *zone)
 
TargetInfoTargetAt (int i) const
 
intptr_t AggregateCallCount () const
 
StaticTypeExactnessState MonomorphicExactness () const
 
bool HasSingleTarget () const
 
bool HasSingleRecognizedTarget () const
 
const FunctionFirstTarget () const
 
const FunctionMostPopularTarget () const
 
void Print () const
 
bool ReceiverIs (intptr_t cid) const
 
bool ReceiverIsSmiOrMint () const
 
void Write (FlowGraphSerializer *s) const
 
 CallTargets (FlowGraphDeserializer *d)
 
- Public Member Functions inherited from dart::Cids
 Cids (Zone *zone)
 
bool Equals (const Cids &other) const
 
bool HasClassId (intptr_t cid) const
 
void Add (CidRange *target)
 
CidRangeoperator[] (intptr_t index) const
 
CidRangeAt (int index) const
 
intptr_t length () const
 
void SetLength (intptr_t len)
 
bool is_empty () const
 
void Sort (int compare(CidRange *const *a, CidRange *const *b))
 
bool IsMonomorphic () const
 
intptr_t MonomorphicReceiverCid () const
 
intptr_t ComputeLowestCid () const
 
intptr_t ComputeHighestCid () 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 const CallTargetsCreateMonomorphic (Zone *zone, intptr_t receiver_cid, const Function &target)
 
static const CallTargetsCreate (Zone *zone, const ICData &ic_data)
 
static const CallTargetsCreateAndExpand (Zone *zone, const ICData &ic_data)
 
- Static Public Member Functions inherited from dart::Cids
static CidsCreateForArgument (Zone *zone, const BinaryFeedback &binary_feedback, int argument_number)
 
static CidsCreateMonomorphic (Zone *zone, intptr_t cid)
 

Additional Inherited Members

- Protected Attributes inherited from dart::Cids
GrowableArray< CidRange * > cid_ranges_
 

Detailed Description

Definition at line 774 of file il.h.

Constructor & Destructor Documentation

◆ CallTargets() [1/2]

dart::CallTargets::CallTargets ( Zone zone)
inlineexplicit

Definition at line 776 of file il.h.

776: Cids(zone) {}
Cids(Zone *zone)
Definition il.h:732

◆ CallTargets() [2/2]

dart::CallTargets::CallTargets ( FlowGraphDeserializer d)
explicit

Definition at line 305 of file il_serializer.cc.

305 : Cids(d->zone()) {
306 const intptr_t len = d->Read<intptr_t>();
307 cid_ranges_.EnsureLength(len, nullptr);
308 for (intptr_t i = 0; i < len; ++i) {
309 const intptr_t cid_start = d->Read<intptr_t>();
310 const intptr_t cid_end = d->Read<intptr_t>();
311 const Function& target = d->Read<const Function&>();
312 const intptr_t count = d->Read<intptr_t>();
313 const StaticTypeExactnessState exactness =
314 StaticTypeExactnessState::Decode(d->Read<int8_t>());
315 TargetInfo* t = new (d->zone())
316 TargetInfo(cid_start, cid_end, &target, count, exactness);
317 cid_ranges_[i] = t;
318 }
319}
int count
GrowableArray< CidRange * > cid_ranges_
Definition il.h:768
static StaticTypeExactnessState Decode(int8_t value)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
uint32_t * target

Member Function Documentation

◆ AggregateCallCount()

intptr_t dart::CallTargets::AggregateCallCount ( ) const

Definition at line 5530 of file il.cc.

5530 {
5531 intptr_t sum = 0;
5532 for (int i = 0; i < length(); i++) {
5533 sum += TargetAt(i)->count;
5534 }
5535 return sum;
5536}
TargetInfo * TargetAt(int i) const
Definition il.h:790
intptr_t length() const
Definition il.h:752
intptr_t count
Definition il.h:722

◆ Create()

const CallTargets * dart::CallTargets::Create ( Zone zone,
const ICData ic_data 
)
static

Definition at line 4132 of file il.cc.

4132 {
4133 CallTargets* targets = new (zone) CallTargets(zone);
4134 targets->CreateHelper(zone, ic_data);
4135 targets->Sort(OrderById);
4136 targets->MergeIntoRanges();
4137 return targets;
4138}
CallTargets(Zone *zone)
Definition il.h:776
static int OrderById(CidRange *const *a, CidRange *const *b)
Definition il.cc:635

◆ CreateAndExpand()

const CallTargets * dart::CallTargets::CreateAndExpand ( Zone zone,
const ICData ic_data 
)
static

Definition at line 4140 of file il.cc.

4141 {
4142 CallTargets& targets = *new (zone) CallTargets(zone);
4143 targets.CreateHelper(zone, ic_data);
4144
4145 if (targets.is_empty() || targets.IsMonomorphic()) {
4146 return &targets;
4147 }
4148
4149 targets.Sort(OrderById);
4150
4151 Array& args_desc_array = Array::Handle(zone, ic_data.arguments_descriptor());
4152 ArgumentsDescriptor args_desc(args_desc_array);
4153 String& name = String::Handle(zone, ic_data.target_name());
4154
4155 Function& fn = Function::Handle(zone);
4156
4157 intptr_t length = targets.length();
4158
4159 // Merging/extending cid ranges is also done in Cids::CreateAndExpand.
4160 // If changing this code, consider also adjusting Cids code.
4161
4162 // Spread class-ids to preceding classes where a lookup yields the same
4163 // method. A polymorphic target is not really the same method since its
4164 // behaviour depends on the receiver class-id, so we don't spread the
4165 // class-ids in that case.
4166 for (int idx = 0; idx < length; idx++) {
4167 int lower_limit_cid = (idx == 0) ? -1 : targets[idx - 1].cid_end;
4168 auto target_info = targets.TargetAt(idx);
4169 const Function& target = *target_info->target;
4170 if (target.is_polymorphic_target()) continue;
4171 for (int i = target_info->cid_start - 1; i > lower_limit_cid; i--) {
4172 bool class_is_abstract = false;
4173 if (FlowGraphCompiler::LookupMethodFor(i, name, args_desc, &fn,
4174 &class_is_abstract) &&
4175 fn.ptr() == target.ptr()) {
4176 if (!class_is_abstract) {
4177 target_info->cid_start = i;
4178 target_info->exactness = StaticTypeExactnessState::NotTracking();
4179 }
4180 } else {
4181 break;
4182 }
4183 }
4184 }
4185
4186 // Spread class-ids to following classes where a lookup yields the same
4187 // method.
4188 const intptr_t max_cid = IsolateGroup::Current()->class_table()->NumCids();
4189 for (int idx = 0; idx < length; idx++) {
4190 int upper_limit_cid =
4191 (idx == length - 1) ? max_cid : targets[idx + 1].cid_start;
4192 auto target_info = targets.TargetAt(idx);
4193 const Function& target = *target_info->target;
4194 if (target.is_polymorphic_target()) continue;
4195 // The code below makes attempt to avoid spreading class-id range
4196 // into a suffix that consists purely of abstract classes to
4197 // shorten the range.
4198 // However such spreading is beneficial when it allows to
4199 // merge to consecutive ranges.
4200 intptr_t cid_end_including_abstract = target_info->cid_end;
4201 for (int i = target_info->cid_end + 1; i < upper_limit_cid; i++) {
4202 bool class_is_abstract = false;
4203 if (FlowGraphCompiler::LookupMethodFor(i, name, args_desc, &fn,
4204 &class_is_abstract) &&
4205 fn.ptr() == target.ptr()) {
4206 cid_end_including_abstract = i;
4207 if (!class_is_abstract) {
4208 target_info->cid_end = i;
4209 target_info->exactness = StaticTypeExactnessState::NotTracking();
4210 }
4211 } else {
4212 break;
4213 }
4214 }
4215
4216 // Check if we have a suffix that consists of abstract classes
4217 // and expand into it if that would allow us to merge this
4218 // range with subsequent range.
4219 if ((cid_end_including_abstract > target_info->cid_end) &&
4220 (idx < length - 1) &&
4221 ((cid_end_including_abstract + 1) == targets[idx + 1].cid_start) &&
4222 (target.ptr() == targets.TargetAt(idx + 1)->target->ptr())) {
4223 target_info->cid_end = cid_end_including_abstract;
4224 target_info->exactness = StaticTypeExactnessState::NotTracking();
4225 }
4226 }
4227 targets.MergeIntoRanges();
4228 return &targets;
4229}
intptr_t NumCids() const
static bool LookupMethodFor(int class_id, const String &name, const ArgumentsDescriptor &args_desc, Function *fn_return, bool *class_is_abstract_return=nullptr)
static IsolateGroup * Current()
Definition isolate.h:534
ClassTable * class_table() const
Definition isolate.h:491
static Object & Handle()
Definition object.h:407
static StaticTypeExactnessState NotTracking()
const char *const name

◆ CreateMonomorphic()

const CallTargets * dart::CallTargets::CreateMonomorphic ( Zone zone,
intptr_t  receiver_cid,
const Function target 
)
static

Definition at line 4121 of file il.cc.

4123 {
4124 CallTargets* targets = new (zone) CallTargets(zone);
4125 const intptr_t count = 1;
4126 targets->cid_ranges_.Add(new (zone) TargetInfo(
4127 receiver_cid, receiver_cid, &Function::ZoneHandle(zone, target.ptr()),
4129 return targets;
4130}
static Object & ZoneHandle()
Definition object.h:419

◆ FirstTarget()

const Function & dart::CallTargets::FirstTarget ( ) const

Definition at line 5515 of file il.cc.

5515 {
5516 ASSERT(length() != 0);
5517 DEBUG_ASSERT(TargetAt(0)->target->IsNotTemporaryScopedHandle());
5518 return *TargetAt(0)->target;
5519}
#define DEBUG_ASSERT(cond)
Definition assert.h:321
#define ASSERT(E)
const Function * target
Definition il.h:721

◆ HasSingleRecognizedTarget()

bool dart::CallTargets::HasSingleRecognizedTarget ( ) const

Definition at line 5502 of file il.cc.

5502 {
5503 if (!HasSingleTarget()) return false;
5505}
bool HasSingleTarget() const
Definition il.cc:5507
const Function & FirstTarget() const
Definition il.cc:5515
MethodRecognizer::Kind recognized_kind() const
Definition object.h:3599

◆ HasSingleTarget()

bool dart::CallTargets::HasSingleTarget ( ) const

Definition at line 5507 of file il.cc.

5507 {
5508 if (length() == 0) return false;
5509 for (int i = 0; i < length(); i++) {
5510 if (TargetAt(i)->target->ptr() != TargetAt(0)->target->ptr()) return false;
5511 }
5512 return true;
5513}
ObjectPtr ptr() const
Definition object.h:332

◆ MonomorphicExactness()

StaticTypeExactnessState dart::CallTargets::MonomorphicExactness ( ) const

Definition at line 809 of file il.cc.

809 {
811 return TargetAt(0)->exactness;
812}
bool IsMonomorphic() const
Definition il.cc:799
StaticTypeExactnessState exactness
Definition il.h:723

◆ MostPopularTarget()

const Function & dart::CallTargets::MostPopularTarget ( ) const

Definition at line 5521 of file il.cc.

5521 {
5522 ASSERT(length() != 0);
5523 DEBUG_ASSERT(TargetAt(0)->target->IsNotTemporaryScopedHandle());
5524 for (int i = 1; i < length(); i++) {
5525 ASSERT(TargetAt(i)->count <= TargetAt(0)->count);
5526 }
5527 return *TargetAt(0)->target;
5528}

◆ Print()

void dart::CallTargets::Print ( ) const

Definition at line 4261 of file il.cc.

4261 {
4262 for (intptr_t i = 0; i < length(); i++) {
4263 THR_Print("cid = [%" Pd ", %" Pd "], count = %" Pd ", target = %s\n",
4264 TargetAt(i)->cid_start, TargetAt(i)->cid_end, TargetAt(i)->count,
4265 TargetAt(i)->target->ToQualifiedCString());
4266 }
4267}
#define THR_Print(format,...)
Definition log.h:20
#define Pd
Definition globals.h:408

◆ ReceiverIs()

bool dart::CallTargets::ReceiverIs ( intptr_t  cid) const
inline

Definition at line 802 of file il.h.

802 {
804 }
intptr_t MonomorphicReceiverCid() const
Definition il.cc:804
const intptr_t cid

◆ ReceiverIsSmiOrMint()

bool dart::CallTargets::ReceiverIsSmiOrMint ( ) const
inline

Definition at line 805 of file il.h.

805 {
806 if (cid_ranges_.is_empty()) {
807 return false;
808 }
809 for (intptr_t i = 0, n = cid_ranges_.length(); i < n; i++) {
810 for (intptr_t j = cid_ranges_[i]->cid_start; j <= cid_ranges_[i]->cid_end;
811 j++) {
812 if (j != kSmiCid && j != kMintCid) {
813 return false;
814 }
815 }
816 }
817 return true;
818 }

◆ TargetAt()

TargetInfo * dart::CallTargets::TargetAt ( int  i) const
inline

Definition at line 790 of file il.h.

790{ return static_cast<TargetInfo*>(At(i)); }
CidRange * At(int index) const
Definition il.h:750

◆ Write()

void dart::CallTargets::Write ( FlowGraphSerializer s) const

Definition at line 292 of file il_serializer.cc.

292 {
293 const intptr_t len = cid_ranges_.length();
294 s->Write<intptr_t>(len);
295 for (intptr_t i = 0; i < len; ++i) {
296 TargetInfo* t = TargetAt(i);
297 s->Write<intptr_t>(t->cid_start);
298 s->Write<intptr_t>(t->cid_end);
299 s->Write<const Function&>(*(t->target));
300 s->Write<intptr_t>(t->count);
301 s->Write<int8_t>(t->exactness.Encode());
302 }
303}
struct MyStruct s

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