LLVM  14.0.0git
LegacyPassNameParser.h
Go to the documentation of this file.
1 //===- LegacyPassNameParser.h -----------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the PassNameParser and FilteredPassNameParser<> classes,
10 // which are used to add command line arguments to a utility for all of the
11 // passes that have been registered into the system.
12 //
13 // The PassNameParser class adds ALL passes linked into the system (that are
14 // creatable) as command line arguments to the tool (when instantiated with the
15 // appropriate command line option template). The FilteredPassNameParser<>
16 // template is used for the same purposes as PassNameParser, except that it only
17 // includes passes that have a PassType that are compatible with the filter
18 // (which is the template argument).
19 //
20 // Note that this is part of the legacy pass manager infrastructure and will be
21 // (eventually) going away.
22 //
23 //===----------------------------------------------------------------------===//
24 
25 #ifndef LLVM_IR_LEGACYPASSNAMEPARSER_H
26 #define LLVM_IR_LEGACYPASSNAMEPARSER_H
27 
28 #include "llvm/ADT/STLExtras.h"
29 #include "llvm/Pass.h"
33 #include <cstring>
34 
35 namespace llvm {
36 
37 //===----------------------------------------------------------------------===//
38 // PassNameParser class - Make use of the pass registration mechanism to
39 // automatically add a command line argument to opt for each pass.
40 //
42  public cl::parser<const PassInfo*> {
43 public:
45  ~PassNameParser() override;
46 
47  void initialize() {
49 
50  // Add all of the passes to the map that got initialized before 'this' did.
52  }
53 
54  // ignorablePassImpl - Can be overriden in subclasses to refine the list of
55  // which passes we want to include.
56  //
57  virtual bool ignorablePassImpl(const PassInfo *P) const { return false; }
58 
59  inline bool ignorablePass(const PassInfo *P) const {
60  // Ignore non-selectable and non-constructible passes! Ignore
61  // non-optimizations.
62  return P->getPassArgument().empty() || P->getNormalCtor() == nullptr ||
64  }
65 
66  // Implement the PassRegistrationListener callbacks used to populate our map
67  //
68  void passRegistered(const PassInfo *P) override {
69  if (ignorablePass(P)) return;
70  if (findOption(P->getPassArgument().data()) != getNumOptions()) {
71  errs() << "Two passes with the same argument (-"
72  << P->getPassArgument() << ") attempted to be registered!\n";
73  llvm_unreachable(nullptr);
74  }
75  addLiteralOption(P->getPassArgument().data(), P, P->getPassName().data());
76  }
77  void passEnumerate(const PassInfo *P) override { passRegistered(P); }
78 
79  // printOptionInfo - Print out information about this option. Override the
80  // default implementation to sort the table before we print...
81  void printOptionInfo(const cl::Option &O, size_t GlobalWidth) const override {
82  PassNameParser *PNP = const_cast<PassNameParser*>(this);
83  array_pod_sort(PNP->Values.begin(), PNP->Values.end(), ValCompare);
85  }
86 
87 private:
88  // ValCompare - Provide a sorting comparator for Values elements...
89  static int ValCompare(const PassNameParser::OptionInfo *VT1,
90  const PassNameParser::OptionInfo *VT2) {
91  return VT1->Name.compare(VT2->Name);
92  }
93 };
94 
95 } // End llvm namespace
96 
97 #endif
llvm::array_pod_sort
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
Definition: STLExtras.h:1450
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::PassNameParser::initialize
void initialize()
Definition: LegacyPassNameParser.h:47
llvm::cl::parser< const PassInfo * >::getNumOptions
unsigned getNumOptions() const override
Definition: CommandLine.h:826
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
Pass.h
llvm::PassNameParser::passRegistered
void passRegistered(const PassInfo *P) override
Callback functions - These functions are invoked whenever a pass is loaded or removed from the curren...
Definition: LegacyPassNameParser.h:68
ErrorHandling.h
llvm::PassNameParser::ignorablePassImpl
virtual bool ignorablePassImpl(const PassInfo *P) const
Definition: LegacyPassNameParser.h:57
llvm::PassInfo
PassInfo class - An instance of this class exists for every pass known by the system,...
Definition: PassInfo.h:30
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:893
STLExtras.h
llvm::cl::generic_parser_base::initialize
void initialize()
Definition: CommandLine.h:765
llvm::PassNameParser::passEnumerate
void passEnumerate(const PassInfo *P) override
passEnumerate - Callback function invoked when someone calls enumeratePasses on this PassRegistration...
Definition: LegacyPassNameParser.h:77
llvm::cl::generic_parser_base::printOptionInfo
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
Definition: CommandLine.cpp:1984
CommandLine.h
llvm::cl::generic_parser_base::findOption
unsigned findOption(StringRef Name)
Definition: CommandLine.cpp:1937
llvm::PassRegistrationListener::enumeratePasses
void enumeratePasses()
enumeratePasses - Iterate over the registered passes, calling the passEnumerate callback on each Pass...
Definition: Pass.cpp:210
llvm::PassNameParser::printOptionInfo
void printOptionInfo(const cl::Option &O, size_t GlobalWidth) const override
Definition: LegacyPassNameParser.h:81
llvm::PassNameParser::PassNameParser
PassNameParser(cl::Option &O)
Definition: Pass.cpp:214
llvm::cl::parser
Definition: CommandLine.h:809
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:197
llvm::cl::Option
Definition: CommandLine.h:249
llvm::PassRegistrationListener
PassRegistrationListener class - This class is meant to be derived from by clients that are intereste...
Definition: PassSupport.h:200
llvm::cl::parser< const PassInfo * >::addLiteralOption
void addLiteralOption(StringRef Name, const DT &V, StringRef HelpStr)
addLiteralOption - Add an entry to the mapping table.
Definition: CommandLine.h:857
llvm::PassNameParser
Definition: LegacyPassNameParser.h:41
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
llvm::cl::parser::Values
SmallVector< OptionInfo, 8 > Values
Definition: CommandLine.h:818
llvm::PassNameParser::~PassNameParser
~PassNameParser() override
raw_ostream.h
llvm::PassNameParser::ignorablePass
bool ignorablePass(const PassInfo *P) const
Definition: LegacyPassNameParser.h:59