<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 18, 2011, at 3:07 PM, Chandler Carruth wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On Tue, Oct 18, 2011 at 2:59 PM, Cameron Zwarich <span dir="ltr"><<a href="mailto:zwarich@apple.com">zwarich@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">
<div class="im">I think this should really live as a CodeGen pass. Is there any good reason to make it an IR pass?</div></blockquote><div><br></div><div>So, as it happens, I was *completely* wrong here. CodeGen correctly preserves the ordering of blocks from IR, *unless* it can do folding, etc.</div></div></blockquote><div><br></div><div>That's right. However, the CFG changes quite a bit during CodeGen.</div><div><br></div><div>Switches can be lowered into branch trees, multiple passes can split critical edges, and then there is taildup and tailmerge.</div><div><br></div><div>An IR code layout algorithm simply doesn't know the final CFG.</div><div><br></div><blockquote type="cite"><div class="gmail_quote"><div>As for why it should be an IR pass, mostly because once the selection dag runs through the code, we can never recover all of the freedom we have at the IR level. To start with, splicing MBBs around requires known about the terminators (which we only some of the time do), and it requires re-writing them a touch to account for the different fall-through pattern. To make matters worse, at this point we don't have the nicely analyzable 'switch' terminator (I think), and so the existing MBB placement code just bails on non-branch-exit blocks.</div></div></blockquote><div><br></div><div>Those are all the wrong reasons for not doing the right thing.</div><div><br></div><div>Some basic blocks are glued together and must be placed next to each other. That situation can be recognized by "MBB->canFallThrough() && TII->AnalyzeBranch(MBB..)".</div><div><br></div><div>Treat glued-together blocks as super-blocks, and everything should be as breezy as IR.</div><div><br></div><div>I realize the MBB interface is not the prettiest. Suggestions for cleaning it up are very welcome.</div><div><br></div><div>/jakob</div><div><br></div></div></body></html>