From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 789FC384B400 for ; Wed, 15 Apr 2020 03:17:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 789FC384B400 Received: by mail-ot1-x330.google.com with SMTP id b13so2027929oti.3 for ; Tue, 14 Apr 2020 20:17:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Twyhjq2YFQzk6EIe/f5aZvO+lWkhc6MjIv/y041zB6g=; b=AkKcwTmsEJzwgd3FGoMUsCOKx9D0EIFHmDQQehYLopIYDin0c37aoHP9lqWVLXGXFH SdPmRxG+nnrePmEXEXwQF9o5krzVWtspMrIFZdIrq67nkBT9QVziZGrJNMBM7mT7ffsv RNtUocCl//UQRqFYYnDliNwP1Bbo8mXsZnzduw59XQXZizo62b8/jplec87iYp+nm0N2 hr5c+6IEFvXoNynBju+Bq1INhScB/aNlGtqJVuDghAcVWg7Ee91EUqsZ5A8P5+7N2iZo FEMeVSSbMWX+mCC+jHTgscdumM4hvw01HcKG7A7hb4mFAD6XZMSGpRP1zZLznf/Gn0Gn 2SRA== X-Gm-Message-State: AGi0PubMCnafKO79tsz/ugOxd8SdH7tHQDCt0t4YQdlmU6a1h7c49DTp 7tvl6qtFJwI/tQEkzvgi3C1JcIGQfh7LPVPnM+wgYeAw X-Google-Smtp-Source: APiQypIfRrUJlYofHp82HQX+E9FSuwSXF+IXyGyMMEP9oerUtkKQ2ggxw+4ae0G2vQDFFc2Dckoy8j3MZr5rrY7lJZI= X-Received: by 2002:a9d:748a:: with SMTP id t10mr22411275otk.244.1586920659525; Tue, 14 Apr 2020 20:17:39 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?B?6YOR6ZWQ5Lic?= Date: Wed, 15 Apr 2020 11:17:42 +0800 Message-ID: Subject: add a new instruction to gcc To: gcc-help@gcc.gnu.org X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_2, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Apr 2020 03:17:42 -0000 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