OLD | NEW |
1 //===- subzero/src/IceTargetLoweringX86BaseImpl.h - x86 lowering -*- C++ -*-==// | 1 //===- subzero/src/IceTargetLoweringX86BaseImpl.h - x86 lowering -*- C++ -*-==// |
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 6191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6202 // during phi lowering assignments | 6202 // during phi lowering assignments |
6203 BoolFlagSaver B(RandomizationPoolingPaused, true); | 6203 BoolFlagSaver B(RandomizationPoolingPaused, true); |
6204 PhiLowering::prelowerPhis32Bit<TargetX86Base<TraitsType>>( | 6204 PhiLowering::prelowerPhis32Bit<TargetX86Base<TraitsType>>( |
6205 this, Context.getNode(), Func); | 6205 this, Context.getNode(), Func); |
6206 } | 6206 } |
6207 | 6207 |
6208 template <typename TraitsType> | 6208 template <typename TraitsType> |
6209 void TargetX86Base<TraitsType>::genTargetHelperCallFor(Inst *Instr) { | 6209 void TargetX86Base<TraitsType>::genTargetHelperCallFor(Inst *Instr) { |
6210 uint32_t StackArgumentsSize = 0; | 6210 uint32_t StackArgumentsSize = 0; |
6211 if (auto *Arith = llvm::dyn_cast<InstArithmetic>(Instr)) { | 6211 if (auto *Arith = llvm::dyn_cast<InstArithmetic>(Instr)) { |
6212 const char *HelperName = nullptr; | 6212 RuntimeHelperFuncID HelperID = H_Num; |
6213 Variable *Dest = Arith->getDest(); | 6213 Variable *Dest = Arith->getDest(); |
6214 Type DestTy = Dest->getType(); | 6214 Type DestTy = Dest->getType(); |
6215 if (!Traits::Is64Bit && DestTy == IceType_i64) { | 6215 if (!Traits::Is64Bit && DestTy == IceType_i64) { |
6216 switch (Arith->getOp()) { | 6216 switch (Arith->getOp()) { |
6217 default: | 6217 default: |
6218 return; | 6218 return; |
6219 case InstArithmetic::Udiv: | 6219 case InstArithmetic::Udiv: |
6220 HelperName = H_udiv_i64; | 6220 HelperID = H_udiv_i64; |
6221 break; | 6221 break; |
6222 case InstArithmetic::Sdiv: | 6222 case InstArithmetic::Sdiv: |
6223 HelperName = H_sdiv_i64; | 6223 HelperID = H_sdiv_i64; |
6224 break; | 6224 break; |
6225 case InstArithmetic::Urem: | 6225 case InstArithmetic::Urem: |
6226 HelperName = H_urem_i64; | 6226 HelperID = H_urem_i64; |
6227 break; | 6227 break; |
6228 case InstArithmetic::Srem: | 6228 case InstArithmetic::Srem: |
6229 HelperName = H_srem_i64; | 6229 HelperID = H_srem_i64; |
6230 break; | 6230 break; |
6231 } | 6231 } |
6232 } else if (isVectorType(DestTy)) { | 6232 } else if (isVectorType(DestTy)) { |
6233 Variable *Dest = Arith->getDest(); | 6233 Variable *Dest = Arith->getDest(); |
6234 Operand *Src0 = Arith->getSrc(0); | 6234 Operand *Src0 = Arith->getSrc(0); |
6235 Operand *Src1 = Arith->getSrc(1); | 6235 Operand *Src1 = Arith->getSrc(1); |
6236 switch (Arith->getOp()) { | 6236 switch (Arith->getOp()) { |
6237 default: | 6237 default: |
6238 return; | 6238 return; |
6239 case InstArithmetic::Mul: | 6239 case InstArithmetic::Mul: |
(...skipping 13 matching lines...) Expand all Loading... |
6253 scalarizeArithmetic(Arith->getOp(), Dest, Src0, Src1); | 6253 scalarizeArithmetic(Arith->getOp(), Dest, Src0, Src1); |
6254 Arith->setDeleted(); | 6254 Arith->setDeleted(); |
6255 return; | 6255 return; |
6256 } | 6256 } |
6257 } else { | 6257 } else { |
6258 switch (Arith->getOp()) { | 6258 switch (Arith->getOp()) { |
6259 default: | 6259 default: |
6260 return; | 6260 return; |
6261 case InstArithmetic::Frem: | 6261 case InstArithmetic::Frem: |
6262 if (isFloat32Asserting32Or64(DestTy)) | 6262 if (isFloat32Asserting32Or64(DestTy)) |
6263 HelperName = H_frem_f32; | 6263 HelperID = H_frem_f32; |
6264 else | 6264 else |
6265 HelperName = H_frem_f64; | 6265 HelperID = H_frem_f64; |
6266 } | 6266 } |
6267 } | 6267 } |
6268 constexpr SizeT MaxSrcs = 2; | 6268 constexpr SizeT MaxSrcs = 2; |
6269 InstCall *Call = makeHelperCall(HelperName, Dest, MaxSrcs); | 6269 InstCall *Call = makeHelperCall(HelperID, Dest, MaxSrcs); |
6270 Call->addArg(Arith->getSrc(0)); | 6270 Call->addArg(Arith->getSrc(0)); |
6271 Call->addArg(Arith->getSrc(1)); | 6271 Call->addArg(Arith->getSrc(1)); |
6272 StackArgumentsSize = getCallStackArgumentsSizeBytes(Call); | 6272 StackArgumentsSize = getCallStackArgumentsSizeBytes(Call); |
6273 Context.insert(Call); | 6273 Context.insert(Call); |
6274 Arith->setDeleted(); | 6274 Arith->setDeleted(); |
6275 } else if (auto *Cast = llvm::dyn_cast<InstCast>(Instr)) { | 6275 } else if (auto *Cast = llvm::dyn_cast<InstCast>(Instr)) { |
6276 InstCast::OpKind CastKind = Cast->getCastKind(); | 6276 InstCast::OpKind CastKind = Cast->getCastKind(); |
6277 Operand *Src0 = Cast->getSrc(0); | 6277 Operand *Src0 = Cast->getSrc(0); |
6278 const Type SrcType = Src0->getType(); | 6278 const Type SrcType = Src0->getType(); |
6279 Variable *Dest = Cast->getDest(); | 6279 Variable *Dest = Cast->getDest(); |
6280 const Type DestTy = Dest->getType(); | 6280 const Type DestTy = Dest->getType(); |
6281 const char *HelperName = nullptr; | 6281 RuntimeHelperFuncID HelperID = H_Num; |
6282 Variable *CallDest = Dest; | 6282 Variable *CallDest = Dest; |
6283 switch (CastKind) { | 6283 switch (CastKind) { |
6284 default: | 6284 default: |
6285 return; | 6285 return; |
6286 case InstCast::Fptosi: | 6286 case InstCast::Fptosi: |
6287 if (!Traits::Is64Bit && DestTy == IceType_i64) { | 6287 if (!Traits::Is64Bit && DestTy == IceType_i64) { |
6288 HelperName = isFloat32Asserting32Or64(SrcType) ? H_fptosi_f32_i64 | 6288 HelperID = isFloat32Asserting32Or64(SrcType) ? H_fptosi_f32_i64 |
6289 : H_fptosi_f64_i64; | 6289 : H_fptosi_f64_i64; |
6290 } else { | 6290 } else { |
6291 return; | 6291 return; |
6292 } | 6292 } |
6293 break; | 6293 break; |
6294 case InstCast::Fptoui: | 6294 case InstCast::Fptoui: |
6295 if (isVectorType(DestTy)) { | 6295 if (isVectorType(DestTy)) { |
6296 assert(DestTy == IceType_v4i32 && SrcType == IceType_v4f32); | 6296 assert(DestTy == IceType_v4i32 && SrcType == IceType_v4f32); |
6297 HelperName = H_fptoui_4xi32_f32; | 6297 HelperID = H_fptoui_4xi32_f32; |
6298 } else if (DestTy == IceType_i64 || | 6298 } else if (DestTy == IceType_i64 || |
6299 (!Traits::Is64Bit && DestTy == IceType_i32)) { | 6299 (!Traits::Is64Bit && DestTy == IceType_i32)) { |
6300 if (Traits::Is64Bit) { | 6300 if (Traits::Is64Bit) { |
6301 HelperName = isFloat32Asserting32Or64(SrcType) ? H_fptoui_f32_i64 | 6301 HelperID = isFloat32Asserting32Or64(SrcType) ? H_fptoui_f32_i64 |
6302 : H_fptoui_f64_i64; | 6302 : H_fptoui_f64_i64; |
6303 } else if (isInt32Asserting32Or64(DestTy)) { | 6303 } else if (isInt32Asserting32Or64(DestTy)) { |
6304 HelperName = isFloat32Asserting32Or64(SrcType) ? H_fptoui_f32_i32 | 6304 HelperID = isFloat32Asserting32Or64(SrcType) ? H_fptoui_f32_i32 |
6305 : H_fptoui_f64_i32; | 6305 : H_fptoui_f64_i32; |
6306 } else { | 6306 } else { |
6307 HelperName = isFloat32Asserting32Or64(SrcType) ? H_fptoui_f32_i64 | 6307 HelperID = isFloat32Asserting32Or64(SrcType) ? H_fptoui_f32_i64 |
6308 : H_fptoui_f64_i64; | 6308 : H_fptoui_f64_i64; |
6309 } | 6309 } |
6310 } else { | 6310 } else { |
6311 return; | 6311 return; |
6312 } | 6312 } |
6313 break; | 6313 break; |
6314 case InstCast::Sitofp: | 6314 case InstCast::Sitofp: |
6315 if (!Traits::Is64Bit && SrcType == IceType_i64) { | 6315 if (!Traits::Is64Bit && SrcType == IceType_i64) { |
6316 HelperName = isFloat32Asserting32Or64(DestTy) ? H_sitofp_i64_f32 | 6316 HelperID = isFloat32Asserting32Or64(DestTy) ? H_sitofp_i64_f32 |
6317 : H_sitofp_i64_f64; | 6317 : H_sitofp_i64_f64; |
6318 } else { | 6318 } else { |
6319 return; | 6319 return; |
6320 } | 6320 } |
6321 break; | 6321 break; |
6322 case InstCast::Uitofp: | 6322 case InstCast::Uitofp: |
6323 if (isVectorType(SrcType)) { | 6323 if (isVectorType(SrcType)) { |
6324 assert(DestTy == IceType_v4f32 && SrcType == IceType_v4i32); | 6324 assert(DestTy == IceType_v4f32 && SrcType == IceType_v4i32); |
6325 HelperName = H_uitofp_4xi32_4xf32; | 6325 HelperID = H_uitofp_4xi32_4xf32; |
6326 } else if (SrcType == IceType_i64 || | 6326 } else if (SrcType == IceType_i64 || |
6327 (!Traits::Is64Bit && SrcType == IceType_i32)) { | 6327 (!Traits::Is64Bit && SrcType == IceType_i32)) { |
6328 if (isInt32Asserting32Or64(SrcType)) { | 6328 if (isInt32Asserting32Or64(SrcType)) { |
6329 HelperName = isFloat32Asserting32Or64(DestTy) ? H_uitofp_i32_f32 | 6329 HelperID = isFloat32Asserting32Or64(DestTy) ? H_uitofp_i32_f32 |
6330 : H_uitofp_i32_f64; | 6330 : H_uitofp_i32_f64; |
6331 } else { | 6331 } else { |
6332 HelperName = isFloat32Asserting32Or64(DestTy) ? H_uitofp_i64_f32 | 6332 HelperID = isFloat32Asserting32Or64(DestTy) ? H_uitofp_i64_f32 |
6333 : H_uitofp_i64_f64; | 6333 : H_uitofp_i64_f64; |
6334 } | 6334 } |
6335 } else { | 6335 } else { |
6336 return; | 6336 return; |
6337 } | 6337 } |
6338 break; | 6338 break; |
6339 case InstCast::Bitcast: { | 6339 case InstCast::Bitcast: { |
6340 if (DestTy == Src0->getType()) | 6340 if (DestTy == Src0->getType()) |
6341 return; | 6341 return; |
6342 switch (DestTy) { | 6342 switch (DestTy) { |
6343 default: | 6343 default: |
6344 return; | 6344 return; |
6345 case IceType_i8: | 6345 case IceType_i8: |
6346 assert(Src0->getType() == IceType_v8i1); | 6346 assert(Src0->getType() == IceType_v8i1); |
6347 HelperName = H_bitcast_8xi1_i8; | 6347 HelperID = H_bitcast_8xi1_i8; |
6348 CallDest = Func->makeVariable(IceType_i32); | 6348 CallDest = Func->makeVariable(IceType_i32); |
6349 break; | 6349 break; |
6350 case IceType_i16: | 6350 case IceType_i16: |
6351 assert(Src0->getType() == IceType_v16i1); | 6351 assert(Src0->getType() == IceType_v16i1); |
6352 HelperName = H_bitcast_16xi1_i16; | 6352 HelperID = H_bitcast_16xi1_i16; |
6353 CallDest = Func->makeVariable(IceType_i32); | 6353 CallDest = Func->makeVariable(IceType_i32); |
6354 break; | 6354 break; |
6355 case IceType_v8i1: { | 6355 case IceType_v8i1: { |
6356 assert(Src0->getType() == IceType_i8); | 6356 assert(Src0->getType() == IceType_i8); |
6357 HelperName = H_bitcast_i8_8xi1; | 6357 HelperID = H_bitcast_i8_8xi1; |
6358 Variable *Src0AsI32 = Func->makeVariable(stackSlotType()); | 6358 Variable *Src0AsI32 = Func->makeVariable(stackSlotType()); |
6359 // Arguments to functions are required to be at least 32 bits wide. | 6359 // Arguments to functions are required to be at least 32 bits wide. |
6360 Context.insert<InstCast>(InstCast::Zext, Src0AsI32, Src0); | 6360 Context.insert<InstCast>(InstCast::Zext, Src0AsI32, Src0); |
6361 Src0 = Src0AsI32; | 6361 Src0 = Src0AsI32; |
6362 } break; | 6362 } break; |
6363 case IceType_v16i1: { | 6363 case IceType_v16i1: { |
6364 assert(Src0->getType() == IceType_i16); | 6364 assert(Src0->getType() == IceType_i16); |
6365 HelperName = H_bitcast_i16_16xi1; | 6365 HelperID = H_bitcast_i16_16xi1; |
6366 Variable *Src0AsI32 = Func->makeVariable(stackSlotType()); | 6366 Variable *Src0AsI32 = Func->makeVariable(stackSlotType()); |
6367 // Arguments to functions are required to be at least 32 bits wide. | 6367 // Arguments to functions are required to be at least 32 bits wide. |
6368 Context.insert<InstCast>(InstCast::Zext, Src0AsI32, Src0); | 6368 Context.insert<InstCast>(InstCast::Zext, Src0AsI32, Src0); |
6369 Src0 = Src0AsI32; | 6369 Src0 = Src0AsI32; |
6370 } break; | 6370 } break; |
6371 } | 6371 } |
6372 } break; | 6372 } break; |
6373 } | 6373 } |
6374 constexpr SizeT MaxSrcs = 1; | 6374 constexpr SizeT MaxSrcs = 1; |
6375 InstCall *Call = makeHelperCall(HelperName, CallDest, MaxSrcs); | 6375 InstCall *Call = makeHelperCall(HelperID, CallDest, MaxSrcs); |
6376 Call->addArg(Src0); | 6376 Call->addArg(Src0); |
6377 StackArgumentsSize = getCallStackArgumentsSizeBytes(Call); | 6377 StackArgumentsSize = getCallStackArgumentsSizeBytes(Call); |
6378 Context.insert(Call); | 6378 Context.insert(Call); |
6379 // The PNaCl ABI disallows i8/i16 return types, so truncate the helper call | 6379 // The PNaCl ABI disallows i8/i16 return types, so truncate the helper call |
6380 // result to the appropriate type as necessary. | 6380 // result to the appropriate type as necessary. |
6381 if (CallDest->getType() != Dest->getType()) | 6381 if (CallDest->getType() != Dest->getType()) |
6382 Context.insert<InstCast>(InstCast::Trunc, Dest, CallDest); | 6382 Context.insert<InstCast>(InstCast::Trunc, Dest, CallDest); |
6383 Cast->setDeleted(); | 6383 Cast->setDeleted(); |
6384 } else if (auto *Intrinsic = llvm::dyn_cast<InstIntrinsicCall>(Instr)) { | 6384 } else if (auto *Intrinsic = llvm::dyn_cast<InstIntrinsicCall>(Instr)) { |
6385 CfgVector<Type> ArgTypes; | 6385 CfgVector<Type> ArgTypes; |
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7402 emitGlobal(*Var, SectionSuffix); | 7402 emitGlobal(*Var, SectionSuffix); |
7403 } | 7403 } |
7404 } | 7404 } |
7405 } break; | 7405 } break; |
7406 } | 7406 } |
7407 } | 7407 } |
7408 } // end of namespace X86NAMESPACE | 7408 } // end of namespace X86NAMESPACE |
7409 } // end of namespace Ice | 7409 } // end of namespace Ice |
7410 | 7410 |
7411 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H | 7411 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H |
OLD | NEW |