blob: b2b68828a2265d5c13bcdd720a2cdf7be1fcbaf0 [file] [log] [blame]
Dan Gohmanc2b78612010-11-18 18:45:06 +00001//===-- llvm/CodeGen/ExpandISelPseudos.cpp ----------------------*- C++ -*-===//
Dan Gohman8b67c722010-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 Lattner0ab5e2c2011-04-15 05:18:47 +000010// Expand Pseudo-instructions produced by ISel. These are usually to allow
Dan Gohman8b67c722010-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 Gohmanc2b78612010-11-18 18:45:06 +000017#define DEBUG_TYPE "expand-isel-pseudos"
Chandler Carruthed0881b2012-12-03 16:50:05 +000018#include "llvm/CodeGen/Passes.h"
Dan Gohman8b67c722010-11-16 21:02:37 +000019#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/MachineFunctionPass.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/Support/Debug.h"
Dan Gohman8b67c722010-11-16 21:02:37 +000022#include "llvm/Target/TargetLowering.h"
23#include "llvm/Target/TargetMachine.h"
Dan Gohman8b67c722010-11-16 21:02:37 +000024using namespace llvm;
25
26namespace {
Dan Gohmanc2b78612010-11-18 18:45:06 +000027 class ExpandISelPseudos : public MachineFunctionPass {
Dan Gohman8b67c722010-11-16 21:02:37 +000028 public:
29 static char ID; // Pass identification, replacement for typeid
Dan Gohmanc2b78612010-11-18 18:45:06 +000030 ExpandISelPseudos() : MachineFunctionPass(ID) {}
Dan Gohman8b67c722010-11-16 21:02:37 +000031
32 private:
33 virtual bool runOnMachineFunction(MachineFunction &MF);
34
Dan Gohman8b67c722010-11-16 21:02:37 +000035 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
36 MachineFunctionPass::getAnalysisUsage(AU);
37 }
38 };
39} // end anonymous namespace
40
Dan Gohmanc2b78612010-11-18 18:45:06 +000041char ExpandISelPseudos::ID = 0;
Andrew Trick1fa5bcb2012-02-08 21:23:13 +000042char &llvm::ExpandISelPseudosID = ExpandISelPseudos::ID;
Dan Gohmanc2b78612010-11-18 18:45:06 +000043INITIALIZE_PASS(ExpandISelPseudos, "expand-isel-pseudos",
Andrew Trick1fa5bcb2012-02-08 21:23:13 +000044 "Expand ISel Pseudo-instructions", false, false)
Dan Gohman8b67c722010-11-16 21:02:37 +000045
Dan Gohmanc2b78612010-11-18 18:45:06 +000046bool ExpandISelPseudos::runOnMachineFunction(MachineFunction &MF) {
Dan Gohman8b67c722010-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 Cheng7f8e5632011-12-07 07:15:52 +000058 if (MI->usesCustomInsertionHook()) {
Dan Gohman8b67c722010-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}