LLVM 22.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"
34#include <cstring>
35
36namespace llvm {
37
38//===----------------------------------------------------------------------===//
39// PassNameParser class - Make use of the pass registration mechanism to
40// automatically add a command line argument to opt for each pass.
41//
43 public cl::parser<const PassInfo *> {
44public:
46 ~PassNameParser() override;
47
48 void initialize() {
50
51 // Add all of the passes to the map that got initialized before 'this' did.
53 }
54
55 // ignorablePassImpl - Can be overriden in subclasses to refine the list of
56 // which passes we want to include.
57 //
58 virtual bool ignorablePassImpl(const PassInfo *P) const { return false; }
59
60 inline bool ignorablePass(const PassInfo *P) const {
61 // Ignore non-selectable and non-constructible passes! Ignore
62 // non-optimizations.
63 return P->getPassArgument().empty() || P->getNormalCtor() == nullptr ||
65 }
66
67 // Implement the PassRegistrationListener callbacks used to populate our map
68 //
69 void passRegistered(const PassInfo *P) override {
70 if (ignorablePass(P)) return;
71 if (findOption(P->getPassArgument().data()) != getNumOptions()) {
72 errs() << "Two passes with the same argument (-"
73 << P->getPassArgument() << ") attempted to be registered!\n";
74 llvm_unreachable(nullptr);
75 }
76 addLiteralOption(P->getPassArgument().data(), P, P->getPassName().data());
77 }
78 void passEnumerate(const PassInfo *P) override { passRegistered(P); }
79
80 // printOptionInfo - Print out information about this option. Override the
81 // default implementation to sort the table before we print...
82 void printOptionInfo(const cl::Option &O, size_t GlobalWidth) const override {
83 PassNameParser *PNP = const_cast<PassNameParser*>(this);
84 array_pod_sort(PNP->Values.begin(), PNP->Values.end(), ValCompare);
86 }
87
88private:
89 // ValCompare - Provide a sorting comparator for Values elements...
90 static int ValCompare(const PassNameParser::OptionInfo *VT1,
91 const PassNameParser::OptionInfo *VT2) {
92 return VT1->Name.compare(VT2->Name);
93 }
94};
95
96} // End llvm namespace
97
98#endif
#define LLVM_ABI
Definition Compiler.h:213
#define P(N)
This file contains some templates that are useful if you are working with the STL at all.
PassInfo class - An instance of this class exists for every pass known by the system,...
Definition PassInfo.h:30
void printOptionInfo(const cl::Option &O, size_t GlobalWidth) const override
PassNameParser(cl::Option &O)
Definition Pass.cpp:231
void passRegistered(const PassInfo *P) override
Callback functions - These functions are invoked whenever a pass is loaded or removed from the curren...
void passEnumerate(const PassInfo *P) override
passEnumerate - Callback function invoked when someone calls enumeratePasses on this PassRegistration...
~PassNameParser() override
bool ignorablePass(const PassInfo *P) const
virtual bool ignorablePassImpl(const PassInfo *P) const
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
unsigned findOption(StringRef Name)
SmallVector< OptionInfo, 8 > Values
void addLiteralOption(StringRef Name, const DT &V, StringRef HelpStr)
unsigned getNumOptions() const override
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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:1584
LLVM_ABI void enumeratePasses()
enumeratePasses - Iterate over the registered passes, calling the passEnumerate callback on each Pass...
Definition Pass.cpp:227