OLD | NEW |
1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// | 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 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 // This file implements the TargetLoweringX8632 class, which | 10 // This file implements the TargetLoweringX8632 class, which |
(...skipping 3808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3819 lowerArithmetic(NewArith); | 3819 lowerArithmetic(NewArith); |
3820 return; | 3820 return; |
3821 } | 3821 } |
3822 } | 3822 } |
3823 | 3823 |
3824 InstAssign *Assign = InstAssign::create(Func, Inst->getDest(), Src0); | 3824 InstAssign *Assign = InstAssign::create(Func, Inst->getDest(), Src0); |
3825 lowerAssign(Assign); | 3825 lowerAssign(Assign); |
3826 } | 3826 } |
3827 | 3827 |
3828 void TargetX8632::doAddressOptLoad() { | 3828 void TargetX8632::doAddressOptLoad() { |
3829 Inst *Inst = *Context.getCur(); | 3829 Inst *Inst = Context.getCur(); |
3830 Variable *Dest = Inst->getDest(); | 3830 Variable *Dest = Inst->getDest(); |
3831 Operand *Addr = Inst->getSrc(0); | 3831 Operand *Addr = Inst->getSrc(0); |
3832 Variable *Index = NULL; | 3832 Variable *Index = NULL; |
3833 uint16_t Shift = 0; | 3833 uint16_t Shift = 0; |
3834 int32_t Offset = 0; // TODO: make Constant | 3834 int32_t Offset = 0; // TODO: make Constant |
3835 // Vanilla ICE load instructions should not use the segment registers, | 3835 // Vanilla ICE load instructions should not use the segment registers, |
3836 // and computeAddressOpt only works at the level of Variables and Constants, | 3836 // and computeAddressOpt only works at the level of Variables and Constants, |
3837 // not other OperandX8632Mem, so there should be no mention of segment | 3837 // not other OperandX8632Mem, so there should be no mention of segment |
3838 // registers there either. | 3838 // registers there either. |
3839 const OperandX8632Mem::SegmentRegisters SegmentReg = | 3839 const OperandX8632Mem::SegmentRegisters SegmentReg = |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3997 _store(ValueLo, llvm::cast<OperandX8632Mem>(loOperand(NewAddr))); | 3997 _store(ValueLo, llvm::cast<OperandX8632Mem>(loOperand(NewAddr))); |
3998 } else if (isVectorType(Ty)) { | 3998 } else if (isVectorType(Ty)) { |
3999 _storep(legalizeToVar(Value), NewAddr); | 3999 _storep(legalizeToVar(Value), NewAddr); |
4000 } else { | 4000 } else { |
4001 Value = legalize(Value, Legal_Reg | Legal_Imm); | 4001 Value = legalize(Value, Legal_Reg | Legal_Imm); |
4002 _store(Value, NewAddr); | 4002 _store(Value, NewAddr); |
4003 } | 4003 } |
4004 } | 4004 } |
4005 | 4005 |
4006 void TargetX8632::doAddressOptStore() { | 4006 void TargetX8632::doAddressOptStore() { |
4007 InstStore *Inst = llvm::cast<InstStore>(*Context.getCur()); | 4007 InstStore *Inst = llvm::cast<InstStore>(Context.getCur()); |
4008 Operand *Data = Inst->getData(); | 4008 Operand *Data = Inst->getData(); |
4009 Operand *Addr = Inst->getAddr(); | 4009 Operand *Addr = Inst->getAddr(); |
4010 Variable *Index = NULL; | 4010 Variable *Index = NULL; |
4011 uint16_t Shift = 0; | 4011 uint16_t Shift = 0; |
4012 int32_t Offset = 0; // TODO: make Constant | 4012 int32_t Offset = 0; // TODO: make Constant |
4013 Variable *Base = llvm::dyn_cast<Variable>(Addr); | 4013 Variable *Base = llvm::dyn_cast<Variable>(Addr); |
4014 // Vanilla ICE store instructions should not use the segment registers, | 4014 // Vanilla ICE store instructions should not use the segment registers, |
4015 // and computeAddressOpt only works at the level of Variables and Constants, | 4015 // and computeAddressOpt only works at the level of Variables and Constants, |
4016 // not other OperandX8632Mem, so there should be no mention of segment | 4016 // not other OperandX8632Mem, so there should be no mention of segment |
4017 // registers there either. | 4017 // registers there either. |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4495 Reg->setWeightInfinite(); | 4495 Reg->setWeightInfinite(); |
4496 else | 4496 else |
4497 Reg->setRegNum(RegNum); | 4497 Reg->setRegNum(RegNum); |
4498 return Reg; | 4498 return Reg; |
4499 } | 4499 } |
4500 | 4500 |
4501 void TargetX8632::postLower() { | 4501 void TargetX8632::postLower() { |
4502 if (Ctx->getOptLevel() != Opt_m1) { | 4502 if (Ctx->getOptLevel() != Opt_m1) { |
4503 // Find two-address non-SSA instructions where Dest==Src0, and set | 4503 // Find two-address non-SSA instructions where Dest==Src0, and set |
4504 // the DestNonKillable flag to keep liveness analysis consistent. | 4504 // the DestNonKillable flag to keep liveness analysis consistent. |
4505 for (Inst *Inst : Context) { | 4505 for (auto Inst = Context.begin(), E = Context.end(); Inst != E; ++Inst) { |
4506 if (Inst->isDeleted()) | 4506 if (Inst->isDeleted()) |
4507 continue; | 4507 continue; |
4508 if (Variable *Dest = Inst->getDest()) { | 4508 if (Variable *Dest = Inst->getDest()) { |
4509 // TODO(stichnot): We may need to consider all source | 4509 // TODO(stichnot): We may need to consider all source |
4510 // operands, not just the first one, if using 3-address | 4510 // operands, not just the first one, if using 3-address |
4511 // instructions. | 4511 // instructions. |
4512 if (Inst->getSrcSize() > 0 && Inst->getSrc(0) == Dest) | 4512 if (Inst->getSrcSize() > 0 && Inst->getSrc(0) == Dest) |
4513 Inst->setDestNonKillable(); | 4513 Inst->setDestNonKillable(); |
4514 } | 4514 } |
4515 } | 4515 } |
4516 return; | 4516 return; |
4517 } | 4517 } |
4518 // TODO: Avoid recomputing WhiteList every instruction. | 4518 // TODO: Avoid recomputing WhiteList every instruction. |
4519 RegSetMask RegInclude = RegSet_All; | 4519 RegSetMask RegInclude = RegSet_All; |
4520 RegSetMask RegExclude = RegSet_StackPointer; | 4520 RegSetMask RegExclude = RegSet_StackPointer; |
4521 if (hasFramePointer()) | 4521 if (hasFramePointer()) |
4522 RegExclude |= RegSet_FramePointer; | 4522 RegExclude |= RegSet_FramePointer; |
4523 llvm::SmallBitVector WhiteList = getRegisterSet(RegInclude, RegExclude); | 4523 llvm::SmallBitVector WhiteList = getRegisterSet(RegInclude, RegExclude); |
4524 // Make one pass to black-list pre-colored registers. TODO: If | 4524 // Make one pass to black-list pre-colored registers. TODO: If |
4525 // there was some prior register allocation pass that made register | 4525 // there was some prior register allocation pass that made register |
4526 // assignments, those registers need to be black-listed here as | 4526 // assignments, those registers need to be black-listed here as |
4527 // well. | 4527 // well. |
4528 llvm::DenseMap<const Variable *, const Inst *> LastUses; | 4528 llvm::DenseMap<const Variable *, const Inst *> LastUses; |
4529 // The first pass also keeps track of which instruction is the last | 4529 // The first pass also keeps track of which instruction is the last |
4530 // use for each infinite-weight variable. After the last use, the | 4530 // use for each infinite-weight variable. After the last use, the |
4531 // variable is released to the free list. | 4531 // variable is released to the free list. |
4532 for (Inst *Inst : Context) { | 4532 for (auto Inst = Context.begin(), E = Context.end(); Inst != E; ++Inst) { |
4533 if (Inst->isDeleted()) | 4533 if (Inst->isDeleted()) |
4534 continue; | 4534 continue; |
4535 // Don't consider a FakeKill instruction, because (currently) it | 4535 // Don't consider a FakeKill instruction, because (currently) it |
4536 // is only used to kill all scratch registers at a call site, and | 4536 // is only used to kill all scratch registers at a call site, and |
4537 // we don't want to black-list all scratch registers during the | 4537 // we don't want to black-list all scratch registers during the |
4538 // call lowering. This could become a problem since it relies on | 4538 // call lowering. This could become a problem since it relies on |
4539 // the lowering sequence not keeping any infinite-weight variables | 4539 // the lowering sequence not keeping any infinite-weight variables |
4540 // live across a call. TODO(stichnot): Consider replacing this | 4540 // live across a call. TODO(stichnot): Consider replacing this |
4541 // whole postLower() implementation with a robust local register | 4541 // whole postLower() implementation with a robust local register |
4542 // allocator, for example compute live ranges only for pre-colored | 4542 // allocator, for example compute live ranges only for pre-colored |
(...skipping 10 matching lines...) Expand all Loading... |
4553 LastUses[Var] = Inst; | 4553 LastUses[Var] = Inst; |
4554 if (!Var->hasReg()) | 4554 if (!Var->hasReg()) |
4555 continue; | 4555 continue; |
4556 WhiteList[Var->getRegNum()] = false; | 4556 WhiteList[Var->getRegNum()] = false; |
4557 } | 4557 } |
4558 } | 4558 } |
4559 } | 4559 } |
4560 // The second pass colors infinite-weight variables. | 4560 // The second pass colors infinite-weight variables. |
4561 llvm::SmallBitVector AvailableRegisters = WhiteList; | 4561 llvm::SmallBitVector AvailableRegisters = WhiteList; |
4562 llvm::SmallBitVector FreedRegisters(WhiteList.size()); | 4562 llvm::SmallBitVector FreedRegisters(WhiteList.size()); |
4563 for (Inst *Inst : Context) { | 4563 for (auto Inst = Context.begin(), E = Context.end(); Inst != E; ++Inst) { |
4564 FreedRegisters.reset(); | 4564 FreedRegisters.reset(); |
4565 if (Inst->isDeleted()) | 4565 if (Inst->isDeleted()) |
4566 continue; | 4566 continue; |
4567 // Iterate over all variables referenced in the instruction, | 4567 // Iterate over all variables referenced in the instruction, |
4568 // including the Dest variable (if any). If the variable is | 4568 // including the Dest variable (if any). If the variable is |
4569 // marked as infinite-weight, find it a register. If this | 4569 // marked as infinite-weight, find it a register. If this |
4570 // instruction is the last use of the variable in the lowered | 4570 // instruction is the last use of the variable in the lowered |
4571 // sequence, release the register to the free list after this | 4571 // sequence, release the register to the free list after this |
4572 // instruction is completely processed. Note that the first pass | 4572 // instruction is completely processed. Note that the first pass |
4573 // ignores the Dest operand, under the assumption that a | 4573 // ignores the Dest operand, under the assumption that a |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4724 } else if (IsConstant || IsExternal) | 4724 } else if (IsConstant || IsExternal) |
4725 Str << "\t.zero\t" << Size << "\n"; | 4725 Str << "\t.zero\t" << Size << "\n"; |
4726 // Size is part of .comm. | 4726 // Size is part of .comm. |
4727 | 4727 |
4728 if (IsConstant || HasNonzeroInitializer || IsExternal) | 4728 if (IsConstant || HasNonzeroInitializer || IsExternal) |
4729 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4729 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
4730 // Size is part of .comm. | 4730 // Size is part of .comm. |
4731 } | 4731 } |
4732 | 4732 |
4733 } // end of namespace Ice | 4733 } // end of namespace Ice |
OLD | NEW |