public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: 郑镐东 <zhdburner000@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: add a new instruction to gcc
Date: Wed, 15 Apr 2020 11:17:42 +0800	[thread overview]
Message-ID: <CAAUScSxqdFXYjg0JoOe5YBZ9_k12KZNE20dfaSz13CQUQaz_KQ@mail.gmail.com> (raw)

Greetings.

I tried to add a new assembly instruction to gcc, the new instruction is:
"checki rdi,rs1,rs2".I want gcc to insert my assembly statement before the
array's assignment statement during compilation.

For example:
> int func1()
> {
>    int a[10];
>    int b[10];
>    a[0] = 1;
> }
> int func2()
> {
>    int a[10];
>    int b[10];
>    ...
>    ...
>    a[2] = b[3];
> }

I want gcc to compile the above code to do the following:

> int fun1(){
>    int a[10];
>    int b[10];
>    <----------- checki rdi,rs1,rs2
>    // insert my custom assembly code
>    a[0] = 1;
> }
> int func2()
> {
>    int a[10];
>    int b[10];
>    ...
>    ...
>    <----------- checki rdi,rs1,rs2
>    // insert my custom assembly code
>    a[2] = b[3];
> }

I wrote some code in the gimple layer to identify arrays:

> static bool is_array(tree var){
>    if(TREE_CODE(var) == VAR_DECL && TREE_TYPE(var) == ARRAY_TYPE)
>    {
>      return true;
>    }
>    return false;
> }
> static bool find_array_assignments(gimple stmt)
> {
>    if(is_gimple_assign(stmt))
>    {
>      tree lhsop = gimple_assign_lhs(stmt);
>      tree rhsop1 = gimple_assign_rhs1(stmt);
>      tree rhsop2 = gimple_assign_rhs2(stmt);
>      if((lhsop && is_array(lhsop)) || (rhsop1 && is_array(rhsop1)) ||
(rhsop2 && is_array(rhsop2)))
>         return true;
>    }
>    return false;
>  }

But I'm not sure in which file to add the code and I'm also not sure in
which files I need to define my assembly statement and insert it when GCC
recognizes the array.I find some gcc info at gcc.gnu.org, but I couldn't
find a specific example I could refer to.

In general, I want to know which file in GCC I should add the code that
identifies the array to for it to take effect, and I also want to know
which files I should use define_insn to declare my assembly statement to
change and what to add?

Thanks in advance,
Best regards,
wizard

                 reply	other threads:[~2020-04-15  3:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAUScSxqdFXYjg0JoOe5YBZ9_k12KZNE20dfaSz13CQUQaz_KQ@mail.gmail.com \
    --to=zhdburner000@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).