| Dan Gohman | c2b7861 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/ExpandISelPseudos.cpp ----------------------*- C++ -*-===// | 
| Dan Gohman | 8b67c72 | 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 | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 10 | // Expand Pseudo-instructions produced by ISel. These are usually to allow | 
| Dan Gohman | 8b67c72 | 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 |  | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/Passes.h" | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFunction.h" | 
|  | 19 | #include "llvm/CodeGen/MachineFunctionPass.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetLowering.h" | 
| Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetSubtargetInfo.h" | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 23 | using namespace llvm; | 
|  | 24 |  | 
| Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 25 | #define DEBUG_TYPE "expand-isel-pseudos" | 
|  | 26 |  | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 27 | namespace { | 
| Dan Gohman | c2b7861 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 28 | class ExpandISelPseudos : public MachineFunctionPass { | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 29 | public: | 
|  | 30 | static char ID; // Pass identification, replacement for typeid | 
| Dan Gohman | c2b7861 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 31 | ExpandISelPseudos() : MachineFunctionPass(ID) {} | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 32 |  | 
|  | 33 | private: | 
| Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 34 | bool runOnMachineFunction(MachineFunction &MF) override; | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 35 |  | 
| Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 36 | void getAnalysisUsage(AnalysisUsage &AU) const override { | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 37 | MachineFunctionPass::getAnalysisUsage(AU); | 
|  | 38 | } | 
|  | 39 | }; | 
|  | 40 | } // end anonymous namespace | 
|  | 41 |  | 
| Dan Gohman | c2b7861 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 42 | char ExpandISelPseudos::ID = 0; | 
| Andrew Trick | 1fa5bcb | 2012-02-08 21:23:13 +0000 | [diff] [blame] | 43 | char &llvm::ExpandISelPseudosID = ExpandISelPseudos::ID; | 
| Dan Gohman | c2b7861 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 44 | INITIALIZE_PASS(ExpandISelPseudos, "expand-isel-pseudos", | 
| Andrew Trick | 1fa5bcb | 2012-02-08 21:23:13 +0000 | [diff] [blame] | 45 | "Expand ISel Pseudo-instructions", false, false) | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 46 |  | 
| Dan Gohman | c2b7861 | 2010-11-18 18:45:06 +0000 | [diff] [blame] | 47 | bool ExpandISelPseudos::runOnMachineFunction(MachineFunction &MF) { | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 48 | bool Changed = false; | 
| Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 49 | const TargetLowering *TLI = MF.getSubtarget().getTargetLowering(); | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 50 |  | 
|  | 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(); | 
|  | 55 | MBBI != MBBE; ) { | 
|  | 56 | MachineInstr *MI = MBBI++; | 
|  | 57 |  | 
|  | 58 | // If MI is a pseudo, expand it. | 
| Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 59 | if (MI->usesCustomInsertionHook()) { | 
| Dan Gohman | 8b67c72 | 2010-11-16 21:02:37 +0000 | [diff] [blame] | 60 | Changed = true; | 
|  | 61 | MachineBasicBlock *NewMBB = | 
|  | 62 | TLI->EmitInstrWithCustomInserter(MI, MBB); | 
|  | 63 | // The expansion may involve new basic blocks. | 
|  | 64 | if (NewMBB != MBB) { | 
|  | 65 | MBB = NewMBB; | 
|  | 66 | I = NewMBB; | 
|  | 67 | MBBI = NewMBB->begin(); | 
|  | 68 | MBBE = NewMBB->end(); | 
|  | 69 | } | 
|  | 70 | } | 
|  | 71 | } | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | return Changed; | 
|  | 75 | } |