LLVM  12.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 
19 #include "llvm/CodeGen/Passes.h"
22 #include "llvm/InitializePasses.h"
23 #include "llvm/Support/Debug.h"
24 using namespace llvm;
25 
26 #define DEBUG_TYPE "finalize-isel"
27 
28 namespace {
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 
43 char FinalizeISel::ID = 0;
46  "Finalize ISel and expand pseudo-instructions", false, false)
47 
48 bool FinalizeISel::runOnMachineFunction(MachineFunction &MF) {
49  bool Changed = false;
50  const TargetLowering *TLI = MF.getSubtarget().getTargetLowering();
51 
52  // Iterate through each instruction in the function, looking for pseudos.
53  for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
54  MachineBasicBlock *MBB = &*I;
55  for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
56  MBBI != MBBE; ) {
57  MachineInstr &MI = *MBBI++;
58 
59  // If MI is a pseudo, expand it.
60  if (MI.usesCustomInsertionHook()) {
61  Changed = true;
62  MachineBasicBlock *NewMBB = TLI->EmitInstrWithCustomInserter(MI, MBB);
63  // The expansion may involve new basic blocks.
64  if (NewMBB != MBB) {
65  MBB = NewMBB;
66  I = NewMBB->getIterator();
67  MBBI = NewMBB->begin();
68  MBBE = NewMBB->end();
69  }
70  }
71  }
72  }
73 
74  TLI->finalizeLowering(MF);
75 
76  return Changed;
77 }
INITIALIZE_PASS(FinalizeISel, DEBUG_TYPE, "Finalize ISel and expand pseudo-instructions", false, false) bool FinalizeISel
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MachineBasicBlock & MBB
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
self_iterator getIterator()
Definition: ilist_node.h:81
virtual MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const
This method should be implemented by targets that mark instructions with the &#39;usesCustomInserter&#39; fla...
Iterator for intrusive lists based on ilist_node.
Representation of each machine instruction.
Definition: MachineInstr.h:62
#define I(x, y, z)
Definition: MD5.cpp:59
char & FinalizeISelID
This pass expands pseudo-instructions, reserves registers and adjusts machine frame information...
bool usesCustomInsertionHook(QueryType Type=IgnoreBundle) const
Return true if this instruction requires custom insertion support when the DAG scheduler is inserting...
virtual void finalizeLowering(MachineFunction &MF) const
Execute target specific actions to finalize target lowering.
IRTranslator LLVM IR MI
#define DEBUG_TYPE
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file describes how to lower LLVM code to machine code.