LLVM 19.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
24using namespace llvm;
25
26#define DEBUG_TYPE "finalize-isel"
27
28namespace {
29 class FinalizeISel : public MachineFunctionPass {
30 public:
31 static char ID; // Pass identification, replacement for typeid
32 FinalizeISel() : MachineFunctionPass(ID) {}
33
34 private:
35 bool runOnMachineFunction(MachineFunction &MF) override;
36
37 void getAnalysisUsage(AnalysisUsage &AU) const override {
39 }
40 };
41} // end anonymous namespace
42
43char FinalizeISel::ID = 0;
44char &llvm::FinalizeISelID = FinalizeISel::ID;
46 "Finalize ISel and expand pseudo-instructions", false, false)
47
48bool FinalizeISel::runOnMachineFunction(MachineFunction &MF) {
49 bool Changed = false;
50 const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
51 const TargetLowering *TLI = MF.getSubtarget().getTargetLowering();
52
53 // Iterate through each instruction in the function, looking for pseudos.
54 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
56 for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
57 MBBI != MBBE; ) {
58 MachineInstr &MI = *MBBI++;
59
60 // Set AdjustsStack to true if the instruction selector emits a stack
61 // frame setup instruction or a stack aligning inlineasm.
62 if (TII->isFrameInstr(MI) || MI.isStackAligningInlineAsm())
63 MF.getFrameInfo().setAdjustsStack(true);
64
65 // If MI is a pseudo, expand it.
66 if (MI.usesCustomInsertionHook()) {
67 Changed = true;
69 // The expansion may involve new basic blocks.
70 if (NewMBB != MBB) {
71 MBB = NewMBB;
72 I = NewMBB->getIterator();
73 MBBI = NewMBB->begin();
74 MBBE = NewMBB->end();
75 }
76 }
77 }
78 }
79
80 TLI->finalizeLowering(MF);
81
82 return Changed;
83}
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
#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.
Represent the analysis usage information of a pass.
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...
Representation of each machine instruction.
Definition: MachineInstr.h:69
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...
self_iterator getIterator()
Definition: ilist_node.h:109
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
char & FinalizeISelID
This pass expands pseudo-instructions, reserves registers and adjusts machine frame information.