<div class="__aliyun_email_body_block"><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">H John,</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><br ></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">> <span  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">Probably what we need is a way to override this, which build systems</span><br  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:.0px;text-transform:none;white-space:normal;widows:auto;word-spacing:.0px;"><span  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">> would expect to be properly paired with </span><code  style="caret-color:#000000;color:#000000;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;">-disable-llvm-passes</code><span  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">.</span><br  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:.0px;text-transform:none;white-space:normal;widows:auto;word-spacing:.0px;"><span  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">> So with that option we’d build exactly the same pipeline as we</span><br  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:.0px;text-transform:none;white-space:normal;widows:auto;word-spacing:.0px;"><span  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">> would for a source invocation</span></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><span  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;"><br ></span></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><span  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">I guess turn coro passes by default could one option. What's your opinion?</span></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><span  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;"><br ></span></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><span  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">Thanks,</span></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><span  style="caret-color:#000000;color:#000000;font-family:sans-serif;font-size:14.0px;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">Chuanqi</span></span></div><blockquote  style="margin-right:0;margin-top:0;margin-bottom:0;"><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">------------------------------------------------------------------</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">From:John McCall <rjmccall@apple.com></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">Send Time:2021年7月9日(星期五) 11:15</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">To:Mehdi AMINI <joker.eph@gmail.com></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">Cc:Xun Li <lxfind@gmail.com>; David Blaikie <dblaikie@gmail.com>; Arthur Eubanks <aeubanks@google.com>; chuanqi.xcq <yedeng.yd@linux.alibaba.com>; cfe-dev <cfe-dev@lists.llvm.org></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">Subject:Re: [cfe-dev] Compile .ll file with coroutines intrinsics</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><br ></span></div><div  style="font-family:sans-serif;"><div ><p >On 8 Jul 2021, at 22:01, Mehdi AMINI wrote:</p></div><div ><p >On Thu, Jul 8, 2021 at 6:56 PM John McCall <rjmccall@apple.com> wrote:</p><p >On 8 Jul 2021, at 20:13, Mehdi AMINI wrote:</p><p >On Thu, Jul 8, 2021 at 4:40 PM Xun Li <lxfind@gmail.com> wrote:<br ></p><p >Not sure if I fully understand the question. Do you have a full<br >
example of what you expect but doesn't work?<br >
Are you trying to compile C++ code that uses coroutines, or are you<br >
trying to use opt to compile an .ll file?<br ></p><p >I'm trying to compile IR (.ll or .bc) file: clang support IR as *input*</p><p >as</p><p >well.<br ><br >
So for example with the case you mention:<br ><br >
clang -emit-llvm  -c    -O3  -Xclang -disable-llvm-passes<br >
clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp -std=c++20 -o<br >
coro.bc<br ><br >
This gets me a nice coro.bc file, but I have no way to compile this with<br >
clang right now, it will always crash:<br ><br >
$ clang -c coro.bc<br >
PLEASE submit a bug report to <a  href="https://bugs.llvm.org/" target="_blank">https://bugs.llvm.org/</a> and include the</p><p >crash</p><p >backtrace, preprocessed source, and associated run script.<br >
Stack dump:<br >
0. Program arguments: clang -c coro.bc<br >
1. Code generation<br >
2. Running pass 'Function Pass Manager' on module 'coro.bc'.<br >
3. Running pass 'X86 DAG->DAG Instruction Selection' on function</p><p >'@_Z3foov'</p><p >Segmentation fault</p><p >Coroutines do push the boundaries of LLVM IR in the sense that<br >
(1) there’s a mandatory lowering sequence and (2) because of the<br >
complexity of that lowering, the IR prior to that sequence is<br >
much more of an internal representation than a stable format.<br >
With that said, I don’t know of any inherent reason why running<br >
the coroutine passes multiple times would be a problem.  It’s<br >
probably just some bit of coroutine bookkeeping (the attribute?)<br >
that we fail to remove after lowering.<br ><br >
Also, the exact form of the crash is surprising; I don’t know<br >
why running lowering multiple times would add new things that<br >
ISel wouldn’t recognize.<br ></p><p >Right now this isn't running it multiple times, it is instead never running<br >
it, the backend crashes because ISel does not know about these intrinsics</p></div><div ><p >Ah, I had the opposite problem on my mind, sorry.</p></div><div ><p >(I think we should be friendlier in the failure mode, but that's another<br >
story).</p></div><div ><p >Yes, that’s tricky because, again, LLVM doesn’t like to admit that<br >
mandatory lowering is a thing outside of the codegen prepare passes.<br >
Ideally we’d be able to say that IR in a certain stage never has<br >
certain properties, but we lack the concept of stages.</p></div><div ><p >I use clang to emit IR without running any pass (this is the ` -Xclang<br >
-disable-llvm-passes` part of the invocation).<br ><br >
 Then I'd like to use clang to "resume" compilation of this file, but clang<br >
does not allow me to have an IR input file and run these passes: this is<br >
what I'd like to fix. One option I had in the original email in this thread<br >
was to change clang to honor `-fcoroutines-ts` when the input is an IR file.</p></div><div ><p >Given what I said above about stages, I think clang’s current behavior<br >
of producing fully-lowered IR from <code >-emit-llvm</code> and then expecting<br ><code >.ll</code>/<code >.bc</code> inputs to be fully-lowered IR is the right default.<br >
Probably what we need is a way to override this, which build systems<br >
would expect to be properly paired with <code >-disable-llvm-passes</code>.<br >
So with that option we’d build exactly the same pipeline as we<br >
would for a source invocation.</p><p >Alternatively, we could write something about the expected pipeline<br >
into the IR file.  I don’t know if we build the pipeline before<br >
the initial load of the module.</p><p >John.</p></div></div></blockquote><div ><br ></div></div>