LLVM  9.0.0svn
ExpandISelPseudos.cpp
Go to the documentation of this file.
1 //===-- llvm/CodeGen/ExpandISelPseudos.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 // Expand Pseudo-instructions produced by ISel. These are usually to allow
10 // the expansion to contain control flow, such as a conditional move
11 // implemented with a conditional branch and a phi, or an atomic operation
12 // implemented with a loop.
13 //
14 //===----------------------------------------------------------------------===//
15 
18 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/Support/Debug.h"
22 using namespace llvm;
23 
24 #define DEBUG_TYPE "expand-isel-pseudos"
25 
26 namespace {
27  class ExpandISelPseudos : public MachineFunctionPass {
28  public:
29  static char ID; // Pass identification, replacement for typeid
30  ExpandISelPseudos() : 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 ExpandISelPseudos::ID = 0;
43 INITIALIZE_PASS(ExpandISelPseudos, DEBUG_TYPE,
44  "Expand ISel Pseudo-instructions", false, false)
45 
46 bool ExpandISelPseudos::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;
60  MachineBasicBlock *NewMBB = TLI->EmitInstrWithCustomInserter(MI, MBB);
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  return Changed;
73 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
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...
char & ExpandISelPseudosID
ExpandISelPseudos - This pass expands pseudo-instructions.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define DEBUG_TYPE
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:63
#define I(x, y, z)
Definition: MD5.cpp:58
bool usesCustomInsertionHook(QueryType Type=IgnoreBundle) const
Return true if this instruction requires custom insertion support when the DAG scheduler is inserting...
Definition: MachineInstr.h:890
INITIALIZE_PASS(ExpandISelPseudos, DEBUG_TYPE, "Expand ISel Pseudo-instructions", false, false) bool ExpandISelPseudos
IRTranslator LLVM IR MI
This file describes how to lower LLVM code to machine code.