LLVM  15.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 
21 #include "llvm/InitializePasses.h"
22 using namespace llvm;
23 
24 #define DEBUG_TYPE "finalize-isel"
25 
26 namespace {
27  class FinalizeISel : public MachineFunctionPass {
28  public:
29  static char ID; // Pass identification, replacement for typeid
30  FinalizeISel() : MachineFunctionPass(ID) {}
31 
32  private:
33  bool runOnMachineFunction(MachineFunction &MF) override;
34 
35  void getAnalysisUsage(AnalysisUsage &AU) const override {
37  }
38  };
39 } // end anonymous namespace
40 
41 char FinalizeISel::ID = 0;
44  "Finalize ISel and expand pseudo-instructions", false, false)
45 
46 bool FinalizeISel::runOnMachineFunction(MachineFunction &MF) {
47  bool Changed = false;
48  const TargetLowering *TLI = MF.getSubtarget().getTargetLowering();
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) {
52  MachineBasicBlock *MBB = &*I;
53  for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
54  MBBI != MBBE; ) {
55  MachineInstr &MI = *MBBI++;
56 
57  // If MI is a pseudo, expand it.
58  if (MI.usesCustomInsertionHook()) {
59  Changed = true;
61  // The expansion may involve new basic blocks.
62  if (NewMBB != MBB) {
63  MBB = NewMBB;
64  I = NewMBB->getIterator();
65  MBBI = NewMBB->begin();
66  MBBE = NewMBB->end();
67  }
68  }
69  }
70  }
71 
72  TLI->finalizeLowering(MF);
73 
74  return Changed;
75 }
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:104
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::TargetLowering::EmitInstrWithCustomInserter
virtual MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
Definition: SelectionDAGISel.cpp:292
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
DEBUG_TYPE
#define DEBUG_TYPE
Definition: FinalizeISel.cpp:24
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:103
TargetLowering.h
INITIALIZE_PASS
INITIALIZE_PASS(FinalizeISel, DEBUG_TYPE, "Finalize ISel and expand pseudo-instructions", false, false) bool FinalizeISel
Definition: FinalizeISel.cpp:43
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition: TargetLowering.h:3362
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
I
#define I(x, y, z)
Definition: MD5.cpp:58
MachineFunctionPass.h
llvm::FinalizeISelID
char & FinalizeISelID
This pass expands pseudo-instructions, reserves registers and adjusts machine frame information.
Definition: FinalizeISel.cpp:42
llvm::MachineFunction
Definition: MachineFunction.h:241
MBBI
MachineBasicBlock MachineBasicBlock::iterator MBBI
Definition: AArch64SLSHardening.cpp:75
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition: ilist_node.h:82
TargetSubtargetInfo.h
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::ilist_iterator
Iterator for intrusive lists based on ilist_node.
Definition: ilist_iterator.h:57
llvm::MachineBasicBlock::begin
iterator begin()
Definition: MachineBasicBlock.h:277
llvm::TargetLoweringBase::finalizeLowering
virtual void finalizeLowering(MachineFunction &MF) const
Execute target specific actions to finalize target lowering.
Definition: TargetLoweringBase.cpp:2195
MachineFunction.h
llvm::MachineInstrBundleIterator< MachineInstr >
InitializePasses.h
llvm::MachineBasicBlock::end
iterator end()
Definition: MachineBasicBlock.h:279
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37