CGBuiltin.cpp (200583) | CGBuiltin.cpp (201361) |
---|---|
1//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 195 unchanged lines hidden (view full) --- 204 return RValue::get(Builder.CreateCall(F, ArgValue, "tmp")); 205 } 206 case Builtin::BI__builtin_object_size: { 207 // We pass this builtin onto the optimizer so that it can 208 // figure out the object size in more complex cases. 209 const llvm::Type *ResType[] = { 210 ConvertType(E->getType()) 211 }; | 1//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 195 unchanged lines hidden (view full) --- 204 return RValue::get(Builder.CreateCall(F, ArgValue, "tmp")); 205 } 206 case Builtin::BI__builtin_object_size: { 207 // We pass this builtin onto the optimizer so that it can 208 // figure out the object size in more complex cases. 209 const llvm::Type *ResType[] = { 210 ConvertType(E->getType()) 211 }; |
212 213 // LLVM only supports 0 and 2, make sure that we pass along that 214 // as a boolean. 215 Value *Ty = EmitScalarExpr(E->getArg(1)); 216 ConstantInt *CI = dyn_cast<ConstantInt>(Ty); 217 assert(CI); 218 uint64_t val = CI->getZExtValue(); 219 CI = ConstantInt::get(llvm::Type::getInt1Ty(VMContext), (val & 0x2) >> 1); 220 |
|
212 Value *F = CGM.getIntrinsic(Intrinsic::objectsize, ResType, 1); 213 return RValue::get(Builder.CreateCall2(F, 214 EmitScalarExpr(E->getArg(0)), | 221 Value *F = CGM.getIntrinsic(Intrinsic::objectsize, ResType, 1); 222 return RValue::get(Builder.CreateCall2(F, 223 EmitScalarExpr(E->getArg(0)), |
215 EmitScalarExpr(E->getArg(1)))); | 224 CI)); |
216 } 217 case Builtin::BI__builtin_prefetch: { 218 Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); 219 // FIXME: Technically these constants should of type 'int', yes? 220 RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : 221 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 0); 222 Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : 223 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 3); 224 Value *F = CGM.getIntrinsic(Intrinsic::prefetch, 0, 0); 225 return RValue::get(Builder.CreateCall3(F, Address, RW, Locality)); 226 } 227 case Builtin::BI__builtin_trap: { 228 Value *F = CGM.getIntrinsic(Intrinsic::trap, 0, 0); 229 return RValue::get(Builder.CreateCall(F)); 230 } 231 case Builtin::BI__builtin_unreachable: { | 225 } 226 case Builtin::BI__builtin_prefetch: { 227 Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); 228 // FIXME: Technically these constants should of type 'int', yes? 229 RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : 230 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 0); 231 Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : 232 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 3); 233 Value *F = CGM.getIntrinsic(Intrinsic::prefetch, 0, 0); 234 return RValue::get(Builder.CreateCall3(F, Address, RW, Locality)); 235 } 236 case Builtin::BI__builtin_trap: { 237 Value *F = CGM.getIntrinsic(Intrinsic::trap, 0, 0); 238 return RValue::get(Builder.CreateCall(F)); 239 } 240 case Builtin::BI__builtin_unreachable: { |
241 if (CatchUndefined && HaveInsertPoint()) 242 EmitBranch(getTrapBB()); |
|
232 Value *V = Builder.CreateUnreachable(); 233 Builder.ClearInsertionPoint(); 234 return RValue::get(V); 235 } 236 237 case Builtin::BI__builtin_powi: 238 case Builtin::BI__builtin_powif: 239 case Builtin::BI__builtin_powil: { --- 55 unchanged lines hidden (view full) --- 295 case Builtin::BI__builtin_bzero: { 296 Value *Address = EmitScalarExpr(E->getArg(0)); 297 Builder.CreateCall4(CGM.getMemSetFn(), Address, 298 llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 0), 299 EmitScalarExpr(E->getArg(1)), 300 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); 301 return RValue::get(Address); 302 } | 243 Value *V = Builder.CreateUnreachable(); 244 Builder.ClearInsertionPoint(); 245 return RValue::get(V); 246 } 247 248 case Builtin::BI__builtin_powi: 249 case Builtin::BI__builtin_powif: 250 case Builtin::BI__builtin_powil: { --- 55 unchanged lines hidden (view full) --- 306 case Builtin::BI__builtin_bzero: { 307 Value *Address = EmitScalarExpr(E->getArg(0)); 308 Builder.CreateCall4(CGM.getMemSetFn(), Address, 309 llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 0), 310 EmitScalarExpr(E->getArg(1)), 311 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); 312 return RValue::get(Address); 313 } |
314 case Builtin::BImemcpy: |
|
303 case Builtin::BI__builtin_memcpy: { 304 Value *Address = EmitScalarExpr(E->getArg(0)); 305 Builder.CreateCall4(CGM.getMemCpyFn(), Address, 306 EmitScalarExpr(E->getArg(1)), 307 EmitScalarExpr(E->getArg(2)), 308 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); 309 return RValue::get(Address); 310 } | 315 case Builtin::BI__builtin_memcpy: { 316 Value *Address = EmitScalarExpr(E->getArg(0)); 317 Builder.CreateCall4(CGM.getMemCpyFn(), Address, 318 EmitScalarExpr(E->getArg(1)), 319 EmitScalarExpr(E->getArg(2)), 320 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); 321 return RValue::get(Address); 322 } |
323 case Builtin::BImemmove: |
|
311 case Builtin::BI__builtin_memmove: { 312 Value *Address = EmitScalarExpr(E->getArg(0)); 313 Builder.CreateCall4(CGM.getMemMoveFn(), Address, 314 EmitScalarExpr(E->getArg(1)), 315 EmitScalarExpr(E->getArg(2)), 316 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); 317 return RValue::get(Address); 318 } | 324 case Builtin::BI__builtin_memmove: { 325 Value *Address = EmitScalarExpr(E->getArg(0)); 326 Builder.CreateCall4(CGM.getMemMoveFn(), Address, 327 EmitScalarExpr(E->getArg(1)), 328 EmitScalarExpr(E->getArg(2)), 329 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); 330 return RValue::get(Address); 331 } |
332 case Builtin::BImemset: |
|
319 case Builtin::BI__builtin_memset: { 320 Value *Address = EmitScalarExpr(E->getArg(0)); 321 Builder.CreateCall4(CGM.getMemSetFn(), Address, 322 Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), 323 llvm::Type::getInt8Ty(VMContext)), 324 EmitScalarExpr(E->getArg(2)), 325 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); 326 return RValue::get(Address); 327 } 328 case Builtin::BI__builtin_return_address: { | 333 case Builtin::BI__builtin_memset: { 334 Value *Address = EmitScalarExpr(E->getArg(0)); 335 Builder.CreateCall4(CGM.getMemSetFn(), Address, 336 Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), 337 llvm::Type::getInt8Ty(VMContext)), 338 EmitScalarExpr(E->getArg(2)), 339 llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); 340 return RValue::get(Address); 341 } 342 case Builtin::BI__builtin_return_address: { |
343 Value *Depth = EmitScalarExpr(E->getArg(0)); 344 Depth = Builder.CreateIntCast(Depth, 345 llvm::Type::getInt32Ty(VMContext), 346 false, "tmp"); |
|
329 Value *F = CGM.getIntrinsic(Intrinsic::returnaddress, 0, 0); | 347 Value *F = CGM.getIntrinsic(Intrinsic::returnaddress, 0, 0); |
330 return RValue::get(Builder.CreateCall(F, EmitScalarExpr(E->getArg(0)))); | 348 return RValue::get(Builder.CreateCall(F, Depth)); |
331 } 332 case Builtin::BI__builtin_frame_address: { | 349 } 350 case Builtin::BI__builtin_frame_address: { |
351 Value *Depth = EmitScalarExpr(E->getArg(0)); 352 Depth = Builder.CreateIntCast(Depth, 353 llvm::Type::getInt32Ty(VMContext), 354 false, "tmp"); |
|
333 Value *F = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0); | 355 Value *F = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0); |
334 return RValue::get(Builder.CreateCall(F, EmitScalarExpr(E->getArg(0)))); | 356 return RValue::get(Builder.CreateCall(F, Depth)); |
335 } 336 case Builtin::BI__builtin_extract_return_addr: { 337 // FIXME: There should be a target hook for this 338 return RValue::get(EmitScalarExpr(E->getArg(0))); 339 } 340 case Builtin::BI__builtin_unwind_init: { 341 Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init, 0, 0); 342 return RValue::get(Builder.CreateCall(F)); --- 217 unchanged lines hidden (view full) --- 560 return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); 561 } 562 } 563 564 // If this is an alias for a libm function (e.g. __builtin_sin) turn it into 565 // that function. 566 if (getContext().BuiltinInfo.isLibFunction(BuiltinID) || 567 getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID)) | 357 } 358 case Builtin::BI__builtin_extract_return_addr: { 359 // FIXME: There should be a target hook for this 360 return RValue::get(EmitScalarExpr(E->getArg(0))); 361 } 362 case Builtin::BI__builtin_unwind_init: { 363 Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init, 0, 0); 364 return RValue::get(Builder.CreateCall(F)); --- 217 unchanged lines hidden (view full) --- 582 return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); 583 } 584 } 585 586 // If this is an alias for a libm function (e.g. __builtin_sin) turn it into 587 // that function. 588 if (getContext().BuiltinInfo.isLibFunction(BuiltinID) || 589 getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID)) |
568 return EmitCall(CGM.getBuiltinLibFunction(FD, BuiltinID), 569 E->getCallee()->getType(), E->arg_begin(), 570 E->arg_end()); | 590 return EmitCall(E->getCallee()->getType(), 591 CGM.getBuiltinLibFunction(FD, BuiltinID), 592 ReturnValueSlot(), 593 E->arg_begin(), E->arg_end()); |
571 572 // See if we have a target specific intrinsic. 573 const char *Name = getContext().BuiltinInfo.GetName(BuiltinID); 574 Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic; 575 if (const char *Prefix = 576 llvm::Triple::getArchTypePrefix(Target.getTriple().getArch())) 577 IntrinsicID = Intrinsic::getIntrinsicForGCCBuiltin(Prefix, Name); 578 --- 264 unchanged lines hidden (view full) --- 843 // If palignr is shifting the pair of vectors more than 32 bytes, emit zero. 844 return llvm::Constant::getNullValue(ConvertType(E->getType())); 845 } 846 } 847} 848 849Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, 850 const CallExpr *E) { | 594 595 // See if we have a target specific intrinsic. 596 const char *Name = getContext().BuiltinInfo.GetName(BuiltinID); 597 Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic; 598 if (const char *Prefix = 599 llvm::Triple::getArchTypePrefix(Target.getTriple().getArch())) 600 IntrinsicID = Intrinsic::getIntrinsicForGCCBuiltin(Prefix, Name); 601 --- 264 unchanged lines hidden (view full) --- 866 // If palignr is shifting the pair of vectors more than 32 bytes, emit zero. 867 return llvm::Constant::getNullValue(ConvertType(E->getType())); 868 } 869 } 870} 871 872Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, 873 const CallExpr *E) { |
851 switch (BuiltinID) { 852 default: return 0; 853 } | 874 return 0; |
854} | 875} |