clang  3.9.0
CGCUDARuntime.cpp
Go to the documentation of this file.
1 //===----- 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"
17 #include "CGCall.h"
18 #include "CodeGenFunction.h"
19 #include "clang/AST/Decl.h"
20 #include "clang/AST/ExprCXX.h"
21 
22 using namespace clang;
23 using namespace CodeGen;
24 
26 
28  const CUDAKernelCallExpr *E,
29  ReturnValueSlot ReturnValue) {
30  llvm::BasicBlock *ConfigOKBlock = CGF.createBasicBlock("kcall.configok");
31  llvm::BasicBlock *ContBlock = CGF.createBasicBlock("kcall.end");
32 
34  CGF.EmitBranchOnBoolExpr(E->getConfig(), ContBlock, ConfigOKBlock,
35  /*TrueCount=*/0);
36 
37  eval.begin(CGF);
38  CGF.EmitBlock(ConfigOKBlock);
39 
40  const Decl *TargetDecl = nullptr;
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());
48  CGF.EmitCall(E->getCallee()->getType(), Callee, E, ReturnValue, TargetDecl);
49  CGF.EmitBranch(ContBlock);
50 
51  CGF.EmitBlock(ContBlock);
52  eval.end(CGF);
53 
54  return RValue::get(nullptr);
55 }
ReturnValueSlot - Contains the address where the return value of a function can be stored...
Definition: CGCall.h:151
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
const Expr * getCallee() const
Definition: Expr.h:2188
Defines the clang::Expr interface and subclasses for C++ expressions.
An object to manage conditionally-evaluated expressions.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
RValue EmitCall(const CGFunctionInfo &FnInfo, llvm::Value *Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, CGCalleeInfo CalleeInfo=CGCalleeInfo(), llvm::Instruction **callOrInvoke=nullptr)
EmitCall - Generate a call of the given function, expecting the given result type, and using the given argument list which specifies both the LLVM arguments and the types they were derived from.
Definition: CGCall.cpp:3507
virtual RValue EmitCUDAKernelCallExpr(CodeGenFunction &CGF, const CUDAKernelCallExpr *E, ReturnValueSlot ReturnValue)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
Definition: CGValue.h:38
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:2734
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type, returning the result.
QualType getType() const
Definition: Expr.h:126
detail::InMemoryDirectory::const_iterator E
Represents a call to a CUDA kernel function.
Definition: ExprCXX.h:160
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:397
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block, taking care to avoid creation of branches from dummy blocks.
Definition: CGStmt.cpp:417
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:932
static RValue get(llvm::Value *V)
Definition: CGValue.h:85
const CallExpr * getConfig() const
Definition: ExprCXX.h:173