blob: 2c4a93543cc3dd7acb5e5c3b6bb943f0c1cc6654 [file] [log] [blame]
Dan Gohman8ec9d622010-11-18 18:45:06 +00001//===-- llvm/CodeGen/ExpandISelPseudos.cpp ----------------------*- C++ -*-===//
Dan Gohman668ac2f2010-11-16 21:02:37 +00002//
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 Lattner7a2bdde2011-04-15 05:18:47 +000010// Expand Pseudo-instructions produced by ISel. These are usually to allow
Dan Gohman668ac2f2010-11-16 21:02:37 +000011// 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 Gohman8ec9d622010-11-18 18:45:06 +000017#define DEBUG_TYPE "expand-isel-pseudos"
Dan Gohman668ac2f2010-11-16 21:02:37 +000018#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"
24using namespace llvm;
25
26namespace {
Dan Gohman8ec9d622010-11-18 18:45:06 +000027 class ExpandISelPseudos : public MachineFunctionPass {
Dan Gohman668ac2f2010-11-16 21:02:37 +000028 public:
29 static char ID; // Pass identification, replacement for typeid
Dan Gohman8ec9d622010-11-18 18:45:06 +000030 ExpandISelPseudos() : MachineFunctionPass(ID) {}
Dan Gohman668ac2f2010-11-16 21:02:37 +000031
32 private:
33 virtual bool runOnMachineFunction(MachineFunction &MF);
34
Dan Gohman668ac2f2010-11-16 21:02:37 +000035 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
36 MachineFunctionPass::getAnalysisUsage(AU);
37 }
38 };
39} // end anonymous namespace
40
Dan Gohman8ec9d622010-11-18 18:45:06 +000041char ExpandISelPseudos::ID = 0;
Andrew Trick1dd8c852012-02-08 21:23:13 +000042char &llvm::ExpandISelPseudosID = ExpandISelPseudos::ID;
Dan Gohman8ec9d622010-11-18 18:45:06 +000043INITIALIZE_PASS(ExpandISelPseudos, "expand-isel-pseudos",
Andrew Trick1dd8c852012-02-08 21:23:13 +000044 "Expand ISel Pseudo-instructions", false, false)
Dan Gohman668ac2f2010-11-16 21:02:37 +000045
Dan Gohman8ec9d622010-11-18 18:45:06 +000046bool ExpandISelPseudos::runOnMachineFunction(MachineFunction &MF) {
Dan Gohman668ac2f2010-11-16 21:02:37 +000047 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 Cheng5a96b3d2011-12-07 07:15:52 +000058 if (MI->usesCustomInsertionHook()) {
Dan Gohman668ac2f2010-11-16 21:02:37 +000059 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}