LLVM  14.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"
27 
28 namespace llvm {
29 // Forward declarations.
30 class MachineRegisterInfo;
31 class TargetTransformInfo;
32 
33 /// This pass implements the localization mechanism described at the
34 /// top of this file. One specificity of the implementation is that
35 /// it will materialize one and only one instance of a constant per
36 /// basic block, thus enabling reuse of that constant within that block.
37 /// Moreover, it only materializes constants in blocks where they
38 /// are used. PHI uses are considered happening at the end of the
39 /// related predecessor.
41 public:
42  static char ID;
43 
44 private:
45  /// An input function to decide if the pass should run or not
46  /// on the given MachineFunction.
47  std::function<bool(const MachineFunction &)> DoNotRunPass;
48 
49  /// MRI contains all the register class/bank information that this
50  /// pass uses and updates.
52  /// TTI used for getting remat costs for instructions.
54 
55  /// Check if \p MOUse is used in the same basic block as \p Def.
56  /// If the use is in the same block, we say it is local.
57  /// When the use is not local, \p InsertMBB will contain the basic
58  /// block when to insert \p Def to have a local use.
59  static bool isLocalUse(MachineOperand &MOUse, const MachineInstr &Def,
60  MachineBasicBlock *&InsertMBB);
61 
62  /// Initialize the field members using \p MF.
63  void init(MachineFunction &MF);
64 
66 
67  /// If \p Op is a phi operand and not unique in that phi, that is,
68  /// there are other operands in the phi with the same register,
69  /// return true.
70  bool isNonUniquePhiValue(MachineOperand &Op) const;
71 
72  /// Do inter-block localization from the entry block.
73  bool localizeInterBlock(MachineFunction &MF,
74  LocalizedSetVecT &LocalizedInstrs);
75 
76  /// Do intra-block localization of already localized instructions.
77  bool localizeIntraBlock(LocalizedSetVecT &LocalizedInstrs);
78 
79 public:
80  Localizer();
81  Localizer(std::function<bool(const MachineFunction &)>);
82 
83  StringRef getPassName() const override { return "Localizer"; }
84 
88  }
89 
90  void getAnalysisUsage(AnalysisUsage &AU) const override;
91 
92  bool runOnMachineFunction(MachineFunction &MF) override;
93 };
94 
95 } // End namespace llvm.
96 
97 #endif
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::tgtok::Def
@ Def
Definition: TGLexer.h:50
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:168
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::Localizer::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Localizer.cpp:45
llvm::MachineFunctionProperties::Property::IsSSA
@ IsSSA
llvm::MachineFunctionProperties
Properties which a MachineFunction may have at a given point in time.
Definition: MachineFunction.h:111
MachineIRBuilder.h
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::MachineFunctionProperties::set
MachineFunctionProperties & set(Property P)
Definition: MachineFunction.h:173
llvm::Localizer::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: Localizer.cpp:187
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::Localizer::Localizer
Localizer()
Definition: Localizer.cpp:37
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
MachineFunctionPass.h
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:324
llvm::Localizer::ID
static char ID
Definition: Localizer.h:42
llvm::Localizer::getRequiredProperties
MachineFunctionProperties getRequiredProperties() const override
Definition: Localizer.h:85
llvm::SmallSetVector
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:307
llvm::Localizer::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: Localizer.h:83
SetVector.h
llvm::Localizer
This pass implements the localization mechanism described at the top of this file.
Definition: Localizer.h:40