[{"id":1848120,"web_url":"http://patchwork.ozlabs.org/comment/1848120/","msgid":"<20180129192618.GB3162@embecosm.com>","list_archive_url":null,"date":"2018-01-29T19:26:18","subject":"Re: [PATCH 6/6] [ARC] Add 'aux' variable attribute.","submitter":{"id":65155,"url":"http://patchwork.ozlabs.org/api/people/65155/","name":"Andrew Burgess","email":"andrew.burgess@embecosm.com"},"content":"* Claudiu Zissulescu <Claudiu.Zissulescu@synopsys.com> [2017-11-02 13:30:35 +0100]:\n\n> From: claziss <claziss@synopsys.com>\n> \n> The 'aux' variable attribute is used to directly access the auxiliary\n> register space from C.\n> \n> gcc/\n> 2017-07-25  Claudiu Zissulescu  <claziss@synopsys.com>\n> \n> \t* config/arc/arc.c (arc_handle_aux_attribute): New function.\n> \t(arc_attribute_table): Add 'aux' attribute.\n> \t(arc_in_small_data_p): Consider aux like variables.\n> \t(arc_is_aux_reg_p): New function.\n> \t(arc_asm_output_aligned_decl_local): Ignore 'aux' like variables.\n> \t(arc_get_aux_arg): New function.\n> \t(prepare_move_operands): Handle aux-register access.\n> \t(arc_handle_aux_attribute): New function.\n> \t* doc/extend.texi (ARC Variable attributes): Add subsection.\n> \n> testsuite/\n> 2017-07-25  Claudiu Zissulescu  <claziss@synopsys.com>\n> \n> \t* gcc.target/arc/taux-1.c: New test.\n> \t* gcc.target/arc/taux-2.c: Likewise.\n\nLooks good.\n\nSorry for the time taken to review this series.\n\nThanks,\nAndrew\n\n\n> ---\n>  gcc/config/arc/arc.c                  | 160 +++++++++++++++++++++++++++++++++-\n>  gcc/doc/extend.texi                   |  13 +++\n>  gcc/testsuite/gcc.target/arc/taux-1.c |  38 ++++++++\n>  gcc/testsuite/gcc.target/arc/taux-2.c |  15 ++++\n>  4 files changed, 225 insertions(+), 1 deletion(-)\n>  create mode 100644 gcc/testsuite/gcc.target/arc/taux-1.c\n>  create mode 100644 gcc/testsuite/gcc.target/arc/taux-2.c\n> \n> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c\n> index a397cbd..33f68ef 100644\n> --- a/gcc/config/arc/arc.c\n> +++ b/gcc/config/arc/arc.c\n> @@ -223,6 +223,7 @@ 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>  static tree arc_handle_uncached_attribute (tree *, tree, tree, int, bool *);\n> +static tree arc_handle_aux_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> @@ -257,6 +258,8 @@ const struct attribute_spec arc_attribute_table[] =\n>    /* Bypass caches using .di flag.  */\n>    { \"uncached\", 0, 0, false, true, false, arc_handle_uncached_attribute,\n>      false },\n> +  /* Declare a variable as aux.  */\n> +  { \"aux\", 0, 1, true, false, false, arc_handle_aux_attribute, false },\n>    { NULL, 0, 0, false, false, false, NULL, false }\n>  };\n>  static int arc_comp_type_attributes (const_tree, const_tree);\n> @@ -8071,6 +8074,11 @@ arc_in_small_data_p (const_tree decl)\n>    if (lookup_attribute (\"uncached\", attr))\n>      return false;\n>  \n> +  /* and for aux regs.  */\n> +  attr = DECL_ATTRIBUTES (decl);\n> +  if (lookup_attribute (\"aux\", attr))\n> +    return false;\n> +\n>    if (DECL_SECTION_NAME (decl) != 0)\n>      {\n>        const char *name = DECL_SECTION_NAME (decl);\n> @@ -8238,6 +8246,35 @@ compact_sda_memory_operand (rtx op, machine_mode mode, bool short_p)\n>    return false;\n>  }\n>  \n> +/* Return TRUE if PAT is accessing an aux-reg.  */\n> +\n> +static bool\n> +arc_is_aux_reg_p (rtx pat)\n> +{\n> +  tree attrs = NULL_TREE;\n> +  tree addr;\n> +\n> +  if (!MEM_P (pat))\n> +    return false;\n> +\n> +  /* Get the memory attributes.  */\n> +  addr = MEM_EXPR (pat);\n> +  if (!addr)\n> +    return false;\n> +\n> +  /* Get the attributes.  */\n> +  if (TREE_CODE (addr) == VAR_DECL)\n> +    attrs = DECL_ATTRIBUTES (addr);\n> +  else if (TREE_CODE (addr) == MEM_REF)\n> +    attrs = TYPE_ATTRIBUTES (TREE_TYPE (TREE_OPERAND (addr, 0)));\n> +  else\n> +    return false;\n> +\n> +  if (lookup_attribute (\"aux\", attrs))\n> +    return true;\n> +  return false;\n> +}\n> +\n>  /* Implement ASM_OUTPUT_ALIGNED_DECL_LOCAL.  */\n>  \n>  void\n> @@ -8246,7 +8283,14 @@ arc_asm_output_aligned_decl_local (FILE * stream, tree decl, const char * name,\n>  \t\t\t\t   unsigned HOST_WIDE_INT align,\n>  \t\t\t\t   unsigned HOST_WIDE_INT globalize_p)\n>  {\n> -  int in_small_data =   arc_in_small_data_p (decl);\n> +  int in_small_data = arc_in_small_data_p (decl);\n> +  rtx mem = decl == NULL_TREE ? NULL_RTX : DECL_RTL (decl);\n> +\n> +  /* Don't output aux-reg symbols.  */\n> +  if (mem != NULL_RTX && MEM_P (mem)\n> +      && SYMBOL_REF_P (XEXP (mem, 0))\n> +      && arc_is_aux_reg_p (mem))\n> +    return;\n>  \n>    if (in_small_data)\n>      switch_to_section (get_named_section (NULL, \".sbss\", 0));\n> @@ -8586,12 +8630,80 @@ arc_expand_movmem (rtx *operands)\n>    return true;\n>  }\n>  \n> +static bool\n> +arc_get_aux_arg (rtx pat, int *auxr)\n> +{\n> +  tree attr, addr = MEM_EXPR (pat);\n> +  if (TREE_CODE (addr) != VAR_DECL)\n> +    return false;\n> +\n> +  attr = DECL_ATTRIBUTES (addr);\n> +  if (lookup_attribute (\"aux\", attr))\n> +    {\n> +      tree arg = TREE_VALUE (attr);\n> +      if (arg)\n> +\t{\n> +\t  *auxr = TREE_INT_CST_LOW (TREE_VALUE (arg));\n> +\t  return true;\n> +\t}\n> +    }\n> +\n> +  return false;\n> +}\n> +\n>  /* Prepare operands for move in MODE.  Return true iff the move has\n>     been emitted.  */\n>  \n>  bool\n>  prepare_move_operands (rtx *operands, machine_mode mode)\n>  {\n> +  /* First handle aux attribute.  */\n> +  if (mode == SImode\n> +      && (MEM_P (operands[0]) || MEM_P (operands[1])))\n> +    {\n> +      rtx tmp;\n> +      int auxr = 0;\n> +      if (MEM_P (operands[0]) && arc_is_aux_reg_p (operands[0]))\n> +\t{\n> +\t  /* Save operation.  */\n> +\t  if (arc_get_aux_arg (operands[0], &auxr))\n> +\t    {\n> +\t      tmp = gen_reg_rtx (SImode);\n> +\t      emit_move_insn (tmp, GEN_INT (auxr));\n> +\t    }\n> +\t  else\n> +\t    {\n> +\t      tmp = XEXP (operands[0], 0);\n> +\t    }\n> +\n> +\t  operands[1] = force_reg (SImode, operands[1]);\n> +\t  emit_insn (gen_rtx_UNSPEC_VOLATILE\n> +\t\t     (VOIDmode, gen_rtvec (2, operands[1], tmp),\n> +\t\t      VUNSPEC_ARC_SR));\n> +\t  return true;\n> +\t}\n> +      if (MEM_P (operands[1]) && arc_is_aux_reg_p (operands[1]))\n> +\t{\n> +\t  if (arc_get_aux_arg (operands[1], &auxr))\n> +\t    {\n> +\t      tmp = gen_reg_rtx (SImode);\n> +\t      emit_move_insn (tmp, GEN_INT (auxr));\n> +\t    }\n> +\t  else\n> +\t    {\n> +\t      tmp = XEXP (operands[1], 0);\n> +\t      gcc_assert (GET_CODE (tmp) == SYMBOL_REF);\n> +\t    }\n> +\t  /* Load operation.  */\n> +\t  gcc_assert (REG_P (operands[0]));\n> +\t  emit_insn (gen_rtx_SET (operands[0],\n> +\t\t\t\t  gen_rtx_UNSPEC_VOLATILE\n> +\t\t\t\t  (SImode, gen_rtvec (1, tmp),\n> +\t\t\t\t   VUNSPEC_ARC_LR)));\n> +\t  return true;\n> +\t}\n> +    }\n> +\n>    /* We used to do this only for MODE_INT Modes, but addresses to floating\n>       point variables may well be in the small data section.  */\n>    if (!TARGET_NO_SDATA_SET && small_data_pattern (operands[0], Pmode))\n> @@ -11127,6 +11239,52 @@ arc_is_uncached_mem_p (rtx pat)\n>    return false;\n>  }\n>  \n> +/* Handle aux attribute.  The auxiliary registers are addressed using\n> +   special instructions lr and sr.  The attribute 'aux' indicates if a\n> +   variable refers to the aux-regs and what is the register number\n> +   desired.  */\n> +\n> +static tree\n> +arc_handle_aux_attribute (tree *node,\n> +\t\t\t  tree name, tree args, int,\n> +\t\t\t  bool *no_add_attrs)\n> +{\n> +  /* Isn't it better to use address spaces for the aux-regs?  */\n> +  if (DECL_P (*node))\n> +    {\n> +      if (TREE_CODE (*node) != VAR_DECL)\n> +\t{\n> +\t  error (\"%qE attribute only applies to variables\",  name);\n> +\t  *no_add_attrs = true;\n> +\t}\n> +      else if (args)\n> +\t{\n> +\t  if (TREE_CODE (TREE_VALUE (args)) == NON_LVALUE_EXPR)\n> +\t    TREE_VALUE (args) = TREE_OPERAND (TREE_VALUE (args), 0);\n> +\t  tree arg = TREE_VALUE (args);\n> +\t  if (TREE_CODE (arg) != INTEGER_CST)\n> +\t    {\n> +\t      warning (0, \"%qE attribute allows only an integer \"\n> +\t\t       \"constant argument\", name);\n> +\t      *no_add_attrs = true;\n> +\t    }\n> +\t  /* FIXME! add range check.  TREE_INT_CST_LOW (arg) */\n> +\t}\n> +\n> +      if (TREE_CODE (*node) == VAR_DECL)\n> +\t{\n> +\t  tree fntype = TREE_TYPE (*node);\n> +\t  if (fntype && TREE_CODE (fntype) == POINTER_TYPE)\n> +\t    {\n> +\t      tree attrs = tree_cons (get_identifier (\"aux\"), NULL_TREE,\n> +\t\t\t\t      TYPE_ATTRIBUTES (fntype));\n> +\t      TYPE_ATTRIBUTES (fntype) = attrs;\n> +\t    }\n> +\t}\n> +    }\n> +  return NULL_TREE;\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,\n> diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi\n> index 0f8ba05..1f6ef4e 100644\n> --- a/gcc/doc/extend.texi\n> +++ b/gcc/doc/extend.texi\n> @@ -5803,6 +5803,7 @@ attributes.\n>  \n>  @menu\n>  * Common Variable Attributes::\n> +* ARC Variable Attributes::\n>  * AVR Variable Attributes::\n>  * Blackfin Variable Attributes::\n>  * H8/300 Variable Attributes::\n> @@ -6165,6 +6166,18 @@ The @code{weak} attribute is described in\n>  \n>  @end table\n>  \n> +@node ARC Variable Attributes\n> +@subsection ARC Variable Attributes\n> +\n> +@table @code\n> +@item aux\n> +@cindex @code{aux} variable attribute, ARC\n> +The @code{aux} attribute is used to directly access the ARC's\n> +auxiliary register space from C.  The auxilirary register number is\n> +given via attribute argument.\n> +\n> +@end table\n> +\n>  @node AVR Variable Attributes\n>  @subsection AVR Variable Attributes\n>  \n> diff --git a/gcc/testsuite/gcc.target/arc/taux-1.c b/gcc/testsuite/gcc.target/arc/taux-1.c\n> new file mode 100644\n> index 0000000..a2b7778\n> --- /dev/null\n> +++ b/gcc/testsuite/gcc.target/arc/taux-1.c\n> @@ -0,0 +1,38 @@\n> +/* { dg-do compile } */\n> +/* { dg-options \"-O1 */\n> +\n> +\n> +#define __aux() __attribute__((aux))\n> +\n> +__aux() int *a_ptr;\n> +extern __aux() int a_var;\n> +\n> +/* Generates:\n> +   mov r0, @a_var\n> +   sr  10,[r0]\n> +*/\n> +void foo (void)\n> +{\n> +  a_var = 10;\n> +}\n> +\n> +/* Generates:\n> +   mov r0, @a_ptr\n> +   sr  a_var,[r0]\n> +*/\n> +void foo1 (void)\n> +{\n> +  a_ptr = &a_var;\n> +}\n> +\n> +/* Generates:\n> +   lr  %r1,[a_ptr]\n> +   sr  10,[%r1]\n> +*/\n> +void foo2 (void)\n> +{\n> +  *a_ptr = 10;\n> +}\n> +\n> +/* { dg-final { scan-assembler-times \"sr\" 3 } } */\n> +/* { dg-final { scan-assembler-times \"lr\" 1 } } */\n> diff --git a/gcc/testsuite/gcc.target/arc/taux-2.c b/gcc/testsuite/gcc.target/arc/taux-2.c\n> new file mode 100644\n> index 0000000..5644bcd\n> --- /dev/null\n> +++ b/gcc/testsuite/gcc.target/arc/taux-2.c\n> @@ -0,0 +1,15 @@\n> +/* { dg-do compile } */\n> +/* { dg-options \"-O1 */\n> +\n> +#define __aux(r) __attribute__((aux(r)))\n> +static volatile __aux(0x1000) int var;\n> +\n> +int foo (void)\n> +{\n> +  var++;\n> +}\n> +\n> +/* { dg-final { scan-assembler-times \"sr\" 1 } } */\n> +/* { dg-final { scan-assembler-times \"lr\" 1 } } */\n> +/* { dg-final { scan-assembler \"4096\" } } */\n> +/* { dg-final { scan-assembler-not \"\\\\.type\\tvar, @object\" } } */\n> -- \n> 1.9.1\n>","headers":{"Return-Path":"<gcc-patches-return-472200-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-472200-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=\"x2c4YIEB\"; 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 3zVfdN2x1mz9s71\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 30 Jan 2018 06:26:32 +1100 (AEDT)","(qmail 53611 invoked by alias); 29 Jan 2018 19:26:24 -0000","(qmail 53597 invoked by uid 89); 29 Jan 2018 19:26:24 -0000","from mail-wr0-f175.google.com (HELO mail-wr0-f175.google.com)\n\t(209.85.128.175) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tMon, 29 Jan 2018 19:26:21 +0000","by mail-wr0-f175.google.com with SMTP id d9so8510792wre.3 for\n\t<gcc-patches@gcc.gnu.org>; Mon, 29 Jan 2018 11:26:21 -0800 (PST)","from localhost (host86-152-213-123.range86-152.btcentralplus.com.\n\t[86.152.213.123]) by smtp.gmail.com with ESMTPSA id\n\tx65sm9065325wmg.29.2018.01.29.11.26.18 (version=TLS1_2\n\tcipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tMon, 29 Jan 2018 11:26:18 -0800 (PST)"],"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:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=Ga7KZJkNO5nWjjU9U\n\tvk3WZC8glETPRDz9r5S8qYA7zk4Q6WhUmD2gVV54AA0a26HofmwrAakNFPuODUo0\n\t/RtThw5S5zYN0Fm+5aBVj6SJdrHfMWUjsWWBS+RFU3Cuzm89dYgOomgdZ4PB+yEs\n\tYjN5UOaXZFcQCn6VrXGPy2EjW0=","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:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=ih2bQwRYHqbwblPOshFC2Yg\n\tX22k=; b=x2c4YIEBLDotwYxyUxOFJJJstGCAzF/JrB6wxCFsBLmvh9gYcH8Qfgu\n\tl2jiysHPfTArrdX6hgCOydGnmyhlSi5thryEWdJbyD+GLWOf0nI5KITe80IdVOzl\n\tOcb5yyzyh8htbv7lys9RVDkTcxIqzgEvH03w56Wi2+oQyz4eQQbY=","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=-25.6 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tKAM_STOCKGEN, RCVD_IN_DNSWL_NONE,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=2236","X-HELO":"mail-wr0-f175.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net;\n\ts=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:in-reply-to:user-agent;\n\tbh=rKandS1zErhsmXa5hB8BdQ+5pgcZr5ttfUyBJTN7R/M=;\n\tb=rRld1HTc2ZBHIgBUXSHoIzkX8i/ZyaTLAR5plTsECX7vY4h9hcPA+5JctJhcLzbHwA\n\t7Tu/3aDMqaRrhpe5YoM68AqgbQJ/RjEbndcmaD7gnL4M5FghHzu6Qeyj55hkZQd4f9gL\n\tdMWdS00IwwRx1nQczFEjwFWfr4etIh1FwyefU6nPWdhjXPpELB/qcQqieqvGDXF0pYwH\n\teEHKYKWbgPiFJcKFo3UMv4Pu/Syls3Rz0hroJObczzCddJ5UaJNeTIk8Rys9H3SNPiYp\n\tB/DDbzU6hpA1010fmtXKARlOzOfJoUrykiXo213A547akrIBKqOj6LGCKhq32wGkBJyG\n\t8n/w==","X-Gm-Message-State":"AKwxytfx2dXof0mu3fYyAKX6dT0IsJsPgbmmiE1h81JILA7s7Tx9egSE\tY/u2OTr7moDXdia1bKgZmlt3Zw==","X-Google-Smtp-Source":"AH8x225ZdELu4vIh0UiUMgalcn553EfuGRoCfTDsOc4XnECePSqH/NudHuPAIY7K3Sz8n5Z4SIWK0A==","X-Received":"by 10.223.171.24 with SMTP id q24mr5915105wrc.206.1517253979527;\n\tMon, 29 Jan 2018 11:26:19 -0800 (PST)","Date":"Mon, 29 Jan 2018 19:26:18 +0000","From":"Andrew Burgess <andrew.burgess@embecosm.com>","To":"Claudiu Zissulescu <Claudiu.Zissulescu@synopsys.com>","Cc":"gcc-patches@gcc.gnu.org, Francois.Bedard@synopsys.com","Subject":"Re: [PATCH 6/6] [ARC] Add 'aux' variable attribute.","Message-ID":"<20180129192618.GB3162@embecosm.com>","References":"<1509625835-22344-1-git-send-email-claziss@synopsys.com>\n\t<1509625835-22344-7-git-send-email-claziss@synopsys.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<1509625835-22344-7-git-send-email-claziss@synopsys.com>","X-Editor":"GNU Emacs [ http://www.gnu.org/software/emacs ]","User-Agent":"Mutt/1.9.1 (2017-09-22)","X-IsSubscribed":"yes"}}]