<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi,</p>
<p>EP_EarlyAsPossible only works with FunctionPasses, yes. If you
look at how it's used in PassManagerBuilder, it is only invoked
from populateFunctionPassManager.</p>
<p>The earliest you can add ModulePasses is with
EP_ModuleOptimizerEarly. However, those passes are not added on
O0. If the OptLevel is 0, you can instead add the passes to
EP_EnabledOnOptLevel0.</p>
<p>This might not be early enough for you, but those are the points
that are available for module passes as far as I know.</p>
<p>Regards,<br>
Bevin<br>
</p>
<br>
<div class="moz-cite-prefix">On 2018-06-12 15:46, Son Tuan VU via
llvm-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CA+UYC4o+ObL9adfkdEbuKwvCkFA2UEiWecnhuOtU6fxWAEk_pQ@mail.gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div dir="ltr">Hello all,
<div><br>
</div>
<div>I've followed the example in <a
href="https://github.com/CompilerTeaching/SimplePass/blob/master/SimplePass.cc"
moz-do-not-send="true">https://github.com/CompilerTeaching/SimplePass/blob/master/SimplePass.cc</a>
in order to create a custom pass.</div>
<div><br>
</div>
<div>The pass needs to be added before any transformation, so I
used EP_EarlyAsPossible extension point to register it.
Furthermore, I need to access to every GlobalVariable in the
IR, so my pass has to be a ModulePass, like this:</div>
<div><br>
</div>
<div> struct MyPass : public ModulePass {</div>
<div> static char ID;<br>
</div>
<div>
<div> MyPass(): ModulePass(ID) {}</div>
</div>
<div> virtual bool runOnModule(Module &M) {...}<br>
</div>
<div> ...</div>
<div> }</div>
<div><br>
</div>
<div>However, every time I try to access to the Module object M
inside runOnModule(), clang just crashes. Even a debug
message like <b>outs() << M.getName() << '\n';</b> would
cause a segfault. So am I doing something wrong, like
EP_EarlyAsPossible is really not to be used with ModulePasses,
or is this rather a bug?</div>
<div><br>
</div>
<div>In case this is not a bug, what would be the best way to
manipulate an IR Module as it is coming right out of the
frontend?</div>
<div><br>
</div>
<div>Thanks for your help,</div>
<div><br>
</div>
<div>
<div>
<div class="gmail_signature">
<div dir="ltr">Son Tuan Vu</div>
</div>
</div>
</div>
</div>
<!--'"--><br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>