LLVM 20.0.0git
Pass.h
Go to the documentation of this file.
1//===- Pass.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#ifndef LLVM_SANDBOXIR_PASS_H
10#define LLVM_SANDBOXIR_PASS_H
11
14
15namespace llvm {
16
17class AAResults;
18class ScalarEvolution;
19
20namespace sandboxir {
21
22class Function;
23class Region;
24
25class Analyses {
26 AAResults *AA = nullptr;
27 ScalarEvolution *SE = nullptr;
28
29 Analyses() = default;
30
31public:
32 Analyses(AAResults &AA, ScalarEvolution &SE) : AA(&AA), SE(&SE) {}
33
34public:
35 AAResults &getAA() const { return *AA; }
36 ScalarEvolution &getScalarEvolution() const { return *SE; }
37 /// For use by unit tests.
38 static Analyses emptyForTesting() { return Analyses(); }
39};
40
41/// The base class of a Sandbox IR Pass.
42class Pass {
43protected:
44 /// The pass name. This is also used as a command-line flag and should not
45 /// contain whitespaces.
46 const std::string Name;
47
48public:
49 /// \p Name can't contain any spaces or start with '-'.
51 assert(!Name.contains(' ') &&
52 "A pass name should not contain whitespaces!");
53 assert(!Name.starts_with('-') && "A pass name should not start with '-'!");
54 }
55 virtual ~Pass() {}
56 /// \Returns the name of the pass.
57 StringRef getName() const { return Name; }
58#ifndef NDEBUG
60 Pass.print(OS);
61 return OS;
62 }
63 virtual void print(raw_ostream &OS) const { OS << Name; }
64 LLVM_DUMP_METHOD virtual void dump() const;
65#endif
66 /// Similar to print() but adds a newline. Used for testing.
67 virtual void printPipeline(raw_ostream &OS) const { OS << Name << "\n"; }
68};
69
70/// A pass that runs on a sandbox::Function.
71class FunctionPass : public Pass {
72public:
73 /// \p Name can't contain any spaces or start with '-'.
75 /// \Returns true if it modifies \p F.
76 virtual bool runOnFunction(Function &F, const Analyses &A) = 0;
77};
78
79/// A pass that runs on a sandbox::Region.
80class RegionPass : public Pass {
81public:
82 /// \p Name can't contain any spaces or start with '-'.
84 /// \Returns true if it modifies \p R.
85 virtual bool runOnRegion(Region &R, const Analyses &A) = 0;
86};
87
88} // namespace sandboxir
89} // namespace llvm
90
91#endif // LLVM_SANDBOXIR_PASS_H
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:622
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
The main scalar evolution driver.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Analyses(AAResults &AA, ScalarEvolution &SE)
Definition: Pass.h:32
ScalarEvolution & getScalarEvolution() const
Definition: Pass.h:36
AAResults & getAA() const
Definition: Pass.h:35
static Analyses emptyForTesting()
For use by unit tests.
Definition: Pass.h:38
A pass that runs on a sandbox::Function.
Definition: Pass.h:71
FunctionPass(StringRef Name)
Name can't contain any spaces or start with '-'.
Definition: Pass.h:74
virtual bool runOnFunction(Function &F, const Analyses &A)=0
\Returns true if it modifies F.
The base class of a Sandbox IR Pass.
Definition: Pass.h:42
virtual ~Pass()
Definition: Pass.h:55
virtual void printPipeline(raw_ostream &OS) const
Similar to print() but adds a newline. Used for testing.
Definition: Pass.h:67
const std::string Name
The pass name.
Definition: Pass.h:46
friend raw_ostream & operator<<(raw_ostream &OS, const Pass &Pass)
Definition: Pass.h:59
Pass(StringRef Name)
Name can't contain any spaces or start with '-'.
Definition: Pass.h:50
virtual LLVM_DUMP_METHOD void dump() const
virtual void print(raw_ostream &OS) const
Definition: Pass.h:63
StringRef getName() const
\Returns the name of the pass.
Definition: Pass.h:57
A pass that runs on a sandbox::Region.
Definition: Pass.h:80
virtual bool runOnRegion(Region &R, const Analyses &A)=0
\Returns true if it modifies R.
RegionPass(StringRef Name)
Name can't contain any spaces or start with '-'.
Definition: Pass.h:83
The main job of the Region is to point to new instructions generated by vectorization passes.
Definition: Region.h:54
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18