On Friday 10 August 2007 17:55, David Greene wrote:> On Friday 10 August 2007 15:12, David Greene wrote: > > Perhaps an easier way is to just expose the -simple-register-coalescing > > and -conservative-register-coalescing options to the user, but I don't > > know how to do that on an individual pass bases. opt just jams then all > > in with PassNameParser. PassNameParser.h makes reference to a > > FilteredPassNameParser that sounds closer to what I want but I can't find > > the code for that anywhere. > > I found a fairly elegant way to do this. I implemented what I imagine > FilteredPassNameParser would be. If all goes well I'll post a patch for > discussion.And here it is. It seems to work well. Should I commit it? -Dave //===----------------------------------------------------------------------===// // FilteredPassNameParser class - Make use of the pass registration // mechanism to automatically add a command line argument to opt for // each pass that satisfies a filter criteria. Filter should return // true for passes to be registered as command-line options. // template<typename Filter> class FilteredPassNameParser : public PassNameParser { private: Filter filter; public: bool ignorablePassImpl(const PassInfo *P) const { return !filter(*P); } }; //===----------------------------------------------------------------------===// // PassArgFilter - A filter for use with PassNameFilterParser that only // accepts a Pass whose Arg matches certain strings. // // Use like this: // // extern const char AllowedPassArgs[] = "-anders_aa -dse"; // // static cl::list< // const PassInfo*, // bool, // FilteredPassNameParser<PassArgFilter<AllowedPassArgs> > > // PassList(cl::desc("LLVM optimizations available:")); // // Only the -anders_aa and -dse options will be available to the user. // template<const char *Args> class PassArgFilter { public: bool operator()(const PassInfo &P) const { return std::strstr(Args, P.getPassArgument()) != 0; } };
On Friday 10 August 2007 18:15, David Greene wrote:> template<const char *Args> > class PassArgFilter { > public: > bool operator()(const PassInfo &P) const { > return std::strstr(Args, P.getPassArgument()) != 0; > } > };Ah, Friday. Before you C++ zealots :) point out that Args could contain strings that an unrelated Pass might match (for example, Args="not-so-bad-aa" matched against a pass "bad-aa"), let _this_ C++ zealot point out that the proper way to handle that is through typelists and metaprogramming and that the complexity of that is probably not going into llvm any time soon. :) Have a great weekend all! -Dave
On Aug 10, 2007, at 4:15 PM, David Greene wrote:> On Friday 10 August 2007 17:55, David Greene wrote: >> On Friday 10 August 2007 15:12, David Greene wrote: >>> Perhaps an easier way is to just expose the -simple-register- >>> coalescing >>> and -conservative-register-coalescing options to the user, but I >>> don't >>> know how to do that on an individual pass bases. opt just jams >>> then all >>> in with PassNameParser. PassNameParser.h makes reference to a >>> FilteredPassNameParser that sounds closer to what I want but I >>> can't find >>> the code for that anywhere. >> >> I found a fairly elegant way to do this. I implemented what I >> imagine >> FilteredPassNameParser would be. If all goes well I'll post a >> patch for >> discussion. > > And here it is. It seems to work well. Should I commit it?Is this the complete patch ? As I understand you want to add llvm-gcc command line option, - register-coalescing=<value> where value is either simple or conservative or whatever. In this case you need to get this through llvm-gcc's (i.e. GCC's) command line options processing. So, why not take advantage of GCC's command line processing setup ? See how -Wformat or Wnormalized or other command line option are handled (start from c.opt). Once llvm- gcc has processed your new command line option all you need to do in llvm-backend.cpp is insert opt level option in llvm_initialize_backend (). See how --dsiable-fp-elim is inserted in the pipeline. - Devang
On Monday 13 August 2007 12:19, Devang Patel wrote:> > And here it is. It seems to work well. Should I commit it? > > Is this the complete patch ?Well, it's not a properly formatted patch, or course, but it is all of the code that's needed.> As I understand you want to add llvm-gcc command line option, - > register-coalescing=<value> where value is either simple or > conservative or whatever.No, this isn't for llvm-gcc _per_se_. It's for anyone that wants to register some passes as command line options but not others. It could be used by a wide variety of tools. One of those could be llvm-gcc, but that's for someone else to do.> In this case you need to get this through llvm-gcc's (i.e. GCC's) > command line options processing. So, why not take advantage of GCC's > command line processing setup ?Because this isn't targeted only at gcc. I don't even have a modified llvm-gcc. I'm putting this to use in another tool. -Dave