LLVM 24.0.0git
Pass.cpp
Go to the documentation of this file.
1//===- Pass.cpp - Passes that operate on Sandbox IR -----------------------===//
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
10#include "llvm/Support/Debug.h"
11
12using namespace llvm::sandboxir;
13
14#ifndef NDEBUG
15void Pass::dump() const {
16 print(dbgs());
17 dbgs() << "\n";
18}
19#endif // NDEBUG
20
21bool AuxPassArg::set(bool NewVal) {
22 Registry->Entries[ArgIdx].Val = NewVal;
23 return NewVal;
24}
25
26bool AuxPassArg::get() const { return Registry->Entries[ArgIdx].Val; }
27
29 return Registry->Entries[ArgIdx].FlagStr;
30}
31
32#ifndef NDEBUG
34 auto &E = Registry->Entries[ArgIdx];
35 OS << E.FlagStr << " : " << E.Val;
36}
37
38void AuxPassArg::dump() const {
39 print(dbgs());
40 dbgs() << "\n";
41}
42#endif
43
44AuxPassArgsRegistry::Entry *AuxPassArgsRegistry::getEntry(StringRef Flag) {
45 for (Entry &E : Entries) {
46 if (E.FlagStr == Flag)
47 return &E;
48 }
49 return nullptr;
50}
53 AuxPassArg NewArg(Entries.size(), this);
54 Entries.emplace_back(Flag, false);
55 return NewArg;
57
60 ArgsStr.split(Parts, ',');
61 for (StringRef Part : Parts) {
62 if (Part.empty())
63 continue;
64 Entry *E = getEntry(Part);
65 if (E == nullptr) {
66 std::string ErrStr;
67 raw_string_ostream ErrSS(ErrStr);
68 ErrSS << "Unsupported argument: '" << Part
69 << "'. List of supported args:\n";
70 for (const auto &[ArgStr, Val] : Entries)
71 ErrSS << " '" << ArgStr << "'\n";
72 reportFatalUsageError(ErrStr.c_str());
73 }
74 *E = {Part, true};
75 }
76}
77
78#ifndef NDEBUG
80 if (Entries.empty()) {
81 OS << "No args created yet!\n";
82 return;
83 }
84 for (const Entry &E : Entries)
85 OS << E.FlagStr << " : " << E.Val << "\n";
87
89 print(dbgs());
90 dbgs() << "\n";
91}
92#endif
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition Pass.cpp:141
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition Registry.h:116
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an std::string.
StringRef getFlagStr() const
Definition Pass.cpp:28
LLVM_DUMP_METHOD void dump() const
Definition Pass.cpp:38
void print(raw_ostream &OS) const
Definition Pass.cpp:33
void print(raw_ostream &OS) const
Definition Pass.cpp:79
AuxPassArg createArg(StringRef Flag)
Builder for argument with Flag.
Definition Pass.cpp:52
void parse(StringRef ArgsStr)
Parse the aux argument string ArgsStr and set the values.
Definition Pass.cpp:58
LLVM_DUMP_METHOD void dump() const
Definition Pass.cpp:88
LLVM_ABI virtual LLVM_DUMP_METHOD void dump() const
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177