[LLVMdev] Choosing Alias Analysis

David Greene dag at cray.com
Fri Aug 10 16:15:46 PDT 2007


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;
  }
};



More information about the llvm-dev mailing list