CGCUDARuntime.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include "CGCUDARuntime.h"
  16. #include "clang/AST/Decl.h"
  17. #include "clang/AST/ExprCXX.h"
  18. #include "CGCall.h"
  19. #include "CodeGenFunction.h"
  20. using namespace clang;
  21. using namespace CodeGen;
  22. CGCUDARuntime::~CGCUDARuntime() {}
  23. RValue CGCUDARuntime::EmitCUDAKernelCallExpr(CodeGenFunction &CGF,
  24. const CUDAKernelCallExpr *E,
  25. ReturnValueSlot ReturnValue) {
  26. llvm::BasicBlock *ConfigOKBlock = CGF.createBasicBlock("kcall.configok");
  27. llvm::BasicBlock *ContBlock = CGF.createBasicBlock("kcall.end");
  28. CodeGenFunction::ConditionalEvaluation eval(CGF);
  29. CGF.EmitBranchOnBoolExpr(E->getConfig(), ContBlock, ConfigOKBlock);
  30. eval.begin(CGF);
  31. CGF.EmitBlock(ConfigOKBlock);
  32. const Decl *TargetDecl = 0;
  33. if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E->getCallee())) {
  34. if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) {
  35. TargetDecl = DRE->getDecl();
  36. }
  37. }
  38. llvm::Value *Callee = CGF.EmitScalarExpr(E->getCallee());
  39. CGF.EmitCall(E->getCallee()->getType(), Callee, ReturnValue,
  40. E->arg_begin(), E->arg_end(), TargetDecl);
  41. CGF.EmitBranch(ContBlock);
  42. CGF.EmitBlock(ContBlock);
  43. eval.end(CGF);
  44. return RValue::get(0);
  45. }