1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 /*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10 XX This is the node in the semantic tree graph. It represents the operation XX
11 XX corresponding to the node, and other information during code-gen. XX
13 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
14 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
17 /*****************************************************************************/
20 /*****************************************************************************/
22 #include "vartype.h" // For "var_types"
23 #include "target.h" // For "regNumber"
24 #include "ssaconfig.h" // For "SsaConfig::RESERVED_SSA_NUM"
26 #include "valuenumtype.h"
27 #include "simplerhash.h"
31 // Debugging GenTree is much easier if we add a magic virtual function to make the debugger able to figure out what type it's got.
32 // This is enabled by default in DEBUG. To enable it in RET builds (temporarily!), you need to change the build to define DEBUGGABLE_GENTREE=1,
33 // as well as pass /OPT:NOICF to the linker (or else all the vtables get merged, making the debugging value supplied by them useless).
34 // See protojit.nativeproj for a commented example of setting the build flags correctly.
35 #ifndef DEBUGGABLE_GENTREE
37 #define DEBUGGABLE_GENTREE 1
39 #define DEBUGGABLE_GENTREE 0
41 #endif // !DEBUGGABLE_GENTREE
43 // The SpecialCodeKind enum is used to indicate the type of special (unique)
44 // target block that will be targeted by an instruction.
46 // GenTreeBoundsChk nodes (SCK_RNGCHK_FAIL, SCK_ARG_EXCPN, SCK_ARG_RNG_EXCPN)
47 // - these nodes have a field (gtThrowKind) to indicate which kind
48 // GenTreeOps nodes, for which codegen will generate the branch
49 // - it will use the appropriate kind based on the opcode, though it's not
50 // clear why SCK_OVERFLOW == SCK_ARITH_EXCPN
51 // SCK_PAUSE_EXEC is not currently used.
56 SCK_RNGCHK_FAIL, // target when range check fails
57 SCK_PAUSE_EXEC, // target to stop (e.g. to allow GC)
58 SCK_DIV_BY_ZERO, // target for divide by zero (Not used on X86/X64)
59 SCK_ARITH_EXCPN, // target on arithmetic exception
60 SCK_OVERFLOW = SCK_ARITH_EXCPN, // target on overflow
61 SCK_ARG_EXCPN, // target on ArgumentException (currently used only for SIMD intrinsics)
62 SCK_ARG_RNG_EXCPN, // target on ArgumentOutOfRangeException (currently used only for SIMD intrinsics)
66 /*****************************************************************************/
68 DECLARE_TYPED_ENUM(genTreeOps,BYTE)
70 #define GTNODE(en,sn,cm,ok) GT_ ## en,
75 // GT_CNS_NATIVELONG is the gtOper symbol for GT_CNS_LNG or GT_CNS_INT, depending on the target.
76 // For the 64-bit targets we will only use GT_CNS_INT as it used to represent all the possible sizes
77 // For the 32-bit targets we use a GT_CNS_LNG to hold a 64-bit integer constant and GT_CNS_INT for all others.
78 // In the future when we retarget the JIT for x86 we should consider eliminating GT_CNS_LNG
81 GT_CNS_NATIVELONG = GT_CNS_INT,
83 GT_CNS_NATIVELONG = GT_CNS_LNG,
86 END_DECLARE_TYPED_ENUM(genTreeOps,BYTE)
88 /*****************************************************************************
90 * The following enum defines a set of bit flags that can be used
91 * to classify expression tree nodes. Note that some operators will
92 * have more than one bit set, as follows:
94 * GTK_CONST implies GTK_LEAF
95 * GTK_RELOP implies GTK_BINOP
96 * GTK_LOGOP implies GTK_BINOP
101 GTK_SPECIAL = 0x0000, // unclassified operator (special handling reqd)
103 GTK_CONST = 0x0001, // constant operator
104 GTK_LEAF = 0x0002, // leaf operator
105 GTK_UNOP = 0x0004, // unary operator
106 GTK_BINOP = 0x0008, // binary operator
107 GTK_RELOP = 0x0010, // comparison operator
108 GTK_LOGOP = 0x0020, // logical operator
109 GTK_ASGOP = 0x0040, // assignment operator
111 GTK_KINDMASK= 0x007F, // operator kind mask
113 GTK_COMMUTE = 0x0080, // commutative operator
115 GTK_EXOP = 0x0100, // Indicates that an oper for a node type that extends GenTreeOp (or GenTreeUnOp)
116 // by adding non-node fields to unary or binary operator.
118 GTK_LOCAL = 0x0200, // is a local access (load, store, phi)
120 /* Define composite value(s) */
122 GTK_SMPOP = (GTK_UNOP|GTK_BINOP|GTK_RELOP|GTK_LOGOP)
125 /*****************************************************************************/
127 #define SMALL_TREE_NODES 1
129 /*****************************************************************************/
131 DECLARE_TYPED_ENUM(gtCallTypes,BYTE)
133 CT_USER_FUNC, // User function
134 CT_HELPER, // Jit-helper
135 CT_INDIRECT, // Indirect call
137 CT_COUNT // fake entry (must be last)
139 END_DECLARE_TYPED_ENUM(gtCallTypes,BYTE)
142 /*****************************************************************************/
146 struct InlineCandidateInfo;
148 /*****************************************************************************/
150 // GT_FIELD nodes will be lowered into more "code-gen-able" representations, like
151 // GT_IND's of addresses, or GT_LCL_FLD nodes. We'd like to preserve the more abstract
152 // information, and will therefore annotate such lowered nodes with FieldSeq's. A FieldSeq
153 // represents a (possibly) empty sequence of fields. The fields are in the order
154 // in which they are dereferenced. The first field may be an object field or a struct field;
155 // all subsequent fields must be struct fields.
158 CORINFO_FIELD_HANDLE m_fieldHnd;
159 FieldSeqNode* m_next;
161 FieldSeqNode(CORINFO_FIELD_HANDLE fieldHnd, FieldSeqNode* next) : m_fieldHnd(fieldHnd), m_next(next) {}
163 // returns true when this is the pseudo #FirstElem field sequence
164 bool IsFirstElemFieldSeq();
166 // returns true when this is the pseudo #ConstantIndex field sequence
167 bool IsConstantIndexFieldSeq();
169 // returns true when this is the the pseudo #FirstElem field sequence or the pseudo #ConstantIndex field sequence
170 bool IsPseudoField();
172 // Make sure this provides methods that allow it to be used as a KeyFuncs type in SimplerHash.
173 static int GetHashCode(FieldSeqNode fsn)
175 return static_cast<int>(reinterpret_cast<intptr_t>(fsn.m_fieldHnd)) ^ static_cast<int>(reinterpret_cast<intptr_t>(fsn.m_next));
178 static bool Equals(FieldSeqNode fsn1, FieldSeqNode fsn2)
180 return fsn1.m_fieldHnd == fsn2.m_fieldHnd && fsn1.m_next == fsn2.m_next;
184 // This class canonicalizes field sequences.
187 typedef SimplerHashTable<FieldSeqNode, /*KeyFuncs*/FieldSeqNode, FieldSeqNode*, JitSimplerHashBehavior> FieldSeqNodeCanonMap;
190 FieldSeqNodeCanonMap* m_canonMap;
192 static FieldSeqNode s_notAField; // No value, just exists to provide an address.
194 // Dummy variables to provide the addresses for the "pseudo field handle" statics below.
195 static int FirstElemPseudoFieldStruct;
196 static int ConstantIndexPseudoFieldStruct;
199 FieldSeqStore(IAllocator* alloc);
201 // Returns the (canonical in the store) singleton field sequence for the given handle.
202 FieldSeqNode* CreateSingleton(CORINFO_FIELD_HANDLE fieldHnd);
204 // This is a special distinguished FieldSeqNode indicating that a constant does *not*
205 // represent a valid field sequence. This is "infectious", in the sense that appending it
206 // (on either side) to any field sequence yields the "NotAField()" sequence.
207 static FieldSeqNode* NotAField() { return &s_notAField; }
209 // Returns the (canonical in the store) field sequence representing the concatenation of
210 // the sequences represented by "a" and "b". Assumes that "a" and "b" are canonical; that is,
211 // they are the results of CreateSingleton, NotAField, or Append calls. If either of the arguments
212 // are the "NotAField" value, so is the result.
213 FieldSeqNode* Append(FieldSeqNode* a, FieldSeqNode* b);
215 // We have a few "pseudo" field handles:
217 // This treats the constant offset of the first element of something as if it were a field.
218 // Works for method table offsets of boxed structs, or first elem offset of arrays/strings.
219 static CORINFO_FIELD_HANDLE FirstElemPseudoField;
221 // If there is a constant index, we make a psuedo field to correspond to the constant added to
222 // offset of the indexed field. This keeps the field sequence structure "normalized", especially in the
223 // case where the element type is a struct, so we might add a further struct field offset.
224 static CORINFO_FIELD_HANDLE ConstantIndexPseudoField;
226 static bool IsPseudoField(CORINFO_FIELD_HANDLE hnd)
228 return hnd == FirstElemPseudoField || hnd == ConstantIndexPseudoField;
234 /*****************************************************************************/
236 typedef struct GenTree * GenTreePtr;
237 struct GenTreeArgList;
239 // Forward declarations of the subtypes
240 #define GTSTRUCT_0(fn, en) struct GenTree##fn;
241 #define GTSTRUCT_1(fn, en) struct GenTree##fn;
242 #define GTSTRUCT_2(fn, en, en2) struct GenTree##fn;
243 #define GTSTRUCT_3(fn, en, en2, en3) struct GenTree##fn;
244 #define GTSTRUCT_4(fn, en, en2, en3, en4) struct GenTree##fn;
245 #define GTSTRUCT_N(fn, ...) struct GenTree##fn;
246 #include "gtstructs.h"
248 /*****************************************************************************/
251 #include <pshpack4.h>
256 // We use GT_STRUCT_0 only for the category of simple ops.
257 #define GTSTRUCT_0(fn, en) GenTree##fn* As##fn() \
259 assert(this->OperIsSimple()); \
260 return reinterpret_cast<GenTree##fn*>(this); \
262 GenTree##fn& As##fn##Ref() { return *As##fn(); } \
263 __declspec(property(get=As##fn##Ref)) GenTree##fn& gt##fn;
264 #define GTSTRUCT_1(fn, en) GenTree##fn* As##fn() \
266 assert(this->gtOper == en); \
267 return reinterpret_cast<GenTree##fn*>(this); \
269 GenTree##fn& As##fn##Ref() { return *As##fn(); } \
270 __declspec(property(get=As##fn##Ref)) GenTree##fn& gt##fn;
271 #define GTSTRUCT_2(fn, en, en2) GenTree##fn* As##fn() \
273 assert(this->gtOper == en || this->gtOper == en2); \
274 return reinterpret_cast<GenTree##fn*>(this); \
276 GenTree##fn& As##fn##Ref() { return *As##fn(); } \
277 __declspec(property(get=As##fn##Ref)) GenTree##fn& gt##fn;
278 #define GTSTRUCT_3(fn, en, en2, en3) GenTree##fn* As##fn() \
280 assert(this->gtOper == en || this->gtOper == en2 || this->gtOper == en3); \
281 return reinterpret_cast<GenTree##fn*>(this); \
283 GenTree##fn& As##fn##Ref() { return *As##fn(); } \
284 __declspec(property(get=As##fn##Ref)) GenTree##fn& gt##fn;
286 #define GTSTRUCT_4(fn, en, en2, en3, en4) GenTree##fn* As##fn() \
288 assert(this->gtOper == en || this->gtOper == en2 || this->gtOper == en3 || this->gtOper == en4); \
289 return reinterpret_cast<GenTree##fn*>(this); \
291 GenTree##fn& As##fn##Ref() { return *As##fn(); } \
292 __declspec(property(get=As##fn##Ref)) GenTree##fn& gt##fn;
295 // VC does not optimize out this loop in retail even though the value it computes is unused
296 // so we need a separate version for non-debug
297 #define GTSTRUCT_N(fn, ...) GenTree##fn* As##fn() \
299 genTreeOps validOps[] = {__VA_ARGS__}; \
300 bool found = false; \
301 for (unsigned i=0; i<ArrLen(validOps); i++) { \
302 if (this->gtOper == validOps[i]) \
309 return reinterpret_cast<GenTree##fn*>(this); \
311 GenTree##fn& As##fn##Ref() { return *As##fn(); } \
312 __declspec(property(get=As##fn##Ref)) GenTree##fn& gt##fn;
314 #define GTSTRUCT_N(fn, ...) GenTree##fn* As##fn() \
316 return reinterpret_cast<GenTree##fn*>(this); \
318 GenTree##fn& As##fn##Ref() { return *As##fn(); } \
319 __declspec(property(get=As##fn##Ref)) GenTree##fn& gt##fn;
322 #include "gtstructs.h"
324 genTreeOps gtOper; // enum subtype BYTE
325 var_types gtType; // enum subtype BYTE
327 genTreeOps OperGet() const { return gtOper; }
328 var_types TypeGet() const { return gtType; }
331 genTreeOps gtOperSave; // Only used to save gtOper when we destroy a node, to aid debugging.
338 #define IS_CSE_INDEX(x) (x != 0)
339 #define IS_CSE_USE(x) (x > 0)
340 #define IS_CSE_DEF(x) (x < 0)
341 #define GET_CSE_INDEX(x) ((x > 0) ? x : -x)
342 #define TO_CSE_DEF(x) (-x)
344 signed char gtCSEnum; // 0 or the CSE index (negated if def)
345 // valid only for CSE expressions
347 #endif // FEATURE_ANYCSE
350 unsigned short gtAssertionNum; // 0 or Assertion table index
351 // valid only for non-GT_STMT nodes
353 bool HasAssertion() const { return gtAssertionNum != 0; }
354 void ClearAssertion() { gtAssertionNum = 0; }
356 unsigned short GetAssertion() const { return gtAssertionNum; }
357 void SetAssertion(unsigned short value) { assert((unsigned short)value == value); gtAssertionNum = (unsigned short)value; }
361 #if FEATURE_STACK_FP_X87
362 unsigned char gtFPlvl; // x87 stack depth at this node
363 void gtCopyFPlvl(GenTree * other) { gtFPlvl = other->gtFPlvl; }
364 void gtSetFPlvl(unsigned level) { noway_assert(FitsIn<unsigned char>(level)); gtFPlvl = (unsigned char)level; }
365 #else // FEATURE_STACK_FP_X87
366 void gtCopyFPlvl(GenTree * other) { }
367 void gtSetFPlvl(unsigned level) { }
368 #endif // FEATURE_STACK_FP_X87
371 // Cost metrics on the node. Don't allow direct access to the variable for setting.
377 // You are not allowed to read the cost values before they have been set in gtSetEvalOrder().
378 // Keep track of whether the costs have been initialized, and assert if they are read before being initialized.
379 // Obviously, this information does need to be initialized when a node is created.
380 // This is public so the dumpers can see it.
382 bool gtCostsInitialized;
385 #define MAX_COST UCHAR_MAX
386 #define IND_COST_EX 3 // execution cost for an indirection
388 __declspec(property(get=GetCostEx))
389 unsigned char gtCostEx; // estimate of expression execution cost
391 __declspec(property(get=GetCostSz))
392 unsigned char gtCostSz; // estimate of expression code size cost
394 unsigned char GetCostEx() const { assert(gtCostsInitialized); return _gtCostEx; }
395 unsigned char GetCostSz() const { assert(gtCostsInitialized); return _gtCostSz; }
397 // Set the costs. They are always both set at the same time.
398 // Don't use the "put" property: force calling this function, to make it more obvious in the few places
399 // that set the values.
400 // Note that costs are only set in gtSetEvalOrder() and its callees.
401 void SetCosts(unsigned costEx, unsigned costSz)
403 assert(costEx != (unsigned)-1); // looks bogus
404 assert(costSz != (unsigned)-1); // looks bogus
405 INDEBUG(gtCostsInitialized = true;)
407 _gtCostEx = (costEx > MAX_COST) ? MAX_COST : (unsigned char)costEx;
408 _gtCostSz = (costSz > MAX_COST) ? MAX_COST : (unsigned char)costSz;
411 // Opimized copy function, to avoid the SetCosts() function comparisons, and make it more clear that a node copy is happening.
412 void CopyCosts(const GenTree* const tree)
414 INDEBUG(gtCostsInitialized = tree->gtCostsInitialized;) // If the 'tree' costs aren't initialized, we'll hit an assert below.
415 _gtCostEx = tree->gtCostEx;
416 _gtCostSz = tree->gtCostSz;
419 // Same as CopyCosts, but avoids asserts if the costs we are copying have not been initialized.
420 // This is because the importer, for example, clones nodes, before these costs have been initialized.
421 // Note that we directly access the 'tree' costs, not going through the accessor functions (either
422 // directly or through the properties).
423 void CopyRawCosts(const GenTree* const tree)
425 INDEBUG(gtCostsInitialized = tree->gtCostsInitialized;)
426 _gtCostEx = tree->_gtCostEx;
427 _gtCostSz = tree->_gtCostSz;
432 unsigned char _gtCostEx; // estimate of expression execution cost
433 unsigned char _gtCostSz; // estimate of expression code size cost
436 // Register or register pair number of the node.
443 GT_REGTAG_NONE, // Nothing has been assigned to _gtRegNum/_gtRegPair
444 GT_REGTAG_REG, // _gtRegNum has been assigned
445 #if CPU_LONG_USES_REGPAIR
446 GT_REGTAG_REGPAIR // _gtRegPair has been assigned
449 genRegTag GetRegTag() const
451 #if CPU_LONG_USES_REGPAIR
452 assert(gtRegTag == GT_REGTAG_NONE || gtRegTag == GT_REGTAG_REG || gtRegTag == GT_REGTAG_REGPAIR);
454 assert(gtRegTag == GT_REGTAG_NONE || gtRegTag == GT_REGTAG_REG);
459 genRegTag gtRegTag; // What is in _gtRegNum/_gtRegPair?
466 // NOTE: After LSRA, one of these values may be valid even if GTF_REG_VAL is not set in gtFlags.
467 // They store the register assigned to the node. If a register is not assigned, _gtRegNum is set to REG_NA
468 // or _gtRegPair is set to REG_PAIR_NONE, depending on the node type.
469 regNumberSmall _gtRegNum; // which register the value is in
470 regPairNoSmall _gtRegPair; // which register pair the value is in
475 // The register number is stored in a small format (8 bits), but the getters return and the setters take
476 // a full-size (unsigned) format, to localize the casts here.
478 __declspec(property(get=GetRegNum,put=SetRegNum))
481 // for codegen purposes, is this node a subnode of its parent
482 bool isContained() const;
484 bool isContainedIndir() const;
486 bool isIndirAddrMode();
488 bool isIndir() const;
490 bool isContainedIntOrIImmed() const { return isContained() && IsCnsIntOrI(); }
492 bool isContainedFltOrDblImmed() const { return isContained() && (OperGet() == GT_CNS_DBL); }
494 bool isLclField() const { return OperGet() == GT_LCL_FLD || OperGet() == GT_STORE_LCL_FLD; }
496 bool isContainedLclField() const { return isContained() && isLclField(); }
498 bool isContainedLclVar() const { return isContained() && (OperGet() == GT_LCL_VAR); }
500 // Indicates whether it is a memory op.
501 // Right now it includes Indir and LclField ops.
502 bool isMemoryOp() const { return isIndir() || isLclField(); }
504 bool isContainedMemoryOp() const
506 return (isContained() && isMemoryOp()) || isContainedLclVar();
509 regNumber GetRegNum() const
511 assert((gtRegTag == GT_REGTAG_REG) ||
512 (gtRegTag == GT_REGTAG_NONE)); // TODO-Cleanup: get rid of the NONE case, and fix everyplace that reads undefined values
513 regNumber reg = (regNumber) _gtRegNum;
514 assert((gtRegTag == GT_REGTAG_NONE) || // TODO-Cleanup: get rid of the NONE case, and fix everyplace that reads undefined values
520 void SetRegNum(regNumber reg)
522 assert(reg >= REG_FIRST &&
524 // Make sure the upper bits of _gtRegPair are clear
525 _gtRegPair = (regPairNoSmall) 0;
526 _gtRegNum = (regNumberSmall) reg;
527 INDEBUG(gtRegTag = GT_REGTAG_REG;)
528 assert(_gtRegNum == reg);
531 #if CPU_LONG_USES_REGPAIR
532 __declspec(property(get=GetRegPair,put=SetRegPair))
535 regPairNo GetRegPair() const
537 assert((gtRegTag == GT_REGTAG_REGPAIR) ||
538 (gtRegTag == GT_REGTAG_NONE)); // TODO-Cleanup: get rid of the NONE case, and fix everyplace that reads undefined values
539 regPairNo regPair = (regPairNo) _gtRegPair;
540 assert((gtRegTag == GT_REGTAG_NONE) || // TODO-Cleanup: get rid of the NONE case, and fix everyplace that reads undefined values
541 (regPair >= REG_PAIR_FIRST &&
542 regPair <= REG_PAIR_LAST) ||
543 (regPair == REG_PAIR_NONE)); // allow initializing to an undefined value
547 void SetRegPair(regPairNo regPair)
549 assert((regPair >= REG_PAIR_FIRST &&
550 regPair <= REG_PAIR_LAST) ||
551 (regPair == REG_PAIR_NONE)); // allow initializing to an undefined value
552 _gtRegPair = (regPairNoSmall) regPair;
553 INDEBUG(gtRegTag = GT_REGTAG_REGPAIR;)
554 assert(_gtRegPair == regPair);
558 // Copy the _gtRegNum/_gtRegPair/gtRegTag fields
559 void CopyReg(GenTreePtr from);
561 void gtClearReg(Compiler* compiler);
563 bool gtHasReg() const;
565 regMaskTP gtGetRegMask() const;
567 unsigned gtFlags; // see GTF_xxxx below
570 unsigned gtDebugFlags; // see GTF_DEBUG_xxx below
571 #endif // defined(DEBUG)
573 ValueNumPair gtVNPair;
575 regMaskSmall gtRsvdRegs; // set of fixed trashed registers
576 #ifdef LEGACY_BACKEND
577 regMaskSmall gtUsedRegs; // set of used (trashed) registers
578 #endif // LEGACY_BACKEND
580 #ifndef LEGACY_BACKEND
581 TreeNodeInfo gtLsraInfo;
582 #endif // !LEGACY_BACKEND
584 void SetVNsFromNode(GenTreePtr tree)
586 gtVNPair = tree->gtVNPair;
589 ValueNum GetVN(ValueNumKind vnk) const
591 if (vnk == VNK_Liberal)
593 return gtVNPair.GetLiberal();
597 assert(vnk == VNK_Conservative);
598 return gtVNPair.GetConservative();
601 void SetVN(ValueNumKind vnk, ValueNum vn)
603 if (vnk == VNK_Liberal)
605 return gtVNPair.SetLiberal(vn);
609 assert(vnk == VNK_Conservative);
610 return gtVNPair.SetConservative(vn);
613 void SetVNs(ValueNumPair vnp)
619 gtVNPair = ValueNumPair(); // Initializes both elements to "NoVN".
622 //---------------------------------------------------------------------
623 // The first set of flags can be used with a large set of nodes, and
624 // thus they must all have distinct values. That is, one can test any
625 // expression node for one of these flags.
626 //---------------------------------------------------------------------
628 #define GTF_ASG 0x00000001 // sub-expression contains an assignment
629 #define GTF_CALL 0x00000002 // sub-expression contains a func. call
630 #define GTF_EXCEPT 0x00000004 // sub-expression might throw an exception
631 #define GTF_GLOB_REF 0x00000008 // sub-expression uses global variable(s)
632 #define GTF_ORDER_SIDEEFF 0x00000010 // sub-expression has a re-ordering side effect
634 // If you set these flags, make sure that code:gtExtractSideEffList knows how to find the tree,
635 // otherwise the C# (run csc /o-)
636 // var v = side_eff_operation
637 // with no use of v will drop your tree on the floor.
638 #define GTF_PERSISTENT_SIDE_EFFECTS (GTF_ASG|GTF_CALL)
639 #define GTF_SIDE_EFFECT (GTF_PERSISTENT_SIDE_EFFECTS|GTF_EXCEPT)
640 #define GTF_GLOB_EFFECT (GTF_SIDE_EFFECT|GTF_GLOB_REF)
641 #define GTF_ALL_EFFECT (GTF_GLOB_EFFECT|GTF_ORDER_SIDEEFF)
643 // The extra flag GTF_DEAD is used to tell the consumer of these flags
644 // that we are calling in the context of performing a CSE, thus we
645 // should allow the run-once side effects of running a class constructor.
647 #define GTF_PERSISTENT_SIDE_EFFECTS_IN_CSE (GTF_ASG|GTF_CALL|GTF_DEAD)
649 // Can any side-effects be observed externally, say by a caller method?
650 // For assignments, only assignments to global memory can be observed
651 // externally, whereas simple assignments to local variables can not.
653 // Be careful when using this inside a "try" protected region as the
654 // order of assignments to local variables would need to be preserved
655 // wrt side effects if the variables are alive on entry to the
656 // "catch/finally" region. In such cases, even assignments to locals
657 // will have to be restricted.
658 #define GTF_GLOBALLY_VISIBLE_SIDE_EFFECTS(flags) \
659 (((flags) & (GTF_CALL|GTF_EXCEPT)) || \
660 (((flags) & (GTF_ASG|GTF_GLOB_REF)) == (GTF_ASG|GTF_GLOB_REF)))
662 #define GTF_REVERSE_OPS 0x00000020 // operand op2 should be evaluated before op1 (normally, op1 is evaluated first and op2 is evaluated second)
663 #define GTF_REG_VAL 0x00000040 // operand is sitting in a register (or part of a TYP_LONG operand is sitting in a register)
665 #define GTF_SPILLED 0x00000080 // the value has been spilled
666 #define GTF_SPILLED_OPER 0x00000100 // op1 has been spilled
668 #ifdef LEGACY_BACKEND
669 #define GTF_SPILLED_OP2 0x00000200 // op2 has been spilled
670 #endif // LEGACY_BACKEND
672 #define GTF_REDINDEX_CHECK 0x00000100 // Used for redundant range checks. Disjoint from GTF_SPILLED_OPER
674 #define GTF_ZSF_SET 0x00000400 // the zero(ZF) and sign(SF) flags set to the operand
675 #if FEATURE_SET_FLAGS
676 #define GTF_SET_FLAGS 0x00000800 // Requires that codegen for this node set the flags
677 // Use gtSetFlags() to check this flags
679 #define GTF_IND_NONFAULTING 0x00000800 // An indir that cannot fault. GTF_SET_FLAGS is not used on indirs
682 #define GTF_DEAD 0x00001000 // this node won't be used any more
683 #endif // FEATURE_ANYCSE
685 #define GTF_MAKE_CSE 0x00002000 // Hoisted Expression: try hard to make this into CSE (see optPerformHoistExpr)
686 #define GTF_DONT_CSE 0x00004000 // don't bother CSE'ing this expr
687 #define GTF_COLON_COND 0x00008000 // this node is conditionally executed (part of ? :)
689 #define GTF_NODE_MASK (GTF_COLON_COND)
691 #define GTF_BOOLEAN 0x00040000 // value is known to be 0/1
693 #define GTF_SMALL_OK 0x00080000 // actual small int sufficient
695 #define GTF_UNSIGNED 0x00100000 // with GT_CAST: the source operand is an unsigned type
696 // with operators: the specified node is an unsigned operator
698 #define GTF_LATE_ARG 0x00200000 // the specified node is evaluated to a temp in the arg list, and this temp is added to gtCallLateArgs.
700 #define GTF_SPILL 0x00400000 // needs to be spilled here
701 #define GTF_SPILL_HIGH 0x00040000 // shared with GTF_BOOLEAN
703 #define GTF_COMMON_MASK 0x007FFFFF // mask of all the flags above
705 #define GTF_REUSE_REG_VAL 0x00800000 // This is set by the register allocator on nodes whose value already exists in the
706 // register assigned to this node, so the code generator does not have to generate
707 // code to produce the value.
708 // It is currently used only on constant nodes.
709 // It CANNOT be set on var (GT_LCL*) nodes, or on indir (GT_IND or GT_STOREIND) nodes, since
710 // it is not needed for lclVars and is highly unlikely to be useful for indir nodes
712 //---------------------------------------------------------------------
713 // The following flags can be used only with a small set of nodes, and
714 // thus their values need not be distinct (other than within the set
715 // that goes with a particular node/nodes, of course). That is, one can
716 // only test for one of these flags if the 'gtOper' value is tested as
717 // well to make sure it's the right operator for the particular flag.
718 //---------------------------------------------------------------------
720 // NB: GTF_VAR_* and GTF_REG_* share the same namespace of flags, because
721 // GT_LCL_VAR nodes may be changed to GT_REG_VAR nodes without resetting
722 // the flags. These are also used by GT_LCL_FLD.
723 #define GTF_VAR_DEF 0x80000000 // GT_LCL_VAR -- this is a definition
724 #define GTF_VAR_USEASG 0x40000000 // GT_LCL_VAR -- this is a use/def for a x<op>=y
725 #define GTF_VAR_USEDEF 0x20000000 // GT_LCL_VAR -- this is a use/def as in x=x+y (only the lhs x is tagged)
726 #define GTF_VAR_CAST 0x10000000 // GT_LCL_VAR -- has been explictly cast (variable node may not be type of local)
727 #define GTF_VAR_ITERATOR 0x08000000 // GT_LCL_VAR -- this is a iterator reference in the loop condition
728 #define GTF_VAR_CLONED 0x01000000 // GT_LCL_VAR -- this node has been cloned or is a clone
729 // Relevant for inlining optimizations (see fgInlinePrependStatements)
731 // TODO-Cleanup: Currently, GTF_REG_BIRTH is used only by stackfp
732 // We should consider using it more generally for VAR_BIRTH, instead of
733 // GTF_VAR_DEF && !GTF_VAR_USEASG
734 #define GTF_REG_BIRTH 0x04000000 // GT_REG_VAR -- enregistered variable born here
735 #define GTF_VAR_DEATH 0x02000000 // GT_LCL_VAR, GT_REG_VAR -- variable dies here (last use)
737 #define GTF_VAR_ARR_INDEX 0x00000020 // The variable is part of (the index portion of) an array index expression.
738 // Shares a value with GTF_REVERSE_OPS, which is meaningless for local var.
740 #define GTF_LIVENESS_MASK (GTF_VAR_DEF|GTF_VAR_USEASG|GTF_VAR_USEDEF|GTF_REG_BIRTH|GTF_VAR_DEATH)
742 #define GTF_CALL_UNMANAGED 0x80000000 // GT_CALL -- direct call to unmanaged code
743 #define GTF_CALL_INLINE_CANDIDATE 0x40000000 // GT_CALL -- this call has been marked as an inline candidate
745 #define GTF_CALL_VIRT_KIND_MASK 0x30000000
746 #define GTF_CALL_NONVIRT 0x00000000 // GT_CALL -- a non virtual call
747 #define GTF_CALL_VIRT_STUB 0x10000000 // GT_CALL -- a stub-dispatch virtual call
748 #define GTF_CALL_VIRT_VTABLE 0x20000000 // GT_CALL -- a vtable-based virtual call
750 #define GTF_CALL_NULLCHECK 0x08000000 // GT_CALL -- must check instance pointer for null
751 #define GTF_CALL_POP_ARGS 0x04000000 // GT_CALL -- caller pop arguments?
752 #define GTF_CALL_HOISTABLE 0x02000000 // GT_CALL -- call is hoistable
753 #define GTF_CALL_REG_SAVE 0x01000000 // GT_CALL -- This call preserves all integer regs
754 // For additional flags for GT_CALL node see GTF_CALL_M_
756 #define GTF_NOP_DEATH 0x40000000 // GT_NOP -- operand dies here
758 #define GTF_FLD_NULLCHECK 0x80000000 // GT_FIELD -- need to nullcheck the "this" pointer
759 #define GTF_FLD_VOLATILE 0x40000000 // GT_FIELD/GT_CLS_VAR -- same as GTF_IND_VOLATILE
761 #define GTF_INX_RNGCHK 0x80000000 // GT_INDEX -- the array reference should be range-checked.
762 #define GTF_INX_REFARR_LAYOUT 0x20000000 // GT_INDEX -- same as GTF_IND_REFARR_LAYOUT
763 #define GTF_INX_STRING_LAYOUT 0x40000000 // GT_INDEX -- this uses the special string array layout
765 #define GTF_IND_VOLATILE 0x40000000 // GT_IND -- the load or store must use volatile sematics (this is a nop on X86)
766 #define GTF_IND_REFARR_LAYOUT 0x20000000 // GT_IND -- the array holds object refs (only effects layout of Arrays)
767 #define GTF_IND_TGTANYWHERE 0x10000000 // GT_IND -- the target could be anywhere
768 #define GTF_IND_TLS_REF 0x08000000 // GT_IND -- the target is accessed via TLS
769 #define GTF_IND_ASG_LHS 0x04000000 // GT_IND -- this GT_IND node is (the effective val) of the LHS of an assignment; don't evaluate it independently.
770 #define GTF_IND_UNALIGNED 0x02000000 // GT_IND -- the load or store is unaligned (we assume worst case alignment of 1 byte)
771 #define GTF_IND_INVARIANT 0x01000000 // GT_IND -- the target is invariant (a prejit indirection)
772 #define GTF_IND_ARR_LEN 0x80000000 // GT_IND -- the indirection represents an array length (of the REF contribution to its argument).
773 #define GTF_IND_ARR_INDEX 0x00800000 // GT_IND -- the indirection represents an (SZ) array index
775 #define GTF_IND_FLAGS (GTF_IND_VOLATILE|GTF_IND_REFARR_LAYOUT|GTF_IND_TGTANYWHERE|GTF_IND_NONFAULTING|\
776 GTF_IND_TLS_REF|GTF_IND_UNALIGNED|GTF_IND_INVARIANT|GTF_IND_ARR_INDEX)
778 #define GTF_CLS_VAR_ASG_LHS 0x04000000 // GT_CLS_VAR -- this GT_CLS_VAR node is (the effective val) of the LHS of an assignment; don't evaluate it independently.
780 #define GTF_ADDR_ONSTACK 0x80000000 // GT_ADDR -- this expression is guaranteed to be on the stack
783 #define GTF_ADDRMODE_NO_CSE 0x80000000 // GT_ADD/GT_MUL/GT_LSH -- Do not CSE this node only, forms complex addressing mode
785 #define GTF_MUL_64RSLT 0x40000000 // GT_MUL -- produce 64-bit result
787 #define GTF_MOD_INT_RESULT 0x80000000 // GT_MOD, -- the real tree represented by this
788 // GT_UMOD node evaluates to an int even though
789 // its type is long. The result is
790 // placed in the low member of the
793 #define GTF_RELOP_NAN_UN 0x80000000 // GT_<relop> -- Is branch taken if ops are NaN?
794 #define GTF_RELOP_JMP_USED 0x40000000 // GT_<relop> -- result of compare used for jump or ?:
795 #define GTF_RELOP_QMARK 0x20000000 // GT_<relop> -- the node is the condition for ?:
796 #define GTF_RELOP_SMALL 0x10000000 // GT_<relop> -- We should use a byte or short sized compare (op1->gtType is the small type)
797 #define GTF_RELOP_ZTT 0x08000000 // GT_<relop> -- Loop test cloned for converting while-loops into do-while with explicit "loop test" in the header block.
799 #define GTF_QMARK_CAST_INSTOF 0x80000000 // GT_QMARK -- Is this a top (not nested) level qmark created for castclass or instanceof?
801 #define GTF_BOX_VALUE 0x80000000 // GT_BOX -- "box" is on a value type
803 #define GTF_ICON_HDL_MASK 0xF0000000 // Bits used by handle types below
805 #define GTF_ICON_SCOPE_HDL 0x10000000 // GT_CNS_INT -- constant is a scope handle
806 #define GTF_ICON_CLASS_HDL 0x20000000 // GT_CNS_INT -- constant is a class handle
807 #define GTF_ICON_METHOD_HDL 0x30000000 // GT_CNS_INT -- constant is a method handle
808 #define GTF_ICON_FIELD_HDL 0x40000000 // GT_CNS_INT -- constant is a field handle
809 #define GTF_ICON_STATIC_HDL 0x50000000 // GT_CNS_INT -- constant is a handle to static data
810 #define GTF_ICON_STR_HDL 0x60000000 // GT_CNS_INT -- constant is a string handle
811 #define GTF_ICON_PSTR_HDL 0x70000000 // GT_CNS_INT -- constant is a ptr to a string handle
812 #define GTF_ICON_PTR_HDL 0x80000000 // GT_CNS_INT -- constant is a ldptr handle
813 #define GTF_ICON_VARG_HDL 0x90000000 // GT_CNS_INT -- constant is a var arg cookie handle
814 #define GTF_ICON_PINVKI_HDL 0xA0000000 // GT_CNS_INT -- constant is a pinvoke calli handle
815 #define GTF_ICON_TOKEN_HDL 0xB0000000 // GT_CNS_INT -- constant is a token handle
816 #define GTF_ICON_TLS_HDL 0xC0000000 // GT_CNS_INT -- constant is a TLS ref with offset
817 #define GTF_ICON_FTN_ADDR 0xD0000000 // GT_CNS_INT -- constant is a function address
818 #define GTF_ICON_CIDMID_HDL 0xE0000000 // GT_CNS_INT -- constant is a class or module ID handle
819 #define GTF_ICON_BBC_PTR 0xF0000000 // GT_CNS_INT -- constant is a basic block count pointer
821 #define GTF_ICON_FIELD_OFF 0x08000000 // GT_CNS_INT -- constant is a field offset
823 #define GTF_BLK_HASGCPTR 0x80000000 // GT_COPYBLK -- This struct copy will copy GC Pointers
824 #define GTF_BLK_VOLATILE 0x40000000 // GT_INITBLK/GT_COPYBLK -- is a volatile block operation
825 #define GTF_BLK_UNALIGNED 0x02000000 // GT_INITBLK/GT_COPYBLK -- is an unaligned block operation
827 #define GTF_OVERFLOW 0x10000000 // GT_ADD, GT_SUB, GT_MUL, - Need overflow check
828 // GT_ASG_ADD, GT_ASG_SUB,
830 // Use gtOverflow(Ex)() to check this flag
832 #define GTF_NO_OP_NO 0x80000000 // GT_NO_OP --Have the codegenerator generate a special nop
834 //----------------------------------------------------------------
836 #define GTF_STMT_CMPADD 0x80000000 // GT_STMT -- added by compiler
837 #define GTF_STMT_HAS_CSE 0x40000000 // GT_STMT -- CSE def or use was subsituted
838 #define GTF_STMT_TOP_LEVEL 0x20000000 // GT_STMT -- Top-level statement - true iff gtStmtList->gtPrev == nullptr
839 // True for all stmts when in FGOrderTree
840 #define GTF_STMT_SKIP_LOWER 0x10000000 // GT_STMT -- Skip lowering if we already lowered an embedded stmt.
842 //----------------------------------------------------------------
845 #define GTF_DEBUG_NONE 0x00000000 // No debug flags.
847 #define GTF_DEBUG_NODE_MORPHED 0x00000001 // the node has been morphed (in the global morphing phase)
848 #define GTF_DEBUG_NODE_SMALL 0x00000002
849 #define GTF_DEBUG_NODE_LARGE 0x00000004
851 #define GTF_DEBUG_NODE_MASK 0x00000007 // These flags are all node (rather than operation) properties.
853 #define GTF_DEBUG_VAR_CSE_REF 0x00800000 // GT_LCL_VAR -- This is a CSE LCL_VAR node
854 #endif // defined(DEBUG)
861 unsigned gtSeqNum; // liveness traversal order within the current statement
865 const unsigned short gtOperKindTable[];
868 unsigned OperKind(unsigned gtOper)
870 assert(gtOper < GT_COUNT);
872 return gtOperKindTable[gtOper];
875 unsigned OperKind() const
877 assert(gtOper < GT_COUNT);
879 return gtOperKindTable[gtOper];
882 static bool IsExOp(unsigned opKind)
884 return (opKind & GTK_EXOP) != 0;
886 // Returns the operKind with the GTK_EX_OP bit removed (the
887 // kind of operator, unary or binary, that is extended).
888 static unsigned StripExOp(unsigned opKind)
890 return opKind & ~GTK_EXOP;
894 bool OperIsConst(genTreeOps gtOper)
896 return (OperKind(gtOper) & GTK_CONST ) != 0;
899 bool OperIsConst() const
901 return (OperKind(gtOper) & GTK_CONST ) != 0;
905 bool OperIsLeaf(genTreeOps gtOper)
907 return (OperKind(gtOper) & GTK_LEAF ) != 0;
910 bool OperIsLeaf() const
912 return (OperKind(gtOper) & GTK_LEAF ) != 0;
916 bool OperIsCompare(genTreeOps gtOper)
918 return (OperKind(gtOper) & GTK_RELOP ) != 0;
922 bool OperIsLocal(genTreeOps gtOper)
924 bool result = (OperKind(gtOper) & GTK_LOCAL) != 0;
926 (gtOper == GT_LCL_VAR ||
927 gtOper == GT_PHI_ARG ||
928 gtOper == GT_REG_VAR ||
929 gtOper == GT_LCL_FLD ||
930 gtOper == GT_STORE_LCL_VAR ||
931 gtOper == GT_STORE_LCL_FLD));
936 bool OperIsBlkOp(genTreeOps gtOper)
938 return (gtOper == GT_INITBLK ||
939 gtOper == GT_COPYBLK ||
940 gtOper == GT_COPYOBJ);
944 bool OperIsCopyBlkOp(genTreeOps gtOper)
946 return (gtOper == GT_COPYOBJ || gtOper == GT_COPYBLK);
951 bool OperIsLocalAddr(genTreeOps gtOper)
953 return (gtOper == GT_LCL_VAR_ADDR ||
954 gtOper == GT_LCL_FLD_ADDR);
958 bool OperIsScalarLocal(genTreeOps gtOper)
960 return (gtOper == GT_LCL_VAR ||
961 gtOper == GT_REG_VAR ||
962 gtOper == GT_STORE_LCL_VAR);
966 bool OperIsNonPhiLocal(genTreeOps gtOper)
968 return OperIsLocal(gtOper) && (gtOper != GT_PHI_ARG);
972 bool OperIsLocalRead(genTreeOps gtOper)
974 return (OperIsLocal(gtOper) && !OperIsLocalStore(gtOper));
978 bool OperIsLocalStore(genTreeOps gtOper)
980 return (gtOper == GT_STORE_LCL_VAR ||
981 gtOper == GT_STORE_LCL_FLD);
986 bool OperIsAddrMode(genTreeOps gtOper)
988 return (gtOper == GT_LEA);
991 bool OperIsBlkOp() const
993 return OperIsBlkOp(OperGet());
996 bool OperIsCopyBlkOp() const
998 return OperIsCopyBlkOp(OperGet());
1001 bool OperIsPutArgStk() const
1003 return gtOper == GT_PUTARG_STK;
1006 bool OperIsAddrMode() const
1008 return OperIsAddrMode(OperGet());
1011 bool OperIsLocal() const
1013 return OperIsLocal(OperGet());
1016 bool OperIsLocalAddr() const
1018 return OperIsLocalAddr(OperGet());
1021 bool OperIsScalarLocal() const
1023 return OperIsScalarLocal(OperGet());
1026 bool OperIsNonPhiLocal() const
1028 return OperIsNonPhiLocal(OperGet());
1031 bool OperIsLocalStore() const
1033 return OperIsLocalStore(OperGet());
1036 bool OperIsLocalRead() const
1038 return OperIsLocalRead(OperGet());
1041 bool OperIsCompare()
1043 return (OperKind(gtOper) & GTK_RELOP ) != 0;
1047 bool OperIsLogical(genTreeOps gtOper)
1049 return (OperKind(gtOper) & GTK_LOGOP ) != 0;
1052 bool OperIsLogical() const
1054 return (OperKind(gtOper) & GTK_LOGOP ) != 0;
1058 bool OperIsShift(genTreeOps gtOper)
1060 return (gtOper == GT_LSH) ||
1061 (gtOper == GT_RSH) ||
1065 bool OperIsShift() const
1067 return OperIsShift(OperGet());
1071 bool OperIsRotate(genTreeOps gtOper)
1073 return (gtOper == GT_ROL) ||
1077 bool OperIsRotate() const
1079 return OperIsRotate(OperGet());
1083 bool OperIsShiftOrRotate(genTreeOps gtOper)
1085 return OperIsShift(gtOper) ||
1086 OperIsRotate(gtOper);
1089 bool OperIsShiftOrRotate() const
1091 return OperIsShiftOrRotate(OperGet());
1094 bool OperIsArithmetic() const
1096 genTreeOps op = OperGet();
1110 || OperIsShiftOrRotate(op);
1113 #if !defined(LEGACY_BACKEND) && !defined(_TARGET_64BIT_)
1115 bool OperIsHigh(genTreeOps gtOper)
1130 bool OperIsHigh() const
1132 return OperIsHigh(OperGet());
1134 #endif // !defined(LEGACY_BACKEND) && !defined(_TARGET_64BIT_)
1137 bool OperIsUnary(genTreeOps gtOper)
1139 return (OperKind(gtOper) & GTK_UNOP ) != 0;
1142 bool OperIsUnary() const
1144 return OperIsUnary(gtOper);
1148 bool OperIsBinary(genTreeOps gtOper)
1150 return (OperKind(gtOper) & GTK_BINOP ) != 0;
1153 bool OperIsBinary() const
1155 return OperIsBinary(gtOper);
1159 bool OperIsSimple(genTreeOps gtOper)
1161 return (OperKind(gtOper) & GTK_SMPOP ) != 0;
1165 bool OperIsSpecial(genTreeOps gtOper)
1167 return ((OperKind(gtOper) & GTK_KINDMASK) == GTK_SPECIAL);
1170 bool OperIsSimple() const
1172 return OperIsSimple(gtOper);
1176 bool isCommutativeSIMDIntrinsic();
1178 bool isCommutativeSIMDIntrinsic()
1182 #endif // FEATURE_SIMD
1185 bool OperIsCommutative(genTreeOps gtOper)
1187 return (OperKind(gtOper) & GTK_COMMUTE) != 0;
1190 bool OperIsCommutative()
1192 return OperIsCommutative(gtOper) || (OperIsSIMD(gtOper) && isCommutativeSIMDIntrinsic());
1196 bool OperIsAssignment(genTreeOps gtOper)
1198 return (OperKind(gtOper) & GTK_ASGOP) != 0;
1201 bool OperIsAssignment() const
1203 return OperIsAssignment(gtOper);
1207 bool OperIsIndir(genTreeOps gtOper)
1209 return gtOper == GT_IND || gtOper == GT_STOREIND || gtOper == GT_NULLCHECK;
1212 bool OperIsIndir() const
1214 return OperIsIndir(gtOper);
1218 bool OperIsImplicitIndir(genTreeOps gtOper)
1239 bool OperIsImplicitIndir() const
1241 return OperIsImplicitIndir(gtOper);
1244 bool OperIsStore() const
1246 return OperIsStore(gtOper);
1250 bool OperIsStore(genTreeOps gtOper)
1252 return (gtOper == GT_STOREIND
1253 || gtOper == GT_STORE_LCL_VAR
1254 || gtOper == GT_STORE_LCL_FLD
1255 || gtOper == GT_STORE_CLS_VAR);
1259 bool OperIsAtomicOp(genTreeOps gtOper)
1261 return (gtOper == GT_XADD
1262 || gtOper == GT_XCHG
1263 || gtOper == GT_LOCKADD
1264 || gtOper == GT_CMPXCHG);
1267 bool OperIsAtomicOp()
1269 return OperIsAtomicOp(gtOper);
1272 // This is basically here for cleaner FEATURE_SIMD #ifdefs.
1274 bool OperIsSIMD(genTreeOps gtOper)
1277 return gtOper == GT_SIMD;
1278 #else // !FEATURE_SIMD
1280 #endif // !FEATURE_SIMD
1285 return OperIsSIMD(gtOper);
1288 // Requires that "op" is an op= operator. Returns
1289 // the corresponding "op".
1291 genTreeOps OpAsgToOper(genTreeOps op);
1294 bool NullOp1Legal() const
1296 assert(OperIsSimple(gtOper));
1299 case GT_PHI: case GT_LEA: case GT_RETFILT: case GT_NOP:
1302 return gtType == TYP_VOID;
1308 bool NullOp2Legal() const
1310 assert(OperIsSimple(gtOper));
1311 if (!OperIsBinary(gtOper))
1326 #endif // !FEATURE_SIMD
1334 inline bool RequiresNonNullOp2(genTreeOps oper);
1335 bool IsListForMultiRegArg();
1338 inline bool IsFPZero();
1339 inline bool IsIntegralConst(ssize_t constVal);
1341 inline bool IsBoxedValue();
1345 return gtOper == GT_LIST;
1348 inline GenTreePtr MoveNext();
1350 inline GenTreePtr Current();
1352 inline GenTreePtr *pCurrent();
1354 inline GenTreePtr gtGetOp1();
1356 inline GenTreePtr gtGetOp2();
1358 // Given a tree node, if this is a child of that node, return the pointer to the child node so that it
1359 // can be modified; otherwise, return null.
1360 GenTreePtr* gtGetChildPointer(GenTreePtr parent);
1362 // Get the parent of this node, and optionally capture the pointer to the child so that it can be modified.
1363 GenTreePtr gtGetParent(GenTreePtr** parentChildPtrPtr);
1365 inline GenTreePtr gtEffectiveVal(bool commaOnly = false);
1367 // Return the child of this node if it is a GT_RELOAD or GT_COPY; otherwise simply return the node itself
1368 inline GenTree* gtSkipReloadOrCopy();
1370 // Returns true if it is a call node returning its value in more than one register
1371 inline bool IsMultiRegCall() const;
1373 // Returns true if it is a GT_COPY or GT_RELOAD node
1374 inline bool IsCopyOrReload() const;
1376 // Returns true if it is a GT_COPY or GT_RELOAD of a multi-reg call node
1377 inline bool IsCopyOrReloadOfMultiRegCall() const;
1379 bool OperMayThrow();
1381 unsigned GetScaleIndexMul();
1382 unsigned GetScaleIndexShf();
1383 unsigned GetScaledIndex();
1385 // Returns true if "addr" is a GT_ADD node, at least one of whose arguments is an integer
1386 // (<= 32 bit) constant. If it returns true, it sets "*offset" to (one of the) constant value(s), and
1387 // "*addr" to the other argument.
1388 bool IsAddWithI32Const(GenTreePtr* addr, int* offset);
1390 // Insert 'node' after this node in execution order.
1391 void InsertAfterSelf(GenTree* node, GenTreeStmt* stmt = nullptr);
1395 #if SMALL_TREE_NODES
1397 unsigned char s_gtNodeSizes[];
1401 void InitNodeSize();
1403 size_t GetNodeSize() const;
1405 bool IsNodeProperlySized() const;
1407 void CopyFrom(const GenTree* src, Compiler* comp);
1410 genTreeOps ReverseRelop(genTreeOps relop);
1413 genTreeOps SwapRelop(genTreeOps relop);
1415 //---------------------------------------------------------------------
1418 bool Compare(GenTreePtr op1, GenTreePtr op2, bool swapOK = false);
1420 //---------------------------------------------------------------------
1422 //---------------------------------------------------------------------
1425 const char * NodeName(genTreeOps op);
1428 const char * OpName(genTreeOps op);
1430 //---------------------------------------------------------------------
1432 //---------------------------------------------------------------------
1434 bool IsNothingNode () const;
1435 void gtBashToNOP ();
1437 // Value number update action enumeration
1438 enum ValueNumberUpdate
1440 CLEAR_VN, // Clear value number
1441 PRESERVE_VN // Preserve value number
1444 void SetOper(genTreeOps oper, ValueNumberUpdate vnUpdate = CLEAR_VN); // set gtOper
1445 void SetOperResetFlags (genTreeOps oper); // set gtOper and reset flags
1447 void ChangeOperConst (genTreeOps oper); // ChangeOper(constOper)
1448 // set gtOper and only keep GTF_COMMON_MASK flags
1449 void ChangeOper(genTreeOps oper, ValueNumberUpdate vnUpdate = CLEAR_VN);
1450 void ChangeOperUnchecked (genTreeOps oper);
1452 bool IsLocal() const
1454 return OperIsLocal(OperGet());
1457 // Returns "true" iff 'this' is a GT_LCL_FLD or GT_STORE_LCL_FLD on which the type
1458 // is not the same size as the type of the GT_LCL_VAR.
1459 bool IsPartialLclFld(Compiler* comp);
1461 // Returns "true" iff "this" defines a local variable. Requires "comp" to be the
1462 // current compilation. If returns "true", sets "*pLclVarTree" to the
1463 // tree for the local that is defined, and, if "pIsEntire" is non-null, sets "*pIsEntire" to
1464 // true or false, depending on whether the assignment writes to the entirety of the local
1465 // variable, or just a portion of it.
1466 bool DefinesLocal(Compiler* comp, GenTreeLclVarCommon** pLclVarTree, bool* pIsEntire = nullptr);
1468 // Returns true if "this" represents the address of a local, or a field of a local. If returns true, sets
1469 // "*pLclVarTree" to the node indicating the local variable. If the address is that of a field of this node,
1470 // sets "*pFldSeq" to the field sequence representing that field, else null.
1471 bool IsLocalAddrExpr(Compiler* comp, GenTreeLclVarCommon** pLclVarTree, FieldSeqNode** pFldSeq);
1473 // Simpler variant of the above which just returns the local node if this is an expression that
1474 // yields an address into a local
1475 GenTreeLclVarCommon* IsLocalAddrExpr();
1477 // Determine whether this is an assignment tree of the form X = X (op) Y,
1478 // where Y is an arbitrary tree, and X is a lclVar.
1479 unsigned IsLclVarUpdateTree(GenTree** otherTree, genTreeOps *updateOper);
1481 // If returns "true", "this" may represent the address of a static or instance field
1482 // (or a field of such a field, in the case of an object field of type struct).
1483 // If returns "true", then either "*pObj" is set to the object reference,
1484 // or "*pStatic" is set to the baseAddr or offset to be added to the "*pFldSeq"
1485 // Only one of "*pObj" or "*pStatic" will be set, the other one will be null.
1486 // The boolean return value only indicates that "this" *may* be a field address
1487 // -- the field sequence must also be checked.
1488 // If it is a field address, the field sequence will be a sequence of length >= 1,
1489 // starting with an instance or static field, and optionally continuing with struct fields.
1490 bool IsFieldAddr(Compiler* comp, GenTreePtr* pObj, GenTreePtr* pStatic, FieldSeqNode** pFldSeq);
1492 // Requires "this" to be the address of an array (the child of a GT_IND labeled with GTF_IND_ARR_INDEX).
1493 // Sets "pArr" to the node representing the array (either an array object pointer, or perhaps a byref to the some element).
1494 // Sets "*pArrayType" to the class handle for the array type.
1495 // Sets "*inxVN" to the value number inferred for the array index.
1496 // Sets "*pFldSeq" to the sequence, if any, of struct fields used to index into the array element.
1497 void ParseArrayAddress(Compiler* comp,
1498 struct ArrayInfo* arrayInfo,
1501 FieldSeqNode** pFldSeq);
1503 // Helper method for the above.
1504 void ParseArrayAddressWork(Compiler* comp, ssize_t inputMul, GenTreePtr* pArr, ValueNum* pInxVN, ssize_t* pOffset, FieldSeqNode** pFldSeq);
1506 // Requires "this" to be a GT_IND. Requires the outermost caller to set "*pFldSeq" to nullptr.
1507 // Returns true if it is an array index expression, or access to a (sequence of) struct field(s)
1508 // within a struct array element. If it returns true, sets *arrayInfo to the array information, and sets *pFldSeq to the sequence
1509 // of struct field accesses.
1510 bool ParseArrayElemForm(Compiler* comp, ArrayInfo* arrayInfo, FieldSeqNode** pFldSeq);
1512 // Requires "this" to be the address of a (possible) array element (or struct field within that).
1513 // If it is, sets "*arrayInfo" to the array access info, "*pFldSeq" to the sequence of struct fields
1514 // accessed within the array element, and returns true. If not, returns "false".
1515 bool ParseArrayElemAddrForm(Compiler* comp, ArrayInfo* arrayInfo, FieldSeqNode** pFldSeq);
1517 // Requires "this" to be an int expression. If it is a sequence of one or more integer constants added together,
1518 // returns true and sets "*pFldSeq" to the sequence of fields with which those constants are annotated.
1519 bool ParseOffsetForm(Compiler* comp, FieldSeqNode** pFldSeq);
1521 // Labels "*this" as an array index expression: label all constants and variables that could contribute, as part of an affine expression, to the value of the
1523 void LabelIndex(Compiler* comp, bool isConst = true);
1525 // Assumes that "this" occurs in a context where it is being dereferenced as the LHS of an assignment-like
1526 // statement (assignment, initblk, or copyblk). The "width" should be the number of bytes copied by the
1527 // operation. Returns "true" if "this" is an address of (or within)
1528 // a local variable; sets "*pLclVarTree" to that local variable instance; and, if "pIsEntire" is non-null,
1529 // sets "*pIsEntire" to true if this assignment writes the full width of the local.
1530 bool DefinesLocalAddr(Compiler* comp, unsigned width, GenTreeLclVarCommon** pLclVarTree, bool* pIsEntire);
1532 bool IsRegVar () const
1534 return OperGet() == GT_REG_VAR?true:false;
1538 return (gtFlags & GTF_REG_VAL)?true:false;
1542 gtFlags |= GTF_REG_VAL;
1545 regNumber GetReg() const
1547 return InReg() ? gtRegNum : REG_NA;
1549 bool IsRegVarDeath () const
1551 assert(OperGet() == GT_REG_VAR);
1552 return (gtFlags & GTF_VAR_DEATH)?true:false;
1554 bool IsRegVarBirth () const
1556 assert(OperGet() == GT_REG_VAR);
1557 return (gtFlags & GTF_REG_BIRTH)?true:false;
1559 bool IsReverseOp() const
1561 return (gtFlags & GTF_REVERSE_OPS)?true:false;
1564 inline bool IsCnsIntOrI () const;
1566 inline bool IsIntegralConst () const;
1568 inline bool IsIntCnsFitsInI32 ();
1570 inline bool IsCnsFltOrDbl() const;
1572 inline bool IsCnsNonZeroFltOrDbl();
1574 bool IsIconHandle () const
1576 assert(gtOper == GT_CNS_INT);
1577 return (gtFlags & GTF_ICON_HDL_MASK) ? true : false;
1580 bool IsIconHandle (unsigned handleType) const
1582 assert(gtOper == GT_CNS_INT);
1583 assert((handleType & GTF_ICON_HDL_MASK) != 0); // check that handleType is one of the valid GTF_ICON_* values
1584 assert((handleType & ~GTF_ICON_HDL_MASK) == 0);
1585 return (gtFlags & GTF_ICON_HDL_MASK) == handleType;
1588 // Return just the part of the flags corresponding to the GTF_ICON_*_HDL flag. For example,
1589 // GTF_ICON_SCOPE_HDL. The tree node must be a const int, but it might not be a handle, in which
1590 // case we'll return zero.
1591 unsigned GetIconHandleFlag () const
1593 assert(gtOper == GT_CNS_INT);
1594 return (gtFlags & GTF_ICON_HDL_MASK);
1597 // Mark this node as no longer being a handle; clear its GTF_ICON_*_HDL bits.
1598 void ClearIconHandleMask()
1600 assert(gtOper == GT_CNS_INT);
1601 gtFlags &= ~GTF_ICON_HDL_MASK;
1604 // Return true if the two GT_CNS_INT trees have the same handle flag (GTF_ICON_*_HDL).
1605 static bool SameIconHandleFlag(GenTree* t1, GenTree* t2)
1607 return t1->GetIconHandleFlag() == t2->GetIconHandleFlag();
1610 bool IsArgPlaceHolderNode() const { return OperGet() == GT_ARGPLACE; }
1611 bool IsCall () const { return OperGet() == GT_CALL; }
1612 bool IsStatement () const { return OperGet() == GT_STMT; }
1613 inline bool IsHelperCall ();
1615 bool IsVarAddr () const;
1616 bool gtOverflow () const;
1617 bool gtOverflowEx () const;
1618 bool gtSetFlags () const;
1619 bool gtRequestSetFlags ();
1621 bool gtIsValid64RsltMul ();
1622 static int gtDispFlags (unsigned flags, unsigned debugFlags);
1626 inline var_types CastFromType();
1627 inline var_types& CastToType();
1629 // Returns true if this gentree node is marked by lowering to indicate
1630 // that codegen can still generate code even if it wasn't allocated a
1632 bool IsRegOptional() const;
1634 // Returns "true" iff "*this" is an assignment (GT_ASG) tree that defines an SSA name (lcl = phi(...));
1637 // Returns "true" iff "*this" is a statement containing an assignment that defines an SSA name (lcl = phi(...));
1638 bool IsPhiDefnStmt();
1640 // Can't use an assignment operator, because we need the extra "comp" argument
1641 // (to provide the allocator necessary for the VarSet assignment).
1642 // TODO-Cleanup: Not really needed now, w/o liveset on tree nodes
1643 void CopyTo(class Compiler* comp, const GenTree& gt);
1645 // Like the above, excepts assumes copying from small node to small node.
1646 // (Following the code it replaces, it does *not* copy the GenTree fields,
1647 // which CopyTo does.)
1648 void CopyToSmall(const GenTree& gt);
1650 // Because of the fact that we hid the assignment operator of "BitSet" (in DEBUG),
1651 // we can't synthesize an assignment operator.
1652 // TODO-Cleanup: Could change this w/o liveset on tree nodes
1653 // (This is also necessary for the VTable trick.)
1656 // Returns the number of children of the current node.
1657 unsigned NumChildren();
1659 // Requires "childNum < NumChildren()". Returns the "n"th child of "this."
1660 GenTreePtr GetChild(unsigned childNum);
1662 // The maximum possible # of children of any node.
1663 static const int MAX_CHILDREN = 6;
1665 bool IsReuseRegVal() const
1667 // This can be extended to non-constant nodes, but not to local or indir nodes.
1668 if(OperIsConst() && ((gtFlags & GTF_REUSE_REG_VAL) != 0))
1674 void SetReuseRegVal()
1676 assert(OperIsConst());
1677 gtFlags |= GTF_REUSE_REG_VAL;
1679 void ResetReuseRegVal()
1681 assert(OperIsConst());
1682 gtFlags &= ~GTF_REUSE_REG_VAL;
1687 GenTree& operator=(const GenTree& gt) {
1688 assert(!"Don't copy");
1693 #if DEBUGGABLE_GENTREE
1694 // In DEBUG builds, add a dummy virtual method, to give the debugger run-time type information.
1695 virtual void DummyVirt() {}
1697 typedef void* VtablePtr;
1699 VtablePtr GetVtableForOper(genTreeOps oper);
1700 void SetVtableForOper(genTreeOps oper);
1702 static VtablePtr s_vtablesForOpers[GT_COUNT];
1703 static VtablePtr s_vtableForOp;
1704 #endif // DEBUGGABLE_GENTREE
1707 inline void* operator new(size_t sz, class Compiler*, genTreeOps oper);
1709 inline GenTree(genTreeOps oper, var_types type
1710 DEBUGARG(bool largeNode = false));
1714 /*****************************************************************************/
1715 // In the current design, we never instantiate GenTreeUnOp: it exists only to be
1716 // used as a base class. For unary operators, we instantiate GenTreeOp, with a NULL second
1717 // argument. We check that this is true dynamically. We could tighten this and get static
1718 // checking, but that would entail accessing the first child of a unary operator via something
1719 // like gtUnOp.gtOp1 instead of gtOp.gtOp1.
1720 struct GenTreeUnOp: public GenTree
1725 GenTreeUnOp(genTreeOps oper, var_types type
1726 DEBUGARG(bool largeNode = false)) :
1728 DEBUGARG(largeNode)),
1732 GenTreeUnOp(genTreeOps oper, var_types type, GenTreePtr op1
1733 DEBUGARG(bool largeNode = false)) :
1735 DEBUGARG(largeNode)),
1738 assert(op1 != nullptr || NullOp1Legal());
1739 if (op1 != nullptr) // Propagate effects flags from child.
1740 gtFlags |= op1->gtFlags & GTF_ALL_EFFECT;
1743 #if DEBUGGABLE_GENTREE
1744 GenTreeUnOp() : GenTree(), gtOp1(nullptr) {}
1748 struct GenTreeOp: public GenTreeUnOp
1752 GenTreeOp(genTreeOps oper, var_types type, GenTreePtr op1, GenTreePtr op2
1753 DEBUGARG(bool largeNode = false)) :
1754 GenTreeUnOp(oper, type, op1
1755 DEBUGARG(largeNode)),
1758 // comparisons are always integral types
1759 assert(!GenTree::OperIsCompare(oper) || varTypeIsIntegral(type));
1760 // Binary operators, with a few exceptions, require a non-nullptr
1762 assert(op2 != nullptr || NullOp2Legal());
1763 // Unary operators, on the other hand, require a null second argument.
1764 assert(!OperIsUnary(oper) || op2 == nullptr);
1765 // Propagate effects flags from child. (UnOp handled this for first child.)
1768 gtFlags |= op2->gtFlags & GTF_ALL_EFFECT;
1772 // A small set of types are unary operators with optional arguments. We use
1773 // this constructor to build those.
1774 GenTreeOp(genTreeOps oper, var_types type
1775 DEBUGARG(bool largeNode = false)) :
1776 GenTreeUnOp(oper, type
1777 DEBUGARG(largeNode)),
1780 // Unary operators with optional arguments:
1781 assert(oper == GT_NOP ||
1782 oper == GT_RETURN ||
1783 oper == GT_RETFILT ||
1787 #if DEBUGGABLE_GENTREE
1788 GenTreeOp() : GenTreeUnOp(), gtOp2(nullptr) {}
1793 struct GenTreeVal: public GenTree
1797 GenTreeVal(genTreeOps oper, var_types type, ssize_t val) :
1798 GenTree(oper, type),
1801 #if DEBUGGABLE_GENTREE
1802 GenTreeVal() : GenTree() {}
1806 struct GenTreeIntConCommon: public GenTree
1808 inline INT64 LngValue();
1809 inline void SetLngValue(INT64 val);
1810 inline ssize_t IconValue();
1811 inline void SetIconValue(ssize_t val);
1813 GenTreeIntConCommon(genTreeOps oper, var_types type
1814 DEBUGARG(bool largeNode = false)) :
1816 DEBUGARG(largeNode))
1821 return FitsInI32(IconValue());
1824 static bool FitsInI32(ssize_t val)
1826 #ifdef _TARGET_64BIT_
1827 return (int)val == val;
1833 bool ImmedValNeedsReloc(Compiler* comp);
1834 bool GenTreeIntConCommon::ImmedValCanBeFolded(Compiler* comp, genTreeOps op);
1836 #ifdef _TARGET_XARCH_
1837 bool FitsInAddrBase(Compiler* comp);
1838 bool AddrNeedsReloc(Compiler* comp);
1841 #if DEBUGGABLE_GENTREE
1842 GenTreeIntConCommon() : GenTree() {}
1846 // node representing a read from a physical register
1847 struct GenTreePhysReg: public GenTree
1849 // physregs need a field beyond gtRegNum because
1850 // gtRegNum indicates the destination (and can be changed)
1851 // whereas reg indicates the source
1853 GenTreePhysReg(regNumber r, var_types type=TYP_I_IMPL) :
1854 GenTree(GT_PHYSREG, type), gtSrcReg(r)
1857 #if DEBUGGABLE_GENTREE
1858 GenTreePhysReg() : GenTree() {}
1862 #ifndef LEGACY_BACKEND
1863 // gtJumpTable - Switch Jump Table
1865 // This node stores a DWORD constant that represents the
1866 // absolute address of a jump table for switches. The code
1867 // generator uses this table to code the destination for every case
1868 // in an array of addresses which starting position is stored in
1870 struct GenTreeJumpTable : public GenTreeIntConCommon
1872 ssize_t gtJumpTableAddr;
1874 GenTreeJumpTable(var_types type
1875 DEBUGARG(bool largeNode = false)) :
1876 GenTreeIntConCommon(GT_JMPTABLE, type
1877 DEBUGARG(largeNode))
1879 #if DEBUGGABLE_GENTREE
1880 GenTreeJumpTable() : GenTreeIntConCommon() {}
1883 #endif // !LEGACY_BACKEND
1885 /* gtIntCon -- integer constant (GT_CNS_INT) */
1886 struct GenTreeIntCon: public GenTreeIntConCommon
1889 * This is the GT_CNS_INT struct definition.
1890 * It's used to hold for both int constants and pointer handle constants.
1891 * For the 64-bit targets we will only use GT_CNS_INT as it used to represent all the possible sizes
1892 * For the 32-bit targets we use a GT_CNS_LNG to hold a 64-bit integer constant and GT_CNS_INT for all others.
1893 * In the future when we retarget the JIT for x86 we should consider eliminating GT_CNS_LNG
1895 ssize_t gtIconVal; // Must overlap and have the same offset with the gtIconVal field in GenTreeLngCon below.
1897 /* The InitializeArray intrinsic needs to go back to the newarray statement
1898 to find the class handle of the array so that we can get its size. However,
1899 in ngen mode, the handle in that statement does not correspond to the compile
1900 time handle (rather it lets you get a handle at run-time). In that case, we also
1901 need to store a compile time handle, which goes in this gtCompileTimeHandle field.
1903 ssize_t gtCompileTimeHandle;
1905 // TODO-Cleanup: It's not clear what characterizes the cases where the field
1906 // above is used. It may be that its uses and those of the "gtFieldSeq" field below
1907 // are mutually exclusive, and they could be put in a union. Or else we should separate
1908 // this type into three subtypes.
1910 // If this constant represents the offset of one or more fields, "gtFieldSeq" represents that
1911 // sequence of fields.
1912 FieldSeqNode* gtFieldSeq;
1914 #if defined (LATE_DISASM)
1916 /* If the constant was morphed from some other node,
1917 these fields enable us to get back to what the node
1918 originally represented. See use of gtNewIconHandleNode()
1923 /* Template struct - The significant field of the other
1924 * structs should overlap exactly with this struct
1929 unsigned gtIconHdl1;
1939 CORINFO_CLASS_HANDLE gtIconCls;
1945 GenTreeIntCon(var_types type, ssize_t value
1946 DEBUGARG(bool largeNode = false)) :
1947 GenTreeIntConCommon(GT_CNS_INT, type
1948 DEBUGARG(largeNode)),
1950 gtCompileTimeHandle(0),
1951 gtFieldSeq(FieldSeqStore::NotAField())
1954 GenTreeIntCon(var_types type, ssize_t value, FieldSeqNode* fields
1955 DEBUGARG(bool largeNode = false)) :
1956 GenTreeIntConCommon(GT_CNS_INT, type
1957 DEBUGARG(largeNode)),
1959 gtCompileTimeHandle(0),
1962 assert(fields != NULL);
1965 #ifdef _TARGET_64BIT_
1966 void TruncateOrSignExtend32()
1968 if (gtFlags & GTF_UNSIGNED)
1970 gtIconVal = UINT32(gtIconVal);
1974 gtIconVal = INT32(gtIconVal);
1977 #endif // _TARGET_64BIT_
1979 #if DEBUGGABLE_GENTREE
1980 GenTreeIntCon() : GenTreeIntConCommon() {}
1985 /* gtLngCon -- long constant (GT_CNS_LNG) */
1987 struct GenTreeLngCon: public GenTreeIntConCommon
1989 INT64 gtLconVal; // Must overlap and have the same offset with the gtIconVal field in GenTreeIntCon above.
1992 return (INT32)(gtLconVal & 0xffffffff);
1997 return (INT32)(gtLconVal >> 32);;
2000 GenTreeLngCon(INT64 val) :
2001 GenTreeIntConCommon(GT_CNS_NATIVELONG, TYP_LONG)
2002 { SetLngValue(val); }
2003 #if DEBUGGABLE_GENTREE
2004 GenTreeLngCon() : GenTreeIntConCommon() {}
2009 inline INT64 GenTreeIntConCommon::LngValue()
2011 #ifndef _TARGET_64BIT_
2012 assert(gtOper == GT_CNS_LNG);
2013 return AsLngCon()->gtLconVal;
2019 inline void GenTreeIntConCommon::SetLngValue(INT64 val)
2021 #ifndef _TARGET_64BIT_
2022 assert(gtOper == GT_CNS_LNG);
2023 AsLngCon()->gtLconVal = val;
2025 // Compile time asserts that these two fields overlap and have the same offsets: gtIconVal and gtLconVal
2026 C_ASSERT(offsetof(GenTreeLngCon, gtLconVal) == offsetof(GenTreeIntCon, gtIconVal));
2027 C_ASSERT(sizeof(AsLngCon()->gtLconVal) == sizeof(AsIntCon()->gtIconVal));
2029 SetIconValue(ssize_t(val));
2033 inline ssize_t GenTreeIntConCommon::IconValue()
2035 assert(gtOper == GT_CNS_INT); // We should never see a GT_CNS_LNG for a 64-bit target!
2036 return AsIntCon()->gtIconVal;
2039 inline void GenTreeIntConCommon::SetIconValue(ssize_t val)
2041 assert(gtOper == GT_CNS_INT); // We should never see a GT_CNS_LNG for a 64-bit target!
2042 AsIntCon()->gtIconVal = val;
2045 /* gtDblCon -- double constant (GT_CNS_DBL) */
2047 struct GenTreeDblCon: public GenTree
2051 bool isBitwiseEqual(GenTreeDblCon* other)
2053 unsigned __int64 bits = *(unsigned __int64 *)(>DconVal);
2054 unsigned __int64 otherBits = *(unsigned __int64 *)(&(other->gtDconVal));
2055 return (bits == otherBits);
2058 GenTreeDblCon(double val) :
2059 GenTree(GT_CNS_DBL, TYP_DOUBLE),
2062 #if DEBUGGABLE_GENTREE
2063 GenTreeDblCon() : GenTree() {}
2068 /* gtStrCon -- string constant (GT_CNS_STR) */
2070 struct GenTreeStrCon: public GenTree
2073 CORINFO_MODULE_HANDLE gtScpHnd;
2075 // Because this node can come from an inlined method we need to
2076 // have the scope handle, since it will become a helper call.
2077 GenTreeStrCon(unsigned sconCPX, CORINFO_MODULE_HANDLE mod
2078 DEBUGARG(bool largeNode = false)) :
2079 GenTree(GT_CNS_STR, TYP_REF
2080 DEBUGARG(largeNode)),
2081 gtSconCPX(sconCPX), gtScpHnd(mod)
2083 #if DEBUGGABLE_GENTREE
2084 GenTreeStrCon() : GenTree() {}
2088 // Common supertype of LCL_VAR, LCL_FLD, REG_VAR, PHI_ARG
2089 // This inherits from UnOp because lclvar stores are Unops
2090 struct GenTreeLclVarCommon: public GenTreeUnOp
2093 unsigned _gtLclNum; // The local number. An index into the Compiler::lvaTable array.
2094 unsigned _gtSsaNum; // The SSA number.
2097 GenTreeLclVarCommon(genTreeOps oper, var_types type, unsigned lclNum
2098 DEBUGARG(bool largeNode = false)) :
2099 GenTreeUnOp(oper, type
2100 DEBUGARG(largeNode))
2105 unsigned GetLclNum() const
2109 __declspec(property(get=GetLclNum)) unsigned gtLclNum;
2111 void SetLclNum(unsigned lclNum)
2114 _gtSsaNum = SsaConfig::RESERVED_SSA_NUM;
2117 unsigned GetSsaNum() const
2121 __declspec(property(get=GetSsaNum)) unsigned gtSsaNum;
2123 void SetSsaNum(unsigned ssaNum)
2130 return (gtSsaNum != SsaConfig::RESERVED_SSA_NUM);
2133 #if DEBUGGABLE_GENTREE
2134 GenTreeLclVarCommon() : GenTreeUnOp() {}
2138 // gtLclVar -- load/store/addr of local variable
2140 struct GenTreeLclVar: public GenTreeLclVarCommon
2142 IL_OFFSET gtLclILoffs; // instr offset of ref (only for debug info)
2144 GenTreeLclVar(var_types type, unsigned lclNum, IL_OFFSET ilOffs
2145 DEBUGARG(bool largeNode = false)) :
2146 GenTreeLclVarCommon(GT_LCL_VAR, type, lclNum
2147 DEBUGARG(largeNode)),
2151 GenTreeLclVar(genTreeOps oper, var_types type, unsigned lclNum, IL_OFFSET ilOffs
2152 DEBUGARG(bool largeNode = false)) :
2153 GenTreeLclVarCommon(oper, type, lclNum
2154 DEBUGARG(largeNode)),
2157 assert(OperIsLocal(oper) || OperIsLocalAddr(oper));
2160 #if DEBUGGABLE_GENTREE
2161 GenTreeLclVar() : GenTreeLclVarCommon() {}
2165 // gtLclFld -- load/store/addr of local variable field
2167 struct GenTreeLclFld: public GenTreeLclVarCommon
2169 unsigned gtLclOffs; // offset into the variable to access
2171 FieldSeqNode* gtFieldSeq; // This LclFld node represents some sequences of accesses.
2173 // old/FE style constructor where load/store/addr share same opcode
2174 GenTreeLclFld(var_types type, unsigned lclNum, unsigned lclOffs) :
2175 GenTreeLclVarCommon(GT_LCL_FLD, type, lclNum),
2176 gtLclOffs(lclOffs), gtFieldSeq(NULL)
2178 assert(sizeof(*this) <= s_gtNodeSizes[GT_LCL_FLD]);
2182 GenTreeLclFld(genTreeOps oper, var_types type, unsigned lclNum, unsigned lclOffs) :
2183 GenTreeLclVarCommon(oper, type, lclNum),
2184 gtLclOffs(lclOffs), gtFieldSeq(NULL)
2186 assert(sizeof(*this) <= s_gtNodeSizes[GT_LCL_FLD]);
2188 #if DEBUGGABLE_GENTREE
2189 GenTreeLclFld() : GenTreeLclVarCommon() {}
2193 struct GenTreeRegVar: public GenTreeLclVarCommon
2195 // TODO-Cleanup: Note that the base class GenTree already has a gtRegNum field.
2196 // It's not clear exactly why a GT_REG_VAR has a separate field. When
2197 // GT_REG_VAR is created, the two are identical. It appears that they may
2198 // or may not remain so. In particular, there is a comment in stackfp.cpp
2201 // There used to be an assertion: assert(src->gtRegNum == src->gtRegVar.gtRegNum, ...)
2202 // here, but there's actually no reason to assume that. AFAICT, for FP vars under stack FP,
2203 // src->gtRegVar.gtRegNum is the allocated stack pseudo-register, but src->gtRegNum is the
2204 // FP stack position into which that is loaded to represent a particular use of the variable.
2206 // It might be the case that only for stackfp do they ever differ.
2208 // The following might be possible: the GT_REG_VAR node has a last use prior to a complex
2209 // subtree being evaluated. It could then be spilled from the register. Later,
2210 // it could be unspilled into a different register, which would be recorded at
2211 // the unspill time in the GenTree::gtRegNum, whereas GenTreeRegVar::gtRegNum
2212 // is left alone. It's not clear why that is useful.
2214 // Assuming there is a particular use, like stack fp, that requires it, maybe we
2215 // can get rid of GT_REG_VAR and just leave it as GT_LCL_VAR, using the base class gtRegNum field.
2216 // If we need it for stackfp, we could add a GenTreeStackFPRegVar type, which carries both the
2217 // pieces of information, in a clearer and more specific way (in particular, with
2218 // a different member name).
2223 regNumberSmall _gtRegNum;
2227 GenTreeRegVar(var_types type, unsigned lclNum, regNumber regNum) :
2228 GenTreeLclVarCommon(GT_REG_VAR, type, lclNum
2234 // The register number is stored in a small format (8 bits), but the getters return and the setters take
2235 // a full-size (unsigned) format, to localize the casts here.
2237 __declspec(property(get=GetRegNum,put=SetRegNum))
2240 regNumber GetRegNum() const
2242 return (regNumber) _gtRegNum;
2245 void SetRegNum(regNumber reg)
2247 _gtRegNum = (regNumberSmall) reg;
2248 assert(_gtRegNum == reg);
2251 #if DEBUGGABLE_GENTREE
2252 GenTreeRegVar() : GenTreeLclVarCommon() {}
2256 /* gtCast -- conversion to a different type (GT_CAST) */
2258 struct GenTreeCast: public GenTreeOp
2260 GenTreePtr& CastOp() { return gtOp1; }
2261 var_types gtCastType;
2263 GenTreeCast(var_types type, GenTreePtr op, var_types castType
2264 DEBUGARG(bool largeNode = false)) :
2265 GenTreeOp(GT_CAST, type, op, nullptr
2266 DEBUGARG(largeNode)),
2267 gtCastType(castType)
2269 #if DEBUGGABLE_GENTREE
2270 GenTreeCast() : GenTreeOp() {}
2275 // GT_BOX nodes are place markers for boxed values. The "real" tree
2276 // for most purposes is in gtBoxOp.
2277 struct GenTreeBox: public GenTreeUnOp
2279 // An expanded helper call to implement the "box" if we don't get
2280 // rid of it any other way. Must be in same position as op1.
2282 GenTreePtr& BoxOp() { return gtOp1; }
2283 // This is the statement that contains the assignment tree when the node is an inlined GT_BOX on a value
2285 GenTreePtr gtAsgStmtWhenInlinedBoxValue;
2287 GenTreeBox(var_types type, GenTreePtr boxOp, GenTreePtr asgStmtWhenInlinedBoxValue) :
2288 GenTreeUnOp(GT_BOX, type, boxOp),
2289 gtAsgStmtWhenInlinedBoxValue(asgStmtWhenInlinedBoxValue)
2291 #if DEBUGGABLE_GENTREE
2292 GenTreeBox() : GenTreeUnOp() {}
2298 /* gtField -- data member ref (GT_FIELD) */
2300 struct GenTreeField: public GenTree
2302 GenTreePtr gtFldObj;
2303 CORINFO_FIELD_HANDLE gtFldHnd;
2305 bool gtFldMayOverlap;
2306 #ifdef FEATURE_READYTORUN_COMPILER
2307 CORINFO_CONST_LOOKUP gtFieldLookup;
2310 GenTreeField(var_types type) :
2311 GenTree(GT_FIELD, type
2314 gtFldMayOverlap = false;
2316 #if DEBUGGABLE_GENTREE
2317 GenTreeField() : GenTree() {}
2321 // Represents the Argument list of a call node, as a Lisp-style linked list.
2322 // (Originally I had hoped that this could have *only* the m_arg/m_rest fields, but it turns out
2323 // that enough of the GenTree mechanism is used that it makes sense just to make it a subtype. But
2324 // note that in many ways, this is *not* a "real" node of the tree, but rather a mechanism for
2325 // giving call nodes a flexible number of children. GenTreeArgListNodes never evaluate to registers,
2328 // Note that while this extends GenTreeOp, it is *not* an EXOP. We don't add any new fields, and one
2329 // is free to allocate a GenTreeOp of type GT_LIST. If you use this type, you get the convenient Current/Rest
2330 // method names for the arguments.
2331 struct GenTreeArgList: public GenTreeOp
2333 GenTreePtr& Current() { return gtOp1; }
2334 GenTreeArgList*& Rest() { assert(gtOp2 == NULL || gtOp2->OperGet() == GT_LIST); return *reinterpret_cast<GenTreeArgList**>(>Op2); }
2336 #if DEBUGGABLE_GENTREE
2337 GenTreeArgList() : GenTreeOp() {}
2340 GenTreeArgList(GenTreePtr arg) :
2341 GenTreeArgList(arg, nullptr) {}
2343 GenTreeArgList(GenTreePtr arg, GenTreeArgList* rest) :
2344 GenTreeOp(GT_LIST, TYP_VOID, arg, rest)
2346 // With structs passed in multiple args we could have an arg
2347 // GT_LIST containing a list of LCL_FLDs, see IsListForMultiRegArg()
2349 assert((arg != nullptr) && ((!arg->IsList()) || (arg->IsListForMultiRegArg())));
2350 gtFlags |= arg->gtFlags & GTF_ALL_EFFECT;
2353 gtFlags |= rest->gtFlags & GTF_ALL_EFFECT;
2358 // There was quite a bit of confusion in the code base about which of gtOp1 and gtOp2 was the
2359 // 'then' and 'else' clause of a colon node. Adding these accessors, while not enforcing anything,
2360 // at least *allows* the programmer to be obviously correct.
2361 // However, these conventions seem backward.
2362 // TODO-Cleanup: If we could get these accessors used everywhere, then we could switch them.
2363 struct GenTreeColon: public GenTreeOp
2365 GenTreePtr& ThenNode() { return gtOp2; }
2366 GenTreePtr& ElseNode() { return gtOp1; }
2368 #if DEBUGGABLE_GENTREE
2369 GenTreeColon() : GenTreeOp() {}
2372 GenTreeColon(var_types typ, GenTreePtr thenNode, GenTreePtr elseNode) :
2373 GenTreeOp(GT_COLON, typ, elseNode, thenNode)
2377 // gtCall -- method call (GT_CALL)
2378 typedef class fgArgInfo * fgArgInfoPtr;
2379 enum class InlineObservation;
2381 // Return type descriptor of a GT_CALL node.
2382 // x64 Unix, Arm64, Arm32 and x86 allow a value to be returned in multiple
2383 // registers. For such calls this struct provides the following info
2384 // on their return type
2385 // - type of value returned in each return register
2386 // - ABI return register numbers in which the value is returned
2387 // - count of return registers in which the value is returned
2389 // TODO-ARM: Update this to meet the needs of Arm64 and Arm32
2391 // TODO-AllArch: Right now it is used for describing multi-reg returned types.
2392 // Eventually we would want to use it for describing even single-reg
2393 // returned types (e.g. structs returned in single register x64/arm).
2394 // This would allow us not to lie or normalize single struct return
2395 // values in importer/morph.
2396 struct ReturnTypeDesc
2399 var_types m_regType[MAX_RET_REG_COUNT];
2411 // Initialize the return type descriptor given its type handle
2412 void InitializeReturnType(Compiler* comp, CORINFO_CLASS_HANDLE retClsHnd);
2414 // Reset type descriptor to defaults
2417 for (unsigned i = 0; i < MAX_RET_REG_COUNT; ++i)
2419 m_regType[i] = TYP_UNKNOWN;
2426 //--------------------------------------------------------------------------------------------
2427 // GetReturnRegCount: Get the count of return registers in which the return value is returned.
2433 // Count of return registers.
2434 // Returns 0 if the return type is not returned in registers.
2435 unsigned GetReturnRegCount() const
2440 for (unsigned i = 0; i < MAX_RET_REG_COUNT; ++i)
2442 if (m_regType[i] == TYP_UNKNOWN)
2451 // Any remaining elements in m_regTypes[] should also be TYP_UNKNOWN
2452 for (unsigned i = regCount+1; i < MAX_RET_REG_COUNT; ++i)
2454 assert(m_regType[i] == TYP_UNKNOWN);
2461 //-----------------------------------------------------------------------
2462 // IsMultiRegRetType: check whether the type is returned in multiple
2463 // return registers.
2469 // Returns true if the type is returned in multiple return registers.
2471 // Note that we only have to examine the first two values to determine this
2473 bool IsMultiRegRetType() const
2475 if (MAX_RET_REG_COUNT < 2)
2481 return ((m_regType[0] != TYP_UNKNOWN) &&
2482 (m_regType[1] != TYP_UNKNOWN));
2486 //--------------------------------------------------------------------------
2487 // GetReturnRegType: Get var_type of the return register specified by index.
2490 // index - Index of the return register.
2491 // First return register will have an index 0 and so on.
2494 // var_type of the return register specified by its index.
2495 // asserts if the index does not have a valid register return type.
2497 var_types GetReturnRegType(unsigned index)
2499 var_types result = m_regType[index];
2500 assert(result != TYP_UNKNOWN);
2505 // Get ith ABI return register
2506 regNumber GetABIReturnReg(unsigned idx);
2508 // Get reg mask of ABI return registers
2509 regMaskTP GetABIReturnRegs();
2512 struct GenTreeCall final : public GenTree
2514 GenTreePtr gtCallObjp; // The instance argument ('this' pointer)
2515 GenTreeArgList* gtCallArgs; // The list of arguments in original evaluation order
2516 GenTreeArgList* gtCallLateArgs; // On x86: The register arguments in an optimal order
2517 // On ARM/x64: - also includes any outgoing arg space arguments
2518 // - that were evaluated into a temp LclVar
2519 fgArgInfoPtr fgArgInfo;
2521 #if !FEATURE_FIXED_OUT_ARGS
2522 int regArgListCount;
2526 // TODO-Throughput: Revisit this (this used to be only defined if
2527 // FEATURE_FIXED_OUT_ARGS was enabled, so this makes GenTreeCall 4 bytes bigger on x86).
2528 CORINFO_SIG_INFO* callSig; // Used by tail calls and to register callsites with the EE
2530 #ifdef LEGACY_BACKEND
2531 regMaskTP gtCallRegUsedMask; // mask of registers used to pass parameters
2532 #endif // LEGACY_BACKEND
2534 // State required to support multi-reg returning call nodes.
2535 // For now it is enabled only for x64 unix.
2537 // TODO-AllArch: enable for all call nodes to unify single-reg and multi-reg returns.
2538 #if FEATURE_MULTIREG_RET
2539 ReturnTypeDesc gtReturnTypeDesc;
2541 // gtRegNum would always be the first return reg.
2542 // The following array holds the other reg numbers of multi-reg return.
2543 regNumber gtOtherRegs[MAX_RET_REG_COUNT - 1];
2545 // GTF_SPILL or GTF_SPILLED flag on a multi-reg call node indicates that one or
2546 // more of its result regs are in that state. The spill flag of each of the
2547 // return register is stored in the below array.
2548 unsigned gtSpillFlags[MAX_RET_REG_COUNT];
2551 //-----------------------------------------------------------------------
2552 // GetReturnTypeDesc: get the type descriptor of return value of the call
2558 // Type descriptor of the value returned by call
2561 // Right now implemented only for x64 unix and yet to be
2562 // implemented for other multi-reg target arch (Arm64/Arm32/x86).
2564 // TODO-AllArch: enable for all call nodes to unify single-reg and multi-reg returns.
2565 ReturnTypeDesc* GetReturnTypeDesc()
2567 #if FEATURE_MULTIREG_RET
2568 return >ReturnTypeDesc;
2574 //---------------------------------------------------------------------------
2575 // GetRegNumByIdx: get ith return register allocated to this call node.
2578 // idx - index of the return register
2581 // Return regNumber of ith return register of call node.
2582 // Returns REG_NA if there is no valid return register for the given index.
2584 regNumber GetRegNumByIdx(unsigned idx) const
2586 assert(idx < MAX_RET_REG_COUNT);
2593 #if FEATURE_MULTIREG_RET
2594 return gtOtherRegs[idx-1];
2600 //----------------------------------------------------------------------
2601 // SetRegNumByIdx: set ith return register of this call node
2605 // idx - index of the return register
2610 void SetRegNumByIdx(regNumber reg, unsigned idx)
2612 assert(idx < MAX_RET_REG_COUNT);
2618 #if FEATURE_MULTIREG_RET
2621 gtOtherRegs[idx - 1] = reg;
2622 assert(gtOtherRegs[idx - 1] == reg);
2629 //----------------------------------------------------------------------------
2630 // ClearOtherRegs: clear multi-reg state to indicate no regs are allocated
2638 void ClearOtherRegs()
2640 #if FEATURE_MULTIREG_RET
2641 for (unsigned i = 0; i < MAX_RET_REG_COUNT - 1; ++i)
2643 gtOtherRegs[i] = REG_NA;
2648 //----------------------------------------------------------------------------
2649 // CopyOtherRegs: copy multi-reg state from the given call node to this node
2652 // fromCall - GenTreeCall node from which to copy multi-reg state
2657 void CopyOtherRegs(GenTreeCall* fromCall)
2659 #if FEATURE_MULTIREG_RET
2660 for (unsigned i = 0; i < MAX_RET_REG_COUNT - 1; ++i)
2662 this->gtOtherRegs[i] = fromCall->gtOtherRegs[i];
2667 // Get reg mask of all the valid registers of gtOtherRegs array
2668 regMaskTP GetOtherRegMask() const;
2670 //----------------------------------------------------------------------
2671 // GetRegSpillFlagByIdx: get spill flag associated with the return register
2672 // specified by its index.
2675 // idx - Position or index of the return register
2678 // Returns GTF_* flags associated with.
2679 unsigned GetRegSpillFlagByIdx(unsigned idx) const
2681 assert(idx < MAX_RET_REG_COUNT);
2683 #if FEATURE_MULTIREG_RET
2684 return gtSpillFlags[idx];
2686 assert(!"unreached");
2691 //----------------------------------------------------------------------
2692 // SetRegSpillFlagByIdx: set spill flags for the return register
2693 // specified by its index.
2696 // flags - GTF_* flags
2697 // idx - Position or index of the return register
2701 void SetRegSpillFlagByIdx(unsigned flags, unsigned idx)
2703 assert(idx < MAX_RET_REG_COUNT);
2705 #if FEATURE_MULTIREG_RET
2706 gtSpillFlags[idx] = flags;
2712 //-------------------------------------------------------------------
2713 // clearOtherRegFlags: clear GTF_* flags associated with gtOtherRegs
2720 void ClearOtherRegFlags()
2722 #if FEATURE_MULTIREG_RET
2723 for (unsigned i = 0; i < MAX_RET_REG_COUNT; ++i)
2725 gtSpillFlags[i] = 0;
2730 //-------------------------------------------------------------------------
2731 // CopyOtherRegFlags: copy GTF_* flags associated with gtOtherRegs from
2732 // the given call node.
2735 // fromCall - GenTreeCall node from which to copy
2740 void CopyOtherRegFlags(GenTreeCall* fromCall)
2742 #if FEATURE_MULTIREG_RET
2743 for (unsigned i = 0; i < MAX_RET_REG_COUNT; ++i)
2745 this->gtSpillFlags[i] = fromCall->gtSpillFlags[i];
2750 #define GTF_CALL_M_EXPLICIT_TAILCALL 0x0001 // GT_CALL -- the call is "tail" prefixed and importer has performed tail call checks
2751 #define GTF_CALL_M_TAILCALL 0x0002 // GT_CALL -- the call is a tailcall
2752 #define GTF_CALL_M_VARARGS 0x0004 // GT_CALL -- the call uses varargs ABI
2753 #define GTF_CALL_M_RETBUFFARG 0x0008 // GT_CALL -- first parameter is the return buffer argument
2754 #define GTF_CALL_M_DELEGATE_INV 0x0010 // GT_CALL -- call to Delegate.Invoke
2755 #define GTF_CALL_M_NOGCCHECK 0x0020 // GT_CALL -- not a call for computing full interruptability
2756 #define GTF_CALL_M_SPECIAL_INTRINSIC 0x0040 // GT_CALL -- function that could be optimized as an intrinsic
2757 // in special cases. Used to optimize fast way out in morphing
2758 #define GTF_CALL_M_UNMGD_THISCALL 0x0080 // "this" pointer (first argument) should be enregistered (only for GTF_CALL_UNMANAGED)
2759 #define GTF_CALL_M_VIRTSTUB_REL_INDIRECT 0x0080 // the virtstub is indirected through a relative address (only for GTF_CALL_VIRT_STUB)
2760 #define GTF_CALL_M_NONVIRT_SAME_THIS 0x0080 // callee "this" pointer is equal to caller this pointer (only for GTF_CALL_NONVIRT)
2761 #define GTF_CALL_M_FRAME_VAR_DEATH 0x0100 // GT_CALL -- the compLvFrameListRoot variable dies here (last use)
2763 #ifndef LEGACY_BACKEND
2764 #define GTF_CALL_M_TAILCALL_VIA_HELPER 0x0200 // GT_CALL -- call is a tail call dispatched via tail call JIT helper.
2765 #endif // !LEGACY_BACKEND
2767 #if FEATURE_TAILCALL_OPT
2768 #define GTF_CALL_M_IMPLICIT_TAILCALL 0x0400 // GT_CALL -- call is an opportunistic tail call and importer has performed tail call checks
2769 #define GTF_CALL_M_TAILCALL_TO_LOOP 0x0800 // GT_CALL -- call is a fast recursive tail call that can be converted into a loop
2772 #define GTF_CALL_M_PINVOKE 0x1000 // GT_CALL -- call is a pinvoke. This mirrors VM flag CORINFO_FLG_PINVOKE.
2773 // A call marked as Pinvoke is not necessarily a GT_CALL_UNMANAGED. For e.g.
2774 // an IL Stub dynamically generated for a PInvoke declaration is flagged as
2775 // a Pinvoke but not as an unmanaged call. See impCheckForPInvokeCall() to
2776 // know when these flags are set.
2778 #define GTF_CALL_M_R2R_REL_INDIRECT 0x2000 // GT_CALL -- ready to run call is indirected through a relative address
2780 bool IsUnmanaged() const { return (gtFlags & GTF_CALL_UNMANAGED) != 0; }
2781 bool NeedsNullCheck() const { return (gtFlags & GTF_CALL_NULLCHECK) != 0; }
2782 bool CallerPop() const { return (gtFlags & GTF_CALL_POP_ARGS) != 0; }
2783 bool IsVirtual() const { return (gtFlags & GTF_CALL_VIRT_KIND_MASK) != GTF_CALL_NONVIRT; }
2784 bool IsVirtualStub() const { return (gtFlags & GTF_CALL_VIRT_KIND_MASK) == GTF_CALL_VIRT_STUB; }
2785 bool IsVirtualVtable() const { return (gtFlags & GTF_CALL_VIRT_KIND_MASK) == GTF_CALL_VIRT_VTABLE; }
2786 bool IsInlineCandidate() const { return (gtFlags & GTF_CALL_INLINE_CANDIDATE) != 0; }
2788 #ifndef LEGACY_BACKEND
2789 bool HasNonStandardAddedArgs(Compiler* compiler) const;
2790 int GetNonStandardAddedArgCount(Compiler* compiler) const;
2791 #endif // !LEGACY_BACKEND
2793 // Returns true if this call uses a retBuf argument and its calling convention
2794 bool HasRetBufArg() const
2796 return (gtCallMoreFlags & GTF_CALL_M_RETBUFFARG) != 0;
2799 //-------------------------------------------------------------------------
2800 // TreatAsHasRetBufArg:
2803 // compiler, the compiler instance so that we can call eeGetHelperNum
2806 // Returns true if we treat the call as if it has a retBuf argument
2807 // This method may actually have a retBuf argument
2808 // or it could be a JIT helper that we are still transforming during
2809 // the importer phase.
2812 // On ARM64 marking the method with the GTF_CALL_M_RETBUFFARG flag
2813 // will make HasRetBufArg() return true, but will also force the
2814 // use of register x8 to pass the RetBuf argument.
2816 bool TreatAsHasRetBufArg(Compiler* compiler) const;
2818 //-----------------------------------------------------------------------------------------
2819 // HasMultiRegRetVal: whether the call node returns its value in multiple return registers.
2825 // True if the call is returning a multi-reg return value. False otherwise.
2828 // This is implemented only for x64 Unix and yet to be implemented for
2829 // other multi-reg return target arch (arm64/arm32/x86).
2831 // TODO-ARM: Implement this routine for Arm64 and Arm32
2832 bool HasMultiRegRetVal() const
2834 #ifdef FEATURE_UNIX_AMD64_STRUCT_PASSING
2835 return varTypeIsStruct(gtType) && !HasRetBufArg();
2836 #elif defined(_TARGET_X86_) && !defined(LEGACY_BACKEND)
2837 // LEGACY_BACKEND does not use multi reg returns for calls with long return types
2838 return varTypeIsLong(gtType);
2844 // Returns true if VM has flagged this method as CORINFO_FLG_PINVOKE.
2845 bool IsPInvoke() const { return (gtCallMoreFlags & GTF_CALL_M_PINVOKE) != 0; }
2847 // Note that the distinction of whether tail prefixed or an implicit tail call
2848 // is maintained on a call node till fgMorphCall() after which it will be
2849 // either a tail call (i.e. IsTailCall() is true) or a non-tail call.
2850 bool IsTailPrefixedCall() const { return (gtCallMoreFlags & GTF_CALL_M_EXPLICIT_TAILCALL) != 0; }
2852 // This method returning "true" implies that tail call flowgraph morhphing has
2853 // performed final checks and committed to making a tail call.
2854 bool IsTailCall() const { return (gtCallMoreFlags & GTF_CALL_M_TAILCALL) != 0; }
2856 // This method returning "true" implies that importer has performed tail call checks
2857 // and providing a hint that this can be converted to a tail call.
2858 bool CanTailCall() const { return IsTailPrefixedCall() || IsImplicitTailCall(); }
2860 #ifndef LEGACY_BACKEND
2861 bool IsTailCallViaHelper() const { return IsTailCall() && (gtCallMoreFlags & GTF_CALL_M_TAILCALL_VIA_HELPER); }
2862 #else // LEGACY_BACKEND
2863 bool IsTailCallViaHelper() const { return true; }
2864 #endif // LEGACY_BACKEND
2866 #if FEATURE_FASTTAILCALL
2867 bool IsFastTailCall() const { return IsTailCall() && !(gtCallMoreFlags & GTF_CALL_M_TAILCALL_VIA_HELPER); }
2868 #else // !FEATURE_FASTTAILCALL
2869 bool IsFastTailCall() const { return false; }
2870 #endif // !FEATURE_FASTTAILCALL
2872 #if FEATURE_TAILCALL_OPT
2873 // Returns true if this is marked for opportunistic tail calling.
2874 // That is, can be tail called though not explicitly prefixed with "tail" prefix.
2875 bool IsImplicitTailCall() const { return (gtCallMoreFlags & GTF_CALL_M_IMPLICIT_TAILCALL) != 0; }
2876 bool IsTailCallConvertibleToLoop() const { return (gtCallMoreFlags & GTF_CALL_M_TAILCALL_TO_LOOP) != 0; }
2877 #else // !FEATURE_TAILCALL_OPT
2878 bool IsImplicitTailCall() const { return false; }
2879 bool IsTailCallConvertibleToLoop() const { return false; }
2880 #endif // !FEATURE_TAILCALL_OPT
2882 bool IsSameThis() const { return (gtCallMoreFlags & GTF_CALL_M_NONVIRT_SAME_THIS) != 0; }
2883 bool IsDelegateInvoke() const { return (gtCallMoreFlags & GTF_CALL_M_DELEGATE_INV) != 0; }
2884 bool IsVirtualStubRelativeIndir() const { return (gtCallMoreFlags & GTF_CALL_M_VIRTSTUB_REL_INDIRECT) != 0; }
2886 #ifdef FEATURE_READYTORUN_COMPILER
2887 bool IsR2RRelativeIndir() const { return (gtCallMoreFlags & GTF_CALL_M_R2R_REL_INDIRECT) != 0; }
2888 void setEntryPoint(CORINFO_CONST_LOOKUP entryPoint)
2890 gtEntryPoint = entryPoint;
2891 if (gtEntryPoint.accessType == IAT_PVALUE)
2893 gtCallMoreFlags |= GTF_CALL_M_R2R_REL_INDIRECT;
2896 #endif // FEATURE_READYTORUN_COMPILER
2898 bool IsVarargs() const { return (gtCallMoreFlags & GTF_CALL_M_VARARGS) != 0; }
2900 unsigned short gtCallMoreFlags; // in addition to gtFlags
2902 unsigned char gtCallType :3; // value from the gtCallTypes enumeration
2903 unsigned char gtReturnType :5; // exact return type
2905 CORINFO_CLASS_HANDLE gtRetClsHnd; // The return type handle of the call if it is a struct; always available
2909 // only used for CALLI unmanaged calls (CT_INDIRECT)
2910 GenTreePtr gtCallCookie;
2911 // gtInlineCandidateInfo is only used when inlining methods
2912 InlineCandidateInfo* gtInlineCandidateInfo;
2913 void* gtStubCallStubAddr; // GTF_CALL_VIRT_STUB - these are never inlined
2914 CORINFO_GENERIC_HANDLE compileTimeHelperArgumentHandle; // Used to track type handle argument of dynamic helpers
2915 void* gtDirectCallAddress; // Used to pass direct call address between lower and codegen
2918 // expression evaluated after args are placed which determines the control target
2919 GenTree * gtControlExpr;
2923 CORINFO_METHOD_HANDLE gtCallMethHnd; // CT_USER_FUNC
2924 GenTreePtr gtCallAddr; // CT_INDIRECT
2927 #ifdef FEATURE_READYTORUN_COMPILER
2928 // Call target lookup info for method call from a Ready To Run module
2929 CORINFO_CONST_LOOKUP gtEntryPoint;
2932 #if defined(DEBUG) || defined(INLINE_DATA)
2933 // For non-inline candidates, track the first observation
2934 // that blocks candidacy.
2935 InlineObservation gtInlineObservation;
2937 // IL offset of the call wrt its parent method.
2938 IL_OFFSET gtRawILOffset;
2939 #endif // defined(DEBUG) || defined(INLINE_DATA)
2941 bool IsHelperCall() const
2943 return gtCallType == CT_HELPER;
2946 bool IsHelperCall(CORINFO_METHOD_HANDLE callMethHnd) const
2948 return IsHelperCall() && (callMethHnd == gtCallMethHnd);
2951 bool IsHelperCall(Compiler* compiler, unsigned helper) const;
2953 GenTreeCall(var_types type) :
2954 GenTree(GT_CALL, type)
2957 #if DEBUGGABLE_GENTREE
2958 GenTreeCall() : GenTree()
2964 struct GenTreeCmpXchg: public GenTree
2966 GenTreePtr gtOpLocation;
2967 GenTreePtr gtOpValue;
2968 GenTreePtr gtOpComparand;
2970 GenTreeCmpXchg(var_types type, GenTreePtr loc, GenTreePtr val, GenTreePtr comparand) :
2971 GenTree(GT_CMPXCHG, type),
2972 gtOpLocation(loc), gtOpValue(val), gtOpComparand(comparand)
2974 // There's no reason to do a compare-exchange on a local location, so we'll assume that all of these
2975 // have global effects.
2976 gtFlags |= GTF_GLOB_EFFECT;
2978 #if DEBUGGABLE_GENTREE
2979 GenTreeCmpXchg() : GenTree() {}
2985 struct GenTreeFptrVal: public GenTree
2987 CORINFO_METHOD_HANDLE gtFptrMethod;
2989 #ifdef FEATURE_READYTORUN_COMPILER
2990 CORINFO_CONST_LOOKUP gtEntryPoint;
2991 CORINFO_RESOLVED_TOKEN* gtLdftnResolvedToken;
2994 GenTreeFptrVal(var_types type, CORINFO_METHOD_HANDLE meth) :
2995 GenTree(GT_FTN_ADDR, type),
2998 #if DEBUGGABLE_GENTREE
2999 GenTreeFptrVal() : GenTree() {}
3004 struct GenTreeQmark : public GenTreeOp
3006 // Livesets on entry to then and else subtrees
3007 VARSET_TP gtThenLiveSet;
3008 VARSET_TP gtElseLiveSet;
3010 // The "Compiler*" argument is not a DEBUGARG here because we use it to keep track of the set of
3011 // (possible) QMark nodes.
3012 GenTreeQmark(var_types type, GenTreePtr cond, GenTreePtr colonOp, class Compiler* comp);
3014 #if DEBUGGABLE_GENTREE
3015 GenTreeQmark() : GenTreeOp(GT_QMARK, TYP_INT, NULL, NULL) {}
3019 /* gtIntrinsic -- intrinsic (possibly-binary op [NULL op2 is allowed] with an additional field) */
3021 struct GenTreeIntrinsic: public GenTreeOp
3023 CorInfoIntrinsics gtIntrinsicId;
3024 CORINFO_METHOD_HANDLE gtMethodHandle; // Method handle of the method which is treated as an intrinsic.
3026 #ifdef FEATURE_READYTORUN_COMPILER
3027 // Call target lookup info for method call from a Ready To Run module
3028 CORINFO_CONST_LOOKUP gtEntryPoint;
3031 GenTreeIntrinsic(var_types type, GenTreePtr op1, CorInfoIntrinsics intrinsicId, CORINFO_METHOD_HANDLE methodHandle) :
3032 GenTreeOp(GT_INTRINSIC, type, op1, NULL),
3033 gtIntrinsicId(intrinsicId),
3034 gtMethodHandle(methodHandle)
3037 GenTreeIntrinsic(var_types type, GenTreePtr op1, GenTreePtr op2, CorInfoIntrinsics intrinsicId, CORINFO_METHOD_HANDLE methodHandle) :
3038 GenTreeOp(GT_INTRINSIC, type, op1, op2),
3039 gtIntrinsicId(intrinsicId),
3040 gtMethodHandle(methodHandle)
3043 #if DEBUGGABLE_GENTREE
3044 GenTreeIntrinsic() : GenTreeOp() {}
3050 /* gtSIMD -- SIMD intrinsic (possibly-binary op [NULL op2 is allowed] with additional fields) */
3051 struct GenTreeSIMD: public GenTreeOp
3053 SIMDIntrinsicID gtSIMDIntrinsicID; // operation Id
3054 var_types gtSIMDBaseType; // SIMD vector base type
3055 unsigned gtSIMDSize; // SIMD vector size in bytes
3057 GenTreeSIMD(var_types type, GenTreePtr op1, SIMDIntrinsicID simdIntrinsicID, var_types baseType, unsigned size) :
3058 GenTreeOp(GT_SIMD, type, op1, nullptr),
3059 gtSIMDIntrinsicID(simdIntrinsicID),
3060 gtSIMDBaseType(baseType),
3064 GenTreeSIMD(var_types type, GenTreePtr op1, GenTreePtr op2, SIMDIntrinsicID simdIntrinsicID, var_types baseType, unsigned size) :
3065 GenTreeOp(GT_SIMD, type, op1, op2),
3066 gtSIMDIntrinsicID(simdIntrinsicID),
3067 gtSIMDBaseType(baseType),
3071 #if DEBUGGABLE_GENTREE
3072 GenTreeSIMD() : GenTreeOp() {}
3075 #endif // FEATURE_SIMD
3077 /* gtIndex -- array access */
3079 struct GenTreeIndex: public GenTreeOp
3081 GenTreePtr& Arr() { return gtOp1; }
3082 GenTreePtr& Index() { return gtOp2; }
3084 unsigned gtIndElemSize; // size of elements in the array
3085 CORINFO_CLASS_HANDLE gtStructElemClass; // If the element type is a struct, this is the struct type.
3087 GenTreeIndex(var_types type, GenTreePtr arr, GenTreePtr ind, unsigned indElemSize) :
3088 GenTreeOp(GT_INDEX, type, arr, ind),
3089 gtIndElemSize(indElemSize),
3090 gtStructElemClass(nullptr) // We always initialize this after construction.
3093 if (JitConfig.JitSkipArrayBoundCheck() == 1)
3095 // Skip bounds check
3101 gtFlags |= GTF_INX_RNGCHK;
3104 if (type == TYP_REF)
3106 gtFlags |= GTF_INX_REFARR_LAYOUT;
3109 gtFlags |= GTF_EXCEPT|GTF_GLOB_REF;
3111 #if DEBUGGABLE_GENTREE
3112 GenTreeIndex() : GenTreeOp() {}
3116 /* gtArrLen -- array length (GT_ARR_LENGTH)
3117 GT_ARR_LENGTH is used for "arr.length" */
3119 struct GenTreeArrLen: public GenTreeUnOp
3121 GenTreePtr& ArrRef() { return gtOp1; } // the array address node
3123 int gtArrLenOffset; // constant to add to "gtArrRef" to get the address of the array length.
3126 inline int ArrLenOffset() {
3127 return gtArrLenOffset;
3130 GenTreeArrLen(var_types type, GenTreePtr arrRef, int lenOffset) :
3131 GenTreeUnOp(GT_ARR_LENGTH, type, arrRef),
3132 gtArrLenOffset(lenOffset)
3135 #if DEBUGGABLE_GENTREE
3136 GenTreeArrLen() : GenTreeUnOp() {}
3141 // - a comparison value (generally an array length),
3142 // - an index value, and
3143 // - the label to jump to if the index is out of range.
3144 // - the "kind" of the throw block to branch to on failure
3145 // It generates no result.
3147 struct GenTreeBoundsChk: public GenTree
3149 GenTreePtr gtArrLen; // An expression for the length of the array being indexed.
3150 GenTreePtr gtIndex; // The index expression.
3152 GenTreePtr gtIndRngFailBB; // Label to jump to for array-index-out-of-range
3153 SpecialCodeKind gtThrowKind; // Kind of throw block to branch to on failure
3155 /* Only out-of-ranges at same stack depth can jump to the same label (finding return address is easier)
3156 For delayed calling of fgSetRngChkTarget() so that the
3157 optimizer has a chance of eliminating some of the rng checks */
3158 unsigned gtStkDepth;
3160 GenTreeBoundsChk(genTreeOps oper, var_types type, GenTreePtr arrLen, GenTreePtr index, SpecialCodeKind kind) :
3161 GenTree(oper, type),
3162 gtArrLen(arrLen), gtIndex(index),
3163 gtIndRngFailBB(NULL),
3167 // Effects flags propagate upwards.
3168 gtFlags |= (arrLen->gtFlags & GTF_ALL_EFFECT);
3169 gtFlags |= GTF_EXCEPT;
3171 #if DEBUGGABLE_GENTREE
3172 GenTreeBoundsChk() : GenTree() {}
3175 // If the gtArrLen is really an array length, returns array reference, else "NULL".
3176 GenTreePtr GetArray()
3178 if (gtArrLen->OperGet() == GT_ARR_LENGTH)
3180 return gtArrLen->gtArrLen.ArrRef();
3189 // gtArrElem -- general array element (GT_ARR_ELEM), for non "SZ_ARRAYS"
3190 // -- multidimensional arrays, or 1-d arrays with non-zero lower bounds.
3192 struct GenTreeArrElem: public GenTree
3194 GenTreePtr gtArrObj;
3196 #define GT_ARR_MAX_RANK 3
3197 GenTreePtr gtArrInds[GT_ARR_MAX_RANK]; // Indices
3198 unsigned char gtArrRank; // Rank of the array
3200 unsigned char gtArrElemSize; // !!! Caution, this is an "unsigned char", it is used only
3201 // on the optimization path of array intrisics.
3202 // It stores the size of array elements WHEN it can fit
3203 // into an "unsigned char".
3204 // This has caused VSW 571394.
3205 var_types gtArrElemType; // The array element type
3207 // Requires that "inds" is a pointer to an array of "rank" GenTreePtrs for the indices.
3208 GenTreeArrElem(var_types type, GenTreePtr arr, unsigned char rank, unsigned char elemSize, var_types elemType, GenTreePtr* inds) :
3209 GenTree(GT_ARR_ELEM, type),
3210 gtArrObj(arr), gtArrRank(rank), gtArrElemSize(elemSize), gtArrElemType(elemType)
3212 for (unsigned char i = 0; i < rank; i++) gtArrInds[i] = inds[i];
3213 gtFlags |= GTF_EXCEPT;
3215 #if DEBUGGABLE_GENTREE
3216 GenTreeArrElem() : GenTree() {}
3220 //--------------------------------------------
3222 // GenTreeArrIndex (gtArrIndex): Expression to bounds-check the index for one dimension of a
3223 // multi-dimensional or non-zero-based array., and compute the effective index
3224 // (i.e. subtracting the lower bound).
3227 // This node is similar in some ways to GenTreeBoundsChk, which ONLY performs the check.
3228 // The reason that this node incorporates the check into the effective index computation is
3229 // to avoid duplicating the codegen, as the effective index is required to compute the
3231 // TODO-CQ: Enable optimization of the lower bound and length by replacing this:
3234 // +--* ArrIndex[i, ]
3235 // with something like:
3237 // /--* ArrLowerBound[i, ]
3239 // +--* ArrLen[i, ] (either generalize GT_ARR_LENGTH or add a new node)
3241 // +--* ArrIndex[i, ]
3242 // Which could, for example, be optimized to the following when known to be within bounds:
3243 // /--* TempForLowerBoundDim0
3247 struct GenTreeArrIndex: public GenTreeOp
3249 // The array object - may be any expression producing an Array reference, but is likely to be a lclVar.
3250 GenTreePtr& ArrObj() { return gtOp1; }
3251 // The index expression - may be any integral expression.
3252 GenTreePtr& IndexExpr() { return gtOp2; }
3253 unsigned char gtCurrDim; // The current dimension
3254 unsigned char gtArrRank; // Rank of the array
3255 var_types gtArrElemType; // The array element type
3257 GenTreeArrIndex(var_types type, GenTreePtr arrObj, GenTreePtr indexExpr,
3258 unsigned char currDim, unsigned char arrRank, var_types elemType) :
3259 GenTreeOp(GT_ARR_INDEX, type, arrObj, indexExpr),
3260 gtCurrDim(currDim), gtArrRank(arrRank), gtArrElemType(elemType)
3262 gtFlags |= GTF_EXCEPT;
3264 #if DEBUGGABLE_GENTREE
3267 // Used only for GenTree::GetVtableForOper()
3268 GenTreeArrIndex() : GenTreeOp() {}
3272 // Represents either an InitBlk, InitObj, CpBlk or CpObj
3274 struct GenTreeBlkOp : public GenTreeOp
3277 // The destination for the CpBlk/CpObj/InitBlk/InitObj to copy bits to
3279 assert(gtOp1->gtOper == GT_LIST);
3280 return gtOp1->gtOp.gtOp1;
3283 // True if this BlkOpNode is a volatile memory operation.
3284 bool IsVolatile() const { return (gtFlags & GTF_BLK_VOLATILE) != 0; }
3286 // Instruction selection: during codegen time, what code sequence we will be using
3287 // to encode this operation.
3296 bool gtBlkOpGcUnsafe;
3298 GenTreeBlkOp(genTreeOps oper) :
3299 GenTreeOp(oper, TYP_VOID DEBUGARG(true)),
3300 gtBlkOpKind(BlkOpKindInvalid),
3301 gtBlkOpGcUnsafe(false)
3303 assert(OperIsBlkOp(oper));
3306 #if DEBUGGABLE_GENTREE
3309 GenTreeBlkOp() : GenTreeOp(){}
3310 #endif // DEBUGGABLE_GENTREE
3313 // gtObj -- 'object' (GT_OBJ). */
3315 struct GenTreeObj: public GenTreeUnOp
3317 // The address of the block.
3318 GenTreePtr& Addr() { return gtOp1; }
3320 CORINFO_CLASS_HANDLE gtClass; // the class of the object
3322 GenTreeObj(var_types type, GenTreePtr addr, CORINFO_CLASS_HANDLE cls) :
3323 GenTreeUnOp(GT_OBJ, type, addr),
3326 gtFlags |= GTF_GLOB_REF; // An Obj is always a global reference.
3329 #if DEBUGGABLE_GENTREE
3330 GenTreeObj() : GenTreeUnOp() {}
3334 // Represents a CpObj MSIL Node.
3335 struct GenTreeCpObj : public GenTreeBlkOp
3338 // The source for the CpBlk/CpObj to copy bits from
3339 GenTreePtr Source() {
3340 assert(gtOper == GT_COPYOBJ && gtOp1->gtOper == GT_LIST);
3341 return gtOp1->gtOp.gtOp2;
3344 // In the case of CopyObj, this is the class token that represents the type that is being copied.
3345 GenTreePtr ClsTok() { return gtOp2; }
3347 // If non-null, this array represents the gc-layout of the class that is being copied
3351 // If non-zero, this is the number of slots in the class layout that
3352 // contain gc-pointers.
3353 unsigned gtGcPtrCount;
3355 // If non-zero, the number of pointer-sized slots that constitutes the class token in CpObj.
3358 GenTreeCpObj(unsigned gcPtrCount, unsigned gtSlots, BYTE* gtGcPtrs) :
3359 GenTreeBlkOp(GT_COPYOBJ),
3361 gtGcPtrCount(gcPtrCount),
3364 #if DEBUGGABLE_GENTREE
3367 GenTreeCpObj() : GenTreeBlkOp(),
3371 #endif // DEBUGGABLE_GENTREE
3374 // Represents either an InitBlk or InitObj MSIL OpCode.
3375 struct GenTreeInitBlk : public GenTreeBlkOp
3379 // The value used to fill the destination buffer.
3380 GenTreePtr InitVal() { assert(gtOp1->gtOper == GT_LIST);
3381 return gtOp1->gtOp.gtOp2; }
3383 // The size of the buffer to be copied.
3384 GenTreePtr Size() { return gtOp2; }
3386 GenTreeInitBlk() : GenTreeBlkOp(GT_INITBLK){}
3388 #if DEBUGGABLE_GENTREE
3391 #endif // DEBUGGABLE_GENTREE
3394 // Represents a CpBlk or CpObj with no GC-pointers MSIL OpCode.
3395 struct GenTreeCpBlk : public GenTreeBlkOp
3399 // The value used to fill the destination buffer.
3400 // The source for the CpBlk/CpObj to copy bits from
3401 GenTreePtr Source() { assert(gtOp1->gtOper == GT_LIST);
3402 return gtOp1->gtOp.gtOp2; }
3404 // The size of the buffer to be copied.
3405 GenTreePtr Size() { return gtOp2; }
3407 GenTreeCpBlk() : GenTreeBlkOp(GT_COPYBLK){}
3409 #if DEBUGGABLE_GENTREE
3412 #endif // DEBUGGABLE_GENTREE
3415 //--------------------------------------------
3417 // GenTreeArrOffset (gtArrOffset): Expression to compute the accumulated offset for the address
3418 // of an element of a multi-dimensional or non-zero-based array.
3421 // The result of this expression is (gtOffset * dimSize) + gtIndex
3422 // where dimSize is the length/stride/size of the dimension, and is obtained from gtArrObj.
3423 // This node is generated in conjunction with the GenTreeArrIndex node, which computes the
3424 // effective index for a single dimension. The sub-trees can be separately optimized, e.g.
3425 // within a loop body where the expression for the 0th dimension may be invariant.
3427 // Here is an example of how the tree might look for a two-dimension array reference:
3431 // +--* ArrIndex[i, ]
3433 // /--| arrOffs[i, ]
3436 // +--* ArrIndex[*,j]
3438 // /--| arrOffs[*,j]
3439 // TODO-CQ: see comment on GenTreeArrIndex for how its representation may change. When that
3440 // is done, we will also want to replace the <arrObj> argument to arrOffs with the
3441 // ArrLen as for GenTreeArrIndex.
3443 struct GenTreeArrOffs: public GenTree
3445 GenTreePtr gtOffset; // The accumulated offset for lower dimensions - must be TYP_I_IMPL, and
3446 // will either be a CSE temp, the constant 0, or another GenTreeArrOffs node.
3447 GenTreePtr gtIndex; // The effective index for the current dimension - must be non-negative
3448 // and can be any expression (though it is likely to be either a GenTreeArrIndex,
3449 // node, a lclVar, or a constant).
3450 GenTreePtr gtArrObj; // The array object - may be any expression producing an Array reference,
3451 // but is likely to be a lclVar.
3452 unsigned char gtCurrDim; // The current dimension
3453 unsigned char gtArrRank; // Rank of the array
3454 var_types gtArrElemType; // The array element type
3456 GenTreeArrOffs(var_types type, GenTreePtr offset, GenTreePtr index, GenTreePtr arrObj,
3457 unsigned char currDim, unsigned char rank, var_types elemType) :
3458 GenTree(GT_ARR_OFFSET, type), gtOffset(offset), gtIndex(index), gtArrObj(arrObj),
3459 gtCurrDim(currDim), gtArrRank(rank), gtArrElemType(elemType)
3461 assert(index->gtFlags & GTF_EXCEPT);
3462 gtFlags |= GTF_EXCEPT;
3464 #if DEBUGGABLE_GENTREE
3465 GenTreeArrOffs() : GenTree() {}
3469 /* gtAddrMode -- Target-specific canonicalized addressing expression (GT_LEA) */
3471 struct GenTreeAddrMode: public GenTreeOp
3473 // Address is Base + Index*Scale + Offset.
3474 // These are the legal patterns:
3476 // Base // Base != nullptr && Index == nullptr && Scale == 0 && Offset == 0
3477 // Base + Index*Scale // Base != nullptr && Index != nullptr && Scale != 0 && Offset == 0
3478 // Base + Offset // Base != nullptr && Index == nullptr && Scale == 0 && Offset != 0
3479 // Base + Index*Scale + Offset // Base != nullptr && Index != nullptr && Scale != 0 && Offset != 0
3480 // Index*Scale // Base == nullptr && Index != nullptr && Scale > 1 && Offset == 0
3481 // Index*Scale + Offset // Base == nullptr && Index != nullptr && Scale > 1 && Offset != 0
3482 // Offset // Base == nullptr && Index == nullptr && Scale == 0 && Offset != 0
3485 // 1. Base + Index is legal with Scale==1
3486 // 2. If Index is null, Scale should be zero (or unintialized / unused)
3487 // 3. If Scale==1, then we should have "Base" instead of "Index*Scale", and "Base + Offset" instead of "Index*Scale + Offset".
3489 // First operand is base address/pointer
3490 bool HasBase() const { return gtOp1 != nullptr; }
3491 GenTreePtr& Base() { return gtOp1; }
3493 // Second operand is scaled index value
3494 bool HasIndex() const { return gtOp2 != nullptr; }
3495 GenTreePtr& Index() { return gtOp2; }
3497 unsigned gtScale; // The scale factor
3498 unsigned gtOffset; // The offset to add
3500 GenTreeAddrMode(var_types type, GenTreePtr base, GenTreePtr index,
3501 unsigned scale, unsigned offset) :
3502 GenTreeOp(GT_LEA, type, base, index )
3507 #if DEBUGGABLE_GENTREE
3510 // Used only for GenTree::GetVtableForOper()
3511 GenTreeAddrMode() : GenTreeOp() {}
3515 // Indir is just an op, no additional data, but some additional abstractions
3516 struct GenTreeIndir: public GenTreeOp
3518 // like an assign, op1 is the destination
3519 GenTreePtr& Addr() { return gtOp1; }
3521 // these methods provide an interface to the indirection node which
3529 GenTreeIndir(genTreeOps oper, var_types type, GenTree *addr, GenTree *data) :
3530 GenTreeOp(oper, type, addr, data)
3534 #if DEBUGGABLE_GENTREE
3537 // Used only for GenTree::GetVtableForOper()
3538 GenTreeIndir() : GenTreeOp() {}
3542 // Read-modify-write status of a RMW memory op rooted at a storeInd
3544 STOREIND_RMW_STATUS_UNKNOWN, // RMW status of storeInd unknown
3545 // Default status unless modified by IsRMWMemOpRootedAtStoreInd()
3547 // One of these denote storeind is a RMW memory operation.
3548 STOREIND_RMW_DST_IS_OP1, // StoreInd is known to be a RMW memory op and dst candidate is op1
3549 STOREIND_RMW_DST_IS_OP2, // StoreInd is known to be a RMW memory op and dst candidate is op2
3551 // One of these denote the reason for storeind is marked as non-RMW operation
3552 STOREIND_RMW_UNSUPPORTED_ADDR, // Addr mode is not yet supported for RMW memory
3553 STOREIND_RMW_UNSUPPORTED_OPER, // Operation is not supported for RMW memory
3554 STOREIND_RMW_UNSUPPORTED_TYPE, // Type is not supported for RMW memory
3555 STOREIND_RMW_INDIR_UNEQUAL // Indir to read value is not equivalent to indir that writes the value
3558 // StoreInd is just a BinOp, with additional RMW status
3559 struct GenTreeStoreInd: public GenTreeIndir
3561 #if !CPU_LOAD_STORE_ARCH
3562 // The below flag is set and used during lowering
3563 RMWStatus gtRMWStatus;
3565 bool IsRMWStatusUnknown() { return gtRMWStatus == STOREIND_RMW_STATUS_UNKNOWN; }
3566 bool IsNonRMWMemoryOp() {
3567 return gtRMWStatus == STOREIND_RMW_UNSUPPORTED_ADDR ||
3568 gtRMWStatus == STOREIND_RMW_UNSUPPORTED_OPER ||
3569 gtRMWStatus == STOREIND_RMW_UNSUPPORTED_TYPE ||
3570 gtRMWStatus == STOREIND_RMW_INDIR_UNEQUAL;
3572 bool IsRMWMemoryOp() { return gtRMWStatus == STOREIND_RMW_DST_IS_OP1 || gtRMWStatus == STOREIND_RMW_DST_IS_OP2; }
3573 bool IsRMWDstOp1() { return gtRMWStatus == STOREIND_RMW_DST_IS_OP1; }
3574 bool IsRMWDstOp2() { return gtRMWStatus == STOREIND_RMW_DST_IS_OP2; }
3575 #endif //!CPU_LOAD_STORE_ARCH
3577 RMWStatus GetRMWStatus() {
3578 #if !CPU_LOAD_STORE_ARCH
3581 return STOREIND_RMW_STATUS_UNKNOWN;
3585 void SetRMWStatusDefault()
3587 #if !CPU_LOAD_STORE_ARCH
3588 gtRMWStatus = STOREIND_RMW_STATUS_UNKNOWN;
3592 void SetRMWStatus(RMWStatus status)
3594 #if !CPU_LOAD_STORE_ARCH
3595 gtRMWStatus = status;
3599 GenTreePtr& Data() { return gtOp2; }
3601 GenTreeStoreInd(var_types type, GenTree *destPtr, GenTree *data) :
3602 GenTreeIndir(GT_STOREIND, type, destPtr, data)
3604 SetRMWStatusDefault();
3607 #if DEBUGGABLE_GENTREE
3610 // Used only for GenTree::GetVtableForOper()
3611 GenTreeStoreInd() : GenTreeIndir() { SetRMWStatusDefault(); }
3616 /* gtRetExp -- Place holder for the return expression from an inline candidate (GT_RET_EXPR) */
3618 struct GenTreeRetExpr: public GenTree
3620 GenTreePtr gtInlineCandidate;
3622 CORINFO_CLASS_HANDLE gtRetClsHnd;
3624 GenTreeRetExpr(var_types type) :
3625 GenTree(GT_RET_EXPR, type)
3627 #if DEBUGGABLE_GENTREE
3628 GenTreeRetExpr() : GenTree() {}
3633 /* gtStmt -- 'statement expr' (GT_STMT) */
3635 class InlineContext;
3637 struct GenTreeStmt: public GenTree
3639 GenTreePtr gtStmtExpr; // root of the expression tree
3640 GenTreePtr gtStmtList; // first node (for forward walks)
3641 InlineContext* gtInlineContext; // The inline context for this statement.
3643 #if defined(DEBUGGING_SUPPORT) || defined(DEBUG)
3644 IL_OFFSETX gtStmtILoffsx; // instr offset (if available)
3648 IL_OFFSET gtStmtLastILoffs;// instr offset at end of stmt
3651 bool gtStmtIsTopLevel()
3653 return (gtFlags & GTF_STMT_TOP_LEVEL) != 0;
3656 bool gtStmtIsEmbedded()
3658 return !gtStmtIsTopLevel();
3661 // Return the next statement, if it is embedded, otherwise nullptr
3662 GenTreeStmt* gtStmtNextIfEmbedded()
3664 GenTree* nextStmt = gtNext;
3665 if (nextStmt != nullptr && nextStmt->gtStmt.gtStmtIsEmbedded())
3667 return nextStmt->AsStmt();
3675 GenTree* gtStmtNextTopLevelStmt()
3677 GenTree* nextStmt = gtNext;
3678 while (nextStmt != nullptr && nextStmt->gtStmt.gtStmtIsEmbedded())
3680 nextStmt = nextStmt->gtNext;
3685 __declspec(property(get=getNextStmt))
3686 GenTreeStmt* gtNextStmt;
3688 __declspec(property(get=getPrevStmt))
3689 GenTreeStmt* gtPrevStmt;
3691 GenTreeStmt* getNextStmt()
3693 if (gtNext == nullptr)
3696 return gtNext->AsStmt();
3699 GenTreeStmt* getPrevStmt()
3701 if (gtPrev == nullptr)
3704 return gtPrev->AsStmt();
3707 GenTreeStmt(GenTreePtr expr, IL_OFFSETX offset)
3708 : GenTree(GT_STMT, TYP_VOID)
3710 , gtStmtList(nullptr)
3711 , gtInlineContext(nullptr)
3712 #if defined(DEBUGGING_SUPPORT) || defined(DEBUG)
3713 , gtStmtILoffsx(offset)
3716 , gtStmtLastILoffs(BAD_IL_OFFSET)
3719 // Statements can't have statements as part of their expression tree.
3720 assert(expr->gtOper != GT_STMT);
3722 gtFlags |= GTF_STMT_TOP_LEVEL;
3724 // Set the statement to have the same costs as the top node of the tree.
3725 // This is used long before costs have been assigned, so we need to copy
3730 #if DEBUGGABLE_GENTREE
3731 GenTreeStmt() : GenTree(GT_STMT, TYP_VOID) {}
3738 /* NOTE: Any tree nodes that are larger than 8 bytes (two ints or
3739 pointers) must be flagged as 'large' in GenTree::InitNodeSize().
3743 /* gtClsVar -- 'static data member' (GT_CLS_VAR) */
3745 struct GenTreeClsVar: public GenTree
3747 CORINFO_FIELD_HANDLE gtClsVarHnd;
3748 FieldSeqNode* gtFieldSeq;
3750 GenTreeClsVar(var_types type, CORINFO_FIELD_HANDLE clsVarHnd, FieldSeqNode* fldSeq) :
3751 GenTree(GT_CLS_VAR, type),
3752 gtClsVarHnd(clsVarHnd),
3755 gtFlags |= GTF_GLOB_REF;
3757 #if DEBUGGABLE_GENTREE
3758 GenTreeClsVar() : GenTree() {}
3762 /* gtArgPlace -- 'register argument placeholder' (GT_ARGPLACE) */
3764 struct GenTreeArgPlace: public GenTree
3766 CORINFO_CLASS_HANDLE gtArgPlaceClsHnd; // Needed when we have a TYP_STRUCT argument
3768 GenTreeArgPlace(var_types type, CORINFO_CLASS_HANDLE clsHnd) :
3769 GenTree(GT_ARGPLACE, type),
3770 gtArgPlaceClsHnd(clsHnd)
3772 #if DEBUGGABLE_GENTREE
3773 GenTreeArgPlace() : GenTree() {}
3777 /* gtLabel -- code label target (GT_LABEL) */
3779 struct GenTreeLabel: public GenTree
3781 BasicBlock* gtLabBB;
3783 GenTreeLabel(BasicBlock* bb) :
3784 GenTree(GT_LABEL, TYP_VOID),
3787 #if DEBUGGABLE_GENTREE
3788 GenTreeLabel() : GenTree() {}
3792 /* gtPhiArg -- phi node rhs argument, var = phi(phiarg, phiarg, phiarg...); GT_PHI_ARG */
3793 struct GenTreePhiArg: public GenTreeLclVarCommon
3795 BasicBlock * gtPredBB;
3797 GenTreePhiArg(var_types type, unsigned lclNum, unsigned snum, BasicBlock* block)
3798 : GenTreeLclVarCommon(GT_PHI_ARG, type, lclNum)
3804 #if DEBUGGABLE_GENTREE
3805 GenTreePhiArg() : GenTreeLclVarCommon() {}
3809 /* gtPutArgStk -- Argument passed on stack */
3811 struct GenTreePutArgStk: public GenTreeUnOp
3813 unsigned gtSlotNum; // Slot number of the argument to be passed on stack
3815 #if FEATURE_FASTTAILCALL
3816 bool putInIncomingArgArea; // Whether this arg needs to be placed in incoming arg area.
3817 // By default this is false and will be placed in out-going arg area.
3818 // Fast tail calls set this to true.
3819 // In future if we need to add more such bool fields consider bit fields.
3825 FEATURE_UNIX_AMD64_STRUCT_PASSING_ONLY_ARG(unsigned numSlots)
3826 FEATURE_UNIX_AMD64_STRUCT_PASSING_ONLY_ARG(bool isStruct),
3827 bool _putInIncomingArgArea = false
3828 DEBUGARG(GenTreePtr callNode = NULL)
3829 DEBUGARG(bool largeNode = false))
3831 GenTreeUnOp(oper, type DEBUGARG(largeNode)),
3833 putInIncomingArgArea(_putInIncomingArgArea)
3834 #ifdef FEATURE_UNIX_AMD64_STRUCT_PASSING
3835 , gtPutArgStkKind(PutArgStkKindInvalid),
3836 gtNumSlots(numSlots),
3837 gtIsStruct(isStruct),
3838 gtNumberReferenceSlots(0),
3840 #endif // FEATURE_UNIX_AMD64_STRUCT_PASSING
3853 FEATURE_UNIX_AMD64_STRUCT_PASSING_ONLY_ARG(unsigned numSlots)
3854 FEATURE_UNIX_AMD64_STRUCT_PASSING_ONLY_ARG(bool isStruct),
3855 bool _putInIncomingArgArea = false
3856 DEBUGARG(GenTreePtr callNode = NULL)
3857 DEBUGARG(bool largeNode = false))
3859 GenTreeUnOp(oper, type, op1 DEBUGARG(largeNode)),
3861 putInIncomingArgArea(_putInIncomingArgArea)
3862 #ifdef FEATURE_UNIX_AMD64_STRUCT_PASSING
3863 , gtPutArgStkKind(PutArgStkKindInvalid),
3864 gtNumSlots(numSlots),
3865 gtIsStruct(isStruct),
3866 gtNumberReferenceSlots(0),
3868 #endif // FEATURE_UNIX_AMD64_STRUCT_PASSING
3875 #else // !FEATURE_FASTTAILCALL
3881 FEATURE_UNIX_AMD64_STRUCT_PASSING_ONLY_ARG(unsigned numSlots)
3882 FEATURE_UNIX_AMD64_STRUCT_PASSING_ONLY_ARG(bool isStruct)
3883 DEBUGARG(GenTreePtr callNode = NULL)
3884 DEBUGARG(bool largeNode = false))
3886 GenTreeUnOp(oper, type DEBUGARG(largeNode)),
3888 #ifdef FEATURE_UNIX_AMD64_STRUCT_PASSING
3889 , gtPutArgStkKind(PutArgStkKindInvalid),
3890 gtNumSlots(numSlots),
3891 gtIsStruct(isStruct),
3892 gtNumberReferenceSlots(0),
3894 #endif // FEATURE_UNIX_AMD64_STRUCT_PASSING
3907 FEATURE_UNIX_AMD64_STRUCT_PASSING_ONLY_ARG(unsigned numSlots)
3908 FEATURE_UNIX_AMD64_STRUCT_PASSING_ONLY_ARG(bool isStruct)
3909 DEBUGARG(GenTreePtr callNode = NULL)
3910 DEBUGARG(bool largeNode = false))
3912 GenTreeUnOp(oper, type, op1 DEBUGARG(largeNode)),
3914 #ifdef FEATURE_UNIX_AMD64_STRUCT_PASSING
3915 , gtPutArgStkKind(PutArgStkKindInvalid),
3916 gtNumSlots(numSlots),
3917 gtIsStruct(isStruct),
3918 gtNumberReferenceSlots(0),
3920 #endif // FEATURE_UNIX_AMD64_STRUCT_PASSING
3926 #endif // FEATURE_FASTTAILCALL
3928 unsigned getArgOffset() { return gtSlotNum * TARGET_POINTER_SIZE; }
3930 #ifdef FEATURE_UNIX_AMD64_STRUCT_PASSING
3931 unsigned getArgSize() { return gtNumSlots * TARGET_POINTER_SIZE; }
3932 #endif // FEATURE_UNIX_AMD64_STRUCT_PASSING
3934 #ifdef FEATURE_UNIX_AMD64_STRUCT_PASSING
3935 //------------------------------------------------------------------------
3936 // setGcPointers: Sets the number of references and the layout of the struct object returned by the VM.
3939 // numPointers - Number of pointer references.
3940 // pointers - layout of the struct (with pointers marked.)
3946 // This data is used in the codegen for GT_PUTARG_STK to decide how to copy the struct to the stack by value.
3947 // If no pointer references are used, block copying instructions are used.
3948 // Otherwise the pointer reference slots are copied atomically in a way that gcinfo is emitted.
3949 // Any non pointer references between the pointer reference slots are copied in block fashion.
3951 void setGcPointers(unsigned numPointers, BYTE* pointers)
3953 gtNumberReferenceSlots = numPointers;
3954 gtGcPtrs = pointers;
3956 #endif // FEATURE_UNIX_AMD64_STRUCT_PASSING
3959 GenTreePtr gtCall; // the call node to which this argument belongs
3962 #ifdef FEATURE_UNIX_AMD64_STRUCT_PASSING
3963 // Instruction selection: during codegen time, what code sequence we will be using
3964 // to encode this operation.
3966 enum PutArgStkKind : __int8
3968 PutArgStkKindInvalid,
3969 PutArgStkKindRepInstr,
3970 PutArgStkKindUnroll,
3973 PutArgStkKind gtPutArgStkKind;
3975 unsigned gtNumSlots; // Number of slots for the argument to be passed on stack
3976 bool gtIsStruct; // This stack arg is a struct.
3977 unsigned gtNumberReferenceSlots; // Number of reference slots.
3978 BYTE* gtGcPtrs; // gcPointers
3979 #endif // FEATURE_UNIX_AMD64_STRUCT_PASSING
3981 #if DEBUGGABLE_GENTREE
3982 GenTreePutArgStk() : GenTreeUnOp() {}
3986 // Represents GT_COPY or GT_RELOAD node
3987 struct GenTreeCopyOrReload : public GenTreeUnOp
3989 // State required to support copy/reload of a multi-reg call node.
3990 // First register is is always given by gtRegNum.
3992 #if FEATURE_MULTIREG_RET
3993 regNumber gtOtherRegs[MAX_RET_REG_COUNT - 1];
3996 //----------------------------------------------------------
3997 // ClearOtherRegs: set gtOtherRegs to REG_NA.
4005 void ClearOtherRegs()
4007 #if FEATURE_MULTIREG_RET
4008 for (unsigned i = 0; i < MAX_RET_REG_COUNT - 1; ++i)
4010 gtOtherRegs[i] = REG_NA;
4015 //-----------------------------------------------------------
4016 // GetRegNumByIdx: Get regNumber of ith position.
4019 // idx - register position.
4022 // Returns regNumber assigned to ith position.
4024 regNumber GetRegNumByIdx(unsigned idx) const
4026 assert(idx < MAX_RET_REG_COUNT);
4033 #if FEATURE_MULTIREG_RET
4034 return gtOtherRegs[idx - 1];
4040 //-----------------------------------------------------------
4041 // SetRegNumByIdx: Set the regNumber for ith position.
4045 // idx - register position.
4050 void SetRegNumByIdx(regNumber reg, unsigned idx)
4052 assert(idx < MAX_RET_REG_COUNT);
4058 #if FEATURE_MULTIREG_RET
4061 gtOtherRegs[idx - 1] = reg;
4062 assert(gtOtherRegs[idx - 1] == reg);
4072 //----------------------------------------------------------------------------
4073 // CopyOtherRegs: copy multi-reg state from the given copy/reload node to this
4077 // from - GenTree node from which to copy multi-reg state
4082 // TODO-ARM: Implement this routine for Arm64 and Arm32
4083 // TODO-X86: Implement this routine for x86
4084 void CopyOtherRegs(GenTreeCopyOrReload* from)
4086 assert(OperGet() == from->OperGet());
4088 #ifdef FEATURE_UNIX_AMD64_STRUCT_PASSING
4089 for (unsigned i = 0; i < MAX_RET_REG_COUNT - 1; ++i)
4091 gtOtherRegs[i] = from->gtOtherRegs[i];
4096 GenTreeCopyOrReload(genTreeOps oper,
4098 GenTree* op1) : GenTreeUnOp(oper, type, op1)
4104 #if DEBUGGABLE_GENTREE
4105 GenTreeCopyOrReload() : GenTreeUnOp() {}
4109 //------------------------------------------------------------------------
4110 // Deferred inline functions of GenTree -- these need the subtypes above to
4111 // be defined already.
4112 //------------------------------------------------------------------------
4114 //------------------------------------------------------------------------
4115 // IsFPZero: Checks whether this is a floating point constant with value 0.0
4118 // Returns true iff the tree is an GT_CNS_DBL, with value of 0.0.
4120 inline bool GenTree::IsFPZero()
4122 if ((gtOper == GT_CNS_DBL) && (gtDblCon.gtDconVal == 0.0))
4127 //------------------------------------------------------------------------
4128 // IsIntegralConst: Checks whether this is a constant node with the given value
4131 // constVal - the value of interest
4134 // Returns true iff the tree is an integral constant opcode, with
4138 // Like gtIconVal, the argument is of ssize_t, so cannot check for
4139 // long constants in a target-independent way.
4141 inline bool GenTree::IsIntegralConst(ssize_t constVal)
4144 if ((gtOper == GT_CNS_INT) && (gtIntConCommon.IconValue() == constVal))
4147 if ((gtOper == GT_CNS_LNG) && (gtIntConCommon.LngValue() == constVal))
4153 inline bool GenTree::IsBoxedValue()
4155 assert(gtOper != GT_BOX || gtBox.BoxOp() != NULL);
4156 return (gtOper == GT_BOX) && (gtFlags & GTF_BOX_VALUE);
4159 inline GenTreePtr GenTree::MoveNext()
4166 //------------------------------------------------------------------------
4167 // IsListForMultiRegArg: Given an GenTree node that represents an argument
4168 // enforce (or don't enforce) the following invariant.
4170 // For LEGACY_BACKEND or architectures that don't support MultiReg args
4171 // we don't allow a GT_LIST at all.
4173 // Currently for AMD64 UNIX we allow a limited case where a GT_LIST is
4174 // allowed but every element must be a GT_LCL_FLD.
4176 // For the future targets that allow for Multireg args (and this includes
4177 // the current ARM64 target) we allow a GT_LIST of arbitrary nodes, these
4178 // would typically start out as GT_LCL_VARs or GT_LCL_FLDS or GT_INDs,
4179 // but could be changed into constants or GT_COMMA trees by the later
4180 // optimization phases.
4183 // instance method for a GenTree node
4186 // true: the GenTree node is accepted as a valid argument
4187 // false: the GenTree node is not accepted as a valid argumeny
4189 inline bool GenTree::IsListForMultiRegArg()
4193 // We don't have a GT_LIST, so just return true.
4196 else // We do have a GT_LIST
4198 #if defined(LEGACY_BACKEND) || !FEATURE_MULTIREG_ARGS
4200 // Not allowed to have a GT_LIST for an argument
4201 // unless we have a RyuJIT backend and FEATURE_MULTIREG_ARGS
4205 #else // we have RyuJIT backend and FEATURE_MULTIREG_ARGS
4207 #ifdef FEATURE_UNIX_AMD64_STRUCT_PASSING
4208 // For UNIX ABI we currently only allow a GT_LIST of GT_LCL_FLDs nodes
4209 GenTree* gtListPtr = this;
4210 while (gtListPtr != nullptr)
4212 // ToDo: fix UNIX_AMD64 so that we do not generate this kind of a List
4213 // Note the list as currently created is malformed, as the last entry is a nullptr
4214 if (gtListPtr->Current() == nullptr)
4217 // Only a list of GT_LCL_FLDs is allowed
4218 if (gtListPtr->Current()->OperGet() != GT_LCL_FLD)
4222 gtListPtr = gtListPtr->MoveNext();
4224 #endif // FEATURE_UNIX_AMD64_STRUCT_PASSING
4226 // Note that for non-UNIX ABI the GT_LIST may contain any node
4228 // We allow this GT_LIST as an argument
4231 #endif // RyuJIT backend and FEATURE_MULTIREG_ARGS
4236 inline GenTreePtr GenTree::Current()
4242 inline GenTreePtr *GenTree::pCurrent()
4245 return &(gtOp.gtOp1);
4248 inline GenTreePtr GenTree::gtGetOp1()
4255 inline bool GenTree::RequiresNonNullOp2(genTreeOps oper)
4308 inline GenTreePtr GenTree::gtGetOp2()
4310 /* gtOp.gtOp2 is only valid for GTK_BINOP nodes. */
4312 GenTreePtr op2 = OperIsBinary() ? gtOp.gtOp2 : nullptr;
4314 // This documents the genTreeOps for which gtOp.gtOp2 cannot be nullptr.
4315 // This helps prefix in its analyis of code which calls gtGetOp2()
4317 assert((op2 != nullptr) || !RequiresNonNullOp2(gtOper));
4322 inline GenTreePtr GenTree::gtEffectiveVal(bool commaOnly)
4327 return gtOp.gtOp2->gtEffectiveVal(commaOnly);
4330 if (!commaOnly && gtOp.gtOp1 != NULL)
4331 return gtOp.gtOp1->gtEffectiveVal();
4341 inline GenTree* GenTree::gtSkipReloadOrCopy()
4343 // There can be only one reload or copy (we can't have a reload/copy of a reload/copy)
4344 if (gtOper == GT_RELOAD || gtOper == GT_COPY)
4346 assert(gtGetOp1()->OperGet() != GT_RELOAD && gtGetOp1()->OperGet() != GT_COPY);
4352 //-----------------------------------------------------------------------------------
4353 // IsMultiRegCall: whether a call node returning its value in more than one register
4359 // Returns true if this GenTree is a multi register returning call
4360 inline bool GenTree::IsMultiRegCall() const
4364 // We cannot use AsCall() as it is not declared const
4365 const GenTreeCall* call = reinterpret_cast<const GenTreeCall *>(this);
4366 return call->HasMultiRegRetVal();
4372 //-------------------------------------------------------------------------
4373 // IsCopyOrReload: whether this is a GT_COPY or GT_RELOAD node.
4379 // Returns true if this GenTree is a copy or reload node.
4380 inline bool GenTree::IsCopyOrReload() const
4382 return (gtOper == GT_COPY || gtOper == GT_RELOAD);
4385 //-----------------------------------------------------------------------------------
4386 // IsCopyOrReloadOfMultiRegCall: whether this is a GT_COPY or GT_RELOAD of a multi-reg
4393 // Returns true if this GenTree is a copy or reload of multi-reg call node.
4394 inline bool GenTree::IsCopyOrReloadOfMultiRegCall() const
4396 if (IsCopyOrReload())
4398 GenTree* t = const_cast<GenTree*>(this);
4399 return t->gtGetOp1()->IsMultiRegCall();
4405 inline bool GenTree::IsCnsIntOrI() const
4407 return (gtOper == GT_CNS_INT);
4410 inline bool GenTree::IsIntegralConst() const
4412 #ifdef _TARGET_64BIT_
4413 return IsCnsIntOrI();
4414 #else // !_TARGET_64BIT_
4415 return ((gtOper == GT_CNS_INT) || (gtOper == GT_CNS_LNG));
4416 #endif // !_TARGET_64BIT_
4419 inline bool GenTree::IsIntCnsFitsInI32()
4421 #ifdef _TARGET_64BIT_
4422 return IsCnsIntOrI() && ((int)gtIntConCommon.IconValue() == gtIntConCommon.IconValue());
4423 #else // !_TARGET_64BIT_
4424 return IsCnsIntOrI();
4425 #endif // !_TARGET_64BIT_
4428 inline bool GenTree::IsCnsFltOrDbl() const
4430 return OperGet() == GT_CNS_DBL;
4433 inline bool GenTree::IsCnsNonZeroFltOrDbl()
4435 if (OperGet() == GT_CNS_DBL)
4437 double constValue = gtDblCon.gtDconVal;
4438 return *(__int64*)&constValue != 0;
4444 inline bool GenTree::IsHelperCall() { return OperGet() == GT_CALL && gtCall.gtCallType == CT_HELPER; }
4446 inline var_types GenTree::CastFromType() { return this->gtCast.CastOp()->TypeGet(); }
4447 inline var_types& GenTree::CastToType() { return this->gtCast.gtCastType; }
4450 /*****************************************************************************/
4452 #ifndef _HOST_64BIT_
4453 #include <poppack.h>
4456 /*****************************************************************************/
4458 #if SMALL_TREE_NODES
4460 // In debug, on some platforms (e.g., when LATE_DISASM is defined), GenTreeIntCon is bigger than GenTreeLclFld.
4462 size_t TREE_NODE_SZ_SMALL = max(sizeof(GenTreeIntCon), sizeof(GenTreeLclFld));
4464 #endif // SMALL_TREE_NODES
4467 size_t TREE_NODE_SZ_LARGE = sizeof(GenTreeCall);
4469 /*****************************************************************************
4470 * Types returned by GenTree::lvaLclVarRefs()
4475 VR_INVARIANT = 0x00, // an invariant value
4477 VR_IND_REF = 0x01, // an object reference
4478 VR_IND_SCL = 0x02, // a non-object reference
4479 VR_GLB_VAR = 0x04, // a global (clsVar)
4481 // Add a temp define to avoid merge conflict.
4482 #define VR_IND_PTR VR_IND_REF
4484 /*****************************************************************************/
4485 #endif // !GENTREE_H
4486 /*****************************************************************************/