Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:26

0001 //===- Pass.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 #ifndef LLVM_SANDBOXIR_PASS_H
0010 #define LLVM_SANDBOXIR_PASS_H
0011 
0012 #include "llvm/Support/ErrorHandling.h"
0013 #include "llvm/Support/raw_ostream.h"
0014 
0015 namespace llvm {
0016 
0017 class AAResults;
0018 class ScalarEvolution;
0019 class TargetTransformInfo;
0020 
0021 namespace sandboxir {
0022 
0023 class Function;
0024 class Region;
0025 
0026 class Analyses {
0027   AAResults *AA = nullptr;
0028   ScalarEvolution *SE = nullptr;
0029   TargetTransformInfo *TTI = nullptr;
0030 
0031   Analyses() = default;
0032 
0033 public:
0034   Analyses(AAResults &AA, ScalarEvolution &SE, TargetTransformInfo &TTI)
0035       : AA(&AA), SE(&SE), TTI(&TTI) {}
0036 
0037 public:
0038   AAResults &getAA() const { return *AA; }
0039   ScalarEvolution &getScalarEvolution() const { return *SE; }
0040   TargetTransformInfo &getTTI() const { return *TTI; }
0041   /// For use by unit tests.
0042   static Analyses emptyForTesting() { return Analyses(); }
0043 };
0044 
0045 /// The base class of a Sandbox IR Pass.
0046 class Pass {
0047 protected:
0048   /// The pass name. This is also used as a command-line flag and should not
0049   /// contain whitespaces.
0050   const std::string Name;
0051 
0052 public:
0053   /// \p Name can't contain any spaces or start with '-'.
0054   Pass(StringRef Name) : Name(Name) {
0055     assert(!Name.contains(' ') &&
0056            "A pass name should not contain whitespaces!");
0057     assert(!Name.starts_with('-') && "A pass name should not start with '-'!");
0058   }
0059   virtual ~Pass() {}
0060   /// \Returns the name of the pass.
0061   StringRef getName() const { return Name; }
0062 #ifndef NDEBUG
0063   friend raw_ostream &operator<<(raw_ostream &OS, const Pass &Pass) {
0064     Pass.print(OS);
0065     return OS;
0066   }
0067   virtual void print(raw_ostream &OS) const { OS << Name; }
0068   LLVM_DUMP_METHOD virtual void dump() const;
0069 #endif
0070   /// Similar to print() but adds a newline. Used for testing.
0071   virtual void printPipeline(raw_ostream &OS) const { OS << Name << "\n"; }
0072 };
0073 
0074 /// A pass that runs on a sandbox::Function.
0075 class FunctionPass : public Pass {
0076 public:
0077   /// \p Name can't contain any spaces or start with '-'.
0078   FunctionPass(StringRef Name) : Pass(Name) {}
0079   /// \Returns true if it modifies \p F.
0080   virtual bool runOnFunction(Function &F, const Analyses &A) = 0;
0081 };
0082 
0083 /// A pass that runs on a sandbox::Region.
0084 class RegionPass : public Pass {
0085 public:
0086   /// \p Name can't contain any spaces or start with '-'.
0087   RegionPass(StringRef Name) : Pass(Name) {}
0088   /// \Returns true if it modifies \p R.
0089   virtual bool runOnRegion(Region &R, const Analyses &A) = 0;
0090 };
0091 
0092 } // namespace sandboxir
0093 } // namespace llvm
0094 
0095 #endif // LLVM_SANDBOXIR_PASS_H