1 //== llvm/CodeGen/GlobalISel/Localizer.h - Localizer -------------*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// \file This file describes the interface of the Localizer pass.
11 /// This pass moves/duplicates constant-like instructions close to their uses.
12 /// Its primarily goal is to workaround the deficiencies of the fast register
14 /// With GlobalISel constants are all materialized in the entry block of
15 /// a function. However, the fast allocator cannot rematerialize constants and
16 /// has a lot more live-ranges to deal with and will most likely end up
18 /// By pushing the constants close to their use, we only create small
20 //===----------------------------------------------------------------------===//
22 #ifndef LLVM_CODEGEN_GLOBALISEL_LOCALIZER_H
23 #define LLVM_CODEGEN_GLOBALISEL_LOCALIZER_H
25 #include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
26 #include "llvm/CodeGen/MachineFunctionPass.h"
29 // Forward declarations.
30 class MachineRegisterInfo;
32 /// This pass implements the localization mechanism described at the
33 /// top of this file. One specificity of the implementation is that
34 /// it will materialize one and only one instance of a constant per
35 /// basic block, thus enabling reuse of that constant within that block.
36 /// Moreover, it only materializes constants in blocks where they
37 /// are used. PHI uses are considered happening at the end of the
38 /// related predecessor.
39 class Localizer : public MachineFunctionPass {
44 /// MRI contains all the register class/bank information that this
45 /// pass uses and updates.
46 MachineRegisterInfo *MRI;
48 /// Check whether or not \p MI needs to be moved close to its uses.
49 static bool shouldLocalize(const MachineInstr &MI);
51 /// Check if \p MOUse is used in the same basic block as \p Def.
52 /// If the use is in the same block, we say it is local.
53 /// When the use is not local, \p InsertMBB will contain the basic
54 /// block when to insert \p Def to have a local use.
55 static bool isLocalUse(MachineOperand &MOUse, const MachineInstr &Def,
56 MachineBasicBlock *&InsertMBB);
58 /// Initialize the field members using \p MF.
59 void init(MachineFunction &MF);
64 StringRef getPassName() const override { return "Localizer"; }
66 MachineFunctionProperties getRequiredProperties() const override {
67 return MachineFunctionProperties()
68 .set(MachineFunctionProperties::Property::IsSSA)
69 .set(MachineFunctionProperties::Property::Legalized)
70 .set(MachineFunctionProperties::Property::RegBankSelected);
73 bool runOnMachineFunction(MachineFunction &MF) override;
76 } // End namespace llvm.