LLVM 20.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 // Iterate through each instruction in the function, looking for pseudos.
51 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
53 for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
54 MBBI != MBBE; ) {
55 MachineInstr &MI = *MBBI++;
56
57 // Set AdjustsStack to true if the instruction selector emits a stack
58 // frame setup instruction or a stack aligning inlineasm.
59 if (TII->isFrameInstr(MI) || MI.isStackAligningInlineAsm())
61
62 // If MI is a pseudo, expand it.
63 if (MI.usesCustomInsertionHook()) {
64 Changed = true;
66 // The expansion may involve new basic blocks.
67 if (NewMBB != MBB) {
68 PreserveCFG = false;
69 MBB = NewMBB;
70 I = NewMBB->getIterator();
71 MBBI = NewMBB->begin();
72 MBBE = NewMBB->end();
73 }
74 }
75 }
76 }
77
78 TLI->finalizeLowering(MF);
79
80 return {Changed, PreserveCFG};
81}
82
83char FinalizeISel::ID = 0;
84char &llvm::FinalizeISelID = FinalizeISel::ID;
86 "Finalize ISel and expand pseudo-instructions", false, false)
87
88bool FinalizeISel::runOnMachineFunction(MachineFunction &MF) {
89 return runImpl(MF).first;
90}
91
94 auto [Changed, PreserveCFG] = runImpl(MF);
95 if (!Changed)
98 if (PreserveCFG)
99 PA.preserveSet<CFGAnalyses>();
100 return PA;
101}
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
static bool runImpl(Function &F, const TargetLowering &TLI)
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:58
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
This file describes how to lower LLVM code to machine code.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
Represent the analysis usage information of a pass.
Represents analyses that only rely on functions' control flow.
Definition: Analysis.h:72
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &)
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
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.
Representation of each machine instruction.
Definition: MachineInstr.h:69
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
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:132
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
char & FinalizeISelID
This pass expands pseudo-instructions, reserves registers and adjusts machine frame information.