LLVM 18.0.0git
Localizer.h
Go to the documentation of this file.
1//== llvm/CodeGen/GlobalISel/Localizer.h - Localizer -------------*- 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/// \file This file describes the interface of the Localizer pass.
10/// This pass moves/duplicates constant-like instructions close to their uses.
11/// Its primarily goal is to workaround the deficiencies of the fast register
12/// allocator.
13/// With GlobalISel constants are all materialized in the entry block of
14/// a function. However, the fast allocator cannot rematerialize constants and
15/// has a lot more live-ranges to deal with and will most likely end up
16/// spilling a lot.
17/// By pushing the constants close to their use, we only create small
18/// live-ranges.
19//===----------------------------------------------------------------------===//
20
21#ifndef LLVM_CODEGEN_GLOBALISEL_LOCALIZER_H
22#define LLVM_CODEGEN_GLOBALISEL_LOCALIZER_H
23
24#include "llvm/ADT/SetVector.h"
26
27namespace llvm {
28// Forward declarations.
29class AnalysisUsage;
30class MachineBasicBlock;
31class MachineInstr;
32class MachineOperand;
33class MachineRegisterInfo;
34class TargetTransformInfo;
35
36/// This pass implements the localization mechanism described at the
37/// top of this file. One specificity of the implementation is that
38/// it will materialize one and only one instance of a constant per
39/// basic block, thus enabling reuse of that constant within that block.
40/// Moreover, it only materializes constants in blocks where they
41/// are used. PHI uses are considered happening at the end of the
42/// related predecessor.
44public:
45 static char ID;
46
47private:
48 /// An input function to decide if the pass should run or not
49 /// on the given MachineFunction.
50 std::function<bool(const MachineFunction &)> DoNotRunPass;
51
52 /// MRI contains all the register class/bank information that this
53 /// pass uses and updates.
54 MachineRegisterInfo *MRI = nullptr;
55 /// TTI used for getting remat costs for instructions.
56 TargetTransformInfo *TTI = nullptr;
57
58 /// Check if \p MOUse is used in the same basic block as \p Def.
59 /// If the use is in the same block, we say it is local.
60 /// When the use is not local, \p InsertMBB will contain the basic
61 /// block when to insert \p Def to have a local use.
62 static bool isLocalUse(MachineOperand &MOUse, const MachineInstr &Def,
63 MachineBasicBlock *&InsertMBB);
64
65 /// Initialize the field members using \p MF.
66 void init(MachineFunction &MF);
67
69
70 /// If \p Op is a phi operand and not unique in that phi, that is,
71 /// there are other operands in the phi with the same register,
72 /// return true.
73 bool isNonUniquePhiValue(MachineOperand &Op) const;
74
75 /// Do inter-block localization from the entry block.
76 bool localizeInterBlock(MachineFunction &MF,
77 LocalizedSetVecT &LocalizedInstrs);
78
79 /// Do intra-block localization of already localized instructions.
80 bool localizeIntraBlock(LocalizedSetVecT &LocalizedInstrs);
81
82public:
83 Localizer();
84 Localizer(std::function<bool(const MachineFunction &)>);
85
86 StringRef getPassName() const override { return "Localizer"; }
87
91 }
92
93 void getAnalysisUsage(AnalysisUsage &AU) const override;
94
95 bool runOnMachineFunction(MachineFunction &MF) override;
96};
97
98} // End namespace llvm.
99
100#endif
This file implements a set that has insertion order iteration characteristics.
Represent the analysis usage information of a pass.
This class represents an Operation in the Expression.
This pass implements the localization mechanism described at the top of this file.
Definition: Localizer.h:43
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Localizer.cpp:46
static char ID
Definition: Localizer.h:45
MachineFunctionProperties getRequiredProperties() const override
Definition: Localizer.h:88
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: Localizer.cpp:199
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: Localizer.h:86
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
Definition: MachineInstr.h:68
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:370
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18