LLVM 24.0.0git
FinalizeISel.cpp
Go to the documentation of this file.
1//===-- llvm/CodeGen/FinalizeISel.cpp ---------------------------*- 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/// This pass expands Pseudo-instructions produced by ISel, fixes register
10/// reservations and may do machine frame information adjustments.
11/// The pseudo instructions are used to allow the expansion to contain control
12/// flow, such as a conditional move implemented with a conditional branch and a
13/// phi, or an atomic operation implemented with a loop.
14//
15//===----------------------------------------------------------------------===//
16
25using namespace llvm;
26
27#define DEBUG_TYPE "finalize-isel"
28
29namespace {
30 class FinalizeISel : public MachineFunctionPass {
31 public:
32 static char ID; // Pass identification, replacement for typeid
33 FinalizeISel() : MachineFunctionPass(ID) {}
34
35 private:
36 bool runOnMachineFunction(MachineFunction &MF) override;
37
38 void getAnalysisUsage(AnalysisUsage &AU) const override {
40 }
41 };
42} // end anonymous namespace
43
44static std::pair<bool, bool> runImpl(MachineFunction &MF) {
45 bool Changed = false;
46 bool PreserveCFG = true;
49
50 // GlobalISel finalizes lowering in InstructionSelect.
51 if (!MF.getProperties().hasSelected())
52 TLI->finalizeLowering(MF);
53
54 // Iterate through each instruction in the function, looking for pseudos.
55 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
57 for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
58 MBBI != MBBE; ) {
59 MachineInstr &MI = *MBBI++;
60
61 // Set AdjustsStack to true if the instruction selector emits a stack
62 // frame setup instruction or a stack aligning inlineasm.
63 if (TII->isFrameInstr(MI) || MI.isStackAligningInlineAsm())
65
66 // If MI is a pseudo, expand it.
67 if (MI.usesCustomInsertionHook()) {
68 Changed = true;
70 // The expansion may involve new basic blocks.
71 if (NewMBB != MBB) {
72 PreserveCFG = false;
73 MBB = NewMBB;
74 I = NewMBB->getIterator();
75 MBBI = NewMBB->begin();
76 MBBE = NewMBB->end();
77 }
78 }
79 }
80 }
81 return {Changed, PreserveCFG};
82}
83
84char FinalizeISel::ID = 0;
85char &llvm::FinalizeISelID = FinalizeISel::ID;
87 "Finalize ISel and expand pseudo-instructions", false, false)
88
89bool FinalizeISel::runOnMachineFunction(MachineFunction &MF) {
90 return runImpl(MF).first;
91}
92
95 auto [Changed, PreserveCFG] = runImpl(MF);
96 if (!Changed)
99 if (PreserveCFG)
100 PA.preserveSet<CFGAnalyses>();
101 return PA;
102}
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool runImpl(MachineFunction &MF)
Definition CFIFixup.cpp:304
static std::pair< bool, bool > runImpl(MachineFunction &MF)
#define DEBUG_TYPE
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
This file describes how to lower LLVM code to machine code.
Represent the analysis usage information of a pass.
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &)
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
BasicBlockListType::iterator iterator
const MachineFunctionProperties & getProperties() const
Get the function properties.
Representation of each machine instruction.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
TargetInstrInfo - Interface to description of machine instruction set.
virtual void finalizeLowering(MachineFunction &MF) const
Execute target specific actions to finalize target lowering.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
virtual MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetLowering * getTargetLowering() const
self_iterator getIterator()
Definition ilist_node.h:123
Changed
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI char & FinalizeISelID
This pass expands pseudo-instructions, reserves registers and adjusts machine frame information.