PeepsMD.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "Backend.h"
  6. // PeepsMD::Init
  7. void
  8. PeepsMD::Init(Peeps *peeps)
  9. {
  10. this->peeps = peeps;
  11. }
  12. // PeepsMD::ProcessImplicitRegs
  13. // Note: only do calls for now
  14. void
  15. PeepsMD::ProcessImplicitRegs(IR::Instr *instr)
  16. {
  17. if (LowererMD::IsCall(instr))
  18. {
  19. this->peeps->ClearReg(RegEAX);
  20. this->peeps->ClearReg(RegECX);
  21. this->peeps->ClearReg(RegEDX);
  22. this->peeps->ClearReg(RegXMM0);
  23. this->peeps->ClearReg(RegXMM1);
  24. this->peeps->ClearReg(RegXMM2);
  25. this->peeps->ClearReg(RegXMM3);
  26. this->peeps->ClearReg(RegXMM4);
  27. this->peeps->ClearReg(RegXMM5);
  28. this->peeps->ClearReg(RegXMM6);
  29. this->peeps->ClearReg(RegXMM7);
  30. }
  31. else if (instr->m_opcode == Js::OpCode::IMUL)
  32. {
  33. this->peeps->ClearReg(RegEDX);
  34. }
  35. else if (instr->m_opcode == Js::OpCode::IDIV || instr->m_opcode == Js::OpCode::DIV)
  36. {
  37. if (instr->GetDst()->AsRegOpnd()->GetReg() == RegEDX)
  38. {
  39. this->peeps->ClearReg(RegEAX);
  40. }
  41. else
  42. {
  43. Assert(instr->GetDst()->AsRegOpnd()->GetReg() == RegEAX);
  44. this->peeps->ClearReg(RegEDX);
  45. }
  46. }
  47. else if (instr->m_opcode == Js::OpCode::XCHG)
  48. {
  49. // At time of writing, I believe that src1 is always identical to dst, but clear both for robustness.
  50. // Either of XCHG's operands (but not both) can be a memory address, so only clear registers.
  51. if (instr->GetSrc1()->IsRegOpnd())
  52. {
  53. this->peeps->ClearReg(instr->GetSrc1()->AsRegOpnd()->GetReg());
  54. }
  55. if (instr->GetSrc2()->IsRegOpnd())
  56. {
  57. this->peeps->ClearReg(instr->GetSrc2()->AsRegOpnd()->GetReg());
  58. }
  59. }
  60. }
  61. void
  62. PeepsMD::PeepAssign(IR::Instr *instr)
  63. {
  64. IR::Opnd *src = instr->GetSrc1();
  65. IR::Opnd *dst = instr->GetDst();
  66. if (instr->m_opcode == Js::OpCode::MOV && src->IsIntConstOpnd()
  67. && src->AsIntConstOpnd()->GetValue() == 0 && dst->IsRegOpnd())
  68. {
  69. Assert(instr->GetSrc2() == NULL);
  70. instr->m_opcode = Js::OpCode::XOR;
  71. instr->ReplaceSrc1(dst);
  72. instr->SetSrc2(dst);
  73. } else if ((instr->m_opcode == Js::OpCode::MOVSD || instr->m_opcode == Js::OpCode::MOVSS || instr->m_opcode == Js::OpCode::MOVUPS) && src->IsRegOpnd() && dst->IsRegOpnd())
  74. {
  75. // MOVAPS has 1 byte shorter encoding
  76. instr->m_opcode = Js::OpCode::MOVAPS;
  77. }
  78. else if (instr->m_opcode == Js::OpCode::MOVSD_ZERO)
  79. {
  80. instr->m_opcode = Js::OpCode::XORPS;
  81. instr->SetSrc1(dst);
  82. instr->SetSrc2(dst);
  83. }
  84. }