clang API Documentation

CGCUDARuntime.cpp
Go to the documentation of this file.
00001 //===----- CGCUDARuntime.cpp - Interface to CUDA Runtimes -----------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This provides an abstract class for CUDA code generation.  Concrete
00011 // subclasses of this implement code generation for specific CUDA
00012 // runtime libraries.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #include "CGCUDARuntime.h"
00017 #include "clang/AST/Decl.h"
00018 #include "clang/AST/ExprCXX.h"
00019 #include "CGCall.h"
00020 #include "CodeGenFunction.h"
00021 
00022 using namespace clang;
00023 using namespace CodeGen;
00024 
00025 CGCUDARuntime::~CGCUDARuntime() {}
00026 
00027 RValue CGCUDARuntime::EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
00028                                              const CUDAKernelCallExpr *E,
00029                                              ReturnValueSlot ReturnValue) {
00030   llvm::BasicBlock *ConfigOKBlock = CGF.createBasicBlock("kcall.configok");
00031   llvm::BasicBlock *ContBlock = CGF.createBasicBlock("kcall.end");
00032 
00033   CodeGenFunction::ConditionalEvaluation eval(CGF);
00034   CGF.EmitBranchOnBoolExpr(E->getConfig(), ContBlock, ConfigOKBlock);
00035 
00036   eval.begin(CGF);
00037   CGF.EmitBlock(ConfigOKBlock);
00038 
00039   const Decl *TargetDecl = 0;
00040   if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E->getCallee())) {
00041     if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) {
00042       TargetDecl = DRE->getDecl();
00043     }
00044   }
00045 
00046   llvm::Value *Callee = CGF.EmitScalarExpr(E->getCallee());
00047   CGF.EmitCall(E->getCallee()->getType(), Callee, ReturnValue,
00048                E->arg_begin(), E->arg_end(), TargetDecl);
00049   CGF.EmitBranch(ContBlock);
00050 
00051   CGF.EmitBlock(ContBlock);
00052   eval.end(CGF);
00053 
00054   return RValue::get(0);
00055 }