add a new instruction to gcc

郑镐东 zhdburner000@gmail.com
Wed Apr 15 03:17:42 GMT 2020


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



More information about the Gcc-help mailing list