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