<p style="font-family:Arial;">
        Hi all,
</p>
<p style="font-family:Arial;">
        <br>
</p>
<p style="font-family:Arial;">
        The initial patches for upstraming LoongArch backend to LLVM are under review. Some of them have been approved and we'd like to get more inputs from you if <span style="font-family:Arial;">interested</span>. Comments are very appreciated.
</p>
<p style="font-family:Arial;">
        <br>
</p>
<p style="font-family:Arial;">
        Thanks,
</p>
<p style="font-family:Arial;">
        Weining
</p>
<br>
<blockquote name="replyContent" class="ReferenceQuote" style="font-family:Arial;padding-left:5px;margin-left:5px;border-left:2px solid #B6B6B6;margin-right:0px;">
        -----Original Messages-----<br>
<b>From:</b><span id="rc_from">"Weining Lu" <luweining@loongson.cn></span><br>
<b>Sent Time:</b><span id="rc_senttime">2021-12-17 15:23:33 (Friday)</span><br>
<b>To:</b> "Renato Golin" <rengolin@gmail.com><br>
<b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org>, "余银" <yuyin-hf@loongson.cn>, "翟小娟" <zhaixiaojuan@loongson.cn><br>
<b>Subject:</b> Re: Re: [llvm-dev] [RFC] Add a new backend called LoongArch<br>
<br>
        <p style="font-family:SimSun;">
                <span style="font-family:SimSun;white-space:normal;">Thanks for your comments. Renato</span> 
        </p>
        <p style="font-family:SimSun;">
                <br>
        </p>
        <p style="font-family:SimSun;">
                Per your questions:
        </p>
        <p style="font-family:SimSun;">
                1. <span style="font-family:SimSun;white-space:normal;">Loongson Binary Translation (LBT)  is targeting binary translation from other <span style="font-family:SimSun;white-space:normal;">architectures(like X86, ARM) to LoongArch.</span></span> 
        </p>
        <p style="font-family:SimSun;">
                <span style="font-family:SimSun;white-space:normal;"><span style="font-family:SimSun;white-space:normal;">2. Right, currently <span style="font-family:SimSun;white-space:normal;">the documents for <span style="font-family:SimSun;white-space:normal;">binary translation and vector extension are TBD. But those will be available before we <span style="font-family:SimSun;white-space:normal;">bringing these extensions to LLVM.</span></span></span></span></span> 
        </p>
        <p style="font-family:SimSun;">
                <span style="font-family:SimSun;white-space:normal;"><span style="font-family:SimSun;white-space:normal;"><span style="font-family:SimSun;white-space:normal;"><span style="font-family:SimSun;white-space:normal;">3. H<span style="font-family:SimSun;white-space:normal;">ardware</span> or emulator: AFAIK there are some PC based on 3A5000 can be bought at https://www.jd.com/ (a Chinese online shopping website. I'm not sure if there is an English version ). </span></span></span></span> 
        </p>
        <p style="font-family:SimSun;">
                <span style="font-family:SimSun;white-space:normal;"><span style="font-family:SimSun;white-space:normal;"><span style="font-family:SimSun;white-space:normal;"><span style="font-family:SimSun;white-space:normal;">   Searching "3A5000" will show several products, like https://item.jd.com/100015866577.html and https://item.jd.com/100023656622.html</span></span></span></span> 
        </p>
        <p style="font-family:SimSun;">
                <span style="font-family:SimSun;white-space:normal;"><span style="font-family:SimSun;white-space:normal;"><span style="font-family:SimSun;white-space:normal;"><span style="font-family:SimSun;white-space:normal;">   Beside this, qemu and CLFS are available at https://github.com/loongson/build-tools which are convenient to try on.</span></span></span></span> 
        </p>
        <p style="font-family:SimSun;">
                4. The 5 initial patches are
        </p>
        <p style="font-family:SimSun;">
                <span style="font-family:SimSun;">https://reviews.llvm.org/D115857</span> 
        </p>
        <p style="font-family:SimSun;">
                https://reviews.llvm.org/D115859
        </p>
        <p style="font-family:SimSun;">
                <span style="font-family:SimSun;white-space:normal;">https://reviews.llvm.org/D115860</span> 
        </p>
        <p style="font-family:SimSun;">
                <span style="font-family:SimSun;white-space:normal;">https://reviews.llvm.org/D115861</span> 
        </p>
        <p style="font-family:SimSun;">
                <span style="font-family:SimSun;white-space:normal;">https://reviews.llvm.org/D115862</span> 
        </p>
        <p style="font-family:SimSun;">
                Please help to reivew them or recommend other reviewers. Any comments are appreciate.
        </p>
        <p style="font-family:SimSun;">
                <br>
        </p>
        <p style="font-family:SimSun;">
                Thanks,
        </p>
        <p style="font-family:SimSun;">
                Weining
        </p>
        <p style="font-family:SimSun;">
                <br>
        </p>
        <blockquote name="replyContent" class="ReferenceQuote" style="font-family:SimSun;padding-left:5px;margin-left:5px;border-left:2px solid #B6B6B6;margin-right:0px;">
                -----原始邮件-----<br>
