LLVM API Documentation

ExpandISelPseudos.cpp
Go to the documentation of this file.
00001 //===-- llvm/CodeGen/ExpandISelPseudos.cpp ----------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // Expand Pseudo-instructions produced by ISel. These are usually to allow
00011 // the expansion to contain control flow, such as a conditional move
00012 // implemented with a conditional branch and a phi, or an atomic operation
00013 // implemented with a loop.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #define DEBUG_TYPE "expand-isel-pseudos"
00018 #include "llvm/CodeGen/Passes.h"
00019 #include "llvm/CodeGen/MachineFunction.h"
00020 #include "llvm/CodeGen/MachineFunctionPass.h"
00021 #include "llvm/Support/Debug.h"
00022 #include "llvm/Target/TargetLowering.h"
00023 #include "llvm/Target/TargetMachine.h"
00024 using namespace llvm;
00025 
00026 namespace {
00027   class ExpandISelPseudos : public MachineFunctionPass {
00028   public:
00029     static char ID; // Pass identification, replacement for typeid
00030     ExpandISelPseudos() : MachineFunctionPass(ID) {}
00031 
00032   private:
00033     virtual bool runOnMachineFunction(MachineFunction &MF);
00034 
00035     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00036       MachineFunctionPass::getAnalysisUsage(AU);
00037     }
00038   };
00039 } // end anonymous namespace
00040 
00041 char ExpandISelPseudos::ID = 0;
00042 char &llvm::ExpandISelPseudosID = ExpandISelPseudos::ID;
00043 INITIALIZE_PASS(ExpandISelPseudos, "expand-isel-pseudos",
00044                 "Expand ISel Pseudo-instructions", false, false)
00045 
00046 bool ExpandISelPseudos::runOnMachineFunction(MachineFunction &MF) {
00047   bool Changed = false;
00048   const TargetLowering *TLI = MF.getTarget().getTargetLowering();
00049 
00050   // Iterate through each instruction in the function, looking for pseudos.
00051   for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
00052     MachineBasicBlock *MBB = I;
00053     for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
00054          MBBI != MBBE; ) {
00055       MachineInstr *MI = MBBI++;
00056 
00057       // If MI is a pseudo, expand it.
00058       if (MI->usesCustomInsertionHook()) {
00059         Changed = true;
00060         MachineBasicBlock *NewMBB =
00061           TLI->EmitInstrWithCustomInserter(MI, MBB);
00062         // The expansion may involve new basic blocks.
00063         if (NewMBB != MBB) {
00064           MBB = NewMBB;
00065           I = NewMBB;
00066           MBBI = NewMBB->begin();
00067           MBBE = NewMBB->end();
00068         }
00069       }
00070     }
00071   }
00072 
00073   return Changed;
00074 }