-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathFunc.h
1168 lines (1003 loc) · 41.2 KB
/
Func.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.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
struct CodeGenWorkItem;
class Lowerer;
class Inline;
class FlowGraph;
#if defined(_M_ARM32_OR_ARM64)
#include "UnwindInfoManager.h"
#endif
struct Int64RegPair
{
IR::Opnd* high = nullptr;
IR::Opnd* low = nullptr;
};
struct Cloner
{
Cloner(Lowerer *lowerer, JitArenaAllocator *alloc) :
alloc(alloc),
symMap(nullptr),
labelMap(nullptr),
lowerer(lowerer),
instrFirst(nullptr),
instrLast(nullptr),
fRetargetClonedBranch(FALSE),
clonedInstrGetOrigArgSlotSym(false)
{
}
~Cloner()
{
if (symMap)
{
Adelete(alloc, symMap);
}
if (labelMap)
{
Adelete(alloc, labelMap);
}
}
void AddInstr(IR::Instr * instrOrig, IR::Instr * instrClone);
void Finish();
void RetargetClonedBranches();
JitArenaAllocator *alloc;
HashTable<StackSym*> *symMap;
HashTable<IR::LabelInstr*> *labelMap;
Lowerer * lowerer;
IR::Instr * instrFirst;
IR::Instr * instrLast;
BOOL fRetargetClonedBranch;
bool clonedInstrGetOrigArgSlotSym;
};
/*
* This class keeps track of various information required for Stack Arguments optimization with formals.
*/
class StackArgWithFormalsTracker
{
private:
BVSparse<JitArenaAllocator> * formalsArraySyms; //Tracks Formal parameter Array - Is this Bv required explicitly?
StackSym** formalsIndexToStackSymMap; //Tracks the stack sym for each formal
StackSym* m_scopeObjSym; // Tracks the stack sym for the scope object that is created.
JitArenaAllocator* alloc;
public:
StackArgWithFormalsTracker(JitArenaAllocator *alloc):
formalsArraySyms(nullptr),
formalsIndexToStackSymMap(nullptr),
m_scopeObjSym(nullptr),
alloc(alloc)
{
}
BVSparse<JitArenaAllocator> * GetFormalsArraySyms();
void SetFormalsArraySyms(SymID symId);
StackSym ** GetFormalsIndexToStackSymMap();
void SetStackSymInFormalsIndexMap(StackSym * sym, Js::ArgSlot formalsIndex, Js::ArgSlot formalsCount);
void SetScopeObjSym(StackSym * sym);
StackSym * GetScopeObjSym();
};
typedef JsUtil::Pair<uint32, IR::LabelInstr*> YieldOffsetResumeLabel;
typedef JsUtil::List<YieldOffsetResumeLabel, JitArenaAllocator> YieldOffsetResumeLabelList;
typedef HashTable<uint32, JitArenaAllocator> SlotArrayCheckTable;
struct FrameDisplayCheckRecord
{
SlotArrayCheckTable *table;
uint32 slotId;
FrameDisplayCheckRecord() : table(nullptr), slotId((uint32)-1) {}
};
typedef HashTable<FrameDisplayCheckRecord*, JitArenaAllocator> FrameDisplayCheckTable;
class Func
{
public:
Func(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
ThreadContextInfo * threadContextInfo,
ScriptContextInfo * scriptContextInfo,
JITOutputIDL * outputData,
Js::EntryPointInfo* epInfo,
const FunctionJITRuntimeInfo *const runtimeInfo,
JITTimePolymorphicInlineCacheInfo * const polymorphicInlineCacheInfo, void * const codeGenAllocators,
#if !FLOATVAR
CodeGenNumberAllocator * numberAllocator,
#endif
Js::ScriptContextProfiler *const codeGenProfiler, const bool isBackgroundJIT, Func * parentFunc = nullptr,
uint postCallByteCodeOffset = Js::Constants::NoByteCodeOffset,
Js::RegSlot returnValueRegSlot = Js::Constants::NoRegister, const bool isInlinedConstructor = false,
Js::ProfileId callSiteIdInParentFunc = UINT16_MAX, bool isGetterSetter = false);
public:
void * GetCodeGenAllocators()
{
return this->GetTopFunc()->m_codeGenAllocators;
}
InProcCodeGenAllocators * GetInProcCodeGenAllocators()
{
Assert(!JITManager::GetJITManager()->IsJITServer());
return reinterpret_cast<InProcCodeGenAllocators*>(this->GetTopFunc()->m_codeGenAllocators);
}
#if ENABLE_OOP_NATIVE_CODEGEN
OOPCodeGenAllocators * const GetOOPCodeGenAllocators()
{
Assert(JITManager::GetJITManager()->IsJITServer());
return reinterpret_cast<OOPCodeGenAllocators*>(this->GetTopFunc()->m_codeGenAllocators);
}
#endif
NativeCodeData::Allocator *GetNativeCodeDataAllocator()
{
return &this->GetTopFunc()->nativeCodeDataAllocator;
}
NativeCodeData::Allocator *GetTransferDataAllocator()
{
return &this->GetTopFunc()->transferDataAllocator;
}
#if !FLOATVAR
CodeGenNumberAllocator * GetNumberAllocator()
{
return this->numberAllocator;
}
#endif
#if !FLOATVAR
XProcNumberPageSegmentImpl* GetXProcNumberAllocator()
{
if (this->GetJITOutput()->GetOutputData()->numberPageSegments == nullptr)
{
XProcNumberPageSegmentImpl* seg = (XProcNumberPageSegmentImpl*)midl_user_allocate(sizeof(XProcNumberPageSegment));
if (seg == nullptr)
{
Js::Throw::OutOfMemory();
}
this->GetJITOutput()->GetOutputData()->numberPageSegments = new (seg) XProcNumberPageSegmentImpl();
}
return (XProcNumberPageSegmentImpl*)this->GetJITOutput()->GetOutputData()->numberPageSegments;
}
#endif
Js::ScriptContextProfiler *GetCodeGenProfiler() const
{
#ifdef PROFILE_EXEC
return m_codeGenProfiler;
#else
return nullptr;
#endif
}
bool IsOOPJIT() const { return JITManager::GetJITManager()->IsOOPJITEnabled(); }
void InitLocalClosureSyms();
bool HasAnyStackNestedFunc() const { return this->hasAnyStackNestedFunc; }
bool DoStackNestedFunc() const { return this->stackNestedFunc; }
bool DoStackFrameDisplay() const { return this->stackClosure; }
bool DoStackScopeSlots() const { return this->stackClosure; }
bool IsBackgroundJIT() const { return this->m_isBackgroundJIT; }
bool HasArgumentSlot() const { return this->GetInParamsCount() != 0 && !this->IsLoopBody(); }
bool IsLoopBody() const { return m_workItem->IsLoopBody(); }
bool IsLoopBodyInTry() const;
bool IsLoopBodyInTryFinally() const;
bool CanAllocInPreReservedHeapPageSegment();
void SetDoFastPaths();
bool DoFastPaths() const { Assert(this->hasCalledSetDoFastPaths); return this->m_doFastPaths; }
bool DoLoopFastPaths() const
{
return
(!IsSimpleJit() || CONFIG_FLAG(NewSimpleJit)) &&
!PHASE_OFF(Js::FastPathPhase, this) &&
!PHASE_OFF(Js::LoopFastPathPhase, this);
}
bool DoGlobOpt() const
{
return
!PHASE_OFF(Js::GlobOptPhase, this) && !IsSimpleJit() &&
(!GetTopFunc()->HasTry() || GetTopFunc()->CanOptimizeTryCatch()) &&
(!GetTopFunc()->HasFinally() || GetTopFunc()->CanOptimizeTryFinally());
}
bool DoInline() const
{
#ifdef _M_IX86
return DoGlobOpt() && !GetTopFunc()->HasTry();
#else
return DoGlobOpt();
#endif
}
bool DoOptimizeTry() const
{
Assert(IsTopFunc());
return DoGlobOpt();
}
bool CanOptimizeTryFinally() const
{
return !this->m_workItem->IsLoopBody() && !PHASE_OFF(Js::OptimizeTryFinallyPhase, this) &&
(!this->HasProfileInfo() || !this->GetReadOnlyProfileInfo()->IsOptimizeTryFinallyDisabled());
}
bool CanOptimizeTryCatch() const
{
return !this->m_workItem->IsLoopBody() && !PHASE_OFF(Js::OptimizeTryCatchPhase, this);
}
bool DoSimpleJitDynamicProfile() const;
bool IsSimpleJit() const { return m_workItem->GetJitMode() == ExecutionMode::SimpleJit; }
JITTimeWorkItem * GetWorkItem() const
{
return m_workItem;
}
ThreadContext * GetInProcThreadContext() const
{
Assert(!IsOOPJIT());
return (ThreadContext*)m_threadContextInfo;
}
ServerThreadContext* GetOOPThreadContext() const
{
Assert(IsOOPJIT());
return (ServerThreadContext*)m_threadContextInfo;
}
ThreadContextInfo * GetThreadContextInfo() const
{
return m_threadContextInfo;
}
ScriptContextInfo * GetScriptContextInfo() const
{
return m_scriptContextInfo;
}
JITOutput* GetJITOutput()
{
return &m_output;
}
const JITOutput* GetJITOutput() const
{
return &m_output;
}
const JITTimeFunctionBody * GetJITFunctionBody() const
{
return m_workItem->GetJITFunctionBody();
}
Js::EntryPointInfo* GetInProcJITEntryPointInfo() const
{
Assert(!IsOOPJIT());
return m_entryPointInfo;
}
char16* GetDebugNumberSet(wchar(&bufferToWriteTo)[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE]) const
{
return m_workItem->GetJITTimeInfo()->GetDebugNumberSet(bufferToWriteTo);
}
void TryCodegen();
static void Codegen(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
ThreadContextInfo * threadContextInfo,
ScriptContextInfo * scriptContextInfo,
JITOutputIDL * outputData,
Js::EntryPointInfo* epInfo, // for in-proc jit only
const FunctionJITRuntimeInfo *const runtimeInfo,
JITTimePolymorphicInlineCacheInfo * const polymorphicInlineCacheInfo, void * const codeGenAllocators,
#if !FLOATVAR
CodeGenNumberAllocator * numberAllocator,
#endif
Js::ScriptContextProfiler *const codeGenProfiler, const bool isBackgroundJIT);
int32 StackAllocate(int size);
int32 StackAllocate(StackSym *stackSym, int size);
void SetArgOffset(StackSym *stackSym, int32 offset);
int32 GetLocalVarSlotOffset(int32 slotId);
int32 GetHasLocalVarChangedOffset();
bool IsJitInDebugMode() const;
bool IsNonTempLocalVar(uint32 slotIndex);
void OnAddSym(Sym* sym);
uint GetLocalFunctionId() const
{
return m_workItem->GetJITTimeInfo()->GetLocalFunctionId();
}
uint GetSourceContextId() const
{
return m_workItem->GetJITFunctionBody()->GetSourceContextId();
}
#ifdef MD_GROW_LOCALS_AREA_UP
void AjustLocalVarSlotOffset();
#endif
bool DoGlobOptsForGeneratorFunc() const;
static int32 AdjustOffsetValue(int32 offset);
static inline uint32 GetDiagLocalSlotSize()
{
// For the debug purpose we will have fixed stack slot size
// We will allocated the 8 bytes for each variable.
return MachDouble;
}
#ifdef DBG
// The pattern used to pre-fill locals for CHK builds.
// When we restore bailout values we check for this pattern, this is how we assert for non-initialized variables/garbage.
static const uint32 c_debugFillPattern4 = 0xcececece;
static const unsigned __int64 c_debugFillPattern8 = 0xcececececececece;
#if defined(TARGET_32)
static const uint32 c_debugFillPattern = c_debugFillPattern4;
#elif defined(TARGET_64)
static const unsigned __int64 c_debugFillPattern = c_debugFillPattern8;
#else
#error unsupported platform
#endif
#endif
uint32 GetInstrCount();
inline Js::ScriptContext* GetScriptContext() const
{
Assert(!IsOOPJIT());
return static_cast<Js::ScriptContext*>(this->GetScriptContextInfo());
}
void NumberInstrs();
bool IsTopFunc() const { return this->parentFunc == nullptr; }
Func const * GetTopFunc() const { return this->topFunc; }
Func * GetTopFunc() { return this->topFunc; }
void SetFirstArgOffset(IR::Instr* inlineeStart);
uint GetFunctionNumber() const
{
return m_workItem->GetJITFunctionBody()->GetFunctionNumber();
}
BOOL HasTry() const
{
Assert(this->IsTopFunc());
return this->GetJITFunctionBody()->HasTry();
}
bool HasFinally() const
{
Assert(this->IsTopFunc());
return this->GetJITFunctionBody()->HasFinally();
}
bool HasThis() const
{
Assert(this->IsTopFunc());
Assert(this->GetJITFunctionBody()); // For now we always have a function body
return this->GetJITFunctionBody()->HasThis();
}
Js::ArgSlot GetInParamsCount() const
{
Assert(this->IsTopFunc());
return this->GetJITFunctionBody()->GetInParamsCount();
}
bool IsGlobalFunc() const
{
Assert(this->IsTopFunc());
return this->GetJITFunctionBody()->IsGlobalFunc();
}
uint16 GetArgUsedForBranch() const;
intptr_t GetWeakFuncRef() const;
const FunctionJITRuntimeInfo * GetRuntimeInfo() const { return m_runtimeInfo; }
bool IsLambda() const
{
Assert(this->IsTopFunc());
Assert(this->GetJITFunctionBody()); // For now we always have a function body
return this->GetJITFunctionBody()->IsLambda();
}
bool IsTrueLeaf() const
{
return !GetHasCalls() && !GetHasImplicitCalls();
}
StackSym *EnsureLoopParamSym();
void UpdateForInLoopMaxDepth(uint forInLoopMaxDepth);
int GetForInEnumeratorArrayOffset() const;
StackSym *GetFuncObjSym() const { return m_funcObjSym; }
void SetFuncObjSym(StackSym *sym) { m_funcObjSym = sym; }
StackSym *GetJavascriptLibrarySym() const { return m_javascriptLibrarySym; }
void SetJavascriptLibrarySym(StackSym *sym) { m_javascriptLibrarySym = sym; }
StackSym *GetScriptContextSym() const { return m_scriptContextSym; }
void SetScriptContextSym(StackSym *sym) { m_scriptContextSym = sym; }
StackSym *GetFunctionBodySym() const { return m_functionBodySym; }
void SetFunctionBodySym(StackSym *sym) { m_functionBodySym = sym; }
StackSym *GetLocalClosureSym() const { return m_localClosureSym; }
void SetLocalClosureSym(StackSym *sym) { m_localClosureSym = sym; }
StackSym *GetParamClosureSym() const { return m_paramClosureSym; }
void SetParamClosureSym(StackSym *sym) { m_paramClosureSym = sym; }
StackSym *GetLocalFrameDisplaySym() const { return m_localFrameDisplaySym; }
void SetLocalFrameDisplaySym(StackSym *sym) { m_localFrameDisplaySym = sym; }
void AddStableSlotSym(PropertySym *sym);
bool IsStableSlotSym(PropertySym *sym) const;
BVSparse<JitArenaAllocator> *GetStableSlotSyms() const;
intptr_t GetJittedLoopIterationsSinceLastBailoutAddress() const;
void EnsurePinnedTypeRefs();
void PinTypeRef(void* typeRef);
void EnsureSingleTypeGuards();
Js::JitTypePropertyGuard* GetOrCreateSingleTypeGuard(intptr_t typeAddr);
void EnsureEquivalentTypeGuards();
void InitializeEquivalentTypeGuard(Js::JitEquivalentTypeGuard * guard);
Js::JitEquivalentTypeGuard * CreateEquivalentTypeGuard(JITTypeHolder type, uint32 objTypeSpecFldId);
Js::JitPolyEquivalentTypeGuard * CreatePolyEquivalentTypeGuard(uint32 objTypeSpecFldId);
void ThrowIfScriptClosed();
void EnsurePropertyGuardsByPropertyId();
void EnsureCtorCachesByPropertyId();
void LinkGuardToPropertyId(Js::PropertyId propertyId, Js::JitIndexedPropertyGuard* guard);
void LinkCtorCacheToPropertyId(Js::PropertyId propertyId, JITTimeConstructorCache* cache);
JITTimeConstructorCache * GetConstructorCache(const Js::ProfileId profiledCallSiteId);
void SetConstructorCache(const Js::ProfileId profiledCallSiteId, JITTimeConstructorCache* constructorCache);
void EnsurePropertiesWrittenTo();
void EnsureCallSiteToArgumentsOffsetFixupMap();
IR::LabelInstr * EnsureFuncStartLabel();
IR::LabelInstr * GetFuncStartLabel();
IR::LabelInstr * EnsureFuncEndLabel();
IR::LabelInstr * GetFuncEndLabel();
#ifdef _M_X64
void SetSpillSize(int32 spillSize)
{
m_spillSize = spillSize;
}
int32 GetSpillSize()
{
return m_spillSize;
}
void SetArgsSize(int32 argsSize)
{
m_argsSize = argsSize;
}
int32 GetArgsSize()
{
return m_argsSize;
}
void SetSavedRegSize(int32 savedRegSize)
{
m_savedRegSize = savedRegSize;
}
int32 GetSavedRegSize()
{
return m_savedRegSize;
}
#endif
bool IsInlinee() const
{
Assert(m_inlineeFrameStartSym ? (m_inlineeFrameStartSym->m_offset != -1) : true);
return m_inlineeFrameStartSym != nullptr;
}
void SetInlineeFrameStartSym(StackSym *sym)
{
Assert(m_inlineeFrameStartSym == nullptr);
m_inlineeFrameStartSym = sym;
}
void SetInlineeStart(IR::Instr *inlineeStartInstr)
{
Assert(inlineeStart == nullptr);
inlineeStart = inlineeStartInstr;
}
IR::Instr* GetInlineeStart()
{
return inlineeStart;
}
IR::SymOpnd *GetInlineeArgCountSlotOpnd()
{
return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_Argc * MachPtr);
}
IR::SymOpnd *GetNextInlineeFrameArgCountSlotOpnd()
{
Assert(!this->m_hasInlineArgsOpt);
if (this->m_hasInlineArgsOpt)
{
// If the function has inlineArgsOpt turned on, jitted code will not write to stack slots for inlinee's function object
// and arguments, until needed. If we attempt to read from those slots, we may be reading uninitialized memory.
throw Js::OperationAbortedException();
}
return GetInlineeOpndAtOffset((Js::Constants::InlineeMetaArgCount + actualCount) * MachPtr);
}
IR::SymOpnd *GetInlineeFunctionObjectSlotOpnd()
{
Assert(!this->m_hasInlineArgsOpt);
if (this->m_hasInlineArgsOpt)
{
// If the function has inlineArgsOpt turned on, jitted code will not write to stack slots for inlinee's function object
// and arguments, until needed. If we attempt to read from those slots, we may be reading uninitialized memory.
throw Js::OperationAbortedException();
}
return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_FunctionObject * MachPtr);
}
IR::SymOpnd *GetInlineeArgumentsObjectSlotOpnd()
{
return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_ArgumentsObject * MachPtr);
}
IR::SymOpnd *GetInlineeArgvSlotOpnd()
{
Assert(!this->m_hasInlineArgsOpt);
if (this->m_hasInlineArgsOpt)
{
// If the function has inlineArgsOpt turned on, jitted code will not write to stack slots for inlinee's function object
// and arguments, until needed. If we attempt to read from those slots, we may be reading uninitialized memory.
throw Js::OperationAbortedException();
}
return GetInlineeOpndAtOffset(Js::Constants::InlineeMetaArgIndex_Argv * MachPtr);
}
bool IsInlined() const
{
return this->parentFunc != nullptr;
}
bool IsInlinedConstructor() const
{
return this->isInlinedConstructor;
}
bool IsTJLoopBody()const {
return this->isTJLoopBody;
}
Js::Var AllocateNumber(double value);
ObjTypeSpecFldInfo* GetObjTypeSpecFldInfo(const uint index) const;
ObjTypeSpecFldInfo* GetGlobalObjTypeSpecFldInfo(uint propertyInfoId) const;
// Gets an inline cache pointer to use in jitted code. Cached data may not be stable while jitting. Does not return null.
intptr_t GetRuntimeInlineCache(const uint index) const;
JITTimePolymorphicInlineCache * GetRuntimePolymorphicInlineCache(const uint index) const;
byte GetPolyCacheUtil(const uint index) const;
byte GetPolyCacheUtilToInitialize(const uint index) const;
#if LOWER_SPLIT_INT64
Int64RegPair FindOrCreateInt64Pair(IR::Opnd*);
void Int64SplitExtendLoopLifetime(Loop* loop);
#endif
#if defined(_M_ARM32_OR_ARM64)
RegNum GetLocalsPointer() const;
#endif
#if DBG_DUMP
void Dump(IRDumpFlags flags);
void Dump();
void DumpHeader();
#endif
#if DBG_DUMP || defined(ENABLE_IR_VIEWER)
LPCSTR GetVtableName(INT_PTR address);
#endif
#if DBG_DUMP | defined(VTUNE_PROFILING)
bool DoRecordNativeMap() const;
#endif
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
void DumpFullFunctionName();
#endif
public:
JitArenaAllocator * m_alloc;
const FunctionJITRuntimeInfo *const m_runtimeInfo;
ThreadContextInfo * m_threadContextInfo;
ScriptContextInfo * m_scriptContextInfo;
JITTimeWorkItem * m_workItem;
JITTimePolymorphicInlineCacheInfo *const m_polymorphicInlineCacheInfo;
// This indicates how many constructor caches we inserted into the constructorCaches array, not the total size of the array.
uint constructorCacheCount;
// This array maps callsite ids to constructor caches. The size corresponds to the number of callsites in the function.
JITTimeConstructorCache** constructorCaches;
typedef JsUtil::BaseHashSet<void*, JitArenaAllocator, PowerOf2SizePolicy> TypeRefSet;
TypeRefSet* pinnedTypeRefs;
typedef JsUtil::BaseDictionary<intptr_t, Js::JitTypePropertyGuard*, JitArenaAllocator, PowerOf2SizePolicy> TypePropertyGuardDictionary;
TypePropertyGuardDictionary* singleTypeGuards;
typedef SListCounted<Js::JitEquivalentTypeGuard*> EquivalentTypeGuardList;
EquivalentTypeGuardList* equivalentTypeGuards;
typedef JsUtil::BaseHashSet<Js::JitIndexedPropertyGuard*, JitArenaAllocator, PowerOf2SizePolicy> IndexedPropertyGuardSet;
typedef JsUtil::BaseDictionary<Js::PropertyId, IndexedPropertyGuardSet*, JitArenaAllocator, PowerOf2SizePolicy> PropertyGuardByPropertyIdMap;
PropertyGuardByPropertyIdMap* propertyGuardsByPropertyId;
typedef JsUtil::BaseHashSet<intptr_t, JitArenaAllocator, PowerOf2SizePolicy> CtorCacheSet;
typedef JsUtil::BaseDictionary<Js::PropertyId, CtorCacheSet*, JitArenaAllocator, PowerOf2SizePolicy> CtorCachesByPropertyIdMap;
CtorCachesByPropertyIdMap* ctorCachesByPropertyId;
typedef JsUtil::BaseDictionary<Js::ProfileId, int32, JitArenaAllocator, PrimeSizePolicy> CallSiteToArgumentsOffsetFixupMap;
CallSiteToArgumentsOffsetFixupMap* callSiteToArgumentsOffsetFixupMap;
int indexedPropertyGuardCount;
typedef JsUtil::BaseHashSet<Js::PropertyId, JitArenaAllocator> PropertyIdSet;
PropertyIdSet* propertiesWrittenTo;
PropertyIdSet lazyBailoutProperties;
bool anyPropertyMayBeWrittenTo;
SlotArrayCheckTable *slotArrayCheckTable;
FrameDisplayCheckTable *frameDisplayCheckTable;
IR::Instr * m_headInstr;
IR::Instr * m_exitInstr;
IR::Instr * m_tailInstr;
#ifdef _M_X64
int32 m_spillSize;
int32 m_argsSize;
int32 m_savedRegSize;
PrologEncoder m_prologEncoder;
#endif
SymTable * m_symTable;
StackSym * m_loopParamSym;
StackSym * m_funcObjSym;
StackSym * m_javascriptLibrarySym;
StackSym * m_scriptContextSym;
StackSym * m_functionBodySym;
StackSym * m_localClosureSym;
StackSym * m_paramClosureSym;
StackSym * m_localFrameDisplaySym;
StackSym * m_bailoutReturnValueSym;
StackSym * m_hasBailedOutSym;
uint m_forInLoopMaxDepth;
uint m_forInLoopBaseDepth;
int32 m_forInEnumeratorArrayOffset;
int32 m_localStackHeight;
uint frameSize;
uint32 inlineDepth;
uint32 postCallByteCodeOffset;
Js::RegSlot returnValueRegSlot;
Js::RegSlot firstIRTemp;
Js::ArgSlot actualCount;
int32 firstActualStackOffset;
uint32 tryCatchNestingLevel;
uint32 m_totalJumpTableSizeInBytesForSwitchStatements;
#if defined(_M_ARM32_OR_ARM64)
//Offset to arguments from sp + m_localStackHeight;
//For non leaf functions this is (callee saved register count + LR + R11) * MachRegInt
//For leaf functions this is (saved registers) * MachRegInt
int32 m_ArgumentsOffset;
UnwindInfoManager m_unwindInfo;
IR::LabelInstr * m_epilogLabel;
#endif
IR::LabelInstr * m_funcStartLabel;
IR::LabelInstr * m_funcEndLabel;
// Keep track of the maximum number of args on the stack.
uint32 m_argSlotsForFunctionsCalled;
#if DBG
uint32 m_callSiteCount;
#endif
FlowGraph * m_fg;
unsigned int m_labelCount;
BitVector m_regsUsed;
StackSym * tempSymDouble;
StackSym * tempSymBool;
BVSparse<JitArenaAllocator> * bvStableSlotSyms;
uint32 loopCount;
uint32 unoptimizableArgumentsObjReference;
Js::ProfileId callSiteIdInParentFunc;
InlineeFrameInfo* cachedInlineeFrameInfo;
bool m_hasCalls: 1; // This is more accurate compared to m_isLeaf
bool m_hasInlineArgsOpt : 1;
bool m_doFastPaths : 1;
bool hasBailout: 1;
bool hasBailoutInEHRegion : 1;
bool hasStackArgs: 1;
bool hasArgLenAndConstOpt : 1;
bool hasImplicitParamLoad : 1; // True if there is a load of CallInfo, FunctionObject
bool hasThrow : 1;
bool hasUnoptimizedArgumentsAccess : 1; // True if there are any arguments access beyond the simple case of this.apply pattern
bool m_canDoInlineArgsOpt : 1;
bool applyTargetInliningRemovedArgumentsAccess : 1;
bool isGetterSetter : 1;
const bool isInlinedConstructor: 1;
bool hasImplicitCalls: 1;
bool hasTempObjectProducingInstr:1; // At least one instruction which can produce temp object
bool isTJLoopBody : 1;
bool isFlowGraphValid : 1;
bool legalizePostRegAlloc : 1;
#if DBG
bool hasCalledSetDoFastPaths:1;
bool isPostLower:1;
bool isPostRegAlloc:1;
bool isPostPeeps:1;
bool isPostLayout:1;
bool isPostFinalLower:1;
struct InstrByteCodeRegisterUses
{
Js::OpCode capturingOpCode;
BVSparse<JitArenaAllocator>* bv;
};
typedef JsUtil::BaseDictionary<uint32, InstrByteCodeRegisterUses, JitArenaAllocator> ByteCodeRegisterUses;
ByteCodeRegisterUses* byteCodeRegisterUses = nullptr;
BVSparse<JitArenaAllocator>* GetByteCodeOffsetUses(uint offset) const;
typedef JsUtil::Stack<Js::Phase> CurrentPhasesStack;
CurrentPhasesStack currentPhases;
bool IsInPhase(Js::Phase tag);
#endif
void BeginPhase(Js::Phase tag);
void EndPhase(Js::Phase tag, bool dump = true);
void EndProfiler(Js::Phase tag);
void BeginClone(Lowerer *lowerer, JitArenaAllocator *alloc);
void EndClone();
Cloner * GetCloner() const { return GetTopFunc()->m_cloner; }
InstrMap * GetCloneMap() const { return GetTopFunc()->m_cloneMap; }
void ClearCloneMap() { Assert(this->IsTopFunc()); this->m_cloneMap = nullptr; }
bool HasByteCodeOffset() const { return !this->GetTopFunc()->hasInstrNumber; }
bool DoMaintainByteCodeOffset() const { return this->HasByteCodeOffset() && this->GetTopFunc()->maintainByteCodeOffset; }
void StopMaintainByteCodeOffset() { this->GetTopFunc()->maintainByteCodeOffset = false; }
Func * GetParentFunc() const { return parentFunc; }
uint GetMaxInlineeArgOutSize() const { return this->maxInlineeArgOutSize; }
void UpdateMaxInlineeArgOutSize(uint inlineeArgOutSize);
#if DBG_DUMP
ptrdiff_t m_codeSize;
#endif
bool GetHasCalls() const { return this->m_hasCalls; }
void SetHasCallsOnSelfAndParents()
{
Func *curFunc = this;
while (curFunc)
{
curFunc->m_hasCalls = true;
curFunc = curFunc->GetParentFunc();
}
}
void SetHasInstrNumber(bool has) { this->GetTopFunc()->hasInstrNumber = has; }
bool HasInstrNumber() const { return this->GetTopFunc()->hasInstrNumber; }
bool HasInlinee() const { Assert(this->IsTopFunc()); return this->hasInlinee; }
void SetHasInlinee() { Assert(this->IsTopFunc()); this->hasInlinee = true; }
bool GetThisOrParentInlinerHasArguments() const { return thisOrParentInlinerHasArguments; }
bool GetHasStackArgs() const
{
return this->hasStackArgs && !IsStackArgOptDisabled() && !PHASE_OFF1(Js::StackArgOptPhase);
}
void SetHasStackArgs(bool has) { this->hasStackArgs = has;}
bool IsStackArgsEnabled()
{
Func* curFunc = this;
bool isStackArgsEnabled = GetJITFunctionBody()->UsesArgumentsObject() && curFunc->GetHasStackArgs();
Func * topFunc = curFunc->GetTopFunc();
if (topFunc != nullptr)
{
isStackArgsEnabled = isStackArgsEnabled && topFunc->GetHasStackArgs();
}
return isStackArgsEnabled;
}
bool GetHasImplicitParamLoad() const { return this->hasImplicitParamLoad; }
void SetHasImplicitParamLoad() { this->hasImplicitParamLoad = true; }
bool GetHasThrow() const { return this->hasThrow; }
void SetHasThrow() { this->hasThrow = true; }
bool GetHasUnoptimizedArgumentsAccess() const { return this->hasUnoptimizedArgumentsAccess; }
void SetHasUnoptimizedArgumentsAccess(bool args)
{
// Once set to 'true' make sure this does not become false
if (!this->hasUnoptimizedArgumentsAccess)
{
this->hasUnoptimizedArgumentsAccess = args;
}
if (args)
{
Func *curFunc = this->GetParentFunc();
while (curFunc)
{
curFunc->hasUnoptimizedArgumentsAccess = args;
curFunc = curFunc->GetParentFunc();
}
}
}
void DisableCanDoInlineArgOpt()
{
Func* curFunc = this;
while (curFunc)
{
curFunc->m_canDoInlineArgsOpt = false;
curFunc->m_hasInlineArgsOpt = false;
curFunc = curFunc->GetParentFunc();
}
}
bool ShouldLegalizePostRegAlloc() const { return topFunc->legalizePostRegAlloc; }
bool GetApplyTargetInliningRemovedArgumentsAccess() const { return this->applyTargetInliningRemovedArgumentsAccess;}
void SetApplyTargetInliningRemovedArgumentsAccess() { this->applyTargetInliningRemovedArgumentsAccess = true;}
bool GetHasMarkTempObjects() const { return this->hasMarkTempObjects; }
void SetHasMarkTempObjects() { this->hasMarkTempObjects = true; }
bool GetHasNonSimpleParams() const { return this->hasNonSimpleParams; }
void SetHasNonSimpleParams() { this->hasNonSimpleParams = true; }
bool GetHasImplicitCalls() const { return this->hasImplicitCalls;}
void SetHasImplicitCalls(bool has) { this->hasImplicitCalls = has;}
void SetHasImplicitCallsOnSelfAndParents()
{
this->SetHasImplicitCalls(true);
Func *curFunc = this->GetParentFunc();
while (curFunc && !curFunc->IsTopFunc())
{
curFunc->SetHasImplicitCalls(true);
curFunc = curFunc->GetParentFunc();
}
}
bool GetHasTempObjectProducingInstr() const { return this->hasTempObjectProducingInstr; }
void SetHasTempObjectProducingInstr(bool has) { this->hasTempObjectProducingInstr = has; }
const JITTimeProfileInfo * GetReadOnlyProfileInfo() const { return GetJITFunctionBody()->GetReadOnlyProfileInfo(); }
bool HasProfileInfo() const { return GetJITFunctionBody()->HasProfileInfo(); }
bool HasArrayInfo()
{
const auto top = this->GetTopFunc();
return this->HasProfileInfo() && this->GetWeakFuncRef() && !(top->HasTry() && !top->DoOptimizeTry()) &&
top->DoGlobOpt() && !PHASE_OFF(Js::LoopFastPathPhase, top);
}
static Js::OpCode GetLoadOpForType(IRType type)
{
if (type == TyVar || IRType_IsFloat(type))
{
return Js::OpCode::Ld_A;
}
else
{
Assert(IRType_IsNativeInt(type));
return Js::OpCode::Ld_I4;
}
}
static Js::BuiltinFunction GetBuiltInIndex(IR::Opnd* opnd)
{
Assert(opnd);
Js::BuiltinFunction index;
if (opnd->IsRegOpnd())
{
index = opnd->AsRegOpnd()->m_sym->m_builtInIndex;
}
else if (opnd->IsSymOpnd())
{
PropertySym *propertySym = opnd->AsSymOpnd()->m_sym->AsPropertySym();
index = Js::JavascriptLibrary::GetBuiltinFunctionForPropId(propertySym->m_propertyId);
}
else
{
index = Js::BuiltinFunction::None;
}
return index;
}
static bool IsBuiltInInlinedInLowerer(IR::Opnd* opnd)
{
Assert(opnd);
Js::BuiltinFunction index = Func::GetBuiltInIndex(opnd);
switch (index)
{
case Js::BuiltinFunction::JavascriptString_CharAt:
case Js::BuiltinFunction::JavascriptString_CharCodeAt:
case Js::BuiltinFunction::JavascriptString_CodePointAt:
case Js::BuiltinFunction::Math_Abs:
case Js::BuiltinFunction::JavascriptArray_Push:
case Js::BuiltinFunction::JavascriptString_Replace:
case Js::BuiltinFunction::JavascriptObject_HasOwnProperty:
case Js::BuiltinFunction::JavascriptArray_IsArray:
return true;
default:
return false;
}
}
void AddYieldOffsetResumeLabel(uint32 offset, IR::LabelInstr* label)
{
m_yieldOffsetResumeLabelList->Add(YieldOffsetResumeLabel(offset, label));
}
template <typename Fn>
void MapYieldOffsetResumeLabels(Fn fn)
{
m_yieldOffsetResumeLabelList->Map(fn);
}
template <typename Fn>
bool MapUntilYieldOffsetResumeLabels(Fn fn)
{
return m_yieldOffsetResumeLabelList->MapUntil(fn);
}
void RemoveYieldOffsetResumeLabel(const YieldOffsetResumeLabel& yorl)
{
m_yieldOffsetResumeLabelList->Remove(yorl);
}
void RemoveDeadYieldOffsetResumeLabel(IR::LabelInstr* label)
{
uint32 offset;
bool found = m_yieldOffsetResumeLabelList->MapUntil([&offset, &label](int i, YieldOffsetResumeLabel& yorl)
{
if (yorl.Second() == label)
{
offset = yorl.First();
return true;
}
return false;
});
Assert(found);
RemoveYieldOffsetResumeLabel(YieldOffsetResumeLabel(offset, label));
AddYieldOffsetResumeLabel(offset, nullptr);
}
IR::Instr * GetFunctionEntryInsertionPoint();
IR::IndirOpnd * GetConstantAddressIndirOpnd(intptr_t address, IR::Opnd *largeConstOpnd, IR::AddrOpndKind kind, IRType type, Js::OpCode loadOpCode);
void MarkConstantAddressSyms(BVSparse<JitArenaAllocator> * bv);
void DisableConstandAddressLoadHoist() { canHoistConstantAddressLoad = false; }