LLVM 23.0.0git
Combiner.h
Go to the documentation of this file.
1//== ----- llvm/CodeGen/GlobalISel/Combiner.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/// \file
9/// This contains the base class for all Combiners generated by TableGen.
10/// Backends need to create class that inherits from "Combiner" and put all of
11/// the TableGen-erated code in there, as it implements the virtual functions.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_GLOBALISEL_COMBINER_H
16#define LLVM_CODEGEN_GLOBALISEL_COMBINER_H
17
22
23namespace llvm {
25class GISelCSEInfo;
26class MachineFunction;
28
29/// Combiner implementation. This is per-function, so passes need to recreate
30/// one of these each time they enter a new function.
31///
32/// TODO: Is it worth making this module-wide?
34private:
35 using WorkListTy = GISelWorkList<512>;
36
38 template <CombinerInfo::ObserverLevel Lvl> class WorkListMaintainerImpl;
39
40 WorkListTy WorkList;
41
42 // We have a little hack here where keep the owned pointers private, and only
43 // expose a reference. This has two purposes:
44 // - Avoid derived classes messing with those pointers.
45 // - Keep the API consistent. CInfo, MF, MRI, etc. are all accessed as
46 // references. Accessing Observer/B as pointers unnecessarily leaks
47 // implementation details into derived classes.
48 std::unique_ptr<MachineIRBuilder> Builder;
49 std::unique_ptr<WorkListMaintainer> WLObserver;
50 std::unique_ptr<GISelObserverWrapper> ObserverWrapper;
51
52 bool HasSetupMF = false;
53
54 static bool tryDCE(MachineInstr &MI, MachineRegisterInfo &MRI);
55
56public:
57 /// If CSEInfo is not null, then the Combiner will use CSEInfo as the observer
58 /// and also create a CSEMIRBuilder. Pass nullptr if CSE is not needed.
61 ~Combiner() override;
62
63 virtual bool tryCombineAll(MachineInstr &I) const = 0;
64
66
67protected:
74
76};
77
78} // End namespace llvm.
79
80#endif // LLVM_CODEGEN_GLOBALISEL_COMBINER_H
Option class for Targets to specify which operations are combined how and when.
#define LLVM_ABI
Definition Compiler.h:213
This contains common code to allow clients to notify changes to machine instr.
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
This file declares the MachineIRBuilder class.
This class acts as the glue that joins the CombinerHelper to the overall Combine algorithm.
Definition Combiner.cpp:52
GISelCSEInfo * CSEInfo
Definition Combiner.h:75
bool combineMachineInstrs()
Definition Combiner.cpp:252
MachineRegisterInfo & MRI
Definition Combiner.h:72
Combiner(MachineFunction &MF, const CombinerInfo &CInfo, GISelValueTracking *VT, GISelCSEInfo *CSEInfo=nullptr)
If CSEInfo is not null, then the Combiner will use CSEInfo as the observer and also create a CSEMIRBu...
Definition Combiner.cpp:224
MachineIRBuilder & B
Definition Combiner.h:70
GISelValueTracking * VT
Definition Combiner.h:73
~Combiner() override
MachineFunction & MF
Definition Combiner.h:71
const CombinerInfo & CInfo
Definition Combiner.h:68
GISelChangeObserver & Observer
Definition Combiner.h:69
virtual bool tryCombineAll(MachineInstr &I) const =0
The CSE Analysis object.
Definition CSEInfo.h:72
Abstract class that contains various methods for clients to notify about changes.
Helper class to build MachineInstr.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
This is an optimization pass for GlobalISel generic memory operations.