AILBlock.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections.Generic;
  2. namespace ChocolArm64.Translation
  3. {
  4. class AILBlock : IAILEmit
  5. {
  6. public long IntInputs { get; private set; }
  7. public long IntOutputs { get; private set; }
  8. public long IntAwOutputs { get; private set; }
  9. public long VecInputs { get; private set; }
  10. public long VecOutputs { get; private set; }
  11. public long VecAwOutputs { get; private set; }
  12. public bool HasStateStore { get; private set; }
  13. public List<IAILEmit> ILEmitters { get; private set; }
  14. public AILBlock Next { get; set; }
  15. public AILBlock Branch { get; set; }
  16. public AILBlock()
  17. {
  18. ILEmitters = new List<IAILEmit>();
  19. }
  20. public void Add(IAILEmit ILEmitter)
  21. {
  22. if (ILEmitter is AILBarrier)
  23. {
  24. //Those barriers are used to separate the groups of CIL
  25. //opcodes emitted by each ARM instruction.
  26. //We can only consider the new outputs for doing input elimination
  27. //after all the CIL opcodes used by the instruction being emitted.
  28. IntAwOutputs = IntOutputs;
  29. VecAwOutputs = VecOutputs;
  30. }
  31. else if (ILEmitter is AILOpCodeLoad Ld && AILEmitter.IsRegIndex(Ld.Index))
  32. {
  33. switch (Ld.IoType)
  34. {
  35. case AIoType.Flag: IntInputs |= ((1L << Ld.Index) << 32) & ~IntAwOutputs; break;
  36. case AIoType.Int: IntInputs |= (1L << Ld.Index) & ~IntAwOutputs; break;
  37. case AIoType.Vector: VecInputs |= (1L << Ld.Index) & ~VecAwOutputs; break;
  38. }
  39. }
  40. else if (ILEmitter is AILOpCodeStore St)
  41. {
  42. if (AILEmitter.IsRegIndex(St.Index))
  43. {
  44. switch (St.IoType)
  45. {
  46. case AIoType.Flag: IntOutputs |= (1L << St.Index) << 32; break;
  47. case AIoType.Int: IntOutputs |= 1L << St.Index; break;
  48. case AIoType.Vector: VecOutputs |= 1L << St.Index; break;
  49. }
  50. }
  51. if (St.IoType == AIoType.Fields)
  52. {
  53. HasStateStore = true;
  54. }
  55. }
  56. ILEmitters.Add(ILEmitter);
  57. }
  58. public void Emit(AILEmitter Context)
  59. {
  60. foreach (IAILEmit ILEmitter in ILEmitters)
  61. {
  62. ILEmitter.Emit(Context);
  63. }
  64. }
  65. }
  66. }