Dan Gohman | 8ec9d62 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/ExpandISelPseudos.cpp ----------------------*- C++ -*-===// |
Dan Gohman | 668ac2f | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 10 | // Expand Pseudo-instructions produced by ISel. These are usually to allow |
Dan Gohman | 668ac2f | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 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. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Dan Gohman | 8ec9d62 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 17 | #define DEBUG_TYPE "expand-isel-pseudos" |
Dan Gohman | 668ac2f | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFunction.h" |
| 19 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 20 | #include "llvm/CodeGen/Passes.h" |
| 21 | #include "llvm/Target/TargetLowering.h" |
| 22 | #include "llvm/Target/TargetMachine.h" |
| 23 | #include "llvm/Support/Debug.h" |
| 24 | using namespace llvm; |
| 25 | |
| 26 | namespace { |
Dan Gohman | 8ec9d62 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 27 | class ExpandISelPseudos : public MachineFunctionPass { |
Dan Gohman | 668ac2f | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 28 | public: |
| 29 | static char ID; // Pass identification, replacement for typeid |
Dan Gohman | 8ec9d62 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 30 | ExpandISelPseudos() : MachineFunctionPass(ID) {} |
Dan Gohman | 668ac2f | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 31 | |
| 32 | private: |
| 33 | virtual bool runOnMachineFunction(MachineFunction &MF); |
| 34 | |
Dan Gohman | 668ac2f | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 35 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 36 | MachineFunctionPass::getAnalysisUsage(AU); |
| 37 | } |
| 38 | }; |
| 39 | } // end anonymous namespace |
| 40 | |
Dan Gohman | 8ec9d62 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 41 | char ExpandISelPseudos::ID = 0; |
Andrew Trick | 1dd8c85 | 2012-02-08 21:23:13 +0000 | [diff] [blame^] | 42 | char &llvm::ExpandISelPseudosID = ExpandISelPseudos::ID; |
Dan Gohman | 8ec9d62 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 43 | INITIALIZE_PASS(ExpandISelPseudos, "expand-isel-pseudos", |
Andrew Trick | 1dd8c85 | 2012-02-08 21:23:13 +0000 | [diff] [blame^] | 44 | "Expand ISel Pseudo-instructions", false, false) |
Dan Gohman | 668ac2f | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 45 | |
Dan Gohman | 8ec9d62 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 46 | bool ExpandISelPseudos::runOnMachineFunction(MachineFunction &MF) { |
Dan Gohman | 668ac2f | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 47 | bool Changed = false; |
| 48 | const TargetLowering *TLI = MF.getTarget().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. |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 58 | if (MI->usesCustomInsertionHook()) { |
Dan Gohman | 668ac2f | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 59 | Changed = true; |
| 60 | MachineBasicBlock *NewMBB = |
| 61 | TLI->EmitInstrWithCustomInserter(MI, MBB); |
| 62 | // The expansion may involve new basic blocks. |
| 63 | if (NewMBB != MBB) { |
| 64 | MBB = NewMBB; |
| 65 | I = NewMBB; |
| 66 | MBBI = NewMBB->begin(); |
| 67 | MBBE = NewMBB->end(); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | return Changed; |
| 74 | } |