summaryrefslogtreecommitdiffstats
path: root/polly/lib/CodeGen/PPCGCodeGeneration.cpp
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2016-07-19 07:33:16 +0000
committerTobias Grosser <tobias@grosser.es>2016-07-19 07:33:16 +0000
commit5260c041ea8fab9b1f290f8242f653c7bdd1db64 (patch)
tree5d35cc02592059a71fec1a4f89f9f759b1daeafb /polly/lib/CodeGen/PPCGCodeGeneration.cpp
parent59ab070523fb53fa686ef625cc2f0e3462d63528 (diff)
downloadbcm5719-llvm-5260c041ea8fab9b1f290f8242f653c7bdd1db64.tar.gz
bcm5719-llvm-5260c041ea8fab9b1f290f8242f653c7bdd1db64.zip
GPGPU: Emit in-kernel synchronization statements
We use this opportunity to further classify the different user statements that can arise and add TODOs for the ones not yet implemented. llvm-svn: 275957
Diffstat (limited to 'polly/lib/CodeGen/PPCGCodeGeneration.cpp')
-rw-r--r--polly/lib/CodeGen/PPCGCodeGeneration.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/polly/lib/CodeGen/PPCGCodeGeneration.cpp b/polly/lib/CodeGen/PPCGCodeGeneration.cpp
index de261fcf172..050a71e0940 100644
--- a/polly/lib/CodeGen/PPCGCodeGeneration.cpp
+++ b/polly/lib/CodeGen/PPCGCodeGeneration.cpp
@@ -115,6 +115,8 @@ private:
/// - ScopStmt: A computational statement (TODO)
/// - Kernel: A GPU kernel call (TODO)
/// - Data-Transfer: A GPU <-> CPU data-transfer (TODO)
+ /// - In-kernel synchronization
+ /// - In-kernel memory copy statement
///
/// @param UserStmt The ast node to generate code for.
virtual void createUser(__isl_take isl_ast_node *UserStmt);
@@ -153,6 +155,9 @@ private:
/// @param The kernel to generate the intrinsic functions for.
void insertKernelIntrinsics(ppcg_kernel *Kernel);
+ /// Create an in-kernel synchronization call.
+ void createKernelSync();
+
/// Finalize the generation of the kernel function.
///
/// Free the LLVM-IR module corresponding to the kernel and -- if requested --
@@ -160,6 +165,14 @@ private:
void finalizeKernelFunction();
};
+/// Check if one string is a prefix of another.
+///
+/// @param String The string in which to look for the prefix.
+/// @param Prefix The prefix to look for.
+static bool isPrefix(std::string String, std::string Prefix) {
+ return String.find(Prefix) == 0;
+}
+
void GPUNodeBuilder::createUser(__isl_take isl_ast_node *UserStmt) {
isl_ast_expr *Expr = isl_ast_node_user_get_expr(UserStmt);
isl_ast_expr *StmtExpr = isl_ast_expr_get_op_arg(Expr, 0);
@@ -174,11 +187,47 @@ void GPUNodeBuilder::createUser(__isl_take isl_ast_node *UserStmt) {
return;
}
+ if (isPrefix(Str, "to_device") || isPrefix(Str, "from_device")) {
+ // TODO: Insert memory copies
+ isl_ast_expr_free(Expr);
+ isl_ast_node_free(UserStmt);
+ return;
+ }
+
+ isl_id *Anno = isl_ast_node_get_annotation(UserStmt);
+ struct ppcg_kernel_stmt *KernelStmt =
+ (struct ppcg_kernel_stmt *)isl_id_get_user(Anno);
+ isl_id_free(Anno);
+
+ switch (KernelStmt->type) {
+ case ppcg_kernel_domain:
+ // TODO Create kernel user stmt
+ isl_ast_expr_free(Expr);
+ isl_ast_node_free(UserStmt);
+ return;
+ case ppcg_kernel_copy:
+ // TODO: Create kernel copy stmt
+ isl_ast_expr_free(Expr);
+ isl_ast_node_free(UserStmt);
+ return;
+ case ppcg_kernel_sync:
+ createKernelSync();
+ isl_ast_expr_free(Expr);
+ isl_ast_node_free(UserStmt);
+ return;
+ }
+
isl_ast_expr_free(Expr);
isl_ast_node_free(UserStmt);
return;
}
+void GPUNodeBuilder::createKernelSync() {
+ Module *M = Builder.GetInsertBlock()->getParent()->getParent();
+ auto *Sync = Intrinsic::getDeclaration(M, Intrinsic::nvvm_barrier0);
+ Builder.CreateCall(Sync, {});
+}
+
void GPUNodeBuilder::createKernel(__isl_take isl_ast_node *KernelStmt) {
isl_id *Id = isl_ast_node_get_annotation(KernelStmt);
ppcg_kernel *Kernel = (ppcg_kernel *)isl_id_get_user(Id);
OpenPOWER on IntegriCloud