|
|
|||
File indexing completed on 2026-05-10 08:44:07
0001 //===- LegacyPassNameParser.h -----------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 // This file contains the PassNameParser and FilteredPassNameParser<> classes, 0010 // which are used to add command line arguments to a utility for all of the 0011 // passes that have been registered into the system. 0012 // 0013 // The PassNameParser class adds ALL passes linked into the system (that are 0014 // creatable) as command line arguments to the tool (when instantiated with the 0015 // appropriate command line option template). The FilteredPassNameParser<> 0016 // template is used for the same purposes as PassNameParser, except that it only 0017 // includes passes that have a PassType that are compatible with the filter 0018 // (which is the template argument). 0019 // 0020 // Note that this is part of the legacy pass manager infrastructure and will be 0021 // (eventually) going away. 0022 // 0023 //===----------------------------------------------------------------------===// 0024 0025 #ifndef LLVM_IR_LEGACYPASSNAMEPARSER_H 0026 #define LLVM_IR_LEGACYPASSNAMEPARSER_H 0027 0028 #include "llvm/ADT/STLExtras.h" 0029 #include "llvm/Pass.h" 0030 #include "llvm/Support/CommandLine.h" 0031 #include "llvm/Support/ErrorHandling.h" 0032 #include "llvm/Support/raw_ostream.h" 0033 #include <cstring> 0034 0035 namespace llvm { 0036 0037 //===----------------------------------------------------------------------===// 0038 // PassNameParser class - Make use of the pass registration mechanism to 0039 // automatically add a command line argument to opt for each pass. 0040 // 0041 class PassNameParser : public PassRegistrationListener, 0042 public cl::parser<const PassInfo*> { 0043 public: 0044 PassNameParser(cl::Option &O); 0045 ~PassNameParser() override; 0046 0047 void initialize() { 0048 cl::parser<const PassInfo*>::initialize(); 0049 0050 // Add all of the passes to the map that got initialized before 'this' did. 0051 enumeratePasses(); 0052 } 0053 0054 // ignorablePassImpl - Can be overriden in subclasses to refine the list of 0055 // which passes we want to include. 0056 // 0057 virtual bool ignorablePassImpl(const PassInfo *P) const { return false; } 0058 0059 inline bool ignorablePass(const PassInfo *P) const { 0060 // Ignore non-selectable and non-constructible passes! Ignore 0061 // non-optimizations. 0062 return P->getPassArgument().empty() || P->getNormalCtor() == nullptr || 0063 ignorablePassImpl(P); 0064 } 0065 0066 // Implement the PassRegistrationListener callbacks used to populate our map 0067 // 0068 void passRegistered(const PassInfo *P) override { 0069 if (ignorablePass(P)) return; 0070 if (findOption(P->getPassArgument().data()) != getNumOptions()) { 0071 errs() << "Two passes with the same argument (-" 0072 << P->getPassArgument() << ") attempted to be registered!\n"; 0073 llvm_unreachable(nullptr); 0074 } 0075 addLiteralOption(P->getPassArgument().data(), P, P->getPassName().data()); 0076 } 0077 void passEnumerate(const PassInfo *P) override { passRegistered(P); } 0078 0079 // printOptionInfo - Print out information about this option. Override the 0080 // default implementation to sort the table before we print... 0081 void printOptionInfo(const cl::Option &O, size_t GlobalWidth) const override { 0082 PassNameParser *PNP = const_cast<PassNameParser*>(this); 0083 array_pod_sort(PNP->Values.begin(), PNP->Values.end(), ValCompare); 0084 cl::parser<const PassInfo*>::printOptionInfo(O, GlobalWidth); 0085 } 0086 0087 private: 0088 // ValCompare - Provide a sorting comparator for Values elements... 0089 static int ValCompare(const PassNameParser::OptionInfo *VT1, 0090 const PassNameParser::OptionInfo *VT2) { 0091 return VT1->Name.compare(VT2->Name); 0092 } 0093 }; 0094 0095 } // End llvm namespace 0096 0097 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|