Chromium Code Reviews| 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 3274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3285 // Add a fake use of esp to make sure esp stays alive for the entire | 3285 // Add a fake use of esp to make sure esp stays alive for the entire |
| 3286 // function. Otherwise post-call esp adjustments get dead-code | 3286 // function. Otherwise post-call esp adjustments get dead-code |
| 3287 // eliminated. TODO: Are there more places where the fake use | 3287 // eliminated. TODO: Are there more places where the fake use |
| 3288 // should be inserted? E.g. "void f(int n){while(1) g(n);}" may not | 3288 // should be inserted? E.g. "void f(int n){while(1) g(n);}" may not |
| 3289 // have a ret instruction. | 3289 // have a ret instruction. |
| 3290 Variable *esp = Func->getTarget()->getPhysicalRegister(Reg_esp); | 3290 Variable *esp = Func->getTarget()->getPhysicalRegister(Reg_esp); |
| 3291 Context.insert(InstFakeUse::create(Func, esp)); | 3291 Context.insert(InstFakeUse::create(Func, esp)); |
| 3292 } | 3292 } |
| 3293 | 3293 |
| 3294 void TargetX8632::lowerSelect(const InstSelect *Inst) { | 3294 void TargetX8632::lowerSelect(const InstSelect *Inst) { |
| 3295 // a=d?b:c ==> cmp d,0; a=b; jne L1; FakeUse(a); a=c; L1: | |
| 3296 Variable *Dest = Inst->getDest(); | 3295 Variable *Dest = Inst->getDest(); |
| 3297 Operand *SrcT = Inst->getTrueOperand(); | 3296 Operand *SrcT = Inst->getTrueOperand(); |
| 3298 Operand *SrcF = Inst->getFalseOperand(); | 3297 Operand *SrcF = Inst->getFalseOperand(); |
| 3299 Operand *Condition = legalize(Inst->getCondition()); | 3298 Operand *Condition = Inst->getCondition(); |
| 3300 Constant *Zero = Ctx->getConstantZero(IceType_i32); | |
| 3301 InstX8632Label *Label = InstX8632Label::create(Func, this); | |
| 3302 | 3299 |
| 3303 if (Dest->getType() == IceType_i64) { | 3300 if (isVectorType(Dest->getType())) { |
| 3304 Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); | 3301 // a=d?b:c ==> d=sext(d); a=(b&d)|(c&~d) |
| 3305 Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); | 3302 // TODO(wala): SSE4.1 has blendvps and pblendvb. SSE4.1 also has |
| 3306 Operand *SrcLoRI = legalize(loOperand(SrcT), Legal_Reg | Legal_Imm, true); | 3303 // blendps and pblendw for constant condition operands. |
| 3307 Operand *SrcHiRI = legalize(hiOperand(SrcT), Legal_Reg | Legal_Imm, true); | 3304 Type SrcTy = SrcT->getType(); |
| 3308 _cmp(Condition, Zero); | 3305 Variable *T = makeReg(SrcTy); |
| 3309 _mov(DestLo, SrcLoRI); | 3306 Variable *T2 = makeReg(SrcTy); |
| 3310 _mov(DestHi, SrcHiRI); | 3307 // Sign extend the condition operand if applicable. |
| 3311 _br(InstX8632Br::Br_ne, Label); | 3308 if (SrcTy == IceType_v4f32) { |
| 3312 Context.insert(InstFakeUse::create(Func, DestLo)); | 3309 // The sext operation takes only integer arguments. |
| 3313 Context.insert(InstFakeUse::create(Func, DestHi)); | 3310 Variable *T3 = Func->makeVariable(IceType_v4i32, Context.getNode()); |
| 3314 Operand *SrcFLo = loOperand(SrcF); | 3311 lowerCast(InstCast::create(Func, InstCast::Sext, T3, Condition)); |
| 3315 Operand *SrcFHi = hiOperand(SrcF); | 3312 _movp(T, T3); |
| 3316 SrcLoRI = legalize(SrcFLo, Legal_Reg | Legal_Imm, true); | 3313 } else if (typeElementType(SrcTy) != IceType_i1) { |
| 3317 SrcHiRI = legalize(SrcFHi, Legal_Reg | Legal_Imm, true); | 3314 lowerCast(InstCast::create(Func, InstCast::Sext, T, Condition)); |
| 3318 _mov(DestLo, SrcLoRI); | 3315 } else { |
| 3319 _mov(DestHi, SrcHiRI); | 3316 _movp(T, Condition); |
| 3317 } | |
| 3318 // ALIGNHACK: Until stack alignment support is implemented, the | |
| 3319 // bitwise vector instructions need to have both operands in | |
| 3320 // registers. Once there is support for stack alignment, LEGAL_HACK | |
| 3321 // can be removed. | |
| 3322 #define LEGAL_HACK(Vect) legalizeToVar((Vect)) | |
| 3323 _movp(T2, T); | |
| 3324 _pand(T, LEGAL_HACK(SrcT)); | |
| 3325 _pandn(T2, LEGAL_HACK(SrcF)); | |
| 3326 _por(T, T2); | |
| 3327 _movp(Dest, T); | |
| 3328 #undef LEGAL_HACK | |
| 3320 } else { | 3329 } else { |
|
Jim Stichnoth
2014/07/23 20:06:37
I'd echo Jan's comment from the other CL - add a r
wala
2014/07/23 20:49:54
Done.
| |
| 3321 _cmp(Condition, Zero); | 3330 // a=d?b:c ==> cmp d,0; a=b; jne L1; FakeUse(a); a=c; L1: |
| 3322 SrcT = legalize(SrcT, Legal_Reg | Legal_Imm, true); | 3331 Operand *ConditionRMI = legalize(Condition); |
| 3323 _mov(Dest, SrcT); | 3332 Constant *Zero = Ctx->getConstantZero(IceType_i32); |
| 3324 _br(InstX8632Br::Br_ne, Label); | 3333 InstX8632Label *Label = InstX8632Label::create(Func, this); |
| 3325 Context.insert(InstFakeUse::create(Func, Dest)); | 3334 |
| 3326 SrcF = legalize(SrcF, Legal_Reg | Legal_Imm, true); | 3335 if (Dest->getType() == IceType_i64) { |
| 3327 _mov(Dest, SrcF); | 3336 Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); |
| 3337 Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); | |
| 3338 Operand *SrcLoRI = legalize(loOperand(SrcT), Legal_Reg | Legal_Imm, true); | |
| 3339 Operand *SrcHiRI = legalize(hiOperand(SrcT), Legal_Reg | Legal_Imm, true); | |
| 3340 _cmp(ConditionRMI, Zero); | |
| 3341 _mov(DestLo, SrcLoRI); | |
| 3342 _mov(DestHi, SrcHiRI); | |
| 3343 _br(InstX8632Br::Br_ne, Label); | |
| 3344 Context.insert(InstFakeUse::create(Func, DestLo)); | |
| 3345 Context.insert(InstFakeUse::create(Func, DestHi)); | |
| 3346 Operand *SrcFLo = loOperand(SrcF); | |
| 3347 Operand *SrcFHi = hiOperand(SrcF); | |
| 3348 SrcLoRI = legalize(SrcFLo, Legal_Reg | Legal_Imm, true); | |
| 3349 SrcHiRI = legalize(SrcFHi, Legal_Reg | Legal_Imm, true); | |
| 3350 _mov(DestLo, SrcLoRI); | |
| 3351 _mov(DestHi, SrcHiRI); | |
| 3352 } else { | |
| 3353 _cmp(ConditionRMI, Zero); | |
| 3354 SrcT = legalize(SrcT, Legal_Reg | Legal_Imm, true); | |
| 3355 _mov(Dest, SrcT); | |
| 3356 _br(InstX8632Br::Br_ne, Label); | |
| 3357 Context.insert(InstFakeUse::create(Func, Dest)); | |
| 3358 SrcF = legalize(SrcF, Legal_Reg | Legal_Imm, true); | |
| 3359 _mov(Dest, SrcF); | |
| 3360 } | |
| 3361 | |
| 3362 Context.insert(Label); | |
| 3328 } | 3363 } |
| 3329 | |
| 3330 Context.insert(Label); | |
| 3331 } | 3364 } |
| 3332 | 3365 |
| 3333 void TargetX8632::lowerStore(const InstStore *Inst) { | 3366 void TargetX8632::lowerStore(const InstStore *Inst) { |
| 3334 Operand *Value = Inst->getData(); | 3367 Operand *Value = Inst->getData(); |
| 3335 Operand *Addr = Inst->getAddr(); | 3368 Operand *Addr = Inst->getAddr(); |
| 3336 OperandX8632Mem *NewAddr = FormMemoryOperand(Addr, Value->getType()); | 3369 OperandX8632Mem *NewAddr = FormMemoryOperand(Addr, Value->getType()); |
| 3337 | 3370 |
| 3338 if (NewAddr->getType() == IceType_i64) { | 3371 if (NewAddr->getType() == IceType_i64) { |
| 3339 Value = legalize(Value); | 3372 Value = legalize(Value); |
| 3340 Operand *ValueHi = legalize(hiOperand(Value), Legal_Reg | Legal_Imm, true); | 3373 Operand *ValueHi = legalize(hiOperand(Value), Legal_Reg | Legal_Imm, true); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3752 for (SizeT i = 0; i < Size; ++i) { | 3785 for (SizeT i = 0; i < Size; ++i) { |
| 3753 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; | 3786 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; |
| 3754 } | 3787 } |
| 3755 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 3788 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
| 3756 } | 3789 } |
| 3757 Str << "\t" << (IsInternal ? ".local" : ".global") << "\t" << MangledName | 3790 Str << "\t" << (IsInternal ? ".local" : ".global") << "\t" << MangledName |
| 3758 << "\n"; | 3791 << "\n"; |
| 3759 } | 3792 } |
| 3760 | 3793 |
| 3761 } // end of namespace Ice | 3794 } // end of namespace Ice |
| OLD | NEW |