PeepsMD.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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(RegRAX);
  20. this->peeps->ClearReg(RegRCX);
  21. this->peeps->ClearReg(RegRDX);
  22. this->peeps->ClearReg(RegR8);
  23. this->peeps->ClearReg(RegR9);
  24. this->peeps->ClearReg(RegR10);
  25. this->peeps->ClearReg(RegR11);
  26. this->peeps->ClearReg(RegXMM0);
  27. this->peeps->ClearReg(RegXMM1);
  28. this->peeps->ClearReg(RegXMM2);
  29. this->peeps->ClearReg(RegXMM3);
  30. this->peeps->ClearReg(RegXMM4);
  31. this->peeps->ClearReg(RegXMM5);
  32. }
  33. else if (instr->m_opcode == Js::OpCode::IMUL)
  34. {
  35. this->peeps->ClearReg(RegRDX);
  36. }
  37. else if (instr->m_opcode == Js::OpCode::IDIV)
  38. {
  39. if (instr->GetDst()->AsRegOpnd()->GetReg() == RegRDX)
  40. {
  41. this->peeps->ClearReg(RegRAX);
  42. }
  43. else
  44. {
  45. Assert(instr->GetDst()->AsRegOpnd()->GetReg() == RegRAX);
  46. this->peeps->ClearReg(RegRDX);
  47. }
  48. }
  49. }
  50. void
  51. PeepsMD::PeepAssign(IR::Instr *instr)
  52. {
  53. IR::Opnd* dst = instr->GetDst();
  54. IR::Opnd* src = instr->GetSrc1();
  55. if(dst->IsRegOpnd() && instr->m_opcode == Js::OpCode::MOV)
  56. {
  57. if (src->IsImmediateOpnd() && src->GetImmediateValue(instr->m_func) == 0)
  58. {
  59. Assert(instr->GetSrc2() == NULL);
  60. // 32-bit XOR has a smaller encoding
  61. if (TySize[dst->GetType()] == MachPtr)
  62. {
  63. dst->SetType(TyInt32);
  64. }
  65. instr->m_opcode = Js::OpCode::XOR;
  66. instr->ReplaceSrc1(dst);
  67. instr->SetSrc2(dst);
  68. }
  69. else if (!instr->isInlineeEntryInstr)
  70. {
  71. if(src->IsIntConstOpnd() && src->GetSize() <= TySize[TyUint32])
  72. {
  73. dst->SetType(TyUint32);
  74. }
  75. else if(src->IsAddrOpnd() && (((size_t)src->AsAddrOpnd()->m_address >> 32) == 0 ))
  76. {
  77. instr->ReplaceSrc1(IR::IntConstOpnd::New(::Math::PointerCastToIntegral<UIntConstType>(src->AsAddrOpnd()->m_address), TyUint32, instr->m_func));
  78. dst->SetType(TyUint32);
  79. }
  80. }
  81. }
  82. else if (((instr->m_opcode == Js::OpCode::MOVSD || instr->m_opcode == Js::OpCode::MOVSS)
  83. && src->IsRegOpnd()
  84. && dst->IsRegOpnd()
  85. && (TySize[src->GetType()] == TySize[dst->GetType()]))
  86. || ((instr->m_opcode == Js::OpCode::MOVUPS)
  87. && src->IsRegOpnd()
  88. && dst->IsRegOpnd())
  89. || (instr->m_opcode == Js::OpCode::MOVAPD))
  90. {
  91. // MOVAPS has 1 byte shorter encoding
  92. instr->m_opcode = Js::OpCode::MOVAPS;
  93. }
  94. else if (instr->m_opcode == Js::OpCode::MOVSD_ZERO)
  95. {
  96. instr->m_opcode = Js::OpCode::XORPS;
  97. instr->SetSrc1(dst);
  98. instr->SetSrc2(dst);
  99. }
  100. }