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
10362 lines (8509 loc) · 420 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 "gentree.h"
#include "lir.h"
#include "block.h"
#include "inline.h"
#include "jiteh.h"
#include "instr.h"
#include "regalloc.h"
#include "sm.h"
#include "simplerhash.h"
#include "cycletimer.h"
#include "blockset.h"
#include "jitstd.h"
#include "arraystack.h"
#include "hashbv.h"
#include "fp.h"
#include "expandarray.h"
#include "tinyarray.h"
#include "valuenum.h"
#include "reglist.h"
#include "jittelemetry.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 "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_STACK_FP_X87
struct FlatFPStateX87; // defined in fp.h
#endif
#if FEATURE_ANYCSE
class CSE_DataFlow; // defined in OptCSE.cpp
#endif
#ifdef DEBUG
struct IndentStack;
#endif
#ifndef LEGACY_BACKEND
class Lowering; // defined in lower.h
#endif
// 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::compGetMem() function for allocation.
//
// Or the more-general IAllocator interface.
void* __cdecl operator new(size_t n, IAllocator* alloc);
void* __cdecl operator new[](size_t n, IAllocator* alloc);
// 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);
/*****************************************************************************/
#ifdef FEATURE_SIMD
#ifdef FEATURE_AVX_SUPPORT
const unsigned TEMP_MAX_SIZE = YMM_REGSIZE_BYTES;
#else // !FEATURE_AVX_SUPPORT
const unsigned TEMP_MAX_SIZE = XMM_REGSIZE_BYTES;
#endif // !FEATURE_AVX_SUPPORT
#else // !FEATURE_SIMD
const unsigned TEMP_MAX_SIZE = sizeof(double);
#endif // !FEATURE_SIMD
const unsigned TEMP_SLOT_COUNT = (TEMP_MAX_SIZE / sizeof(int));
const unsigned FLG_CCTOR = (CORINFO_FLG_CONSTRUCTOR | CORINFO_FLG_STATIC);
#ifdef DEBUG
const int BAD_STK_OFFS = 0xBAADF00D; // for LclVarDsc::lvStkOffs
#endif
// The following holds the Local var info (scope information)
typedef const char* VarName; // Actual ASCII string
struct VarScopeDsc
{
IL_OFFSET vsdLifeBeg; // instr offset of beg of life
IL_OFFSET vsdLifeEnd; // instr offset of end of life
unsigned vsdVarNum; // (remapped) LclVarDsc number
#ifdef DEBUG
VarName vsdName; // name of the var
#endif
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.
};
/*****************************************************************************
*
* The following holds the local variable counts and the descriptor table.
*/
// This is the location of a definition.
struct DefLoc
{
BasicBlock* m_blk;
GenTreePtr m_tree;
DefLoc() : m_blk(nullptr), m_tree(nullptr)
{
}
};
// This class encapsulates all info about a local variable that may vary for different SSA names
// in the family.
class LclSsaVarDsc
{
public:
ValueNumPair m_vnPair;
DefLoc m_defLoc;
LclSsaVarDsc()
{
}
};
typedef ExpandArray<LclSsaVarDsc> PerSsaArray;
class LclVarDsc
{
public:
// The constructor. Most things can just be zero'ed.
LclVarDsc(Compiler* comp);
// 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 a register argument?
unsigned char lvFramePointerBased : 1; // 0 = off of REG_SPBASE (e.g., ESP), 1 = off of REG_FPBASE (e.g., EBP)
unsigned char lvStructGcCount : 3; // if struct, how many GC pointer (stop counting at 7). The only use of values >1
// is to help determine whether to use block init in the prolog.
unsigned char lvOnFrame : 1; // (part of) the variable lives on the frame
unsigned char lvDependReg : 1; // did the predictor depend upon this being enregistered
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.
#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 lvRefAssign : 1; // involved in pointer assignment
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 lvIsParam is false), or implicit byref parameter
// (if lvIsParam is true)
#if OPT_BOOL_OPS
unsigned char lvIsBoolean : 1; // set if variable is boolean
#endif
unsigned char lvRngOptDone : 1; // considered for range check opt?
unsigned char lvLoopInc : 1; // incremented in the loop?
unsigned char lvLoopAsg : 1; // reassigned in the loop (other than a monotonic inc/dec for the index var)?
unsigned char lvArrIndx : 1; // used as an array index?
unsigned char lvArrIndxOff : 1; // used as an array index with an offset?
unsigned char lvArrIndxDom : 1; // index dominates loop exit
#if ASSERTION_PROP
unsigned char lvSingleDef : 1; // variable has a single def
unsigned char lvDisqualify : 1; // variable is no longer OK for add copy optimization
unsigned char lvVolatileHint : 1; // hint for AssertionProp
#endif
unsigned char lvSpilled : 1; // enregistered variable was spilled
#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 lvContainsFloatingFields : 1; // Does this struct contains floating point fields?
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
unsigned char _lvIsHfa : 1; // Is this a struct variable who's class handle is an HFA type
unsigned char _lvIsHfaRegArg : 1; // Is this a HFA argument variable? // TODO-CLEANUP: Remove this and replace
// with (lvIsRegArg && lvIsHfa())
unsigned char _lvHfaTypeIsFloat : 1; // Is the HFA type float or double?
#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
#ifndef LEGACY_BACKEND
unsigned char lvLRACandidate : 1; // Tracked for linear scan register allocation purposes
#endif // !LEGACY_BACKEND
#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
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 lvArgReg;
}
else if (slotNum == 1)
{
return lvOtherArgReg;
}
else
{
assert(false && "Invalid slotNum!");
}
unreached();
}
#endif // FEATURE_MULTIREG_ARGS
bool lvIsHfa() const
{
#ifdef FEATURE_HFA
return _lvIsHfa;
#else
return false;
#endif
}
void lvSetIsHfa()
{
#ifdef FEATURE_HFA
_lvIsHfa = true;
#endif
}
bool lvIsHfaRegArg() const
{
#ifdef FEATURE_HFA
return _lvIsHfaRegArg;
#else
return false;
#endif
}
void lvSetIsHfaRegArg(bool value = true)
{
#ifdef FEATURE_HFA
_lvIsHfaRegArg = value;
#endif
}
bool lvHfaTypeIsFloat() const
{
#ifdef FEATURE_HFA
return _lvHfaTypeIsFloat;
#else
return false;
#endif
}
void lvSetHfaTypeIsFloat(bool value)
{
#ifdef FEATURE_HFA
_lvHfaTypeIsFloat = value;
#endif
}
// 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(lvType == TYP_STRUCT);
#ifdef _TARGET_ARM_
return lvExactSize / sizeof(float);
#else // _TARGET_ARM64_
if (lvHfaTypeIsFloat())
{
return lvExactSize / sizeof(float);
}
else
{
return lvExactSize / sizeof(double);
}
#endif // _TARGET_ARM64_
}
// 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). For LEGACY_BACKEND, this is only set if lvRegister is
// non-zero. For non-LEGACY_BACKEND, it is set during codegen any time the
// variable is enregistered (in non-LEGACY_BACKEND, 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 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
#ifndef LEGACY_BACKEND
union {
regNumberSmall _lvArgInitReg; // the register into which the argument is moved at entry
regPairNoSmall _lvArgInitRegPair; // the register pair into which the argument is moved at entry
};
#endif // !LEGACY_BACKEND
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.
/////////////////////
__declspec(property(get = GetRegNum, put = SetRegNum)) regNumber lvRegNum;
regNumber GetRegNum() const
{
return (regNumber)_lvRegNum;
}
void SetRegNum(regNumber reg)
{
_lvRegNum = (regNumberSmall)reg;
assert(_lvRegNum == reg);
}
/////////////////////
#if defined(_TARGET_64BIT_)
__declspec(property(get = GetOtherReg, put = SetOtherReg)) regNumber lvOtherReg;
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_
__declspec(property(get = GetOtherReg, put = SetOtherReg)) regNumber lvOtherReg;
regNumber GetOtherReg() const
{
return (regNumber)_lvOtherReg;
}
void SetOtherReg(regNumber reg)
{
_lvOtherReg = (regNumberSmall)reg;
assert(_lvOtherReg == reg);
}
#endif // !_TARGET_64BIT_
/////////////////////
__declspec(property(get = GetArgReg, put = SetArgReg)) regNumber lvArgReg;
regNumber GetArgReg() const
{
return (regNumber)_lvArgReg;
}
void SetArgReg(regNumber reg)
{
_lvArgReg = (regNumberSmall)reg;
assert(_lvArgReg == reg);
}
#if FEATURE_MULTIREG_ARGS
__declspec(property(get = GetOtherArgReg, put = SetOtherArgReg)) regNumber lvOtherArgReg;
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
/////////////////////
#ifndef LEGACY_BACKEND
__declspec(property(get = GetArgInitReg, put = SetArgInitReg)) regNumber lvArgInitReg;
regNumber GetArgInitReg() const
{
return (regNumber)_lvArgInitReg;
}
void SetArgInitReg(regNumber reg)
{
_lvArgInitReg = (regNumberSmall)reg;
assert(_lvArgInitReg == reg);
}
/////////////////////
__declspec(property(get = GetArgInitRegPair, put = SetArgInitRegPair)) regPairNo lvArgInitRegPair;
regPairNo GetArgInitRegPair() const
{
regPairNo regPair = (regPairNo)_lvArgInitRegPair;
assert(regPair >= REG_PAIR_FIRST && regPair <= REG_PAIR_LAST);
return regPair;
}
void SetArgInitRegPair(regPairNo regPair)
{
assert(regPair >= REG_PAIR_FIRST && regPair <= REG_PAIR_LAST);
_lvArgInitRegPair = (regPairNoSmall)regPair;
assert(_lvArgInitRegPair == regPair);
}
/////////////////////
bool lvIsRegCandidate() const
{
return lvLRACandidate != 0;
}
bool lvIsInReg() const
{
return lvIsRegCandidate() && (lvRegNum != REG_STK);
}
#else // LEGACY_BACKEND
bool lvIsRegCandidate() const
{
return lvTracked != 0;
}
bool lvIsInReg() const
{
return lvRegister != 0;
}
#endif // LEGACY_BACKEND
regMaskTP lvRegMask() const
{
regMaskTP regMask = RBM_NONE;
if (varTypeIsFloating(TypeGet()))
{
if (lvRegNum != REG_STK)
{
regMask = genRegMaskFloat(lvRegNum, TypeGet());
}
}
else
{
if (lvRegNum != REG_STK)
{
regMask = genRegMask(lvRegNum);
}
// For longs we may have two regs
if (isRegPairType(lvType) && lvOtherReg != REG_STK)
{
regMask |= genRegMask(lvOtherReg);
}
}
return regMask;
}
regMaskSmall lvPrefReg; // set of regs it prefers to live in
unsigned short lvVarIndex; // variable tracking index
unsigned short lvRefCnt; // unweighted (real) reference count. For implicit by reference
// parameters, this gets hijacked from fgMarkImplicitByRefArgs
// 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.
unsigned lvRefCntWtd; // weighted reference count
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().
if ((lvType == TYP_SIMD12) && !lvIsParam)
{
assert(lvExactSize == 12);
return 16;
}
#endif // defined(FEATURE_SIMD) && !defined(_TARGET_64BIT_)
return (unsigned)(roundUp(lvExactSize, TARGET_POINTER_SIZE));
}
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
BYTE* lvGcLayout; // GC layout info for structs
#if ASSERTION_PROP
BlockSet lvRefBlks; // Set of blocks that contain refs
GenTreePtr 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 % sizeof(void*)) == 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 lvaResetSortAgainFlag(Compiler* pComp);
void decRefCnts(BasicBlock::weight_t weight, Compiler* pComp, bool propagate = true);
void incRefCnts(BasicBlock::weight_t weight, Compiler* pComp, bool propagate = true);
void setPrefReg(regNumber regNum, Compiler* pComp);
void addPrefReg(regMaskTP regMask, Compiler* pComp);
bool IsFloatRegType() const
{
return isFloatRegType(lvType) || lvIsHfaRegArg();
}
var_types GetHfaType() const
{
return lvIsHfa() ? (lvHfaTypeIsFloat() ? TYP_FLOAT : TYP_DOUBLE) : TYP_UNDEF;
}
void SetHfaType(var_types type)
{
assert(varTypeIsFloating(type));
lvSetHfaTypeIsFloat(type == TYP_FLOAT);
}
#ifndef LEGACY_BACKEND
var_types lvaArgType();
#endif
PerSsaArray lvPerSsaData;
#ifdef DEBUG
// Keep track of the # of SsaNames, for a bounds check.
unsigned lvNumSsaNames;
#endif
// 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)
{
assert(ssaNum != SsaConfig::RESERVED_SSA_NUM);
assert(SsaConfig::RESERVED_SSA_NUM == 0);
unsigned zeroBased = ssaNum - SsaConfig::UNINIT_SSA_NUM;
assert(zeroBased < lvNumSsaNames);
return &lvPerSsaData.GetRef(zeroBased);
}
#ifdef DEBUG
public:
void PrintVarReg() const
{
if (isRegPairType(TypeGet()))
{
printf("%s:%s", getRegName(lvOtherReg), // hi32
getRegName(lvRegNum)); // lo32
}
else
{
printf("%s", getRegName(lvRegNum));
}
}
#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:
TempDsc(int _tdNum, unsigned _tdSize, var_types _tdType) : tdNum(_tdNum), tdSize((BYTE)_tdSize), tdType(_tdType)
{
#ifdef DEBUG
assert(tdNum <
0); // temps must have a negative number (so they have a different number from all local variables)
tdOffs = BAD_TEMP_OFFSET;
#endif // DEBUG
if (tdNum != _tdNum)
{
IMPL_LIMITATION("too many spill temps");
}
}
#ifdef DEBUG
bool tdLegalOffset() const
{
return tdOffs != BAD_TEMP_OFFSET;
}
#endif // DEBUG
int tdTempOffs() const
{
assert(tdLegalOffset());
return tdOffs;
}
void tdSetTempOffs(int offs)
{
tdOffs = offs;
assert(tdLegalOffset());
}
void tdAdjustTempOffs(int offs)
{
tdOffs += offs;
assert(tdLegalOffset());
}
int tdTempNum() const
{
assert(tdNum < 0);
return tdNum;
}
unsigned tdTempSize() const
{
return tdSize;
}
var_types tdTempType() const
{
return tdType;
}
};
// interface to hide linearscan implementation from rest of compiler
class LinearScanInterface
{
public:
virtual void doLinearScan() = 0;
virtual void recordVarLocationsAtStartOfBB(BasicBlock* bb) = 0;
virtual bool willEnregisterLocalVars() const = 0;
};
LinearScanInterface* getLinearScanAllocator(Compiler* comp);
// Information about arrays: their element type and size, and the offset of the first element.
// We label GT_IND's that are array indices with GTF_IND_ARR_INDEX, and, for such nodes,
// associate an array info via the map retrieved by GetArrayInfoMap(). This information is used,
// for example, in value numbering of array index expressions.
struct ArrayInfo
{
var_types m_elemType;
CORINFO_CLASS_HANDLE m_elemStructType;
unsigned m_elemSize;
unsigned m_elemOffset;
ArrayInfo() : m_elemType(TYP_UNDEF), m_elemStructType(nullptr), m_elemSize(0), m_elemOffset(0)
{
}
ArrayInfo(var_types elemType, unsigned elemSize, unsigned elemOffset, CORINFO_CLASS_HANDLE elemStructType)
: m_elemType(elemType), m_elemStructType(elemStructType), m_elemSize(elemSize), m_elemOffset(elemOffset)
{
}
};
// This enumeration names the phases into which we divide compilation. The phases should completely
// partition a compilation.
enum Phases
{
#define CompPhaseNameMacro(enum_nm, string_nm, short_nm, hasChildren, parent, measureIR) enum_nm,
#include "compphases.h"
PHASE_NUMBER_OF
};
extern const char* PhaseNames[];
extern const char* PhaseEnums[];
extern const LPCWSTR PhaseShortNames[];
// The following enum provides a simple 1:1 mapping to CLR API's
enum API_ICorJitInfo_Names
{
#define DEF_CLR_API(name) API_##name,
#include "ICorJitInfo_API_names.h"
API_COUNT
};
//---------------------------------------------------------------
// Compilation time.
//
// A "CompTimeInfo" is a structure for tracking the compilation time of one or more methods.
// We divide a compilation into a sequence of contiguous phases, and track the total (per-thread) cycles
// of the compilation, as well as the cycles for each phase. We also track the number of bytecodes.
// If there is a failure in reading a timer at any point, the "CompTimeInfo" becomes invalid, as indicated
// by "m_timerFailure" being true.
// If FEATURE_JIT_METHOD_PERF is not set, we define a minimal form of this, enough to let other code compile.
struct CompTimeInfo
{
#ifdef FEATURE_JIT_METHOD_PERF
// The string names of the phases.
static const char* PhaseNames[];
static bool PhaseHasChildren[];
static int PhaseParent[];
static bool PhaseReportsIRSize[];
unsigned m_byteCodeBytes;
unsigned __int64 m_totalCycles;
unsigned __int64 m_invokesByPhase[PHASE_NUMBER_OF];
unsigned __int64 m_cyclesByPhase[PHASE_NUMBER_OF];
#if MEASURE_CLRAPI_CALLS
unsigned __int64 m_CLRinvokesByPhase[PHASE_NUMBER_OF];
unsigned __int64 m_CLRcyclesByPhase[PHASE_NUMBER_OF];
#endif
unsigned m_nodeCountAfterPhase[PHASE_NUMBER_OF];
// For better documentation, we call EndPhase on
// non-leaf phases. We should also call EndPhase on the
// last leaf subphase; obviously, the elapsed cycles between the EndPhase
// for the last leaf subphase and the EndPhase for an ancestor should be very small.
// We add all such "redundant end phase" intervals to this variable below; we print
// it out in a report, so we can verify that it is, indeed, very small. If it ever