blob: 54a28f51bd4b75027cd9d214215c33af7d43ef31 [file] [log] [blame]
Peter Collingbournefe883422011-10-06 18:29:37 +00001//===----- 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 Collingbournefe883422011-10-06 18:29:37 +000017#include "CGCall.h"
18#include "CodeGenFunction.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000019#include "clang/AST/Decl.h"
20#include "clang/AST/ExprCXX.h"
Peter Collingbournefe883422011-10-06 18:29:37 +000021
22using namespace clang;
23using namespace CodeGen;
24
25CGCUDARuntime::~CGCUDARuntime() {}
26
27RValue 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);
Justin Bogneref512b92014-01-06 22:27:43 +000034 CGF.EmitBranchOnBoolExpr(E->getConfig(), ContBlock, ConfigOKBlock,
35 /*TrueCount=*/0);
Peter Collingbournefe883422011-10-06 18:29:37 +000036
37 eval.begin(CGF);
38 CGF.EmitBlock(ConfigOKBlock);
39
40 const Decl *TargetDecl = 0;
41 if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E->getCallee())) {
42 if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) {
43 TargetDecl = DRE->getDecl();
44 }
45 }
46
47 llvm::Value *Callee = CGF.EmitScalarExpr(E->getCallee());
Peter Collingbourneb453cd62013-10-20 21:29:19 +000048 CGF.EmitCall(E->getCallee()->getType(), Callee, E->getLocStart(),
49 ReturnValue, E->arg_begin(), E->arg_end(), TargetDecl);
Peter Collingbournefe883422011-10-06 18:29:37 +000050 CGF.EmitBranch(ContBlock);
51
52 CGF.EmitBlock(ContBlock);
53 eval.end(CGF);
54
55 return RValue::get(0);
56}