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

#include <il.h>

Inheritance diagram for dart::IntConverterInstr:
dart::TemplateDefinition< 1, NoThrow, Pure >

Public Member Functions

 IntConverterInstr (Representation from, Representation to, Value *value, intptr_t deopt_id)
 
Valuevalue () const
 
Representation from () const
 
Representation to () const
 
bool is_truncating () const
 
void mark_truncating ()
 
DefinitionCanonicalize (FlowGraph *flow_graph)
 
virtual bool ComputeCanDeoptimize () const
 
virtual Representation representation () const
 
virtual Representation RequiredInputRepresentation (intptr_t idx) const
 
virtual bool AttributesEqual (const Instruction &other) const
 
virtual intptr_t DeoptimizationTarget () const
 
virtual void InferRange (RangeAnalysis *analysis, Range *range)
 
virtual bool MayCreateUnsafeUntaggedPointer () const
 
 DECLARE_INSTRUCTION (IntConverter)
 
 DECLARE_ATTRIBUTES_NAMED (("from", "to", "is_truncating"),(from(), to(), is_truncating())) PRINT_OPERANDS_TO_SUPPORT DECLARE_INSTRUCTION_SERIALIZABLE_FIELDS(IntConverterInstr
 
- Public Member Functions inherited from dart::TemplateDefinition< 1, NoThrow, Pure >
 TemplateDefinition (intptr_t deopt_id=DeoptId::kNone)
 
 TemplateDefinition (const InstructionSource &source, intptr_t deopt_id=DeoptId::kNone)
 
virtual intptr_t InputCount () const
 
virtual ValueInputAt (intptr_t i) const
 
virtual bool MayThrow () const
 

Public Attributes

 TemplateDefinition
 

Additional Inherited Members

- Public Types inherited from dart::TemplateDefinition< 1, NoThrow, Pure >
using BaseClass = typename Pure< Definition, PureDefinition >::Base
 
- Protected Attributes inherited from dart::TemplateDefinition< 1, NoThrow, Pure >
EmbeddedArray< Value *, Ninputs_
 

Detailed Description

Definition at line 10964 of file il.h.

Constructor & Destructor Documentation

◆ IntConverterInstr()

dart::IntConverterInstr::IntConverterInstr ( Representation  from,
Representation  to,
Value value,
intptr_t  deopt_id 
)
inline

Definition at line 10966 of file il.h.

10970 : TemplateDefinition(deopt_id),
10971 from_representation_(from),
10972 to_representation_(to),
10973 is_truncating_(to == kUnboxedUint32) {
10974 ASSERT(from != to);
10975 // Integer conversion doesn't currently handle non-native representations.
10978 ASSERT(from == kUnboxedInt64 || from == kUnboxedUint32 ||
10979 from == kUnboxedInt32 || from == kUntagged);
10980 ASSERT(to == kUnboxedInt64 || to == kUnboxedUint32 || to == kUnboxedInt32 ||
10981 to == kUntagged);
10982 ASSERT(from != kUntagged || to == kUnboxedIntPtr || to == kUnboxedAddress);
10983 ASSERT(to != kUntagged || from == kUnboxedIntPtr ||
10985 // Don't allow conversions from unsafe untagged addresses.
10987 SetInputAt(0, value);
10988 }
#define ASSERT_EQUAL(expected, actual)
Definition assert.h:309
virtual bool MayCreateUnsafeUntaggedPointer() const
Definition il.h:2573
Value * value() const
Definition il.h:10990
Representation to() const
Definition il.h:10993
Representation from() const
Definition il.h:10992
Definition * definition() const
Definition il.h:103
#define ASSERT(E)
static constexpr Representation kUnboxedAddress
Definition locations.h:182
static constexpr Representation kUnboxedIntPtr
Definition locations.h:176
static constexpr Representation NativeRepresentation(Representation rep)
Definition il.h:8456

Member Function Documentation

◆ AttributesEqual()

virtual bool dart::IntConverterInstr::AttributesEqual ( const Instruction other) const
inlinevirtual

Definition at line 11009 of file il.h.

11009 {
11010 ASSERT(other.IsIntConverter());
11011 auto const converter = other.AsIntConverter();
11012 return (converter->from() == from()) && (converter->to() == to()) &&
11013 (converter->is_truncating() == is_truncating());
11014 }
bool is_truncating() const
Definition il.h:10994

◆ Canonicalize()

Definition * dart::IntConverterInstr::Canonicalize ( FlowGraph flow_graph)

Definition at line 3438 of file il.cc.

3438 {
3439 if (!HasUses()) return nullptr;
3440
3441 // Fold IntConverter({Unboxed}Constant(...)) to UnboxedConstant.
3442 if (auto constant = value()->definition()->AsConstant()) {
3443 if (from() != kUntagged && to() != kUntagged &&
3444 constant->representation() == from() && constant->value().IsInteger()) {
3445 const int64_t value = Integer::Cast(constant->value()).AsInt64Value();
3446 const int64_t result =
3448 if (is_truncating() || (value == result)) {
3450 box ^= box.Canonicalize(flow_graph->thread());
3451 return flow_graph->GetConstant(box, to());
3452 }
3453 }
3454 }
3455
3456 // Fold IntCoverter(b->c, IntConverter(a->b, v)) into IntConverter(a->c, v).
3457 IntConverterInstr* first_converter = value()->definition()->AsIntConverter();
3458 if ((first_converter != nullptr) &&
3459 (first_converter->representation() == from())) {
3460 const auto intermediate_rep = first_converter->representation();
3461 // Only eliminate intermediate conversion if it does not change the value.
3462 auto src_defn = first_converter->value()->definition();
3463 if (intermediate_rep == kUntagged) {
3464 // Both conversions are no-ops, as the other representations must be
3465 // kUnboxedIntPtr.
3466 } else if (!Range::Fits(src_defn->range(), intermediate_rep)) {
3467 return this;
3468 }
3469
3470 // Otherwise it is safe to discard any other conversions from and then back
3471 // to the same integer type.
3472 if (first_converter->from() == to()) {
3473 return src_defn;
3474 }
3475
3476 // Do not merge conversions where the first starts from Untagged or the
3477 // second ends at Untagged, since we expect to see either UnboxedIntPtr
3478 // or UnboxedFfiIntPtr as the other type in an Untagged conversion.
3479 if ((first_converter->from() == kUntagged) || (to() == kUntagged)) {
3480 return this;
3481 }
3482
3484 first_converter->from(), representation(),
3485 first_converter->value()->CopyWithType(),
3486 (to() == kUnboxedInt32) ? GetDeoptId() : DeoptId::kNone);
3487 if ((representation() == kUnboxedInt32) && is_truncating()) {
3488 converter->mark_truncating();
3489 }
3490 flow_graph->InsertBefore(this, converter, env(), FlowGraph::kValue);
3491 return converter;
3492 }
3493
3494 UnboxInt64Instr* unbox_defn = value()->definition()->AsUnboxInt64();
3495 if (unbox_defn != nullptr && (from() == kUnboxedInt64) &&
3496 (to() == kUnboxedInt32) && unbox_defn->HasOnlyInputUse(value())) {
3497 // TODO(vegorov): there is a duplication of code between UnboxedIntConverter
3498 // and code path that unboxes Mint into Int32. We should just schedule
3499 // these instructions close to each other instead of fusing them.
3500 Definition* replacement =
3501 new UnboxInt32Instr(is_truncating() ? UnboxInt32Instr::kTruncate
3502 : UnboxInt32Instr::kNoTruncation,
3503 unbox_defn->value()->CopyWithType(), GetDeoptId());
3504 flow_graph->InsertBefore(this, replacement, env(), FlowGraph::kValue);
3505 return replacement;
3506 }
3507
3508 return this;
3509}
static int64_t TruncateTo(int64_t v, Representation r)
Definition evaluator.cc:81
@ kOld
Definition heap.h:39
void InsertBefore(Instruction *next)
Definition il.h:1274
virtual Representation representation() const
Definition il.h:1254
IntConverterInstr(Representation from, Representation to, Value *value, intptr_t deopt_id)
Definition il.h:10966
virtual Representation representation() const
Definition il.h:11002
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
Definition object.cc:23063
static Object & Handle()
Definition object.h:407
bool Fits(RangeBoundary::RangeSize size) const
GAsyncResult * result
static constexpr const char * kNone
Definition __init__.py:1

◆ ComputeCanDeoptimize()

bool dart::IntConverterInstr::ComputeCanDeoptimize ( ) const
virtual

Definition at line 2025 of file il.cc.

2025 {
2026 return (to() == kUnboxedInt32) && !is_truncating() &&
2027 !RangeUtils::Fits(value()->definition()->range(),
2029}
static bool Fits(Range *range, RangeBoundary::RangeSize size)

◆ DECLARE_ATTRIBUTES_NAMED()

dart::IntConverterInstr::DECLARE_ATTRIBUTES_NAMED ( ("from", "to", "is_truncating")  ,
(from(), to(), is_truncating())   
)

◆ DECLARE_INSTRUCTION()

dart::IntConverterInstr::DECLARE_INSTRUCTION ( IntConverter  )

◆ DeoptimizationTarget()

virtual intptr_t dart::IntConverterInstr::DeoptimizationTarget ( ) const
inlinevirtual

Definition at line 11016 of file il.h.

11016{ return GetDeoptId(); }

◆ from()

Representation dart::IntConverterInstr::from ( ) const
inline

Definition at line 10992 of file il.h.

10992{ return from_representation_; }

◆ InferRange()

void dart::IntConverterInstr::InferRange ( RangeAnalysis analysis,
Range range 
)
virtual

Definition at line 3097 of file range_analysis.cc.

3097 {
3098 ASSERT(to() != kUntagged); // Not an integer-valued definition.
3101
3102 const Range* const value_range = value()->definition()->range();
3103 const Range to_range = Range::Full(to());
3104
3105 if (from() == kUntagged) {
3106 ASSERT(value_range == nullptr); // Not an integer-valued definition.
3107 *range = to_range;
3108 } else if (Range::IsUnknown(value_range)) {
3109 *range = to_range;
3110 } else if (RepresentationUtils::ValueSize(to()) >
3114 // All signed unboxed ints of larger sizes can represent all values for
3115 // signed or unsigned unboxed ints of smaller sizes, and all unsigned
3116 // unboxed ints of larger sizes can represent all values for unsigned
3117 // boxed ints of smaller sizes.
3118 *range = *value_range;
3119 } else if (is_truncating()) {
3120 // Either the bits are being reinterpreted (if the two representations
3121 // are the same size) or a larger value is being truncated. That means
3122 // we need to determine whether or not the value range lies within the
3123 // range of numbers that have the same representation (modulo truncation).
3124 const Range common_range = Range::Full(from()).Intersect(&to_range);
3125 if (value_range->IsWithin(&common_range)) {
3126 *range = *value_range;
3127 } else {
3128 // In most cases, if there are non-representable values, then no
3129 // assumptions can be made about the converted value.
3130 *range = to_range;
3131 }
3132 } else {
3133 // The conversion deoptimizes if the value is outside the range represented
3134 // by to(), so we can just take the intersection.
3135 *range = value_range->Intersect(&to_range);
3136 }
3137
3139}
Range * range() const
Definition il.h:2618
Range Intersect(const Range *other) const
static bool IsUnknown(const Range *other)
static Range Full(RangeBoundary::RangeSize size)
#define ASSERT_VALID_RANGE_FOR_REPRESENTATION(instr, range, representation)
static constexpr size_t ValueSize(Representation rep)
Definition locations.h:112
static constexpr bool IsUnboxedInteger(Representation rep)
Definition locations.h:92
static bool IsUnsignedInteger(Representation rep)
Definition locations.h:126

◆ is_truncating()

bool dart::IntConverterInstr::is_truncating ( ) const
inline

Definition at line 10994 of file il.h.

10994{ return is_truncating_; }

◆ mark_truncating()

void dart::IntConverterInstr::mark_truncating ( )
inline

Definition at line 10996 of file il.h.

10996{ is_truncating_ = true; }

◆ MayCreateUnsafeUntaggedPointer()

virtual bool dart::IntConverterInstr::MayCreateUnsafeUntaggedPointer ( ) const
inlinevirtual

Definition at line 11020 of file il.h.

11020 {
11021 // The compiler no longer converts between unsafe untagged pointers and
11022 // unboxed integers.
11023 return false;
11024 }

◆ representation()

virtual Representation dart::IntConverterInstr::representation ( ) const
inlinevirtual

Definition at line 11002 of file il.h.

11002{ return to(); }

◆ RequiredInputRepresentation()

virtual Representation dart::IntConverterInstr::RequiredInputRepresentation ( intptr_t  idx) const
inlinevirtual

Definition at line 11004 of file il.h.

11004 {
11005 ASSERT(idx == 0);
11006 return from();
11007 }

◆ to()

Representation dart::IntConverterInstr::to ( ) const
inline

Definition at line 10993 of file il.h.

10993{ return to_representation_; }

◆ value()

Value * dart::IntConverterInstr::value ( ) const
inline

Definition at line 10990 of file il.h.

10990{ return inputs_[0]; }
EmbeddedArray< Value *, N > inputs_
Definition il.h:2744

Member Data Documentation

◆ TemplateDefinition

dart::IntConverterInstr::TemplateDefinition

Definition at line 11039 of file il.h.


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