From f04fd9038ee58325748fea2f085d43eddcdb37ad Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Mon, 9 Apr 2018 13:22:00 +0000 Subject: [PATCH] [nvptx] Add memory_barrier insn 2018-04-09 Tom de Vries PR target/84041 * config/nvptx/nvptx.md (define_c_enum "unspecv"): Add UNSPECV_MEMBAR. (define_expand "*memory_barrier"): New define_expand. (define_insn "memory_barrier"): New insn. From-SVN: r259233 --- gcc/ChangeLog | 7 +++++++ gcc/config/nvptx/nvptx.md | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index eef1fe43d62..165b968b062 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-04-09 Tom de Vries + + PR target/84041 + * config/nvptx/nvptx.md (define_c_enum "unspecv"): Add UNSPECV_MEMBAR. + (define_expand "*memory_barrier"): New define_expand. + (define_insn "memory_barrier"): New insn. + 2018-04-09 Andrey Belevantsev PR rtl-optimization/80463 diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md index 4f4453da693..68bba369a12 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -55,6 +55,7 @@ UNSPECV_CAS UNSPECV_XCHG UNSPECV_BARSYNC + UNSPECV_MEMBAR UNSPECV_DIM_POS UNSPECV_FORK @@ -1459,6 +1460,27 @@ "\\tbar.sync\\t%0;" [(set_attr "predicable" "false")]) +(define_expand "memory_barrier" + [(set (match_dup 0) + (unspec_volatile:BLK [(match_dup 0)] UNSPECV_MEMBAR))] + "" +{ + operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode)); + MEM_VOLATILE_P (operands[0]) = 1; +}) + +;; Ptx defines the memory barriers membar.cta, membar.gl and membar.sys +;; (corresponding to cuda functions threadfence_block, threadfence and +;; threadfence_system). For the insn memory_barrier we use membar.sys. This +;; may be overconservative, but before using membar.gl instead we'll need to +;; explain in detail why it's safe to use. For now, use membar.sys. +(define_insn "*memory_barrier" + [(set (match_operand:BLK 0 "" "") + (unspec_volatile:BLK [(match_dup 0)] UNSPECV_MEMBAR))] + "" + "\\tmembar.sys;" + [(set_attr "predicable" "false")]) + (define_insn "nvptx_nounroll" [(unspec_volatile [(const_int 0)] UNSPECV_NOUNROLL)] "" -- 2.30.2