<b>发件人:</b><span id="rc_from">"Renato Golin" <rengolin@gmail.com></span><br>
<b>发送时间:</b><span id="rc_senttime">2021-12-17 04:06:45 (星期五)</span><br>
<b>收件人:</b> "陆伟宁" <luweining@loongson.cn><br>
<b>抄送:</b> llvm-dev <llvm-dev@lists.llvm.org>, "余银" <yuyin-hf@loongson.cn>, "翟小娟" <zhaixiaojuan@loongson.cn><br>
<b>主题:</b> Re: [llvm-dev] [RFC] Add a new backend called LoongArch<br>
<br>
                <div dir="ltr">
                        Hi  Weining,
                        <div>
                                <br>
                        </div>
                        <div>
                                Welcome to the LLVM community!
                        </div>
                        <div>
                                <br>
                        </div>
                        <div>
                                I had a look at the documentation and your fork and the description you gave matches what the community expects of new targets, so thanks for making the effort to know what to do before proposing a new target!
                        </div>
                        <div>
                                <br>
                        </div>
                        <div>
                                Some more comments below...
                        </div>
                        <div>
                                <br>
                                <div class="gmail_quote">
                                        <div dir="ltr" class="gmail_attr">
                                                On Thu, 16 Dec 2021 at 07:55, 陆伟宁 via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
                                        </div>
                                        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid #CCCCCC;padding-left:1ex;">
                                                <span style="font-family:SimSun;">1. LoongArch intro</span><br>
<span style="font-family:SimSun;">LoongArch is a RISC style ISA which is independently designed by Loongson</span><br>
<span style="font-family:SimSun;">Technology in China. It is divided into two versions, the 32-bit version (LA32)</span><br>
<span style="font-family:SimSun;">and the 64-bit version (LA64). LA64 applications have application-level</span><br>
<span style="font-family:SimSun;">backward binary compatibility with LA32 applications. LoongArch is composed of</span><br>
<span style="font-family:SimSun;">a basic part (Loongson Base) and an expanded part. The expansion part includes</span><br>
<span style="font-family:SimSun;">Loongson Binary Translation (LBT), Loongson VirtualiZation (LVZ), Loongson SIMD</span><br>
<span style="font-family:SimSun;">EXtension (LSX) and Loongson Advanced SIMD EXtension(LASX).</span> 
                                        </blockquote>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                That's an interesting target. It seems very sensible on its instruction encoding, data sizes and alignment, etc.
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                I'm just curious about the binary translation unit. Is that to support LA32/LA64 interchangeably (like x86_64 and AArch64 do with their 32-bit counterparts), or is that for some other architecture (like MIPS or Arm)?
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid #CCCCCC;padding-left:1ex;">
                                                <span style="font-family:SimSun;">2. Conform to the policy</span><br>
<span style="font-family:SimSun;">According to <a href="https://llvm.org/docs/DeveloperPolicy.html#adding-a-new-target" target="_blank">https://llvm.org/docs/DeveloperPolicy.html#adding-a-new-target</a></span><br>
<span style="font-family:SimSun;">a) Of couse it will be an experimental target at first.</span><br>
<span style="font-family:SimSun;">b) I'd like to be the code owner of this target.</span><br>
<span style="font-family:SimSun;">c) There is an active community behind the target: <a href="https://github.com/loongson" target="_blank">https://github.com/loongson</a></span><br>
<span style="font-family:SimSun;">   And we will provide builbot support.</span> 
                                        </blockquote>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                Sounds great!
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid #CCCCCC;padding-left:1ex;">
                                                <span style="font-family:SimSun;">d) Documentations:</span><br>
<span style="font-family:SimSun;"> - ISA:</span><br>
<span style="font-family:SimSun;">   <a href="https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html" target="_blank">https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html</a></span><br>
<span style="font-family:SimSun;"> - ABI:</span><br>
<span style="font-family:SimSun;">   <a href="https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html" target="_blank">https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html</a></span><br>
<span style="font-family:SimSun;"> - More docs can be found at:</span><br>
<span style="font-family:SimSun;">   <a href="https://loongson.github.io/LoongArch-Documentation/README-EN.html" target="_blank">https://loongson.github.io/LoongArch-Documentation/README-EN.html</a></span> 
                                        </blockquote>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                Some documents there (binary translation, vector extension) are TBD.
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                Given that the current llvm fork you have is only for basic support, I imagine you'll tackle that after the basic support is merged. Before bringing extensions, we'd need documents for those, too.
                                        </div>
                                        <div>
                                                 <br>
                                        </div>
                                        <div>
                                                The one thing left is to know if there are existing implementations of the hardware (as a product or a dev board) and/or if there are emulators freely available.
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                This is important for people that want to test the back-end on your hardware (for example, while debugging unrelated changes that break on your target).
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid #CCCCCC;padding-left:1ex;">
                                                <span style="font-family:SimSun;">3. Status</span><br>
