Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:23

0001 //== ----- llvm/CodeGen/GlobalISel/Combiner.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 /// \file
0009 /// This contains the base class for all Combiners generated by TableGen.
0010 /// Backends need to create class that inherits from "Combiner" and put all of
0011 /// the TableGen-erated code in there, as it implements the virtual functions.
0012 ///
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_CODEGEN_GLOBALISEL_COMBINER_H
0016 #define LLVM_CODEGEN_GLOBALISEL_COMBINER_H
0017 
0018 #include "llvm/CodeGen/GlobalISel/CombinerInfo.h"
0019 #include "llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h"
0020 #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
0021 #include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
0022 
0023 namespace llvm {
0024 class MachineRegisterInfo;
0025 class GISelCSEInfo;
0026 class TargetPassConfig;
0027 class MachineFunction;
0028 class MachineIRBuilder;
0029 
0030 /// Combiner implementation. This is per-function, so passes need to recreate
0031 /// one of these each time they enter a new function.
0032 ///
0033 /// TODO: Is it worth making this module-wide?
0034 class Combiner : public GIMatchTableExecutor {
0035 private:
0036   using WorkListTy = GISelWorkList<512>;
0037 
0038   class WorkListMaintainer;
0039   template <CombinerInfo::ObserverLevel Lvl> class WorkListMaintainerImpl;
0040 
0041   WorkListTy WorkList;
0042 
0043   // We have a little hack here where keep the owned pointers private, and only
0044   // expose a reference. This has two purposes:
0045   //  - Avoid derived classes messing with those pointers.
0046   //  - Keep the API consistent. CInfo, MF, MRI, etc. are all accessed as
0047   //  references. Accessing Observer/B as pointers unnecessarily leaks
0048   //  implementation details into derived classes.
0049   std::unique_ptr<MachineIRBuilder> Builder;
0050   std::unique_ptr<WorkListMaintainer> WLObserver;
0051   std::unique_ptr<GISelObserverWrapper> ObserverWrapper;
0052 
0053   bool HasSetupMF = false;
0054 
0055   static bool tryDCE(MachineInstr &MI, MachineRegisterInfo &MRI);
0056 
0057 public:
0058   /// If CSEInfo is not null, then the Combiner will use CSEInfo as the observer
0059   /// and also create a CSEMIRBuilder. Pass nullptr if CSE is not needed.
0060   Combiner(MachineFunction &MF, CombinerInfo &CInfo,
0061            const TargetPassConfig *TPC, GISelKnownBits *KB,
0062            GISelCSEInfo *CSEInfo = nullptr);
0063   virtual ~Combiner();
0064 
0065   virtual bool tryCombineAll(MachineInstr &I) const = 0;
0066 
0067   bool combineMachineInstrs();
0068 
0069 protected:
0070   CombinerInfo &CInfo;
0071   GISelChangeObserver &Observer;
0072   MachineIRBuilder &B;
0073   MachineFunction &MF;
0074   MachineRegisterInfo &MRI;
0075   GISelKnownBits *KB;
0076 
0077   const TargetPassConfig *TPC;
0078   GISelCSEInfo *CSEInfo;
0079 };
0080 
0081 } // End namespace llvm.
0082 
0083 #endif // LLVM_CODEGEN_GLOBALISEL_COMBINER_H