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 4135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4146 // TODO: Avoid recomputing WhiteList every instruction. | 4146 // TODO: Avoid recomputing WhiteList every instruction. |
4147 RegSetMask RegInclude = RegSet_All; | 4147 RegSetMask RegInclude = RegSet_All; |
4148 RegSetMask RegExclude = RegSet_None; | 4148 RegSetMask RegExclude = RegSet_None; |
4149 if (hasFramePointer()) | 4149 if (hasFramePointer()) |
4150 RegExclude |= RegSet_FramePointer; | 4150 RegExclude |= RegSet_FramePointer; |
4151 llvm::SmallBitVector WhiteList = getRegisterSet(RegInclude, RegExclude); | 4151 llvm::SmallBitVector WhiteList = getRegisterSet(RegInclude, RegExclude); |
4152 // Make one pass to black-list pre-colored registers. TODO: If | 4152 // Make one pass to black-list pre-colored registers. TODO: If |
4153 // there was some prior register allocation pass that made register | 4153 // there was some prior register allocation pass that made register |
4154 // assignments, those registers need to be black-listed here as | 4154 // assignments, those registers need to be black-listed here as |
4155 // well. | 4155 // well. |
4156 std::map<const Variable *, const Inst *> LastUses; | |
wala
2014/08/18 04:44:54
How about a DenseMap?
"DenseMap is a great way to
Jim Stichnoth
2014/08/18 17:31:02
Nice, done.
| |
4157 // The first pass also keeps track of which instruction is the last | |
4158 // use for each infinite-weight variable. After the last use, the | |
4159 // variable is released to the free list. | |
4156 for (InstList::iterator I = Context.getCur(), E = Context.getEnd(); I != E; | 4160 for (InstList::iterator I = Context.getCur(), E = Context.getEnd(); I != E; |
4157 ++I) { | 4161 ++I) { |
4158 const Inst *Inst = *I; | 4162 const Inst *Inst = *I; |
4159 if (Inst->isDeleted()) | 4163 if (Inst->isDeleted()) |
4160 continue; | 4164 continue; |
4161 if (llvm::isa<InstFakeKill>(Inst)) | 4165 if (llvm::isa<InstFakeKill>(Inst)) |
4162 continue; | 4166 continue; |
jvoung (off chromium)
2014/08/18 16:26:07
The second pass doesn't skip InstFakeKill, could t
Jim Stichnoth
2014/08/18 17:31:02
It probably wouldn't affect LastUses, because Inst
| |
4163 for (SizeT SrcNum = 0; SrcNum < Inst->getSrcSize(); ++SrcNum) { | 4167 for (SizeT SrcNum = 0; SrcNum < Inst->getSrcSize(); ++SrcNum) { |
4164 Operand *Src = Inst->getSrc(SrcNum); | 4168 Operand *Src = Inst->getSrc(SrcNum); |
4165 SizeT NumVars = Src->getNumVars(); | 4169 SizeT NumVars = Src->getNumVars(); |
4166 for (SizeT J = 0; J < NumVars; ++J) { | 4170 for (SizeT J = 0; J < NumVars; ++J) { |
4167 const Variable *Var = Src->getVar(J); | 4171 const Variable *Var = Src->getVar(J); |
4172 // Track last uses of all variables, regardless of whether | |
4173 // they are pre-colored or infinite-weight. | |
4174 LastUses[Var] = Inst; | |
4168 if (!Var->hasReg()) | 4175 if (!Var->hasReg()) |
4169 continue; | 4176 continue; |
4170 WhiteList[Var->getRegNum()] = false; | 4177 WhiteList[Var->getRegNum()] = false; |
4171 } | 4178 } |
4172 } | 4179 } |
4173 } | 4180 } |
4174 // The second pass colors infinite-weight variables. | 4181 // The second pass colors infinite-weight variables. |
4175 llvm::SmallBitVector AvailableRegisters = WhiteList; | 4182 llvm::SmallBitVector AvailableRegisters = WhiteList; |
4183 llvm::SmallBitVector FreedRegisters(WhiteList.size()); | |
4176 for (InstList::iterator I = Context.getCur(), E = Context.getEnd(); I != E; | 4184 for (InstList::iterator I = Context.getCur(), E = Context.getEnd(); I != E; |
4177 ++I) { | 4185 ++I) { |
4186 FreedRegisters.reset(); | |
4178 const Inst *Inst = *I; | 4187 const Inst *Inst = *I; |
4179 if (Inst->isDeleted()) | 4188 if (Inst->isDeleted()) |
4180 continue; | 4189 continue; |
4181 for (SizeT SrcNum = 0; SrcNum < Inst->getSrcSize(); ++SrcNum) { | 4190 // Iterate over all variables referenced in the instruction, |
4182 Operand *Src = Inst->getSrc(SrcNum); | 4191 // including the Dest variable (if any). If the variable is |
4192 // marked as infinite-weight, find it a register. If this | |
4193 // instruction is the last use of the variable in the lowered | |
4194 // sequence, release the register to the free list after this | |
4195 // instruction is completely processed. Note that the first pass | |
4196 // ignores the Dest operand, under the assumption that a | |
4197 // pre-colored Dest will appear as a source operand in some | |
4198 // subsequent instruction in the lowered sequence. | |
4199 Variable *Dest = Inst->getDest(); | |
4200 SizeT NumSrcs = Inst->getSrcSize(); | |
4201 if (Dest) | |
4202 ++NumSrcs; | |
4203 OperandList Srcs(NumSrcs); | |
4204 for (SizeT i = 0; i < Inst->getSrcSize(); ++i) | |
4205 Srcs[i] = Inst->getSrc(i); | |
wala
2014/08/18 04:44:54
Now that Dest is included in this iteration, shoul
wala
2014/08/18 04:46:31
I meant "Dest is included in this OperandList"
Jim Stichnoth
2014/08/18 17:31:02
This should generally be the case for local variab
| |
4206 if (Dest) | |
4207 Srcs[NumSrcs - 1] = Dest; | |
4208 for (SizeT SrcNum = 0; SrcNum < NumSrcs; ++SrcNum) { | |
4209 Operand *Src = Srcs[SrcNum]; | |
4183 SizeT NumVars = Src->getNumVars(); | 4210 SizeT NumVars = Src->getNumVars(); |
4184 for (SizeT J = 0; J < NumVars; ++J) { | 4211 for (SizeT J = 0; J < NumVars; ++J) { |
4185 Variable *Var = Src->getVar(J); | 4212 Variable *Var = Src->getVar(J); |
4186 if (Var->hasReg()) | 4213 if (!Var->hasReg() && Var->getWeight().isInf()) { |
4187 continue; | 4214 llvm::SmallBitVector AvailableTypedRegisters = |
4188 if (!Var->getWeight().isInf()) | |
4189 continue; | |
4190 llvm::SmallBitVector AvailableTypedRegisters = | |
4191 AvailableRegisters & getRegisterSetForType(Var->getType()); | |
4192 if (!AvailableTypedRegisters.any()) { | |
4193 // This is a hack in case we run out of physical registers due | |
4194 // to an excessively long code sequence, as might happen when | |
4195 // lowering arguments in lowerCall(). | |
4196 AvailableRegisters = WhiteList; | |
4197 AvailableTypedRegisters = | |
4198 AvailableRegisters & getRegisterSetForType(Var->getType()); | 4215 AvailableRegisters & getRegisterSetForType(Var->getType()); |
4216 assert(AvailableTypedRegisters.any()); | |
4217 int32_t RegNum = AvailableTypedRegisters.find_first(); | |
4218 Var->setRegNum(RegNum); | |
4219 AvailableRegisters[RegNum] = false; | |
4199 } | 4220 } |
4200 assert(AvailableTypedRegisters.any()); | 4221 if (Var->hasReg() && LastUses[Var] == Inst) { |
wala
2014/08/18 04:44:54
Would it make sense to assert that if Var->hasReg(
Jim Stichnoth
2014/08/18 17:31:02
Done.
BTW, this required initializing RegExclude
| |
4201 int32_t RegNum = AvailableTypedRegisters.find_first(); | 4222 int32_t RegNum = Var->getRegNum(); |
4202 Var->setRegNum(RegNum); | 4223 if (WhiteList[RegNum]) |
4203 AvailableRegisters[RegNum] = false; | 4224 FreedRegisters[RegNum] = true; |
4225 } | |
4204 } | 4226 } |
4205 } | 4227 } |
4228 AvailableRegisters |= FreedRegisters; | |
4206 } | 4229 } |
4207 } | 4230 } |
4208 | 4231 |
4209 template <> void ConstantInteger::emit(GlobalContext *Ctx) const { | 4232 template <> void ConstantInteger::emit(GlobalContext *Ctx) const { |
4210 Ostream &Str = Ctx->getStrEmit(); | 4233 Ostream &Str = Ctx->getStrEmit(); |
4211 Str << (int64_t) getValue(); | 4234 Str << (int64_t) getValue(); |
4212 } | 4235 } |
4213 | 4236 |
4214 template <> void ConstantFloat::emit(GlobalContext *Ctx) const { | 4237 template <> void ConstantFloat::emit(GlobalContext *Ctx) const { |
4215 Ostream &Str = Ctx->getStrEmit(); | 4238 Ostream &Str = Ctx->getStrEmit(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4317 Str << "\t.align\t" << Align << "\n"; | 4340 Str << "\t.align\t" << Align << "\n"; |
4318 Str << MangledName << ":\n"; | 4341 Str << MangledName << ":\n"; |
4319 for (SizeT i = 0; i < Size; ++i) { | 4342 for (SizeT i = 0; i < Size; ++i) { |
4320 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; | 4343 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; |
4321 } | 4344 } |
4322 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4345 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
4323 } | 4346 } |
4324 } | 4347 } |
4325 | 4348 |
4326 } // end of namespace Ice | 4349 } // end of namespace Ice |
OLD | NEW |