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 "CGCall.h"
00018 #include "CodeGenFunction.h"
00019 #include "clang/AST/Decl.h"
00020 #include "clang/AST/ExprCXX.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                            /*TrueCount=*/0);
00036 
00037   eval.begin(CGF);
00038   CGF.EmitBlock(ConfigOKBlock);
00039 
00040   const Decl *TargetDecl = nullptr;
00041   if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E->getCallee())) {
00042     if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) {
00043       TargetDecl = DRE->getDecl();
00044     }
00045   }
00046 
00047   llvm::Value *Callee = CGF.EmitScalarExpr(E->getCallee());
00048   CGF.EmitCall(E->getCallee()->getType(), Callee, E, ReturnValue, TargetDecl);
00049   CGF.EmitBranch(ContBlock);
00050 
00051   CGF.EmitBlock(ContBlock);
00052   eval.end(CGF);
00053 
00054   return RValue::get(nullptr);
00055 }