Peter Collingbourne | 6c0aa5f | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 1 | //===----- CGCUDARuntime.cpp - Interface to CUDA Runtimes -----------------===// |
| 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 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This provides an abstract class for CUDA code generation. Concrete |
| 11 | // subclasses of this implement code generation for specific CUDA |
| 12 | // runtime libraries. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "CGCUDARuntime.h" |
Peter Collingbourne | 6c0aa5f | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 17 | #include "CGCall.h" |
| 18 | #include "CodeGenFunction.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame^] | 19 | #include "clang/AST/Decl.h" |
| 20 | #include "clang/AST/ExprCXX.h" |
Peter Collingbourne | 6c0aa5f | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace clang; |
| 23 | using namespace CodeGen; |
| 24 | |
| 25 | CGCUDARuntime::~CGCUDARuntime() {} |
| 26 | |
| 27 | RValue CGCUDARuntime::EmitCUDAKernelCallExpr(CodeGenFunction &CGF, |
| 28 | const CUDAKernelCallExpr *E, |
| 29 | ReturnValueSlot ReturnValue) { |
| 30 | llvm::BasicBlock *ConfigOKBlock = CGF.createBasicBlock("kcall.configok"); |
| 31 | llvm::BasicBlock *ContBlock = CGF.createBasicBlock("kcall.end"); |
| 32 | |
| 33 | CodeGenFunction::ConditionalEvaluation eval(CGF); |
| 34 | CGF.EmitBranchOnBoolExpr(E->getConfig(), ContBlock, ConfigOKBlock); |
| 35 | |
| 36 | eval.begin(CGF); |
| 37 | CGF.EmitBlock(ConfigOKBlock); |
| 38 | |
| 39 | const Decl *TargetDecl = 0; |
| 40 | if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E->getCallee())) { |
| 41 | if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) { |
| 42 | TargetDecl = DRE->getDecl(); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | llvm::Value *Callee = CGF.EmitScalarExpr(E->getCallee()); |
| 47 | CGF.EmitCall(E->getCallee()->getType(), Callee, ReturnValue, |
| 48 | E->arg_begin(), E->arg_end(), TargetDecl); |
| 49 | CGF.EmitBranch(ContBlock); |
| 50 | |
| 51 | CGF.EmitBlock(ContBlock); |
| 52 | eval.end(CGF); |
| 53 | |
| 54 | return RValue::get(0); |
| 55 | } |