{"id":833330,"url":"http://patchwork.ozlabs.org/api/1.2/patches/833330/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/1509625835-22344-6-git-send-email-claziss@synopsys.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.2/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1509625835-22344-6-git-send-email-claziss@synopsys.com>","list_archive_url":null,"date":"2017-11-02T12:30:34","name":"[5/6,ARC] Add 'uncached' attribute.","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"54436d58ff98f2780322022939a9a9b494af6fc5","submitter":{"id":67086,"url":"http://patchwork.ozlabs.org/api/1.2/people/67086/?format=json","name":"Claudiu Zissulescu","email":"Claudiu.Zissulescu@synopsys.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/1509625835-22344-6-git-send-email-claziss@synopsys.com/mbox/","series":[{"id":11495,"url":"http://patchwork.ozlabs.org/api/1.2/series/11495/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=11495","date":"2017-11-02T12:30:29","name":"New baremetal features and fixes","version":1,"mbox":"http://patchwork.ozlabs.org/series/11495/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/833330/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/833330/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-return-465736-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465736-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"GR7RX5gb\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3ySPgZ1y2Lz9sBW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  2 Nov 2017 23:35:22 +1100 (AEDT)","(qmail 54680 invoked by alias); 2 Nov 2017 12:34:46 -0000","(qmail 53890 invoked by uid 89); 2 Nov 2017 12:34:44 -0000","from us01smtprelay-2.synopsys.com (HELO smtprelay.synopsys.com)\n\t(198.182.47.9) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 02 Nov 2017 12:34:40 +0000","from mailhost.synopsys.com (mailhost3.synopsys.com\n\t[10.12.238.238])\tby smtprelay.synopsys.com (Postfix) with\n\tESMTP id 721BF24E203A; Thu,  2 Nov 2017 05:34:39 -0700 (PDT)","from mailhost.synopsys.com (localhost [127.0.0.1])\tby\n\tmailhost.synopsys.com (Postfix) with ESMTP id 59D72B1F;\n\tThu,  2 Nov 2017 05:34:39 -0700 (PDT)","from US01WEHTC2.internal.synopsys.com\n\t(us01wehtc2-vip.internal.synopsys.com [10.12.239.238])\tby\n\tmailhost.synopsys.com (Postfix) with ESMTP id 4A6D3B1C;\n\tThu,  2 Nov 2017 05:34:39 -0700 (PDT)","from IN01WEHTCB.internal.synopsys.com (10.144.199.106) by\n\tUS01WEHTC2.internal.synopsys.com (10.12.239.237) with\n\tMicrosoft SMTP Server (TLS) id 14.3.266.1;\n\tThu, 2 Nov 2017 05:34:32 -0700","from IN01WEHTCA.internal.synopsys.com (10.144.199.103) by\n\tIN01WEHTCB.internal.synopsys.com (10.144.199.105) with\n\tMicrosoft SMTP Server (TLS) id 14.3.266.1;\n\tThu, 2 Nov 2017 18:04:30 +0530","from nl20droid1.internal.synopsys.com (10.100.24.228) by\n\tIN01WEHTCA.internal.synopsys.com (10.144.199.243) with\n\tMicrosoft SMTP Server (TLS) id 14.3.266.1;\n\tThu, 2 Nov 2017 18:04:30 +0530"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-type; q=dns; s=default; b=LtKh43/mVd9ZgIYm\n\txo/FeZsmeVpqQKGKD+NnqkrKylEabAd0vQI9+Jc+ACaYWIlwmadUdSBfRSdCWbnp\n\t0KaqEBJ8+FH4tbhhUaY4jqW5u4SWkVb/7Liye5XfTiZ5gMVtJFdigzmBig/F6prx\n\txVcZVPB+DjpET2Y3754/KWmyZ5w=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-type; s=default; bh=AqwRdh1r/9qBHVCT+G3wXV\n\tssDzA=; b=GR7RX5gbq5uBNNrtNhOJ9j1/XutKdBnMT8QsvIuk87OKu5SSB3jLQ4\n\tS9fT473tmRdwvmr8CHapJZqYmHK4SlUArAosm2y7BtJqQRdvFnSl/YYIc7icAe5h\n\toBves0+dPz2CSPeD1j5JVpQH4GCiCH+yhg24Wy9zkqE6u3+iJS9hc=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-23.9 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tKAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE,\n\tRP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=bypass, PAT,\n\tH*RU:10.12.239.238, Hx-spam-relays-external:sk:US01WEH","X-HELO":"smtprelay.synopsys.com","From":"Claudiu Zissulescu <Claudiu.Zissulescu@synopsys.com>","To":"<gcc-patches@gcc.gnu.org>","CC":"<Claudiu.Zissulescu@synopsys.com>, <Francois.Bedard@synopsys.com>,\n\t<andrew.burgess@embecosm.com>","Subject":"[PATCH 5/6] [ARC] Add 'uncached' attribute.","Date":"Thu, 2 Nov 2017 13:30:34 +0100","Message-ID":"<1509625835-22344-6-git-send-email-claziss@synopsys.com>","In-Reply-To":"<1509625835-22344-1-git-send-email-claziss@synopsys.com>","References":"<1509625835-22344-1-git-send-email-claziss@synopsys.com>","MIME-Version":"1.0","Content-Type":"text/plain"},"content":"From: claziss <claziss@synopsys.com>\n\nThe _Uncached type qualifier can be used to bypass the cache without\nresorting to declaring variables as volatile.\n\ngcc/\n2017-07-12  Claudiu Zissulescu  <claziss@synopsys.com>\n\n\t* config/arc/arc-protos.h (arc_is_uncached_mem_p): Function proto.\n\t* config/arc/arc.c (arc_handle_uncached_attribute): New function.\n\t(arc_attribute_table): Add 'uncached' attribute.\n\t(arc_print_operand): Print '.di' flag for uncached memory\n\taccesses.\n\t(arc_in_small_data_p): Do not consider for small data the uncached\n\ttypes.\n\t(arc_is_uncached_mem_p): New function.\n\t* config/arc/predicates.md (compact_store_memory_operand): Check\n\tfor uncached memory accesses.\n\t(nonvol_nonimm_operand): Likewise.\n\ngcc/testsuite\n2017-07-12  Claudiu Zissulescu  <claziss@synopsys.com>\n\n\t* gcc.target/arc/uncached.c: New test.\n---\n gcc/config/arc/arc-protos.h             |  1 +\n gcc/config/arc/arc.c                    | 65 ++++++++++++++++++++++++++++++++-\n gcc/config/arc/predicates.md            |  7 +++-\n gcc/testsuite/gcc.target/arc/uncached.c | 18 +++++++++\n 4 files changed, 88 insertions(+), 3 deletions(-)\n create mode 100644 gcc/testsuite/gcc.target/arc/uncached.c","diff":"diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h\nindex f8e7937..cc00730 100644\n--- a/gcc/config/arc/arc-protos.h\n+++ b/gcc/config/arc/arc-protos.h\n@@ -47,6 +47,7 @@ extern void arc_expand_compare_and_swap (rtx *);\n extern bool compact_memory_operand_p (rtx, machine_mode, bool, bool);\n extern int arc_return_address_register (unsigned int);\n extern unsigned int arc_compute_function_type (struct function *);\n+extern bool arc_is_uncached_mem_p (rtx);\n #endif /* RTX_CODE */\n \n extern unsigned int arc_compute_frame_size (int);\ndiff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c\nindex 07dd072..a397cbd 100644\n--- a/gcc/config/arc/arc.c\n+++ b/gcc/config/arc/arc.c\n@@ -222,7 +222,7 @@ static tree arc_handle_interrupt_attribute (tree *, tree, tree, int, bool *);\n static tree arc_handle_fndecl_attribute (tree *, tree, tree, int, bool *);\n static tree arc_handle_jli_attribute (tree *, tree, tree, int, bool *);\n static tree arc_handle_secure_attribute (tree *, tree, tree, int, bool *);\n-\n+static tree arc_handle_uncached_attribute (tree *, tree, tree, int, bool *);\n \n /* Initialized arc_attribute_table to NULL since arc doesnot have any\n    machine specific supported attributes.  */\n@@ -254,6 +254,9 @@ const struct attribute_spec arc_attribute_table[] =\n   /* Call a function using secure-mode.  */\n   { \"secure_call\",  1, 1, false, true, true, arc_handle_secure_attribute,\n     false },\n+  /* Bypass caches using .di flag.  */\n+  { \"uncached\", 0, 0, false, true, false, arc_handle_uncached_attribute,\n+    false },\n   { NULL, 0, 0, false, false, false, NULL, false }\n };\n static int arc_comp_type_attributes (const_tree, const_tree);\n@@ -4135,7 +4138,8 @@ arc_print_operand (FILE *file, rtx x, int code)\n \t refs are defined to use the cache bypass mechanism.  */\n       if (GET_CODE (x) == MEM)\n \t{\n-\t  if (MEM_VOLATILE_P (x) && !TARGET_VOLATILE_CACHE_SET )\n+\t  if ((MEM_VOLATILE_P (x) && !TARGET_VOLATILE_CACHE_SET)\n+\t      || arc_is_uncached_mem_p (x))\n \t    fputs (\".di\", file);\n \t}\n       else\n@@ -8038,6 +8042,7 @@ static bool\n arc_in_small_data_p (const_tree decl)\n {\n   HOST_WIDE_INT size;\n+  tree attr;\n \n   /* Only variables are going into small data area.  */\n   if (TREE_CODE (decl) != VAR_DECL)\n@@ -8061,6 +8066,11 @@ arc_in_small_data_p (const_tree decl)\n       && TREE_THIS_VOLATILE (decl))\n     return false;\n \n+  /* Likewise for uncached data.  */\n+  attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));\n+  if (lookup_attribute (\"uncached\", attr))\n+    return false;\n+\n   if (DECL_SECTION_NAME (decl) != 0)\n     {\n       const char *name = DECL_SECTION_NAME (decl);\n@@ -11066,6 +11076,57 @@ arc_is_secure_call_p (rtx pat)\n   return false;\n }\n \n+/* Handle \"uncached\" qualifier.  */\n+\n+static tree\n+arc_handle_uncached_attribute (tree *node,\n+\t\t\t       tree name, tree args,\n+\t\t\t       int flags ATTRIBUTE_UNUSED,\n+\t\t\t       bool *no_add_attrs)\n+{\n+  if (DECL_P (*node) && TREE_CODE (*node) != TYPE_DECL)\n+    {\n+      error (\"%qE attribute only applies to types\",\n+\t     name);\n+      *no_add_attrs = true;\n+    }\n+  else if (args)\n+    {\n+      warning (OPT_Wattributes, \"argument of %qE attribute ignored\", name);\n+    }\n+  return NULL_TREE;\n+}\n+\n+/* Return TRUE if PAT is a memory addressing an uncached data.  */\n+\n+bool\n+arc_is_uncached_mem_p (rtx pat)\n+{\n+  tree attrs;\n+  tree ttype;\n+  struct mem_attrs *refattrs;\n+\n+  if (!MEM_P (pat))\n+    return false;\n+\n+  /* Get the memory attributes.  */\n+  refattrs = MEM_ATTRS (pat);\n+  if (!refattrs\n+      || !refattrs->expr)\n+    return false;\n+\n+  /* Get the type declaration.  */\n+  ttype = TREE_TYPE (refattrs->expr);\n+  if (!ttype)\n+    return false;\n+\n+  /* Get the type attributes.  */\n+  attrs = TYPE_ATTRIBUTES (ttype);\n+  if (lookup_attribute (\"uncached\", attrs))\n+    return true;\n+  return false;\n+}\n+\n /* Implement TARGET_USE_ANCHORS_FOR_SYMBOL_P.  We don't want to use\n    anchors for small data: the GP register acts as an anchor in that\n    case.  We also don't want to use them for PC-relative accesses,\ndiff --git a/gcc/config/arc/predicates.md b/gcc/config/arc/predicates.md\nindex 3dfe0ca..68887be 100644\n--- a/gcc/config/arc/predicates.md\n+++ b/gcc/config/arc/predicates.md\n@@ -217,6 +217,10 @@\n   if (MEM_VOLATILE_P (op) && !TARGET_VOLATILE_CACHE_SET)\n      return 0;\n \n+  /* likewise for uncached types.  */\n+  if (arc_is_uncached_mem_p (op))\n+     return 0;\n+\n   size = GET_MODE_SIZE (mode);\n \n   /* dword operations really put out 2 instructions, so eliminate them.  */\n@@ -412,7 +416,8 @@\n ;; and only the standard movXX patterns are set up to handle them.\n (define_predicate \"nonvol_nonimm_operand\"\n   (and (match_code \"subreg, reg, mem\")\n-       (match_test \"(GET_CODE (op) != MEM || !MEM_VOLATILE_P (op)) && nonimmediate_operand (op, mode)\"))\n+       (match_test \"(GET_CODE (op) != MEM || !MEM_VOLATILE_P (op)) && nonimmediate_operand (op, mode)\")\n+       (match_test \"!arc_is_uncached_mem_p (op)\"))\n )\n \n ;; Return 1 if OP is a comparison operator valid for the mode of CC.\ndiff --git a/gcc/testsuite/gcc.target/arc/uncached.c b/gcc/testsuite/gcc.target/arc/uncached.c\nnew file mode 100644\nindex 0000000..367e8dc\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/arc/uncached.c\n@@ -0,0 +1,18 @@\n+/* { dg-do compile } */\n+\n+/* Check 'uncached' type attribute.  */\n+\n+typedef volatile unsigned int RwReg  __attribute__ ((uncached));\n+\n+typedef struct {\n+  RwReg UART_THR;\n+  int SIDE_DISH;\n+} UART;\n+\n+void uart_putc(UART *port, char c)\n+{\n+    port->UART_THR = c;\n+    port->SIDE_DISH = c;\n+}\n+\n+/* { dg-final { scan-assembler-times \"st\\.di\" 1 } } */\n","prefixes":["5/6","ARC"]}