OLD | NEW |
1 //===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===// | 1 //===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
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 contains code to emit Builtin calls as LLVM code. | 10 // This contains code to emit Builtin calls as LLVM code. |
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 Addr = CastAddr->getSubExpr(); | 1181 Addr = CastAddr->getSubExpr(); |
1182 continue; | 1182 continue; |
1183 } | 1183 } |
1184 break; | 1184 break; |
1185 } | 1185 } |
1186 return llvm::ConstantInt::get(CGF.Int32Ty, Align); | 1186 return llvm::ConstantInt::get(CGF.Int32Ty, Align); |
1187 } | 1187 } |
1188 | 1188 |
1189 Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID, | 1189 Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID, |
1190 const CallExpr *E) { | 1190 const CallExpr *E) { |
| 1191 #if defined(TARGET_ENABLED_ARM) |
1191 if (BuiltinID == ARM::BI__clear_cache) { | 1192 if (BuiltinID == ARM::BI__clear_cache) { |
1192 const FunctionDecl *FD = E->getDirectCallee(); | 1193 const FunctionDecl *FD = E->getDirectCallee(); |
1193 // Oddly people write this call without args on occasion and gcc accepts | 1194 // Oddly people write this call without args on occasion and gcc accepts |
1194 // it - it's also marked as varargs in the description file. | 1195 // it - it's also marked as varargs in the description file. |
1195 SmallVector<Value*, 2> Ops; | 1196 SmallVector<Value*, 2> Ops; |
1196 for (unsigned i = 0; i < E->getNumArgs(); i++) | 1197 for (unsigned i = 0; i < E->getNumArgs(); i++) |
1197 Ops.push_back(EmitScalarExpr(E->getArg(i))); | 1198 Ops.push_back(EmitScalarExpr(E->getArg(i))); |
1198 llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); | 1199 llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); |
1199 llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); | 1200 llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); |
1200 StringRef Name = FD->getName(); | 1201 StringRef Name = FD->getName(); |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1911 Indices.push_back(ConstantInt::get(Int32Ty, ((i + vi*e) >> 1)+e)); | 1912 Indices.push_back(ConstantInt::get(Int32Ty, ((i + vi*e) >> 1)+e)); |
1912 } | 1913 } |
1913 Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ops[0], vi); | 1914 Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ops[0], vi); |
1914 SV = llvm::ConstantVector::get(Indices); | 1915 SV = llvm::ConstantVector::get(Indices); |
1915 SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vzip"); | 1916 SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vzip"); |
1916 SV = Builder.CreateStore(SV, Addr); | 1917 SV = Builder.CreateStore(SV, Addr); |
1917 } | 1918 } |
1918 return SV; | 1919 return SV; |
1919 } | 1920 } |
1920 } | 1921 } |
| 1922 #else |
| 1923 assert(0 && "EmitARMBuiltinExpr w/out TARGET_ENABLED_ARM defined"); |
| 1924 #endif // TARGET_ENABLED_ARM |
| 1925 return 0; |
1921 } | 1926 } |
1922 | 1927 |
1923 llvm::Value *CodeGenFunction:: | 1928 llvm::Value *CodeGenFunction:: |
1924 BuildVector(const SmallVectorImpl<llvm::Value*> &Ops) { | 1929 BuildVector(const SmallVectorImpl<llvm::Value*> &Ops) { |
1925 assert((Ops.size() & (Ops.size() - 1)) == 0 && | 1930 assert((Ops.size() & (Ops.size() - 1)) == 0 && |
1926 "Not a power-of-two sized vector!"); | 1931 "Not a power-of-two sized vector!"); |
1927 bool AllConstants = true; | 1932 bool AllConstants = true; |
1928 for (unsigned i = 0, e = Ops.size(); i != e && AllConstants; ++i) | 1933 for (unsigned i = 0, e = Ops.size(); i != e && AllConstants; ++i) |
1929 AllConstants &= isa<Constant>(Ops[i]); | 1934 AllConstants &= isa<Constant>(Ops[i]); |
1930 | 1935 |
(...skipping 11 matching lines...) Expand all Loading... |
1942 | 1947 |
1943 for (unsigned i = 0, e = Ops.size(); i != e; ++i) | 1948 for (unsigned i = 0, e = Ops.size(); i != e; ++i) |
1944 Result = Builder.CreateInsertElement(Result, Ops[i], | 1949 Result = Builder.CreateInsertElement(Result, Ops[i], |
1945 llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()),
i)); | 1950 llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()),
i)); |
1946 | 1951 |
1947 return Result; | 1952 return Result; |
1948 } | 1953 } |
1949 | 1954 |
1950 Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, | 1955 Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, |
1951 const CallExpr *E) { | 1956 const CallExpr *E) { |
| 1957 #if defined(TARGET_ENABLED_X86) |
1952 SmallVector<Value*, 4> Ops; | 1958 SmallVector<Value*, 4> Ops; |
1953 | 1959 |
1954 // Find out if any arguments are required to be integer constant expressions. | 1960 // Find out if any arguments are required to be integer constant expressions. |
1955 unsigned ICEArguments = 0; | 1961 unsigned ICEArguments = 0; |
1956 ASTContext::GetBuiltinTypeError Error; | 1962 ASTContext::GetBuiltinTypeError Error; |
1957 getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); | 1963 getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
1958 assert(Error == ASTContext::GE_None && "Should not codegen an error"); | 1964 assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
1959 | 1965 |
1960 for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) { | 1966 for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) { |
1961 // If this is a normal argument, just emit it as a scalar. | 1967 // If this is a normal argument, just emit it as a scalar. |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2341 case X86::BI__builtin_ia32_pswapdsf: | 2347 case X86::BI__builtin_ia32_pswapdsf: |
2342 case X86::BI__builtin_ia32_pswapdsi: | 2348 case X86::BI__builtin_ia32_pswapdsi: |
2343 name = "pswapd"; | 2349 name = "pswapd"; |
2344 ID = Intrinsic::x86_3dnowa_pswapd; | 2350 ID = Intrinsic::x86_3dnowa_pswapd; |
2345 break; | 2351 break; |
2346 } | 2352 } |
2347 llvm::Function *F = CGM.getIntrinsic(ID); | 2353 llvm::Function *F = CGM.getIntrinsic(ID); |
2348 return Builder.CreateCall(F, Ops, name); | 2354 return Builder.CreateCall(F, Ops, name); |
2349 } | 2355 } |
2350 } | 2356 } |
| 2357 #else |
| 2358 assert(0 && "EmitX86BuiltinExpr w/out TARGET_ENABLED_X86 defined!"); |
| 2359 #endif // defined(TARGET_ENABLED_X86) |
| 2360 return 0; |
2351 } | 2361 } |
2352 | 2362 |
2353 Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, | 2363 Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, |
2354 const CallExpr *E) { | 2364 const CallExpr *E) { |
| 2365 #if defined(TARGET_ENABLED_POWERPC) |
2355 SmallVector<Value*, 4> Ops; | 2366 SmallVector<Value*, 4> Ops; |
2356 | 2367 |
2357 for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) | 2368 for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) |
2358 Ops.push_back(EmitScalarExpr(E->getArg(i))); | 2369 Ops.push_back(EmitScalarExpr(E->getArg(i))); |
2359 | 2370 |
2360 Intrinsic::ID ID = Intrinsic::not_intrinsic; | 2371 Intrinsic::ID ID = Intrinsic::not_intrinsic; |
2361 | 2372 |
2362 switch (BuiltinID) { | 2373 switch (BuiltinID) { |
2363 default: return 0; | 2374 default: return 0; |
2364 | 2375 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2430 ID = Intrinsic::ppc_altivec_stvehx; | 2441 ID = Intrinsic::ppc_altivec_stvehx; |
2431 break; | 2442 break; |
2432 case PPC::BI__builtin_altivec_stvewx: | 2443 case PPC::BI__builtin_altivec_stvewx: |
2433 ID = Intrinsic::ppc_altivec_stvewx; | 2444 ID = Intrinsic::ppc_altivec_stvewx; |
2434 break; | 2445 break; |
2435 } | 2446 } |
2436 llvm::Function *F = CGM.getIntrinsic(ID); | 2447 llvm::Function *F = CGM.getIntrinsic(ID); |
2437 return Builder.CreateCall(F, Ops, ""); | 2448 return Builder.CreateCall(F, Ops, ""); |
2438 } | 2449 } |
2439 } | 2450 } |
| 2451 #else |
| 2452 assert(0 && "EmitPPCBuiltinExpr w/out TARGET_ENABLED_POWERPC defined!"); |
| 2453 #endif // TARGET_ENABLED_POWERPC |
| 2454 |
2440 return 0; | 2455 return 0; |
2441 } | 2456 } |
OLD | NEW |