LLVM  8.0.1
Localizer.h
Go to the documentation of this file.
1 //== llvm/CodeGen/GlobalISel/Localizer.h - Localizer -------------*- C++ -*-==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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
13 /// allocator.
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
17 /// spilling a lot.
18 /// By pushing the constants close to their use, we only create small
19 /// live-ranges.
20 //===----------------------------------------------------------------------===//
21 
22 #ifndef LLVM_CODEGEN_GLOBALISEL_LOCALIZER_H
23 #define LLVM_CODEGEN_GLOBALISEL_LOCALIZER_H
24 
27 
28 namespace llvm {
29 // Forward declarations.
30 class MachineRegisterInfo;
31 
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.
40 public:
41  static char ID;
42 
43 private:
44  /// MRI contains all the register class/bank information that this
45  /// pass uses and updates.
47 
48  /// Check whether or not \p MI needs to be moved close to its uses.
49  static bool shouldLocalize(const MachineInstr &MI);
50 
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);
57 
58  /// Initialize the field members using \p MF.
59  void init(MachineFunction &MF);
60 
61 public:
62  Localizer();
63 
64  StringRef getPassName() const override { return "Localizer"; }
65 
71  }
72 
73  void getAnalysisUsage(AnalysisUsage &AU) const override;
74 
75  bool runOnMachineFunction(MachineFunction &MF) override;
76 };
77 
78 } // End namespace llvm.
79 
80 #endif
static char ID
Definition: Localizer.h:41
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This pass implements the localization mechanism described at the top of this file.
Definition: Localizer.h:39
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: Localizer.cpp:61
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: Localizer.h:64
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Localizer.cpp:47
Represent the analysis usage information of a pass.
MachineFunctionProperties getRequiredProperties() const override
Definition: Localizer.h:66
MachineOperand class - Representation of each machine instruction operand.
This file declares the MachineIRBuilder class.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
Definition: MachineInstr.h:64
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Properties which a MachineFunction may have at a given point in time.