-
Notifications
You must be signed in to change notification settings - Fork 82
/
BaseTransform.cs
1507 lines (1214 loc) · 35.4 KB
/
BaseTransform.cs
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) MOSA Project. Licensed under the New BSD License.
using Mosa.Compiler.Common;
using Mosa.Compiler.Common.Exceptions;
namespace Mosa.Compiler.Framework;
[Flags]
public enum TransformType
{ Transform, Auto, Manual, Optimization, Window, Search }
public abstract class BaseTransform : IComparable<BaseTransform>
{
#region Properties
public BaseInstruction Instruction { get; private set; }
public bool Log { get; private set; }
public string Name { get; }
public virtual int Priority { get; } = 0;
public virtual bool IsAuto { get; protected set; }
public bool IsManual => !IsAuto;
public virtual bool IsOptimization { get; protected set; }
public bool IsTranformation => !IsOptimization;
#endregion Properties
#region Constructors
public BaseTransform(BaseInstruction instruction, TransformType type, bool log = false)
{
Instruction = instruction;
Log = log;
IsAuto = type.HasFlag(TransformType.Auto);
IsOptimization = type.HasFlag(TransformType.Optimization);
Name = GetType().FullName.Replace("Mosa.Compiler.", string.Empty).Replace("Mosa.Compiler.Framework.Transforms", "IR").Replace("Transforms.", string.Empty);
}
public BaseTransform(TransformType type, bool log = false)
: this(null, type, log)
{
}
#endregion Constructors
#region Internals
int IComparable<BaseTransform>.CompareTo(BaseTransform other)
{
return Priority.CompareTo(other.Priority);
}
#endregion Internals
#region Abstract Methods
public abstract bool Match(Context context, Transform transform);
public abstract void Transform(Context context, Transform transform);
#endregion Abstract Methods
#region Filter Methods
protected static bool AreSame(Operand operand1, Operand operand2)
{
if (operand1 == operand2)
return true;
if (operand1.IsPhysicalRegister && operand2.IsPhysicalRegister && operand1.Register == operand2.Register)
return true;
if (operand1.IsResolvedConstant && operand2.IsResolvedConstant)
{
if (operand1.IsInteger && operand1.ConstantUnsigned64 == operand2.ConstantUnsigned64)
return true;
if (operand1.IsR4 && operand1.IsR4 && operand1.ConstantDouble == operand2.ConstantDouble)
return true;
if (operand1.IsR8 && operand1.IsR8 && operand2.ConstantFloat == operand2.ConstantFloat)
return true;
}
return false;
}
protected static bool IsConstant(Operand operand)
{
return operand.IsConstant;
}
protected static bool IsCPURegister(Operand operand)
{
return operand.IsPhysicalRegister;
}
protected static bool IsCPURegister(Operand operand, PhysicalRegister register)
{
return operand.IsPhysicalRegister && operand.Register == register;
}
protected static bool IsVirtualRegister(Operand operand)
{
return operand.IsVirtualRegister;
}
protected static bool IsEqual(ulong a, ulong b)
{
return a == b;
}
protected static bool Contains(Operand operand, long a)
{
return operand.IsResolvedConstant && operand.ConstantSigned32 == a;
}
protected static bool Contains(Operand operand, long a, long b)
{
return operand.IsResolvedConstant && (operand.ConstantSigned32 == a || operand.ConstantSigned32 == b);
}
protected static bool Contains(Operand operand, long a, long b, long c)
{
return operand.IsResolvedConstant && (operand.ConstantSigned32 == a || operand.ConstantSigned32 == b || operand.ConstantSigned32 == c);
}
protected static bool Contains(Operand operand, ulong a)
{
return operand.IsResolvedConstant && operand.ConstantUnsigned64 == a;
}
protected static bool Contains(Operand operand, ulong a, ulong b)
{
return operand.IsResolvedConstant && (operand.ConstantUnsigned64 == a || operand.ConstantUnsigned64 == b);
}
protected static bool Contains(Operand operand1, ulong a, ulong b, ulong c)
{
return IsResolvedConstant(operand1) && (operand1.ConstantUnsigned64 == a || operand1.ConstantUnsigned64 == b && operand1.ConstantUnsigned64 == c);
}
protected static bool IsEvenInteger(Operand operand)
{
return operand.IsResolvedConstant && operand.IsInteger && (operand.ConstantUnsigned64 & 1) == 0;
}
protected static bool IsFloatingPoint(Operand operand)
{
return operand.IsFloatingPoint;
}
protected static bool IsGreater(ulong a, ulong b)
{
return a > b;
}
protected static bool IsGreaterOrEqual(ulong a, ulong b)
{
return a >= b;
}
protected static bool IsInteger(Operand operand)
{
return operand.IsInteger;
}
protected static bool IsUnsignedBetween32(Operand operand, uint a, uint b)
{
return operand.IsResolvedConstant && operand.IsInteger && operand.ConstantUnsigned32 >= a && operand.ConstantUnsigned32 <= b;
}
protected static bool IsUnsignedBetween64(Operand operand, uint a, uint b)
{
return operand.IsResolvedConstant && operand.IsInteger && operand.ConstantUnsigned64 >= a && operand.ConstantUnsigned64 <= b;
}
protected static bool IsSignedBetween32(Operand operand, uint a, uint b)
{
return operand.IsResolvedConstant && operand.IsInteger && operand.ConstantSigned32 >= a && operand.ConstantSigned32 <= b;
}
protected static bool IsSignedBetween64(Operand operand, uint a, uint b)
{
return operand.IsResolvedConstant && operand.IsInteger && operand.ConstantSigned64 >= a && operand.ConstantSigned64 <= b;
}
protected static bool IsIntegerBetween0And32(Operand operand)
{
return operand.IsResolvedConstant && operand.IsInteger && operand.ConstantSigned64 >= 0 && operand.ConstantSigned64 <= 32;
}
protected static bool IsIntegerBetween0And64(Operand operand)
{
return operand.IsResolvedConstant && operand.IsInteger && operand.ConstantSigned64 >= 0 && operand.ConstantSigned64 <= 64;
}
protected static bool IsLessOrEqual(ulong a, ulong b)
{
return a <= b;
}
protected static bool IsLessThan(ulong a, ulong b)
{
return a < b;
}
protected static bool IsLessThanZero(ulong a)
{
return (long)a < 0;
}
protected static bool IsNaturalSquareRoot32(Operand operand)
{
if (!operand.IsResolvedConstant)
return false;
var value = operand.ConstantUnsigned32;
var sqrt = Sqrt32(value);
var s2 = sqrt * sqrt;
return value == s2;
}
protected static bool IsNaturalSquareRoot64(Operand operand)
{
if (!operand.IsResolvedConstant)
return false;
var value = operand.ConstantUnsigned64;
var sqrt = Sqrt64(value);
var s2 = sqrt * sqrt;
return value == s2;
}
protected static bool IsOddInteger(Operand operand)
{
return operand.IsResolvedConstant && operand.IsInteger && (operand.ConstantUnsigned64 & 1) == 1;
}
protected static bool IsOne(Operand operand)
{
return operand.IsConstantOne;
}
protected static bool IsParameter(Operand operand)
{
return operand.IsParameter;
}
protected static bool IsPowerOfTwo32(Operand operand)
{
return operand.IsResolvedConstant && BitTwiddling.IsPowerOfTwo(operand.ConstantUnsigned32);
}
protected static bool IsPowerOfTwo64(Operand operand)
{
return operand.IsResolvedConstant && BitTwiddling.IsPowerOfTwo(operand.ConstantUnsigned64);
}
protected static bool IsResolvedConstant(Operand operand)
{
return operand.IsResolvedConstant;
}
protected static bool IsSignedIntegerPositive(Operand operand)
{
return operand.IsResolvedConstant && operand.IsResolvedConstant && operand.IsInteger && operand.ConstantSigned64 >= 0;
}
protected static bool IsUnsignedIntegerPositive(Operand operand)
{
return operand.IsResolvedConstant && operand.IsResolvedConstant && operand.IsInteger && operand.ConstantUnsigned64 >= 0;
}
protected static bool IsZero(Operand operand)
{
return operand.IsConstantZero;
}
protected static bool IsZero(ulong value)
{
return value == 0;
}
public static bool AreAnyStatusFlagsUsed(Context context)
{
return AreStatusFlagsUsed(context.Instruction, context.Node) != TriState.No;
}
public static bool IsCarryFlagUsed(Context context)
{
return IsCarryFlagUsed(context.Node) != TriState.No;
}
protected static bool IsResultAndOperand1Same(Context context)
{
return context.Result == context.Operand1;
}
protected static bool IsResult1Used(Context context)
{
return context.Result.IsUsed;
}
protected static bool IsResult2Used(Context context)
{
return context.Result2.IsUsed;
}
protected static bool IsSignedMax32(uint a)
{
return a == uint.MaxValue;
}
protected static bool IsUnsignedMax32(uint a)
{
return (int)a == int.MaxValue;
}
protected static bool IsSignedMax64(ulong a)
{
return (long)a == long.MaxValue;
}
protected static bool IsUnsignedMax64(ulong a)
{
return a == ulong.MaxValue;
}
#endregion Filter Methods
#region Expression Methods
protected static uint Add32(uint a, uint b)
{
return a + b;
}
protected static ulong Add64(ulong a, ulong b)
{
return a + b;
}
protected static float AddR4(float a, float b)
{
return a + b;
}
protected static double AddR8(double a, double b)
{
return a + b;
}
protected static uint And32(uint a, uint b)
{
return a & b;
}
protected static ulong And64(ulong a, ulong b)
{
return a & b;
}
protected static uint BoolTo32(bool b)
{
return b ? (uint)1 : 0;
}
protected static uint BoolTo32(uint a)
{
return a == 0 ? (uint)0 : 1;
}
protected static long BoolTo64(bool b)
{
return b ? 1 : 0;
}
protected static ulong BoolTo64(ulong a)
{
return a == 0 ? (ulong)0 : 1;
}
protected static float DivR4(float a, float b)
{
return a / b;
}
protected static double DivR8(double a, double b)
{
return a / b;
}
protected static long DivSigned32(long a, long b)
{
return a / b;
}
protected static long DivSigned64(long a, long b)
{
return a / b;
}
protected static uint DivUnsigned32(uint a, uint b)
{
return a / b;
}
protected static ulong DivUnsigned64(ulong a, ulong b)
{
return a / b;
}
protected static uint GetHigh32(ulong a)
{
return (uint)(a >> 32);
}
protected static uint GetHighestSetBitPosition(ulong value)
{
return (uint)BitTwiddling.GetHighestSetBitPosition(value);
}
protected static uint CountTrailingZeros(ulong value)
{
return (uint)BitTwiddling.CountTrailingZeros(value);
}
protected static uint GetPowerOfTwo(ulong value)
{
return BitTwiddling.GetPowerOfTwo(value);
}
protected static uint GetPowerOfTwo(Operand operand)
{
return GetPowerOfTwo(operand.ConstantUnsigned64);
}
protected static uint Max32(uint a, uint b)
{
return Math.Max(a, b);
}
protected static ulong Max64(ulong a, ulong b)
{
return Math.Max(a, b);
}
protected static uint Min32(uint a, uint b)
{
return Math.Min(a, b);
}
protected static ulong Min64(ulong a, ulong b)
{
return Math.Min(a, b);
}
protected static long ModSigned32(long a, long b)
{
return a % b;
}
protected static long ModSigned64(long a, long b)
{
return a % b;
}
protected static uint ModUnsigned32(uint a, uint b)
{
return a % b;
}
protected static ulong ModUnsigned64(ulong a, ulong b)
{
return a % b;
}
protected static float MulR4(float a, float b)
{
return a * b;
}
protected static double MulR8(double a, double b)
{
return a * b;
}
protected static int MulSigned32(int a, int b)
{
return a * b;
}
protected static long MulSigned64(long a, long b)
{
return a * b;
}
protected static uint MulUnsigned32(uint a, uint b)
{
return a * b;
}
protected static ulong MulUnsigned64(ulong a, ulong b)
{
return a * b;
}
protected static uint NaxU32()
{
return uint.MaxValue;
}
protected static int NaxI32()
{
return int.MaxValue;
}
protected static ulong NaxU64()
{
return ulong.MaxValue;
}
protected static long NaxI64()
{
return long.MaxValue;
}
protected static int Neg32(int a)
{
return -a;
}
protected static int Neg32(uint a)
{
return -((int)a);
}
protected static long Neg64(long a)
{
return -a;
}
protected static long Neg64(ulong a)
{
return -((long)a);
}
protected static uint Not32(uint a)
{
return ~a;
}
protected static ulong Not64(ulong a)
{
return ~a;
}
protected static uint Or32(uint a, uint b)
{
return a | b;
}
protected static ulong Or64(ulong a, ulong b)
{
return a | b;
}
protected static float RemR4(float a, float b)
{
return a % b;
}
protected static double RemR8(double a, double b)
{
return a % b;
}
protected static long RemSigned32(long a, long b)
{
return a % b;
}
protected static long RemSigned64(long a, long b)
{
return a % b;
}
protected static uint RemUnsigned32(uint a, uint b)
{
return a % b;
}
protected static ulong RemUnsigned64(ulong a, ulong b)
{
return a % b;
}
protected static uint ShiftLeft32(uint a, long b)
{
return a << (int)b;
}
protected static ulong ShiftLeft64(ulong a, long b)
{
return a << (int)b;
}
protected static ulong ShiftLeft64(ulong a, ulong b)
{
return a << (int)b;
}
protected static uint ShiftRight32(uint a, long b)
{
return a >> (int)b;
}
protected static ulong ShiftRight64(ulong a, long b)
{
return a >> (int)b;
}
protected static uint ArithmeticShiftRight32(uint a, int b)
{
return (uint)((int)a >> b);
}
protected static ulong ArithmeticShiftRight64(ulong a, long b)
{
return (ulong)((long)a >> (int)b);
}
protected static ulong Sqrt32(uint num)
{
if (0 == num)
return 0;
var n = num / 2 + 1;
var n1 = (n + num / n) / 2;
while (n1 < n)
{
n = n1;
n1 = (n + num / n) / 2;
}
return n;
}
protected static ulong Sqrt64(ulong num)
{
if (0 == num)
return 0;
var n = num / 2 + 1;
var n1 = (n + num / n) / 2;
while (n1 < n)
{
n = n1;
n1 = (n + num / n) / 2;
}
return n;
}
protected static long Sqrt64(long num)
{
if (0 == num)
return 0;
var n = num / 2 + 1;
var n1 = (n + num / n) / 2;
while (n1 < n)
{
n = n1;
n1 = (n + num / n) / 2;
}
return n;
}
protected static ulong Square32(uint n)
{
return n * n;
}
protected static ulong Square64(ulong n)
{
return n * n;
}
protected static uint Sub32(uint a, uint b)
{
return a - b;
}
protected static ulong Sub64(ulong a, ulong b)
{
return a - b;
}
protected static float SubR4(float a, float b)
{
return a - b;
}
protected static double SubR8(double a, double b)
{
return a - b;
}
protected static uint To32(Operand operand)
{
return operand.ConstantUnsigned32;
}
protected static uint To32(ulong value)
{
return (uint)value;
}
protected static ulong To64(uint low, uint high)
{
return ((ulong)high << 32) | low;
}
protected static ulong To64(Operand operand)
{
return operand.ConstantUnsigned64;
}
protected static ulong To64(ulong value)
{
return value;
}
protected static byte ToByte(ulong value)
{
return (byte)value;
}
protected static byte ToByte(Operand operand)
{
return (byte)operand.ConstantUnsigned32;
}
protected static float ToR4(Operand operand)
{
return operand.ConstantFloat;
}
protected static float ToR4(float value)
{
return value;
}
protected static float ToR4(int a)
{
return a;
}
protected static float ToR4(long a)
{
return a;
}
protected static double ToR8(Operand operand)
{
return operand.ConstantDouble;
}
protected static double ToR8(double value)
{
return value;
}
protected static double ToR8(int a)
{
return a;
}
protected static double ToR8(long a)
{
return a;
}
protected static ushort ToShort(ulong value)
{
return (ushort)value;
}
protected static ushort ToShort(Operand operand)
{
return (ushort)operand.ConstantUnsigned32;
}
protected static int ToSigned32(Operand operand)
{
return operand.ConstantSigned32;
}
protected static long ToSigned64(Operand operand)
{
return operand.ConstantSigned64;
}
protected static uint Xor32(uint a, uint b)
{
return a ^ b;
}
protected static ulong Xor64(ulong a, ulong b)
{
return a ^ b;
}
protected static uint UseCount(Operand operand)
{
return (uint)operand.Uses.Count;
}
protected static bool IsAddSignedOverflow32(int a, int b)
{
return IntegerTwiddling.IsAddSignedOverflow(a, b);
}
protected static bool IsAddSignedOverflow64(long a, long b)
{
return IntegerTwiddling.IsAddSignedOverflow(a, b);
}
protected static bool IsAddUnsignedOverflow32(uint a, uint b)
{
return IntegerTwiddling.IsAddUnsignedCarry(a, b);
}
protected static bool IsAddUnsignedOverflow64(ulong a, ulong b)
{
return IntegerTwiddling.IsAddUnsignedCarry(a, b);
}
protected static bool IsAddOverflow32(ulong a, ulong b)
{
return IsAddSignedOverflow32((int)a, (int)b) || IsAddUnsignedOverflow32((uint)a, (uint)b);
}
protected static bool IsAddOverflow64(ulong a, ulong b)
{
return IsAddSignedOverflow64((long)a, (long)b) || IsAddUnsignedOverflow64(a, b);
}
#endregion Expression Methods
#region SignExtend Helpers
protected static uint SignExtend16x32(ushort value)
{
return (value & 0x8000) == 0 ? value : value | 0xFFFF0000;
}
protected static ulong SignExtend16x64(ushort value)
{
return (value & 0x8000) == 0 ? value : value | 0xFFFFFFFFFFFF0000ul;
}
protected static ulong SignExtend32x64(uint value)
{
return (value & 0x80000000) == 0 ? value : value | 0xFFFFFFFF00000000ul;
}
protected static uint SignExtend8x32(byte value)
{
return (value & 0x80) == 0 ? value : value | 0xFFFFFF00;
}
protected static ulong SignExtend8x64(byte value)
{
return (value & 0x80) == 0 ? value : value | 0xFFFFFFFFFFFFFF00ul;
}
#endregion SignExtend Helpers
#region Status Helpers
public enum TriState
{ Yes, No, Unknown };
public static TriState AreAnyStatusFlagsUsed(Node node)
{
return AreStatusFlagsUsed(node.Next, true, true, true, true, true);
}
public static TriState IsCarryFlagUsed(Node node)
{
return AreStatusFlagsUsed(node.Next, false, true, false, false, false);
}
public static TriState AreStatusFlagsUsed(BaseInstruction instruction, Node node)
{
return AreStatusFlagsUsed(node.Next,
instruction.IsZeroFlagModified,
instruction.IsCarryFlagModified,
instruction.IsSignFlagModified,
instruction.IsOverflowFlagModified,
instruction.IsParityFlagModified);
}
public static TriState AreStatusFlagsUsed(Node node, bool checkZero, bool checkCarry, bool checkSign, bool checkOverlow, bool checkParity)
{
// if none are being checked, then for sure it's a no
if (!checkZero && !checkCarry && !checkSign && !checkOverlow && !checkParity)
return TriState.No;
for (var at = node; ; at = at.Next)
{
if (at.IsEmptyOrNop)
continue;
if (at.IsBlockEndInstruction)
return TriState.Unknown;
if (at.Instruction == IR.StableObjectTracking
|| at.Instruction == IR.UnstableObjectTracking
|| at.Instruction == IR.Kill
|| at.Instruction == IR.KillAll
|| at.Instruction == IR.KillAllExcept
|| at.Instruction == IR.Gen)
continue;
if (at.Instruction.IsReturn)
return TriState.No;
if (at.Instruction == IR.Epilogue)
return TriState.No;
if (at.Instruction.IsUnconditionalBranch && at.Block.NextBlocks.Count == 1)
{
at = at.BranchTargets[0].First;
continue;
}
if (!at.Instruction.IsFlowNext)
return TriState.Unknown; // Flow direction changed
var instruction = at.Instruction;
if (!instruction.IsPlatformInstruction)
return TriState.Unknown; // Unknown IR instruction
if ((checkZero && instruction.IsZeroFlagUsed)
|| (checkCarry && instruction.IsCarryFlagUsed)
|| (checkSign && instruction.IsSignFlagUsed)
|| (checkOverlow && instruction.IsOverflowFlagUsed)
|| (checkParity && instruction.IsParityFlagUsed))
return TriState.Yes;
if (checkZero && (instruction.IsZeroFlagCleared || instruction.IsZeroFlagSet || instruction.IsZeroFlagUndefined || instruction.IsZeroFlagModified))
checkZero = false;
if (checkCarry && (instruction.IsCarryFlagCleared || instruction.IsCarryFlagSet || instruction.IsCarryFlagUndefined || instruction.IsCarryFlagModified))
checkCarry = false;
if (checkSign && (instruction.IsSignFlagCleared || instruction.IsSignFlagSet || instruction.IsSignFlagUndefined || instruction.IsSignFlagModified))
checkSign = false;
if (checkOverlow && (instruction.IsOverflowFlagCleared || instruction.IsOverflowFlagSet || instruction.IsOverflowFlagUndefined || instruction.IsOverflowFlagModified))
checkOverlow = false;
if (checkParity && (instruction.IsParityFlagCleared || instruction.IsParityFlagSet || instruction.IsParityFlagUndefined || instruction.IsParityFlagModified))
checkParity = false;
if (!checkZero && !checkCarry && !checkSign && !checkOverlow && !checkParity)
return TriState.No;
}
}
#endregion Status Helpers
#region BitTracker Helpers
protected static uint BitValueMax32(Operand operand)
{
return (uint)operand.BitValue.MaxValue;
}