<span style="font-family:SimSun;">We started to implement an out-of-tree LoongArch LLVM port since last year</span><br>
<span style="font-family:SimSun;">based on llvm-8/11 and posted it to <a href="https://github.com/loongson/llvm-project" target="_blank">https://github.com/loongson/llvm-project</a></span><br>
<span style="font-family:SimSun;">last month. This port also adds supports to clang front-end and we finally pass</span><br>
<span style="font-family:SimSun;">100% llvm-test-suite in O0/1/2/3 optimization levels.</span> 
                                        </blockquote>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                This is actually really nice!
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid #CCCCCC;padding-left:1ex;">
                                                <span style="font-family:SimSun;"> But in this port there</span><br>
<span style="font-family:SimSun;">are a few issues we must handle to get it upstreamed.</span><br>
<span style="font-family:SimSun;"> - The codebase is too old that means we may use some out-of-date interfaces.</span> 
                                        </blockquote>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                Your fork is based on the tree as of Oct 2020, that's more than a year ago and in LLVM's timeframes, an eternity.
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                That usually means you'll have to re-write a good portion of your existing code, but I'm assuming you already knew that and is happy to proceed.
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid #CCCCCC;padding-left:1ex;">
                                                <span style="font-family:SimSun;"> - The test coverage is not broad enough.</span> 
                                        </blockquote>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                Given that you pass the test-suite, I'm assuming you can generate a good portion of the use cases. 
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                But it is important to also have extensive LIT tests (IR-to-IR, MIR, DAG, SRC-to-IR, etc) to avoid needing to run the test-suite for basic support testing.
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid #CCCCCC;padding-left:1ex;">
                                                <span style="font-family:SimSun;"> - Coding standard is not met.</span> 
                                        </blockquote>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                I'm sure you know this is a deal breaker. But since you're going to have to re-write good part of the code, I'm also assuming you're happy making your new code meet the standards. :)
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid #CCCCCC;padding-left:1ex;">
                                                <span style="font-family:SimSun;">The current status is that we have completed a series of 5 patches adding</span><br>
<span style="font-family:SimSun;">triple, ELF machine, basic interger instructions and registers definition. We</span><br>
<span style="font-family:SimSun;">will submit them for review later. Any comments are welcome and please do let</span><br>
<span style="font-family:SimSun;">me know if you'd like to be added as a reviewer to future patches.</span> 
                                        </blockquote>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                This sounds like a good start. Let's get to lowering and parsing a function with a few arguments, instructions and a return value, and their respective tests.
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                Name those patches [X/N] with X being 1..N and N being the total number of patches in the first series. They need to be reviewed all at the same time and only when all are approved we can merge them all together.
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                This is important to make sure new targets start at the right place. From them on, you won't need to number the patches, and can incrementally develop your target to reach maturity.
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                So, overall, I think this looks promising. Your target seems to meet the criteria we set for new targets, so looking forward to seeing the initial patches!
                                        </div>
                                        <div>
                                                <br>
                                        </div>
                                        <div>
                                                Thanks!
                                        </div>
                                        <div>
                                                Renato
                                        </div>
                                </div>
                        </div>
                </div>
        </blockquote>
<br>
<br>
<i style="font-variant-numeric:normal;font-variant-east-asian:normal;widows:1;font-family:宋体, Tahoma;font-size:14px;line-height:16.8px;"><span style="color:#c0c0c0;"><span style="font-size:10pt;font-family:宋体;">本邮件及其附件含有龙芯中科的商业秘密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部</span><span style="font-size:10pt;font-family:宋体;">分地泄露、复制或散发)本邮件及其附件中的信息。如果您错收本邮件,请您立即电话或邮件通知发件人并删除本邮件。</span><span lang="EN-US" style="font-size:10pt;font-family:Arial, sans-serif;"> <br>
This email and its attachments contain confidential information from Loongson Technology , which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this email in error, please notify the sender by phone or email immediately and delete it. </span></span></i> 
</blockquote><br><br><i style="font-variant-numeric: normal; font-variant-east-asian: normal; widows: 1; font-family: 宋体, Tahoma; font-size: 14px; line-height: 16.8px;"><font color="#c0c0c0"><span style="font-size: 10pt; font-family: 宋体;">本邮件及其附件含有龙芯中科的商业秘密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部</span><span style="font-size: 10pt; font-family: 宋体;">分地泄露、复制或散发)本邮件及其附件中的信息。如果您错收本邮件,请您立即电话或邮件通知发件人并删除本邮件。</span><span lang="EN-US" style="font-size: 10pt; font-family: Arial, sans-serif;"> <br>This email and its attachments contain confidential information from Loongson Technology , which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this email in error, please notify the sender by phone or email immediately and delete it. </span></font></i>