1f4a2713aSLionel Sambuc //===----- CGCUDARuntime.cpp - Interface to CUDA Runtimes -----------------===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This provides an abstract class for CUDA code generation. Concrete
11f4a2713aSLionel Sambuc // subclasses of this implement code generation for specific CUDA
12f4a2713aSLionel Sambuc // runtime libraries.
13f4a2713aSLionel Sambuc //
14f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
15f4a2713aSLionel Sambuc
16f4a2713aSLionel Sambuc #include "CGCUDARuntime.h"
17f4a2713aSLionel Sambuc #include "CGCall.h"
18f4a2713aSLionel Sambuc #include "CodeGenFunction.h"
19f4a2713aSLionel Sambuc #include "clang/AST/Decl.h"
20f4a2713aSLionel Sambuc #include "clang/AST/ExprCXX.h"
21f4a2713aSLionel Sambuc
22f4a2713aSLionel Sambuc using namespace clang;
23f4a2713aSLionel Sambuc using namespace CodeGen;
24f4a2713aSLionel Sambuc
~CGCUDARuntime()25f4a2713aSLionel Sambuc CGCUDARuntime::~CGCUDARuntime() {}
26f4a2713aSLionel Sambuc
EmitCUDAKernelCallExpr(CodeGenFunction & CGF,const CUDAKernelCallExpr * E,ReturnValueSlot ReturnValue)27f4a2713aSLionel Sambuc RValue CGCUDARuntime::EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
28f4a2713aSLionel Sambuc const CUDAKernelCallExpr *E,
29f4a2713aSLionel Sambuc ReturnValueSlot ReturnValue) {
30f4a2713aSLionel Sambuc llvm::BasicBlock *ConfigOKBlock = CGF.createBasicBlock("kcall.configok");
31f4a2713aSLionel Sambuc llvm::BasicBlock *ContBlock = CGF.createBasicBlock("kcall.end");
32f4a2713aSLionel Sambuc
33f4a2713aSLionel Sambuc CodeGenFunction::ConditionalEvaluation eval(CGF);
34*0a6a1f1dSLionel Sambuc CGF.EmitBranchOnBoolExpr(E->getConfig(), ContBlock, ConfigOKBlock,
35*0a6a1f1dSLionel Sambuc /*TrueCount=*/0);
36f4a2713aSLionel Sambuc
37f4a2713aSLionel Sambuc eval.begin(CGF);
38f4a2713aSLionel Sambuc CGF.EmitBlock(ConfigOKBlock);
39f4a2713aSLionel Sambuc
40*0a6a1f1dSLionel Sambuc const Decl *TargetDecl = nullptr;
41f4a2713aSLionel Sambuc if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E->getCallee())) {
42f4a2713aSLionel Sambuc if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) {
43f4a2713aSLionel Sambuc TargetDecl = DRE->getDecl();
44f4a2713aSLionel Sambuc }
45f4a2713aSLionel Sambuc }
46f4a2713aSLionel Sambuc
47f4a2713aSLionel Sambuc llvm::Value *Callee = CGF.EmitScalarExpr(E->getCallee());
48*0a6a1f1dSLionel Sambuc CGF.EmitCall(E->getCallee()->getType(), Callee, E, ReturnValue, TargetDecl);
49f4a2713aSLionel Sambuc CGF.EmitBranch(ContBlock);
50f4a2713aSLionel Sambuc
51f4a2713aSLionel Sambuc CGF.EmitBlock(ContBlock);
52f4a2713aSLionel Sambuc eval.end(CGF);
53f4a2713aSLionel Sambuc
54*0a6a1f1dSLionel Sambuc return RValue::get(nullptr);
55f4a2713aSLionel Sambuc }
56