[PATCH] D50104: [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 31 14:51:40 PDT 2018

yaxunl added inline comments.

Comment at: lib/CodeGen/CGBuiltin.cpp:3342
       auto *AT = llvm::ArrayType::get(SizeTy, NumArgs - First);
+      // Always insert the alloca in the entry block so it remains static in
+      // the SelectionDAG.
+      BasicBlock *Begin = nullptr;
+      if (Instruction *Entry = CurFn->getEntryBlock().getTerminator()) {
+        Begin = Builder.GetInsertBlock();
+        Builder.SetInsertPoint(Entry);
+      }
       auto *Arr = Builder.CreateAlloca(AT);
       llvm::Value *Ptr;
You may try CreateMemTemp. It should handle the insert position and also debug info.

Comment at: test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl:2
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple amdgcn | FileCheck %s --check-prefixes=COMMON,AMDGPU
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s --check-prefixes=COMMON,SPIR32
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefixes=COMMON,SPIR64
Can we have a run line for debug info?

  rC Clang


More information about the cfe-commits mailing list