forked from dotnet/coreclr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler.h
8784 lines (7064 loc) · 408 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
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license 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 "block.h"
#include "jiteh.h"
#include "instr.h"
#include "regalloc.h"
#include "sm.h"
#include "simplerhash.h"
#include "cycletimer.h"
#include "varset.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"
#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"
/*****************************************************************************
* 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
#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
// 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 */
#include "gentree.h"
/*****************************************************************************/
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);
/*****************************************************************************/
#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;
// We'll need more precise info later...
};
// 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;
};
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.
#ifdef DEBUG
unsigned char lvSafeAddrTaken :1; // variable has its address taken, but it's consumed in the next instruction.
#endif
unsigned char lvArgWrite :1; // variable is a parameter and STARG was used on it
unsigned char lvIsTemp :1; // Short-lifetime compiler temp
#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
#if FANCY_ARRAY_OPT
unsigned char lvAssignOne :1; // assigned at least once?
unsigned char lvAssignTwo :1; // assigned at least twice?
#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 lvDblWasInt :1; // Was this TYP_DOUBLE originally a TYP_INT?
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.
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"
#ifdef _TARGET_ARM_
unsigned char lvDontPromote:1; // Should struct promoter consider this variable for promotion?
unsigned char lvIsHfaRegArg:1; // Is this argument variable holding a HFA register argument.
unsigned char lvHfaTypeIsFloat:1; // Is the HFA type float or double?
#endif
#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
unsigned char lvSIMDType :1; // This is a SIMD struct
unsigned char lvUsedInSIMDIntrinsic :1; // This tells lclvar is used for simd intrinsic
#endif // FEATURE_SIMD
unsigned char lvRegStruct : 1; // This is a reg-sized non-field-addressed struct.
union
{
unsigned lvFieldLclStart; // The index of the local var representing the first field in the promoted struct local.
unsigned lvParentLcl; // The index of the local var representing the parent (i.e. the promoted struct local). Valid on promoted struct local fields.
#ifdef FEATURE_SIMD
var_types lvBaseType; // The base type of a SIMD local var. Valid on TYP_SIMD locals.
#endif // FEATURE_SIMD
};
unsigned char lvFieldCnt; // Number of fields in the promoted VarDsc.
unsigned char lvFldOffset;
unsigned char lvFldOrdinal;
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.
#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);
}
#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
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() // 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((lvType == TYP_STRUCT) ||
(lvType == TYP_BLK) ||
(lvPromoted && lvUnusedStruct));
return (unsigned)(roundUp(lvExactSize, sizeof(void*)));
}
#if defined(DEBUGGING_SUPPORT) || defined(DEBUG)
unsigned lvSlotNum; // original slot # (if remapped)
#endif
typeInfo lvVerTypeInfo; // type info needed for verification
BYTE * lvGcLayout; // GC layout info for structs
#if FANCY_ARRAY_OPT
GenTreePtr lvKnownDim; // array size if known
#endif
#if ASSERTION_PROP
BlockSet lvRefBlks; // Set of blocks that contain refs
GenTreePtr lvDefStmt; // Pointer to the statement with the single definition
EXPSET_TP lvAssertionDep; // Assertions that depend on us (i.e to this var)
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
#ifdef _TARGET_ARM_
lvIsHfaRegArg ||
#endif
isFloatRegType(lvType);
}
#ifdef _TARGET_ARM_
var_types GetHfaType() const
{
assert(lvIsHfaRegArg);
return lvIsHfaRegArg ? (lvHfaTypeIsFloat ? TYP_FLOAT : TYP_DOUBLE) : TYP_UNDEF;
}
void SetHfaType(var_types type)
{
assert(varTypeIsFloating(type));
lvHfaTypeIsFloat = (type == TYP_FLOAT);
}
#endif //_TARGET_ARM_
#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;
};
LinearScanInterface *getLinearScanAllocator(Compiler *comp);
/*****************************************************************************
* Inlining support
*/
// Flags lost during inlining.
#define CORJIT_FLG_LOST_WHEN_INLINING (CORJIT_FLG_BBOPT | \
CORJIT_FLG_BBINSTR | \
CORJIT_FLG_PROF_ENTERLEAVE | \
CORJIT_FLG_DEBUG_EnC | \
CORJIT_FLG_DEBUG_INFO \
)
enum InlInlineHints
{
//Static inline hints are here.
InlLooksLikeWrapperMethod = 0x0001, // The inline candidate looks like it's a simple wrapper method.
InlArgFeedsConstantTest = 0x0002, // One or more of the incoming arguments feeds into a test
//against a constant. This is a good candidate for assertion
//prop.
InlMethodMostlyLdSt = 0x0004, //This method is mostly loads and stores.
InlMethodContainsCondThrow= 0x0008, //Method contains a conditional throw, so it does not bloat the
//code as much.
InlArgFeedsRngChk = 0x0010, //Incoming arg feeds an array bounds check. A good assertion
//prop candidate.
//Dynamic inline hints are here. Only put hints that add to the multiplier in here.
InlIncomingConstFeedsCond = 0x0100, //Incoming argument is constant and feeds a conditional.
InlAllDynamicHints = InlIncomingConstFeedsCond
};
struct InlineCandidateInfo
{
DWORD dwRestrictions;
CORINFO_METHOD_INFO methInfo;
unsigned methAttr;
CORINFO_CLASS_HANDLE clsHandle;
unsigned clsAttr;
var_types fncRetType;
CORINFO_METHOD_HANDLE ilCallerHandle; //the logical IL caller of this inlinee.
CORINFO_CONTEXT_HANDLE exactContextHnd;
CorInfoInitClassResult initClassResult;
};
struct InlArgInfo
{
unsigned argIsUsed :1; // is this arg used at all?
unsigned argIsInvariant:1; // the argument is a constant or a local variable address
unsigned argIsLclVar :1; // the argument is a local variable
unsigned argIsThis :1; // the argument is the 'this' pointer
unsigned argHasSideEff :1; // the argument has side effects
unsigned argHasGlobRef :1; // the argument has a global ref
unsigned argHasTmp :1; // the argument will be evaluated to a temp
unsigned argIsByRefToStructLocal:1; // Is this arg an address of a struct local or a normed struct local or a field in them?
unsigned argHasLdargaOp:1; // Is there LDARGA(s) operation on this argument?
unsigned argTmpNum; // the argument tmp number
GenTreePtr argNode;
GenTreePtr argBashTmpNode; // tmp node created, if it may be replaced with actual arg
};
struct InlLclVarInfo
{
var_types lclTypeInfo;
typeInfo lclVerTypeInfo;
bool lclHasLdlocaOp; // Is there LDLOCA(s) operation on this argument?
};
#ifndef LEGACY_BACKEND
const unsigned int MAX_INL_ARGS = 32; // does not include obj pointer
const unsigned int MAX_INL_LCLS = 32;
#else // LEGACY_BACKEND
const unsigned int MAX_INL_ARGS = 10; // does not include obj pointer
const unsigned int MAX_INL_LCLS = 8;
#endif // LEGACY_BACKEND
class JitInlineResult
{
public:
JitInlineResult() : inlInlineResult((CorInfoInline)0), inlInliner(NULL), inlInlinee(NULL)
#ifdef DEBUG
, inlReason("Invalid inline result"),
#else
, inlReason(NULL),
#endif
reported(false)
{
}
explicit JitInlineResult(CorInfoInline inlineResult,
CORINFO_METHOD_HANDLE inliner,
CORINFO_METHOD_HANDLE inlinee,
const char * reason = NULL)
: inlInlineResult(inlineResult), inlInliner(inliner), inlInlinee(inlinee), inlReason(reason),
reported(false)
{
assert(dontInline(inlineResult) == (reason != NULL));
}
inline CorInfoInline result() const { return inlInlineResult; }
inline const char * reason() const { return inlReason; }
//only call this if you explicitly do not want to report an inline failure.
void setReported() { reported = true; }
inline void report(COMP_HANDLE compCompHnd)
{
if (!reported)
{
compCompHnd->reportInliningDecision(inlInliner, inlInlinee, inlInlineResult, inlReason);
}
reported = true;
}
private:
CorInfoInline inlInlineResult;
CORINFO_METHOD_HANDLE inlInliner;
CORINFO_METHOD_HANDLE inlInlinee;
const char * inlReason;
bool reported;
};
inline bool dontInline(const JitInlineResult& val) {
return(dontInline(val.result()));
}
struct InlineInfo
{
Compiler * InlinerCompiler; // The Compiler instance for the caller (i.e. the inliner)
Compiler * InlineRoot; // The Compiler instance that is the root of the inlining tree of which the owner of "this" is a member.
CORINFO_METHOD_HANDLE fncHandle;
InlineCandidateInfo * inlineCandidateInfo;
JitInlineResult inlineResult;
GenTreePtr retExpr; // The return expression of the inlined candidate.
CORINFO_CONTEXT_HANDLE tokenLookupContextHandle; // The context handle that will be passed to
// impTokenLookupContextHandle in Inlinee's Compiler.
unsigned argCnt;
InlArgInfo inlArgInfo[MAX_INL_ARGS + 1];
int lclTmpNum[MAX_INL_LCLS]; // map local# -> temp# (-1 if unused)
InlLclVarInfo lclVarInfo[MAX_INL_LCLS + MAX_INL_ARGS + 1]; // type information from local sig
bool thisDereferencedFirst;
#ifdef FEATURE_SIMD
bool hasSIMDTypeArgLocalOrReturn;
#endif // FEATURE_SIMD
GenTree * iciCall; // The GT_CALL node to be inlined.
GenTree * iciStmt; // The statement iciCall is in.
BasicBlock * iciBlock; // The basic block iciStmt is in.
};
// 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, hasChildren, parent) enum_nm,
#include "compphases.h"
PHASE_NUMBER_OF
};
//---------------------------------------------------------------
// 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[];
unsigned m_byteCodeBytes;
unsigned __int64 m_totalCycles;
unsigned __int64 m_invokesByPhase[PHASE_NUMBER_OF];
unsigned __int64 m_cyclesByPhase[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
// isn't, this means that we're doing something significant between the end of the last
// declared subphase and the end of its parent.
unsigned __int64 m_parentPhaseEndSlop;
bool m_timerFailure;
CompTimeInfo(unsigned byteCodeBytes);
#endif
};
// TBD: Move this to UtilCode.
// The CLR requires that critical section locks be initialized via its ClrCreateCriticalSection API...but
// that can't be called until the CLR is initialized. If we have static data that we'd like to protect by a
// lock, and we have a statically allocated lock to protect that data, there's an issue in how to initialize
// that lock. We could insert an initialize call in the startup path, but one might prefer to keep the code
// more local. For such situations, CritSecObject solves the initialization problem, via a level of
// indirection. A pointer to the lock is initially null, and when we query for the lock pointer via "Val()".
// If the lock has not yet been allocated, this allocates one (here a leaf lock), and uses a
// CompareAndExchange-based lazy-initialization to update the field. If this fails, the allocated lock is
// destroyed. This will work as long as the first locking attempt occurs after enough CLR initialization has
// happened to make ClrCreateCriticalSection calls legal.
class CritSecObject
{
// CRITSEC_COOKIE is an opaque pointer type.
CRITSEC_COOKIE m_pCs;
public:
CritSecObject()
{
m_pCs = NULL;
}
CRITSEC_COOKIE Val()
{
if (m_pCs == NULL)
{
// CompareExchange-based lazy init.
CRITSEC_COOKIE newCs = ClrCreateCriticalSection(CrstLeafLock, CRST_DEFAULT);
CRITSEC_COOKIE observed = InterlockedCompareExchangeT(&m_pCs, newCs, NULL);
if (observed != NULL)
{
ClrDeleteCriticalSection(newCs);
}
}
return m_pCs;
}
};
#ifdef FEATURE_JIT_METHOD_PERF
// This class summarizes the JIT time information over the course of a run: the number of methods compiled,
// and the total and maximum timings. (These are instances of the "CompTimeInfo" type described above).
// The operation of adding a single method's timing to the summary may be performed concurrently by several
// threads, so it is protected by a lock.
// This class is intended to be used as a singleton type, with only a single instance.
class CompTimeSummaryInfo
{