OLD | NEW |
1 //===- subzero/src/IceTargetLoweringARM32.cpp - ARM32 lowering ------------===// | 1 //===- subzero/src/IceTargetLoweringARM32.cpp - ARM32 lowering ------------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 /// | 9 /// |
10 /// \file | 10 /// \file |
(...skipping 2711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2722 // ARM, shifts only take the lower 8 bits of the shift register, and | 2722 // ARM, shifts only take the lower 8 bits of the shift register, and |
2723 // saturate to the range 0-32, so the negative value will saturate to 32. | 2723 // saturate to the range 0-32, so the negative value will saturate to 32. |
2724 Operand *_32 = legalize(Ctx->getConstantInt32(32), Legal_Reg | Legal_Flex); | 2724 Operand *_32 = legalize(Ctx->getConstantInt32(32), Legal_Reg | Legal_Flex); |
2725 Operand *_0 = | 2725 Operand *_0 = |
2726 legalize(Ctx->getConstantZero(IceType_i32), Legal_Reg | Legal_Flex); | 2726 legalize(Ctx->getConstantZero(IceType_i32), Legal_Reg | Legal_Flex); |
2727 Variable *T0 = makeReg(IceType_i32); | 2727 Variable *T0 = makeReg(IceType_i32); |
2728 Variable *T1 = makeReg(IceType_i32); | 2728 Variable *T1 = makeReg(IceType_i32); |
2729 Variable *T2 = makeReg(IceType_i32); | 2729 Variable *T2 = makeReg(IceType_i32); |
2730 Variable *TA_Hi = makeReg(IceType_i32); | 2730 Variable *TA_Hi = makeReg(IceType_i32); |
2731 Variable *TA_Lo = makeReg(IceType_i32); | 2731 Variable *TA_Lo = makeReg(IceType_i32); |
2732 Variable *Src0RLo = SrcsLo.src0R(this); | 2732 Variable *Src0RLo = SrcsLo.unswappedSrc0R(this); |
2733 Variable *Src0RHi = SrcsHi.unswappedSrc0R(this); | 2733 Variable *Src0RHi = SrcsHi.unswappedSrc0R(this); |
2734 Variable *Src1RLo = SrcsLo.unswappedSrc1R(this); | 2734 Variable *Src1RLo = SrcsLo.unswappedSrc1R(this); |
2735 _rsb(T0, Src1RLo, _32); | 2735 _rsb(T0, Src1RLo, _32); |
2736 _lsr(T1, Src0RLo, T0); | 2736 _lsr(T1, Src0RLo, T0); |
2737 _orr(TA_Hi, T1, OperandARM32FlexReg::create(Func, IceType_i32, Src0RHi, | 2737 _orr(TA_Hi, T1, OperandARM32FlexReg::create(Func, IceType_i32, Src0RHi, |
2738 OperandARM32::LSL, Src1RLo)); | 2738 OperandARM32::LSL, Src1RLo)); |
2739 _sub(T2, Src1RLo, _32); | 2739 _sub(T2, Src1RLo, _32); |
2740 _cmp(T2, _0); | 2740 _cmp(T2, _0); |
2741 _lsl(TA_Hi, Src0RLo, T2, CondARM32::GE); | 2741 _lsl(TA_Hi, Src0RLo, T2, CondARM32::GE); |
2742 _set_dest_redefined(); | 2742 _set_dest_redefined(); |
(...skipping 3738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6481 // peephole style optimizations during or before lowering have access to | 6481 // peephole style optimizations during or before lowering have access to |
6482 // this instruction in undeleted form. See for example | 6482 // this instruction in undeleted form. See for example |
6483 // tryOptimizedCmpxchgCmpBr(). | 6483 // tryOptimizedCmpxchgCmpBr(). |
6484 Iter->second.Instr->setDead(); | 6484 Iter->second.Instr->setDead(); |
6485 ++Iter; | 6485 ++Iter; |
6486 } | 6486 } |
6487 } | 6487 } |
6488 | 6488 |
6489 TargetARM32::Sandboxer::Sandboxer(TargetARM32 *Target, | 6489 TargetARM32::Sandboxer::Sandboxer(TargetARM32 *Target, |
6490 InstBundleLock::Option BundleOption) | 6490 InstBundleLock::Option BundleOption) |
6491 : Bundler(Target, BundleOption), Target(Target) {} | 6491 : Target(Target), BundleOption(BundleOption) {} |
6492 | 6492 |
6493 TargetARM32::Sandboxer::~Sandboxer() {} | 6493 TargetARM32::Sandboxer::~Sandboxer() {} |
6494 | 6494 |
6495 namespace { | 6495 namespace { |
6496 OperandARM32FlexImm *indirectBranchBicMask(Cfg *Func) { | 6496 OperandARM32FlexImm *indirectBranchBicMask(Cfg *Func) { |
6497 constexpr uint32_t Imm8 = 0xFC; // 0xC000000F | 6497 constexpr uint32_t Imm8 = 0xFC; // 0xC000000F |
6498 constexpr uint32_t RotateAmt = 2; | 6498 constexpr uint32_t RotateAmt = 2; |
6499 return OperandARM32FlexImm::create(Func, IceType_i32, Imm8, RotateAmt); | 6499 return OperandARM32FlexImm::create(Func, IceType_i32, Imm8, RotateAmt); |
6500 } | 6500 } |
6501 | 6501 |
6502 OperandARM32FlexImm *memOpBicMask(Cfg *Func) { | 6502 OperandARM32FlexImm *memOpBicMask(Cfg *Func) { |
6503 constexpr uint32_t Imm8 = 0x0C; // 0xC0000000 | 6503 constexpr uint32_t Imm8 = 0x0C; // 0xC0000000 |
6504 constexpr uint32_t RotateAmt = 2; | 6504 constexpr uint32_t RotateAmt = 2; |
6505 return OperandARM32FlexImm::create(Func, IceType_i32, Imm8, RotateAmt); | 6505 return OperandARM32FlexImm::create(Func, IceType_i32, Imm8, RotateAmt); |
6506 } | 6506 } |
6507 | 6507 |
6508 static bool baseNeedsBic(Variable *Base) { | 6508 static bool baseNeedsBic(Variable *Base) { |
6509 return Base->getRegNum() != RegARM32::Reg_r9 && | 6509 return Base->getRegNum() != RegARM32::Reg_r9 && |
6510 Base->getRegNum() != RegARM32::Reg_sp; | 6510 Base->getRegNum() != RegARM32::Reg_sp; |
6511 } | 6511 } |
6512 } // end of anonymous namespace | 6512 } // end of anonymous namespace |
6513 | 6513 |
| 6514 void TargetARM32::Sandboxer::createAutoBundle() { |
| 6515 Bundler = makeUnique<AutoBundle>(Target, BundleOption); |
| 6516 } |
| 6517 |
6514 void TargetARM32::Sandboxer::add_sp(Operand *AddAmount) { | 6518 void TargetARM32::Sandboxer::add_sp(Operand *AddAmount) { |
6515 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp); | 6519 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp); |
| 6520 if (!Target->NeedSandboxing) { |
| 6521 Target->_add(SP, SP, AddAmount); |
| 6522 return; |
| 6523 } |
| 6524 createAutoBundle(); |
6516 Target->_add(SP, SP, AddAmount); | 6525 Target->_add(SP, SP, AddAmount); |
6517 if (Target->NeedSandboxing) { | 6526 Target->_bic(SP, SP, memOpBicMask(Target->Func)); |
6518 Target->_bic(SP, SP, memOpBicMask(Target->Func)); | |
6519 } | |
6520 } | 6527 } |
6521 | 6528 |
6522 void TargetARM32::Sandboxer::align_sp(size_t Alignment) { | 6529 void TargetARM32::Sandboxer::align_sp(size_t Alignment) { |
6523 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp); | 6530 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp); |
| 6531 if (!Target->NeedSandboxing) { |
| 6532 Target->alignRegisterPow2(SP, Alignment); |
| 6533 return; |
| 6534 } |
| 6535 createAutoBundle(); |
6524 Target->alignRegisterPow2(SP, Alignment); | 6536 Target->alignRegisterPow2(SP, Alignment); |
6525 if (Target->NeedSandboxing) { | 6537 Target->_bic(SP, SP, memOpBicMask(Target->Func)); |
6526 Target->_bic(SP, SP, memOpBicMask(Target->Func)); | |
6527 } | |
6528 } | 6538 } |
6529 | 6539 |
6530 InstARM32Call *TargetARM32::Sandboxer::bl(Variable *ReturnReg, | 6540 InstARM32Call *TargetARM32::Sandboxer::bl(Variable *ReturnReg, |
6531 Operand *CallTarget) { | 6541 Operand *CallTarget) { |
6532 if (Target->NeedSandboxing) { | 6542 if (Target->NeedSandboxing) { |
| 6543 createAutoBundle(); |
6533 if (auto *CallTargetR = llvm::dyn_cast<Variable>(CallTarget)) { | 6544 if (auto *CallTargetR = llvm::dyn_cast<Variable>(CallTarget)) { |
6534 Target->_bic(CallTargetR, CallTargetR, | 6545 Target->_bic(CallTargetR, CallTargetR, |
6535 indirectBranchBicMask(Target->Func)); | 6546 indirectBranchBicMask(Target->Func)); |
6536 } | 6547 } |
6537 } | 6548 } |
6538 return Target->Context.insert<InstARM32Call>(ReturnReg, CallTarget); | 6549 return Target->Context.insert<InstARM32Call>(ReturnReg, CallTarget); |
6539 } | 6550 } |
6540 | 6551 |
6541 void TargetARM32::Sandboxer::ldr(Variable *Dest, OperandARM32Mem *Mem, | 6552 void TargetARM32::Sandboxer::ldr(Variable *Dest, OperandARM32Mem *Mem, |
6542 CondARM32::Cond Pred) { | 6553 CondARM32::Cond Pred) { |
6543 Variable *MemBase = Mem->getBase(); | 6554 Variable *MemBase = Mem->getBase(); |
6544 if (Target->NeedSandboxing && baseNeedsBic(MemBase)) { | 6555 if (Target->NeedSandboxing && baseNeedsBic(MemBase)) { |
| 6556 createAutoBundle(); |
6545 assert(!Mem->isRegReg()); | 6557 assert(!Mem->isRegReg()); |
6546 Target->_bic(MemBase, MemBase, memOpBicMask(Target->Func), Pred); | 6558 Target->_bic(MemBase, MemBase, memOpBicMask(Target->Func), Pred); |
6547 } | 6559 } |
6548 Target->_ldr(Dest, Mem, Pred); | 6560 Target->_ldr(Dest, Mem, Pred); |
6549 } | 6561 } |
6550 | 6562 |
6551 void TargetARM32::Sandboxer::ldrex(Variable *Dest, OperandARM32Mem *Mem, | 6563 void TargetARM32::Sandboxer::ldrex(Variable *Dest, OperandARM32Mem *Mem, |
6552 CondARM32::Cond Pred) { | 6564 CondARM32::Cond Pred) { |
6553 Variable *MemBase = Mem->getBase(); | 6565 Variable *MemBase = Mem->getBase(); |
6554 if (Target->NeedSandboxing && baseNeedsBic(MemBase)) { | 6566 if (Target->NeedSandboxing && baseNeedsBic(MemBase)) { |
| 6567 createAutoBundle(); |
6555 assert(!Mem->isRegReg()); | 6568 assert(!Mem->isRegReg()); |
6556 Target->_bic(MemBase, MemBase, memOpBicMask(Target->Func), Pred); | 6569 Target->_bic(MemBase, MemBase, memOpBicMask(Target->Func), Pred); |
6557 } | 6570 } |
6558 Target->_ldrex(Dest, Mem, Pred); | 6571 Target->_ldrex(Dest, Mem, Pred); |
6559 } | 6572 } |
6560 | 6573 |
6561 void TargetARM32::Sandboxer::reset_sp(Variable *Src) { | 6574 void TargetARM32::Sandboxer::reset_sp(Variable *Src) { |
6562 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp); | 6575 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp); |
| 6576 if (!Target->NeedSandboxing) { |
| 6577 Target->_mov_redefined(SP, Src); |
| 6578 return; |
| 6579 } |
| 6580 createAutoBundle(); |
6563 Target->_mov_redefined(SP, Src); | 6581 Target->_mov_redefined(SP, Src); |
6564 if (Target->NeedSandboxing) { | 6582 Target->_bic(SP, SP, memOpBicMask(Target->Func)); |
6565 Target->_bic(SP, SP, memOpBicMask(Target->Func)); | |
6566 } | |
6567 } | 6583 } |
6568 | 6584 |
6569 void TargetARM32::Sandboxer::ret(Variable *RetAddr, Variable *RetValue) { | 6585 void TargetARM32::Sandboxer::ret(Variable *RetAddr, Variable *RetValue) { |
6570 if (Target->NeedSandboxing) { | 6586 if (Target->NeedSandboxing) { |
| 6587 createAutoBundle(); |
6571 Target->_bic(RetAddr, RetAddr, indirectBranchBicMask(Target->Func)); | 6588 Target->_bic(RetAddr, RetAddr, indirectBranchBicMask(Target->Func)); |
6572 } | 6589 } |
6573 Target->_ret(RetAddr, RetValue); | 6590 Target->_ret(RetAddr, RetValue); |
6574 } | 6591 } |
6575 | 6592 |
6576 void TargetARM32::Sandboxer::str(Variable *Src, OperandARM32Mem *Mem, | 6593 void TargetARM32::Sandboxer::str(Variable *Src, OperandARM32Mem *Mem, |
6577 CondARM32::Cond Pred) { | 6594 CondARM32::Cond Pred) { |
6578 Variable *MemBase = Mem->getBase(); | 6595 Variable *MemBase = Mem->getBase(); |
6579 if (Target->NeedSandboxing && baseNeedsBic(MemBase)) { | 6596 if (Target->NeedSandboxing && baseNeedsBic(MemBase)) { |
| 6597 createAutoBundle(); |
6580 assert(!Mem->isRegReg()); | 6598 assert(!Mem->isRegReg()); |
6581 Target->_bic(MemBase, MemBase, memOpBicMask(Target->Func), Pred); | 6599 Target->_bic(MemBase, MemBase, memOpBicMask(Target->Func), Pred); |
6582 } | 6600 } |
6583 Target->_str(Src, Mem, Pred); | 6601 Target->_str(Src, Mem, Pred); |
6584 } | 6602 } |
6585 | 6603 |
6586 void TargetARM32::Sandboxer::strex(Variable *Dest, Variable *Src, | 6604 void TargetARM32::Sandboxer::strex(Variable *Dest, Variable *Src, |
6587 OperandARM32Mem *Mem, CondARM32::Cond Pred) { | 6605 OperandARM32Mem *Mem, CondARM32::Cond Pred) { |
6588 Variable *MemBase = Mem->getBase(); | 6606 Variable *MemBase = Mem->getBase(); |
6589 if (Target->NeedSandboxing && baseNeedsBic(MemBase)) { | 6607 if (Target->NeedSandboxing && baseNeedsBic(MemBase)) { |
| 6608 createAutoBundle(); |
6590 assert(!Mem->isRegReg()); | 6609 assert(!Mem->isRegReg()); |
6591 Target->_bic(MemBase, MemBase, memOpBicMask(Target->Func), Pred); | 6610 Target->_bic(MemBase, MemBase, memOpBicMask(Target->Func), Pred); |
6592 } | 6611 } |
6593 Target->_strex(Dest, Src, Mem, Pred); | 6612 Target->_strex(Dest, Src, Mem, Pred); |
6594 } | 6613 } |
6595 | 6614 |
6596 void TargetARM32::Sandboxer::sub_sp(Operand *SubAmount) { | 6615 void TargetARM32::Sandboxer::sub_sp(Operand *SubAmount) { |
6597 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp); | 6616 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp); |
| 6617 if (!Target->NeedSandboxing) { |
| 6618 Target->_sub(SP, SP, SubAmount); |
| 6619 return; |
| 6620 } |
| 6621 createAutoBundle(); |
6598 Target->_sub(SP, SP, SubAmount); | 6622 Target->_sub(SP, SP, SubAmount); |
6599 if (Target->NeedSandboxing) { | 6623 Target->_bic(SP, SP, memOpBicMask(Target->Func)); |
6600 Target->_bic(SP, SP, memOpBicMask(Target->Func)); | |
6601 } | |
6602 } | 6624 } |
6603 | 6625 |
6604 TargetDataARM32::TargetDataARM32(GlobalContext *Ctx) | 6626 TargetDataARM32::TargetDataARM32(GlobalContext *Ctx) |
6605 : TargetDataLowering(Ctx) {} | 6627 : TargetDataLowering(Ctx) {} |
6606 | 6628 |
6607 void TargetDataARM32::lowerGlobals(const VariableDeclarationList &Vars, | 6629 void TargetDataARM32::lowerGlobals(const VariableDeclarationList &Vars, |
6608 const IceString &SectionSuffix) { | 6630 const IceString &SectionSuffix) { |
6609 const bool IsPIC = Ctx->getFlags().getUseNonsfi(); | 6631 const bool IsPIC = Ctx->getFlags().getUseNonsfi(); |
6610 switch (Ctx->getFlags().getOutFileType()) { | 6632 switch (Ctx->getFlags().getOutFileType()) { |
6611 case FT_Elf: { | 6633 case FT_Elf: { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6796 // However, for compatibility with current NaCl LLVM, don't claim that. | 6818 // However, for compatibility with current NaCl LLVM, don't claim that. |
6797 Str << ".eabi_attribute 14, 3 @ Tag_ABI_PCS_R9_use: Not used\n"; | 6819 Str << ".eabi_attribute 14, 3 @ Tag_ABI_PCS_R9_use: Not used\n"; |
6798 } | 6820 } |
6799 | 6821 |
6800 SmallBitVector TargetARM32::TypeToRegisterSet[RegARM32::RCARM32_NUM]; | 6822 SmallBitVector TargetARM32::TypeToRegisterSet[RegARM32::RCARM32_NUM]; |
6801 SmallBitVector TargetARM32::TypeToRegisterSetUnfiltered[RegARM32::RCARM32_NUM]; | 6823 SmallBitVector TargetARM32::TypeToRegisterSetUnfiltered[RegARM32::RCARM32_NUM]; |
6802 SmallBitVector TargetARM32::RegisterAliases[RegARM32::Reg_NUM]; | 6824 SmallBitVector TargetARM32::RegisterAliases[RegARM32::Reg_NUM]; |
6803 | 6825 |
6804 } // end of namespace ARM32 | 6826 } // end of namespace ARM32 |
6805 } // end of namespace Ice | 6827 } // end of namespace Ice |
OLD | NEW |