<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 10/10/13 11:41 AM, Hongxu Chen
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAJPBKOHavbPENu3b-8RYTh1icm8zRbEXBfpsjUpS12YCx55-GQ@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <div dir="ltr"><br>
        <div class="gmail_extra"><br>
          <br>
          <div class="gmail_quote">On Fri, Oct 11, 2013 at 12:06 AM,
            John Criswell <span dir="ltr"><<a moz-do-not-send="true"
                href="mailto:criswell@illinois.edu" target="_blank">criswell@illinois.edu</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
              <div class="im">On 10/10/13 10:43 AM, Hongxu Chen wrote:<br>
              </div>
              <blockquote class="gmail_quote" style="margin:0px 0px 0px
                0.8ex;border-left:1px solid
                rgb(204,204,204);padding-left:1ex">
                <div class="im">
                  Hi, this question might be a bit silly: apart from the
                  language<br>
                  reference(<a moz-do-not-send="true"
                    href="http://llvm.org/docs/LangRef.html#switch-instruction"
                    target="_blank">http://llvm.org/docs/LangRef.html#switch-instruction</a>)
                  page, are<br>
                  there additional rules for a regular llvm frontend to
                  generate llvm IRs?<br>
                  <br>
                  There are a few cases that I got from
                  clang/llvm-gcc/dragonegg when<br>
                </div>
                compiling *C* source code into llvm IR:
                <div class="im"><br>
                  <br>
                  1. It seems that there is ONLY ONE ReturnInst(and NO
                  InvokeInst) for such<br>
                </div>
                llvm IR; is it legal to add other *ReturnInst*s when
                transforming?<br>
              </blockquote>
              <br>
              An LLVM function can have multiple ReturnInsts as long as
              each one terminates a basic block.  There is a transform
              (UnifyExitNodes, IIRC) that will take a function with
              multiple ReturnInsts and create one with a single
              ReturnInst.  Having a single ReturnInst (exit node)
              simplifies other analyses.
              <div class="im">
                <br>
              </div>
            </blockquote>
            <div>Thanks so much, John; especially for pointing out
              'UnifyExitNodes' pass! <br>
            </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
              <div class="im">
                <br>
                <blockquote class="gmail_quote" style="margin:0px 0px
                  0px 0.8ex;border-left:1px solid
                  rgb(204,204,204);padding-left:1ex">
                  <br>
                  2. Is it possible for a frontend to generate a
                  function whose CFG is<br>
                  something like:<br>
                  <br>
                               bb0<br>
                          /           \<br>
                        bb1          bb2<br>
                      /      \       /      \<br>
                  bb3         bb4        bb5<br>
                      \           |          /<br>
                        \         |        /<br>
                          \       |      /<br>
                                 bb6<br>
                  <br>
                  (In this case, if I understand correctly, bb4 is
                  control dependent on both<br>
                  bb1 and bb2.)<br>
                  I think it at least possible in theory, and there is a
                  simple case:<br>
                </blockquote>
                <br>
              </div>
              Yes, that looks fine to me.  One of the LLVM passes might
              optimize that CFG or put it into some canonical form, but
              that CFG looks fine to me.<br>
              <br>
              -- John T.<br>
            </blockquote>
            <div><br>
            </div>
            <div>Got it!<br>
              <br>
            </div>
            <div>And can I say : as long as it is not explicitly in llvm
              language reference, there are generally no restrictions
              for frontends/transformations to generate IR(of course,
              they pass the verifier)?<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    <br>
    As far as I know, all such restrictions are (or should be)
    documented in the LLVM Language Reference Manual.<br>
    <br>
    That said, you should not generate irreducible CFG's (e.g., a CFG
    with a branch into the middle of a loop).  Those don't play well
    with compiler analyses.<br>
    :)<br>
    <br>
    -- John T.<br>
    <br>
  </body>
</html>