Mikhail Glushenkov
2009-Sep-05 20:32 UTC
[LLVMdev] tblgen bug in handling case , switch_on
Hi, On Sat, Sep 5, 2009 at 9:12 PM, Sanjiv Gupta<sanjiv.gupta at microchip.com> wrote:> Is the patch below ok? > > Index: LLVMCConfigurationEmitter.cpp > ==================================================================> --- LLVMCConfigurationEmitter.cpp (revision 80668) > +++ LLVMCConfigurationEmitter.cpp (working copy) > @@ -1141,6 +1141,7 @@ > Callback, EmitElseIf, OptDescs, O); > } > else { > + EmitElseIf = true; > Callback(arg, (std::string(IndentLevel) + Indent1).c_str(), O); > } > O << IndentLevel << "}\n";No, this is not OK - EmitCaseConstructHandler is supposed to be able to generate both 'if (...) ... if (...) ... if (...) ...' and 'if (...) ... else if (...) ... else ...' forms. That's what the EmitElseIf argument controls. BTW, the example in the documentation generates the 'if (...) ... else if (...) ... else ...' form since the 'case' there is assumed to be inside the 'cmd_line' property. Can you provide a small TableGen code example of what you're trying to do which is not working? -- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments
Mikhail Glushenkov wrote:> Hi, > > On Sat, Sep 5, 2009 at 9:12 PM, Sanjiv Gupta<sanjiv.gupta at microchip.com> wrote: > >> Is the patch below ok? >> >> Index: LLVMCConfigurationEmitter.cpp >> ==================================================================>> --- LLVMCConfigurationEmitter.cpp (revision 80668) >> +++ LLVMCConfigurationEmitter.cpp (working copy) >> @@ -1141,6 +1141,7 @@ >> Callback, EmitElseIf, OptDescs, O); >> } >> else { >> + EmitElseIf = true; >> Callback(arg, (std::string(IndentLevel) + Indent1).c_str(), O); >> } >> O << IndentLevel << "}\n"; >> > > No, this is not OK - EmitCaseConstructHandler is supposed to be able > to generate both 'if (...) ... if (...) ... if (...) ...' and 'if > (...) ... else if (...) ... else ...' forms. That's what the > EmitElseIf argument controls. > > BTW, the example in the documentation generates the 'if (...) ... else > if (...) ... else ...' form since the 'case' there is assumed to be > inside the 'cmd_line' property. > > Can you provide a small TableGen code example of what you're trying to > do which is not working? >I wanted to be able to specify -O0, -O1, -O2 on the mcc16 command line. And -O2 should be default(if none of -O0 or -O1 is specified). So I made following changes to PIC16Base.td, but that didn't work. def optimizer : Tool<[ (in_language "llvm-bitcode"), (out_language "llvm-bitcode"), (output_suffix "bc"), (cmd_line "$CALL(GetBinDir)opt $INFILE -o $OUTFILE"), (actions (case (switch_on "O0"), (append_cmd "-disable-opt"), (switch_on "O1"), (append_cmd "-constmerge -globaldce -globalopt -ipsccp -jump-threading -simplifycfg -gvn -scalarrepl"), (switch_on "O2"), (append_cmd "-constmerge -globaldce -globalopt -ipsccp -jump-threading -simplifycfg -gvn -instcombine -scalarrepl"), (default), (append_cmd "-constmerge -globaldce -globalopt -ipsccp -jump-threading -simplifycfg -gvn -instcombine -scalarrepl"))) ]>;
Mikhail Glushenkov
2009-Sep-06 18:13 UTC
[LLVMdev] tblgen bug in handling case , switch_on
Hi Sanjiv, On Sun, Sep 6, 2009 at 8:07 PM, Mikhail Glushenkov<the.dead.shall.rise at gmail.com> wrote:> [...][Sorry, the formatting was a bit off]> The following snippet gives the expected behaviour (not tested, but > you should get the idea):(case (switch_on "O0"), (append_cmd "-disable-opt"), (or (and (switch_on "O1") (not (switch_on "O0"))), (not (switch_on "O0"))), (append_cmd "-constmerge -globaldce -globalopt -ipsccp -jump-threading -simplifycfg -gvn -scalarrepl"), (or (and (switch_on "O2"), (not (switch_on "O0"))), (not (switch_on "O0"))), (append_cmd "-instcombine"))> -O2 is the default, but -O0 overrides both -O2 and -O1; -O2 overrides -O1.-- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments
Mikhail Glushenkov
2009-Sep-06 21:49 UTC
[LLVMdev] tblgen bug in handling case , switch_on
Hi Sanjiv, On Sun, Sep 6, 2009 at 8:13 PM, Mikhail Glushenkov<the.dead.shall.rise at gmail.com> wrote:> Hi Sanjiv, > > On Sun, Sep 6, 2009 at 8:07 PM, Mikhail > Glushenkov<the.dead.shall.rise at gmail.com> wrote: >> [...] > > [Sorry, the formatting was a bit off] > >> The following snippet gives the expected behaviour (not tested, but >> you should get the idea):BTW, your mail has got me thinking about the semantics of 'case', which is currently somewhat ambiguous (since it depends on context). Probably 'case' should be modified to always mean 'if ... else if ... else if ... [...] else ...' and the 'if (...) ... if (...) ... if (...) ... [...]' form should be called something like 'match'. That would be backwards-incompatible, though. What do you think? -- () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments