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(); |
| 3299 |
| 3300 if (isVectorType(Dest->getType())) { |
| 3301 // a=d?b:c ==> d=sext(d); a=(b&d)|(c&~d) |
| 3302 // TODO(wala): SSE4.1 has blendvps and pblendvb. SSE4.1 also has |
| 3303 // blendps and pblendw for constant condition operands. |
| 3304 Type SrcTy = SrcT->getType(); |
| 3305 Variable *T = makeReg(SrcTy); |
| 3306 Variable *T2 = makeReg(SrcTy); |
| 3307 // Sign extend the condition operand if applicable. |
| 3308 if (SrcTy == IceType_v4f32) { |
| 3309 // The sext operation takes only integer arguments. |
| 3310 Variable *T3 = Func->makeVariable(IceType_v4i32, Context.getNode()); |
| 3311 lowerCast(InstCast::create(Func, InstCast::Sext, T3, Condition)); |
| 3312 _movp(T, T3); |
| 3313 } else if (typeElementType(SrcTy) != IceType_i1) { |
| 3314 lowerCast(InstCast::create(Func, InstCast::Sext, T, Condition)); |
| 3315 } else { |
| 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 |
| 3329 |
| 3330 return; |
| 3331 } |
| 3332 |
| 3333 // a=d?b:c ==> cmp d,0; a=b; jne L1; FakeUse(a); a=c; L1: |
| 3334 Operand *ConditionRMI = legalize(Condition); |
3300 Constant *Zero = Ctx->getConstantZero(IceType_i32); | 3335 Constant *Zero = Ctx->getConstantZero(IceType_i32); |
3301 InstX8632Label *Label = InstX8632Label::create(Func, this); | 3336 InstX8632Label *Label = InstX8632Label::create(Func, this); |
3302 | 3337 |
3303 if (Dest->getType() == IceType_i64) { | 3338 if (Dest->getType() == IceType_i64) { |
3304 Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); | 3339 Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); |
3305 Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); | 3340 Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); |
3306 Operand *SrcLoRI = legalize(loOperand(SrcT), Legal_Reg | Legal_Imm, true); | 3341 Operand *SrcLoRI = legalize(loOperand(SrcT), Legal_Reg | Legal_Imm, true); |
3307 Operand *SrcHiRI = legalize(hiOperand(SrcT), Legal_Reg | Legal_Imm, true); | 3342 Operand *SrcHiRI = legalize(hiOperand(SrcT), Legal_Reg | Legal_Imm, true); |
3308 _cmp(Condition, Zero); | 3343 _cmp(ConditionRMI, Zero); |
3309 _mov(DestLo, SrcLoRI); | 3344 _mov(DestLo, SrcLoRI); |
3310 _mov(DestHi, SrcHiRI); | 3345 _mov(DestHi, SrcHiRI); |
3311 _br(InstX8632Br::Br_ne, Label); | 3346 _br(InstX8632Br::Br_ne, Label); |
3312 Context.insert(InstFakeUse::create(Func, DestLo)); | 3347 Context.insert(InstFakeUse::create(Func, DestLo)); |
3313 Context.insert(InstFakeUse::create(Func, DestHi)); | 3348 Context.insert(InstFakeUse::create(Func, DestHi)); |
3314 Operand *SrcFLo = loOperand(SrcF); | 3349 Operand *SrcFLo = loOperand(SrcF); |
3315 Operand *SrcFHi = hiOperand(SrcF); | 3350 Operand *SrcFHi = hiOperand(SrcF); |
3316 SrcLoRI = legalize(SrcFLo, Legal_Reg | Legal_Imm, true); | 3351 SrcLoRI = legalize(SrcFLo, Legal_Reg | Legal_Imm, true); |
3317 SrcHiRI = legalize(SrcFHi, Legal_Reg | Legal_Imm, true); | 3352 SrcHiRI = legalize(SrcFHi, Legal_Reg | Legal_Imm, true); |
3318 _mov(DestLo, SrcLoRI); | 3353 _mov(DestLo, SrcLoRI); |
3319 _mov(DestHi, SrcHiRI); | 3354 _mov(DestHi, SrcHiRI); |
3320 } else { | 3355 } else { |
3321 _cmp(Condition, Zero); | 3356 _cmp(ConditionRMI, Zero); |
3322 SrcT = legalize(SrcT, Legal_Reg | Legal_Imm, true); | 3357 SrcT = legalize(SrcT, Legal_Reg | Legal_Imm, true); |
3323 _mov(Dest, SrcT); | 3358 _mov(Dest, SrcT); |
3324 _br(InstX8632Br::Br_ne, Label); | 3359 _br(InstX8632Br::Br_ne, Label); |
3325 Context.insert(InstFakeUse::create(Func, Dest)); | 3360 Context.insert(InstFakeUse::create(Func, Dest)); |
3326 SrcF = legalize(SrcF, Legal_Reg | Legal_Imm, true); | 3361 SrcF = legalize(SrcF, Legal_Reg | Legal_Imm, true); |
3327 _mov(Dest, SrcF); | 3362 _mov(Dest, SrcF); |
3328 } | 3363 } |
3329 | 3364 |
3330 Context.insert(Label); | 3365 Context.insert(Label); |
3331 } | 3366 } |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3752 for (SizeT i = 0; i < Size; ++i) { | 3787 for (SizeT i = 0; i < Size; ++i) { |
3753 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; | 3788 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; |
3754 } | 3789 } |
3755 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 3790 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
3756 } | 3791 } |
3757 Str << "\t" << (IsInternal ? ".local" : ".global") << "\t" << MangledName | 3792 Str << "\t" << (IsInternal ? ".local" : ".global") << "\t" << MangledName |
3758 << "\n"; | 3793 << "\n"; |
3759 } | 3794 } |
3760 | 3795 |
3761 } // end of namespace Ice | 3796 } // end of namespace Ice |
OLD | NEW |