1 //===-- llvm/CodeGen/ExpandISelPseudos.cpp ----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Expand Pseudo-instructions produced by ISel. These are usually to allow
11 // the expansion to contain control flow, such as a conditional move
12 // implemented with a conditional branch and a phi, or an atomic operation
13 // implemented with a loop.
15 //===----------------------------------------------------------------------===//
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/CodeGen/TargetLowering.h"
21 #include "llvm/CodeGen/TargetSubtargetInfo.h"
22 #include "llvm/Support/Debug.h"
25 #define DEBUG_TYPE "expand-isel-pseudos"
28 class ExpandISelPseudos
: public MachineFunctionPass
{
30 static char ID
; // Pass identification, replacement for typeid
31 ExpandISelPseudos() : MachineFunctionPass(ID
) {}
34 bool runOnMachineFunction(MachineFunction
&MF
) override
;
36 void getAnalysisUsage(AnalysisUsage
&AU
) const override
{
37 MachineFunctionPass::getAnalysisUsage(AU
);
40 } // end anonymous namespace
42 char ExpandISelPseudos::ID
= 0;
43 char &llvm::ExpandISelPseudosID
= ExpandISelPseudos::ID
;
44 INITIALIZE_PASS(ExpandISelPseudos
, DEBUG_TYPE
,
45 "Expand ISel Pseudo-instructions", false, false)
47 bool ExpandISelPseudos::runOnMachineFunction(MachineFunction
&MF
) {
49 const TargetLowering
*TLI
= MF
.getSubtarget().getTargetLowering();
51 // Iterate through each instruction in the function, looking for pseudos.
52 for (MachineFunction::iterator I
= MF
.begin(), E
= MF
.end(); I
!= E
; ++I
) {
53 MachineBasicBlock
*MBB
= &*I
;
54 for (MachineBasicBlock::iterator MBBI
= MBB
->begin(), MBBE
= MBB
->end();
56 MachineInstr
&MI
= *MBBI
++;
58 // If MI is a pseudo, expand it.
59 if (MI
.usesCustomInsertionHook()) {
61 MachineBasicBlock
*NewMBB
= TLI
->EmitInstrWithCustomInserter(MI
, MBB
);
62 // The expansion may involve new basic blocks.
65 I
= NewMBB
->getIterator();
66 MBBI
= NewMBB
->begin();