This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
compiler.h
10736 lines (8854 loc) · 429 KB
/
compiler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX XX
XX Compiler XX
XX XX
XX Represents the method data we are currently JIT-compiling. XX
XX An instance of this class is created for every method we JIT. XX
XX This contains all the info needed for the method. So allocating a XX
XX a new instance per method makes it thread-safe. XX
XX It should be used to do all the memory management for the compiler run. XX
XX XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/
/*****************************************************************************/
#ifndef _COMPILER_H_
#define _COMPILER_H_
/*****************************************************************************/
#include "jit.h"
#include "opcode.h"
#include "varset.h"
#include "jitstd.h"
#include "jithashtable.h"
#include "gentree.h"
#include "lir.h"
#include "block.h"
#include "inline.h"
#include "jiteh.h"
#include "instr.h"
#include "regalloc.h"
#include "sm.h"
#include "cycletimer.h"
#include "blockset.h"
#include "arraystack.h"
#include "hashbv.h"
#include "jitexpandarray.h"
#include "tinyarray.h"
#include "valuenum.h"
#include "reglist.h"
#include "jittelemetry.h"
#include "namedintrinsiclist.h"
#ifdef LATE_DISASM
#include "disasm.h"
#endif
#include "codegeninterface.h"
#include "regset.h"
#include "jitgcinfo.h"
#if DUMP_GC_TABLES && defined(JIT32_GCENCODER)
#include "gcdump.h"
#endif
#include "emit.h"
#include "hwintrinsic.h"
#include "simd.h"
// This is only used locally in the JIT to indicate that
// a verification block should be inserted
#define SEH_VERIFICATION_EXCEPTION 0xe0564552 // VER
/*****************************************************************************
* Forward declarations
*/
struct InfoHdr; // defined in GCInfo.h
struct escapeMapping_t; // defined in flowgraph.cpp
class emitter; // defined in emit.h
struct ShadowParamVarInfo; // defined in GSChecks.cpp
struct InitVarDscInfo; // defined in register_arg_convention.h
class FgStack; // defined in flowgraph.cpp
#if FEATURE_ANYCSE
class CSE_DataFlow; // defined in OptCSE.cpp
#endif
#ifdef DEBUG
struct IndentStack;
#endif
class Lowering; // defined in lower.h
// The following are defined in this file, Compiler.h
class Compiler;
/*****************************************************************************
* Unwind info
*/
#include "unwind.h"
/*****************************************************************************/
//
// Declare global operator new overloads that use the compiler's arena allocator
//
// I wanted to make the second argument optional, with default = CMK_Unknown, but that
// caused these to be ambiguous with the global placement new operators.
void* __cdecl operator new(size_t n, Compiler* context, CompMemKind cmk);
void* __cdecl operator new[](size_t n, Compiler* context, CompMemKind cmk);
void* __cdecl operator new(size_t n, void* p, const jitstd::placement_t& syntax_difference);
// Requires the definitions of "operator new" so including "LoopCloning.h" after the definitions.
#include "loopcloning.h"
/*****************************************************************************/
/* This is included here and not earlier as it needs the definition of "CSE"
* which is defined in the section above */
/*****************************************************************************/
unsigned genLog2(unsigned value);
unsigned genLog2(unsigned __int64 value);
var_types genActualType(var_types type);
var_types genUnsignedType(var_types type);
var_types genSignedType(var_types type);
unsigned ReinterpretHexAsDecimal(unsigned);
/*****************************************************************************/
const unsigned FLG_CCTOR = (CORINFO_FLG_CONSTRUCTOR | CORINFO_FLG_STATIC);
#ifdef DEBUG
const int BAD_STK_OFFS = 0xBAADF00D; // for LclVarDsc::lvStkOffs
#endif
//------------------------------------------------------------------------
// HFA info shared by LclVarDsc and fgArgTabEntry
//------------------------------------------------------------------------
#ifdef FEATURE_HFA
enum HfaElemKind : unsigned int
{
HFA_ELEM_NONE,
HFA_ELEM_FLOAT,
HFA_ELEM_DOUBLE,
HFA_ELEM_SIMD16
};
inline bool IsHfa(HfaElemKind kind)
{
return kind != HFA_ELEM_NONE;
}
inline var_types HfaTypeFromElemKind(HfaElemKind kind)
{
switch (kind)
{
case HFA_ELEM_FLOAT:
return TYP_FLOAT;
case HFA_ELEM_DOUBLE:
return TYP_DOUBLE;
#ifdef FEATURE_SIMD
case HFA_ELEM_SIMD16:
return TYP_SIMD16;
#endif
case HFA_ELEM_NONE:
return TYP_UNDEF;
default:
assert(!"Invalid HfaElemKind");
return TYP_UNDEF;
}
}
inline HfaElemKind HfaElemKindFromType(var_types type)
{
switch (type)
{
case TYP_FLOAT:
return HFA_ELEM_FLOAT;
case TYP_DOUBLE:
return HFA_ELEM_DOUBLE;
#ifdef FEATURE_SIMD
case TYP_SIMD16:
return HFA_ELEM_SIMD16;
#endif
case TYP_UNDEF:
return HFA_ELEM_NONE;
default:
assert(!"Invalid HFA Type");
return HFA_ELEM_NONE;
}
}
#endif // FEATURE_HFA
// The following holds the Local var info (scope information)
typedef const char* VarName; // Actual ASCII string
struct VarScopeDsc
{
unsigned vsdVarNum; // (remapped) LclVarDsc number
unsigned vsdLVnum; // 'which' in eeGetLVinfo().
// Also, it is the index of this entry in the info.compVarScopes array,
// which is useful since the array is also accessed via the
// compEnterScopeList and compExitScopeList sorted arrays.
IL_OFFSET vsdLifeBeg; // instr offset of beg of life
IL_OFFSET vsdLifeEnd; // instr offset of end of life
#ifdef DEBUG
VarName vsdName; // name of the var
#endif
};
// This class stores information associated with a LclVar SSA definition.
class LclSsaVarDsc
{
// The basic block where the definition occurs. Definitions of uninitialized variables
// are considered to occur at the start of the first basic block (fgFirstBB).
//
// TODO-Cleanup: In the case of uninitialized variables the block is set to nullptr by
// SsaBuilder and changed to fgFirstBB during value numbering. It would be useful to
// investigate and perhaps eliminate this rather unexpected behavior.
BasicBlock* m_block;
// The GT_ASG node that generates the definition, or nullptr for definitions
// of uninitialized variables.
GenTreeOp* m_asg;
public:
LclSsaVarDsc() : m_block(nullptr), m_asg(nullptr)
{
}
LclSsaVarDsc(BasicBlock* block, GenTreeOp* asg) : m_block(block), m_asg(asg)
{
assert((asg == nullptr) || asg->OperIs(GT_ASG));
}
BasicBlock* GetBlock() const
{
return m_block;
}
void SetBlock(BasicBlock* block)
{
m_block = block;
}
GenTreeOp* GetAssignment() const
{
return m_asg;
}
void SetAssignment(GenTreeOp* asg)
{
assert((asg == nullptr) || asg->OperIs(GT_ASG));
m_asg = asg;
}
ValueNumPair m_vnPair;
};
// This class stores information associated with a memory SSA definition.
class SsaMemDef
{
public:
ValueNumPair m_vnPair;
};
//------------------------------------------------------------------------
// SsaDefArray: A resizable array of SSA definitions.
//
// Unlike an ordinary resizable array implementation, this allows only element
// addition (by calling AllocSsaNum) and has special handling for RESERVED_SSA_NUM
// (basically it's a 1-based array). The array doesn't impose any particular
// requirements on the elements it stores and AllocSsaNum forwards its arguments
// to the array element constructor, this way the array supports both LclSsaVarDsc
// and SsaMemDef elements.
//
template <typename T>
class SsaDefArray
{
T* m_array;
unsigned m_arraySize;
unsigned m_count;
static_assert_no_msg(SsaConfig::RESERVED_SSA_NUM == 0);
static_assert_no_msg(SsaConfig::FIRST_SSA_NUM == 1);
// Get the minimum valid SSA number.
unsigned GetMinSsaNum() const
{
return SsaConfig::FIRST_SSA_NUM;
}
// Increase (double) the size of the array.
void GrowArray(CompAllocator alloc)
{
unsigned oldSize = m_arraySize;
unsigned newSize = max(2, oldSize * 2);
T* newArray = alloc.allocate<T>(newSize);
for (unsigned i = 0; i < oldSize; i++)
{
newArray[i] = m_array[i];
}
m_array = newArray;
m_arraySize = newSize;
}
public:
// Construct an empty SsaDefArray.
SsaDefArray() : m_array(nullptr), m_arraySize(0), m_count(0)
{
}
// Reset the array (used only if the SSA form is reconstructed).
void Reset()
{
m_count = 0;
}
// Allocate a new SSA number (starting with SsaConfig::FIRST_SSA_NUM).
template <class... Args>
unsigned AllocSsaNum(CompAllocator alloc, Args&&... args)
{
if (m_count == m_arraySize)
{
GrowArray(alloc);
}
unsigned ssaNum = GetMinSsaNum() + m_count;
m_array[m_count++] = T(jitstd::forward<Args>(args)...);
// Ensure that the first SSA number we allocate is SsaConfig::FIRST_SSA_NUM
assert((ssaNum == SsaConfig::FIRST_SSA_NUM) || (m_count > 1));
return ssaNum;
}
// Get the number of SSA definitions in the array.
unsigned GetCount() const
{
return m_count;
}
// Get a pointer to the SSA definition at the specified index.
T* GetSsaDefByIndex(unsigned index)
{
assert(index < m_count);
return &m_array[index];
}
// Check if the specified SSA number is valid.
bool IsValidSsaNum(unsigned ssaNum) const
{
return (GetMinSsaNum() <= ssaNum) && (ssaNum < (GetMinSsaNum() + m_count));
}
// Get a pointer to the SSA definition associated with the specified SSA number.
T* GetSsaDef(unsigned ssaNum)
{
assert(ssaNum != SsaConfig::RESERVED_SSA_NUM);
return GetSsaDefByIndex(ssaNum - GetMinSsaNum());
}
};
enum RefCountState
{
RCS_INVALID, // not valid to get/set ref counts
RCS_EARLY, // early counts for struct promotion and struct passing
RCS_NORMAL, // normal ref counts (from lvaMarkRefs onward)
};
class LclVarDsc
{
public:
// The constructor. Most things can just be zero'ed.
//
// Initialize the ArgRegs to REG_STK.
// Morph will update if this local is passed in a register.
LclVarDsc()
: _lvArgReg(REG_STK)
,
#if FEATURE_MULTIREG_ARGS
_lvOtherArgReg(REG_STK)
,
#endif // FEATURE_MULTIREG_ARGS
#if ASSERTION_PROP
lvRefBlks(BlockSetOps::UninitVal())
,
#endif // ASSERTION_PROP
lvPerSsaData()
{
}
// note this only packs because var_types is a typedef of unsigned char
var_types lvType : 5; // TYP_INT/LONG/FLOAT/DOUBLE/REF
unsigned char lvIsParam : 1; // is this a parameter?
unsigned char lvIsRegArg : 1; // is this an argument that was passed by register?
unsigned char lvFramePointerBased : 1; // 0 = off of REG_SPBASE (e.g., ESP), 1 = off of REG_FPBASE (e.g., EBP)
unsigned char lvOnFrame : 1; // (part of) the variable lives on the frame
unsigned char lvRegister : 1; // assigned to live in a register? For RyuJIT backend, this is only set if the
// variable is in the same register for the entire function.
unsigned char lvTracked : 1; // is this a tracked variable?
bool lvTrackedNonStruct()
{
return lvTracked && lvType != TYP_STRUCT;
}
unsigned char lvPinned : 1; // is this a pinned variable?
unsigned char lvMustInit : 1; // must be initialized
unsigned char lvAddrExposed : 1; // The address of this variable is "exposed" -- passed as an argument, stored in a
// global location, etc.
// We cannot reason reliably about the value of the variable.
unsigned char lvDoNotEnregister : 1; // Do not enregister this variable.
unsigned char lvFieldAccessed : 1; // The var is a struct local, and a field of the variable is accessed. Affects
// struct promotion.
unsigned char lvInSsa : 1; // The variable is in SSA form (set by SsaBuilder)
#ifdef DEBUG
// These further document the reasons for setting "lvDoNotEnregister". (Note that "lvAddrExposed" is one of the
// reasons;
// also, lvType == TYP_STRUCT prevents enregistration. At least one of the reasons should be true.
unsigned char lvVMNeedsStackAddr : 1; // The VM may have access to a stack-relative address of the variable, and
// read/write its value.
unsigned char lvLiveInOutOfHndlr : 1; // The variable was live in or out of an exception handler, and this required
// the variable to be
// in the stack (at least at those boundaries.)
unsigned char lvLclFieldExpr : 1; // The variable is not a struct, but was accessed like one (e.g., reading a
// particular byte from an int).
unsigned char lvLclBlockOpAddr : 1; // The variable was written to via a block operation that took its address.
unsigned char lvLiveAcrossUCall : 1; // The variable is live across an unmanaged call.
#endif
unsigned char lvIsCSE : 1; // Indicates if this LclVar is a CSE variable.
unsigned char lvHasLdAddrOp : 1; // has ldloca or ldarga opcode on this local.
unsigned char lvStackByref : 1; // This is a compiler temporary of TYP_BYREF that is known to point into our local
// stack frame.
unsigned char lvHasILStoreOp : 1; // there is at least one STLOC or STARG on this local
unsigned char lvHasMultipleILStoreOp : 1; // there is more than one STLOC on this local
unsigned char lvIsTemp : 1; // Short-lifetime compiler temp
#if defined(_TARGET_AMD64_) || defined(_TARGET_ARM64_)
unsigned char lvIsImplicitByRef : 1; // Set if the argument is an implicit byref.
#endif // defined(_TARGET_AMD64_) || defined(_TARGET_ARM64_)
#if OPT_BOOL_OPS
unsigned char lvIsBoolean : 1; // set if variable is boolean
#endif
unsigned char lvSingleDef : 1; // variable has a single def
// before lvaMarkLocalVars: identifies ref type locals that can get type updates
// after lvaMarkLocalVars: identifies locals that are suitable for optAddCopies
#if ASSERTION_PROP
unsigned char lvDisqualify : 1; // variable is no longer OK for add copy optimization
unsigned char lvVolatileHint : 1; // hint for AssertionProp
#endif
#ifndef _TARGET_64BIT_
unsigned char lvStructDoubleAlign : 1; // Must we double align this struct?
#endif // !_TARGET_64BIT_
#ifdef _TARGET_64BIT_
unsigned char lvQuirkToLong : 1; // Quirk to allocate this LclVar as a 64-bit long
#endif
#ifdef DEBUG
unsigned char lvKeepType : 1; // Don't change the type of this variable
unsigned char lvNoLclFldStress : 1; // Can't apply local field stress on this one
#endif
unsigned char lvIsPtr : 1; // Might this be used in an address computation? (used by buffer overflow security
// checks)
unsigned char lvIsUnsafeBuffer : 1; // Does this contain an unsafe buffer requiring buffer overflow security checks?
unsigned char lvPromoted : 1; // True when this local is a promoted struct, a normed struct, or a "split" long on a
// 32-bit target. For implicit byref parameters, this gets hijacked between
// fgRetypeImplicitByRefArgs and fgMarkDemotedImplicitByRefArgs to indicate whether
// references to the arg are being rewritten as references to a promoted shadow local.
unsigned char lvIsStructField : 1; // Is this local var a field of a promoted struct local?
unsigned char lvOverlappingFields : 1; // True when we have a struct with possibly overlapping fields
unsigned char lvContainsHoles : 1; // True when we have a promoted struct that contains holes
unsigned char lvCustomLayout : 1; // True when this struct has "CustomLayout"
unsigned char lvIsMultiRegArg : 1; // true if this is a multireg LclVar struct used in an argument context
unsigned char lvIsMultiRegRet : 1; // true if this is a multireg LclVar struct assigned from a multireg call
#ifdef FEATURE_HFA
HfaElemKind _lvHfaElemKind : 2; // What kind of an HFA this is (HFA_ELEM_NONE if it is not an HFA).
#endif // FEATURE_HFA
#ifdef DEBUG
// TODO-Cleanup: See the note on lvSize() - this flag is only in use by asserts that are checking for struct
// types, and is needed because of cases where TYP_STRUCT is bashed to an integral type.
// Consider cleaning this up so this workaround is not required.
unsigned char lvUnusedStruct : 1; // All references to this promoted struct are through its field locals.
// I.e. there is no longer any reference to the struct directly.
// In this case we can simply remove this struct local.
#endif
unsigned char lvLRACandidate : 1; // Tracked for linear scan register allocation purposes
#ifdef FEATURE_SIMD
// Note that both SIMD vector args and locals are marked as lvSIMDType = true, but the
// type of an arg node is TYP_BYREF and a local node is TYP_SIMD*.
unsigned char lvSIMDType : 1; // This is a SIMD struct
unsigned char lvUsedInSIMDIntrinsic : 1; // This tells lclvar is used for simd intrinsic
var_types lvBaseType : 5; // Note: this only packs because var_types is a typedef of unsigned char
#endif // FEATURE_SIMD
unsigned char lvRegStruct : 1; // This is a reg-sized non-field-addressed struct.
unsigned char lvClassIsExact : 1; // lvClassHandle is the exact type
#ifdef DEBUG
unsigned char lvClassInfoUpdated : 1; // true if this var has updated class handle or exactness
#endif
unsigned char lvImplicitlyReferenced : 1; // true if there are non-IR references to this local (prolog, epilog, gc,
// eh)
union {
unsigned lvFieldLclStart; // The index of the local var representing the first field in the promoted struct
// local. For implicit byref parameters, this gets hijacked between
// fgRetypeImplicitByRefArgs and fgMarkDemotedImplicitByRefArgs to point to the
// struct local created to model the parameter's struct promotion, if any.
unsigned lvParentLcl; // The index of the local var representing the parent (i.e. the promoted struct local).
// Valid on promoted struct local fields.
};
unsigned char lvFieldCnt; // Number of fields in the promoted VarDsc.
unsigned char lvFldOffset;
unsigned char lvFldOrdinal;
#if FEATURE_MULTIREG_ARGS
regNumber lvRegNumForSlot(unsigned slotNum)
{
if (slotNum == 0)
{
return (regNumber)_lvArgReg;
}
else if (slotNum == 1)
{
return GetOtherArgReg();
}
else
{
assert(false && "Invalid slotNum!");
}
unreached();
}
#endif // FEATURE_MULTIREG_ARGS
bool lvIsHfa() const
{
#ifdef FEATURE_HFA
return IsHfa(_lvHfaElemKind);
#else
return false;
#endif
}
bool lvIsHfaRegArg() const
{
#ifdef FEATURE_HFA
return lvIsRegArg && lvIsHfa();
#else
return false;
#endif
}
//------------------------------------------------------------------------------
// lvHfaSlots: Get the number of slots used by an HFA local
//
// Return Value:
// On Arm64 - Returns 1-4 indicating the number of register slots used by the HFA
// On Arm32 - Returns the total number of single FP register slots used by the HFA, max is 8
//
unsigned lvHfaSlots() const
{
assert(lvIsHfa());
assert(varTypeIsStruct(lvType));
unsigned slots = 0;
#ifdef _TARGET_ARM_
slots = lvExactSize / sizeof(float);
assert(slots <= 8);
#elif defined(_TARGET_ARM64_)
switch (_lvHfaElemKind)
{
case HFA_ELEM_NONE:
assert(!"lvHfaSlots called for non-HFA");
break;
case HFA_ELEM_FLOAT:
assert((lvExactSize % 4) == 0);
slots = lvExactSize >> 2;
break;
case HFA_ELEM_DOUBLE:
assert((lvExactSize % 8) == 0);
slots = lvExactSize >> 3;
break;
case HFA_ELEM_SIMD16:
assert((lvExactSize % 16) == 0);
slots = lvExactSize >> 4;
break;
default:
unreached();
}
assert(slots <= 4);
#endif // _TARGET_ARM64_
return slots;
}
// lvIsMultiRegArgOrRet()
// returns true if this is a multireg LclVar struct used in an argument context
// or if this is a multireg LclVar struct assigned from a multireg call
bool lvIsMultiRegArgOrRet()
{
return lvIsMultiRegArg || lvIsMultiRegRet;
}
private:
regNumberSmall _lvRegNum; // Used to store the register this variable is in (or, the low register of a
// register pair). It is set during codegen any time the
// variable is enregistered (lvRegister is only set
// to non-zero if the variable gets the same register assignment for its entire
// lifetime).
#if !defined(_TARGET_64BIT_)
regNumberSmall _lvOtherReg; // Used for "upper half" of long var.
#endif // !defined(_TARGET_64BIT_)
regNumberSmall _lvArgReg; // The (first) register in which this argument is passed.
#if FEATURE_MULTIREG_ARGS
regNumberSmall _lvOtherArgReg; // Used for the second part of the struct passed in a register.
// Note this is defined but not used by ARM32
#endif // FEATURE_MULTIREG_ARGS
regNumberSmall _lvArgInitReg; // the register into which the argument is moved at entry
public:
// The register number is stored in a small format (8 bits), but the getters return and the setters take
// a full-size (unsigned) format, to localize the casts here.
/////////////////////
regNumber GetRegNum() const
{
return (regNumber)_lvRegNum;
}
void SetRegNum(regNumber reg)
{
_lvRegNum = (regNumberSmall)reg;
assert(_lvRegNum == reg);
}
/////////////////////
#if defined(_TARGET_64BIT_)
regNumber GetOtherReg() const
{
assert(!"shouldn't get here"); // can't use "unreached();" because it's NORETURN, which causes C4072
// "unreachable code" warnings
return REG_NA;
}
void SetOtherReg(regNumber reg)
{
assert(!"shouldn't get here"); // can't use "unreached();" because it's NORETURN, which causes C4072
// "unreachable code" warnings
}
#else // !_TARGET_64BIT_
regNumber GetOtherReg() const
{
return (regNumber)_lvOtherReg;
}
void SetOtherReg(regNumber reg)
{
_lvOtherReg = (regNumberSmall)reg;
assert(_lvOtherReg == reg);
}
#endif // !_TARGET_64BIT_
/////////////////////
regNumber GetArgReg() const
{
return (regNumber)_lvArgReg;
}
void SetArgReg(regNumber reg)
{
_lvArgReg = (regNumberSmall)reg;
assert(_lvArgReg == reg);
}
#if FEATURE_MULTIREG_ARGS
regNumber GetOtherArgReg() const
{
return (regNumber)_lvOtherArgReg;
}
void SetOtherArgReg(regNumber reg)
{
_lvOtherArgReg = (regNumberSmall)reg;
assert(_lvOtherArgReg == reg);
}
#endif // FEATURE_MULTIREG_ARGS
#ifdef FEATURE_SIMD
// Is this is a SIMD struct?
bool lvIsSIMDType() const
{
return lvSIMDType;
}
// Is this is a SIMD struct which is used for SIMD intrinsic?
bool lvIsUsedInSIMDIntrinsic() const
{
return lvUsedInSIMDIntrinsic;
}
#else
// If feature_simd not enabled, return false
bool lvIsSIMDType() const
{
return false;
}
bool lvIsUsedInSIMDIntrinsic() const
{
return false;
}
#endif
/////////////////////
regNumber GetArgInitReg() const
{
return (regNumber)_lvArgInitReg;
}
void SetArgInitReg(regNumber reg)
{
_lvArgInitReg = (regNumberSmall)reg;
assert(_lvArgInitReg == reg);
}
/////////////////////
bool lvIsRegCandidate() const
{
return lvLRACandidate != 0;
}
bool lvIsInReg() const
{
return lvIsRegCandidate() && (GetRegNum() != REG_STK);
}
regMaskTP lvRegMask() const
{
regMaskTP regMask = RBM_NONE;
if (varTypeIsFloating(TypeGet()))
{
if (GetRegNum() != REG_STK)
{
regMask = genRegMaskFloat(GetRegNum(), TypeGet());
}
}
else
{
if (GetRegNum() != REG_STK)
{
regMask = genRegMask(GetRegNum());
}
}
return regMask;
}
unsigned short lvVarIndex; // variable tracking index
private:
unsigned short m_lvRefCnt; // unweighted (real) reference count. For implicit by reference
// parameters, this gets hijacked from fgResetImplicitByRefRefCount
// through fgMarkDemotedImplicitByRefArgs, to provide a static
// appearance count (computed during address-exposed analysis)
// that fgMakeOutgoingStructArgCopy consults during global morph
// to determine if eliding its copy is legal.
BasicBlock::weight_t m_lvRefCntWtd; // weighted reference count
public:
unsigned short lvRefCnt(RefCountState state = RCS_NORMAL) const;
void incLvRefCnt(unsigned short delta, RefCountState state = RCS_NORMAL);
void setLvRefCnt(unsigned short newValue, RefCountState state = RCS_NORMAL);
BasicBlock::weight_t lvRefCntWtd(RefCountState state = RCS_NORMAL) const;
void incLvRefCntWtd(BasicBlock::weight_t delta, RefCountState state = RCS_NORMAL);
void setLvRefCntWtd(BasicBlock::weight_t newValue, RefCountState state = RCS_NORMAL);
int lvStkOffs; // stack offset of home
unsigned lvExactSize; // (exact) size of the type in bytes
// Is this a promoted struct?
// This method returns true only for structs (including SIMD structs), not for
// locals that are split on a 32-bit target.
// It is only necessary to use this:
// 1) if only structs are wanted, and
// 2) if Lowering has already been done.
// Otherwise lvPromoted is valid.
bool lvPromotedStruct()
{
#if !defined(_TARGET_64BIT_)
return (lvPromoted && !varTypeIsLong(lvType));
#else // defined(_TARGET_64BIT_)
return lvPromoted;
#endif // defined(_TARGET_64BIT_)
}
unsigned lvSize() const // Size needed for storage representation. Only used for structs or TYP_BLK.
{
// TODO-Review: Sometimes we get called on ARM with HFA struct variables that have been promoted,
// where the struct itself is no longer used because all access is via its member fields.
// When that happens, the struct is marked as unused and its type has been changed to
// TYP_INT (to keep the GC tracking code from looking at it).
// See Compiler::raAssignVars() for details. For example:
// N002 ( 4, 3) [00EA067C] ------------- return struct $346
// N001 ( 3, 2) [00EA0628] ------------- lclVar struct(U) V03 loc2
// float V03.f1 (offs=0x00) -> V12 tmp7
// f8 (last use) (last use) $345
// Here, the "struct(U)" shows that the "V03 loc2" variable is unused. Not shown is that V03
// is now TYP_INT in the local variable table. It's not really unused, because it's in the tree.
assert(varTypeIsStruct(lvType) || (lvType == TYP_BLK) || (lvPromoted && lvUnusedStruct));
#if defined(FEATURE_SIMD) && !defined(_TARGET_64BIT_)
// For 32-bit architectures, we make local variable SIMD12 types 16 bytes instead of just 12. We can't do
// this for arguments, which must be passed according the defined ABI. We don't want to do this for
// dependently promoted struct fields, but we don't know that here. See lvaMapSimd12ToSimd16().
// (Note that for 64-bits, we are already rounding up to 16.)
if ((lvType == TYP_SIMD12) && !lvIsParam)
{
assert(lvExactSize == 12);
return 16;
}
#endif // defined(FEATURE_SIMD) && !defined(_TARGET_64BIT_)
return roundUp(lvExactSize, TARGET_POINTER_SIZE);
}
size_t lvArgStackSize() const;
unsigned lvSlotNum; // original slot # (if remapped)
typeInfo lvVerTypeInfo; // type info needed for verification
CORINFO_CLASS_HANDLE lvClassHnd; // class handle for the local, or null if not known
CORINFO_FIELD_HANDLE lvFieldHnd; // field handle for promoted struct fields
private:
ClassLayout* m_layout; // layout info for structs
public:
#if ASSERTION_PROP
BlockSet lvRefBlks; // Set of blocks that contain refs
Statement* lvDefStmt; // Pointer to the statement with the single definition
void lvaDisqualifyVar(); // Call to disqualify a local variable from use in optAddCopies
#endif
var_types TypeGet() const
{
return (var_types)lvType;
}
bool lvStackAligned() const
{
assert(lvIsStructField);
return ((lvFldOffset % TARGET_POINTER_SIZE) == 0);
}
bool lvNormalizeOnLoad() const
{
return varTypeIsSmall(TypeGet()) &&
// lvIsStructField is treated the same as the aliased local, see fgDoNormalizeOnStore.
(lvIsParam || lvAddrExposed || lvIsStructField);
}
bool lvNormalizeOnStore()
{
return varTypeIsSmall(TypeGet()) &&
// lvIsStructField is treated the same as the aliased local, see fgDoNormalizeOnStore.
!(lvIsParam || lvAddrExposed || lvIsStructField);
}
void incRefCnts(BasicBlock::weight_t weight,
Compiler* pComp,
RefCountState state = RCS_NORMAL,
bool propagate = true);
bool IsFloatRegType() const
{
return isFloatRegType(lvType) || lvIsHfaRegArg();
}
var_types GetHfaType() const
{
#ifdef FEATURE_HFA
assert(lvIsHfa());
return HfaTypeFromElemKind(_lvHfaElemKind);
#else
return TYP_UNDEF;
#endif // FEATURE_HFA
}
void SetHfaType(var_types type)
{
#ifdef FEATURE_HFA
_lvHfaElemKind = HfaElemKindFromType(type);
#endif // FEATURE_HFA
}
var_types lvaArgType();
// Returns true if this variable contains GC pointers (including being a GC pointer itself).
bool HasGCPtr()
{
return varTypeIsGC(lvType) || ((lvType == TYP_STRUCT) && m_layout->HasGCPtr());
}
// Returns the layout of a struct variable.
ClassLayout* GetLayout()
{
assert(varTypeIsStruct(lvType));
return m_layout;
}
// Sets the layout of a struct variable.
void SetLayout(ClassLayout* layout)
{
assert(varTypeIsStruct(lvType));
m_layout = layout;
}
SsaDefArray<LclSsaVarDsc> lvPerSsaData;
// Returns the address of the per-Ssa data for the given ssaNum (which is required
// not to be the SsaConfig::RESERVED_SSA_NUM, which indicates that the variable is
// not an SSA variable).
LclSsaVarDsc* GetPerSsaData(unsigned ssaNum)
{
return lvPerSsaData.GetSsaDef(ssaNum);
}
#ifdef DEBUG
public:
const char* lvReason;
void PrintVarReg() const
{
printf("%s", getRegName(GetRegNum()));
}
#endif // DEBUG
}; // class LclVarDsc
/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX XX
XX TempsInfo XX
XX XX
XX The temporary lclVars allocated by the compiler for code generation XX
XX XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/
/*****************************************************************************
*
* The following keeps track of temporaries allocated in the stack frame
* during code-generation (after register allocation). These spill-temps are
* only used if we run out of registers while evaluating a tree.
*
* These are different from the more common temps allocated by lvaGrabTemp().
*/
class TempDsc
{
public:
TempDsc* tdNext;
private:
int tdOffs;
#ifdef DEBUG
static const int BAD_TEMP_OFFSET = 0xDDDDDDDD; // used as a sentinel "bad value" for tdOffs in DEBUG
#endif // DEBUG
int tdNum;
BYTE tdSize;
var_types tdType;
public: