the various ConstantExpr::get*Ty methods existed to work with issues around
[llvm/stm8.git] / lib / CodeGen / ExpandISelPseudos.cpp
bloba67140ece4a5259d08afb6b336fc7cd7e098b40b
1 //===-- llvm/CodeGen/ExpandISelPseudos.cpp ----------------------*- C++ -*-===//
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 //
10 // Expand Pseudo-instructions produced by ISel. These are usually to allow
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.
15 //===----------------------------------------------------------------------===//
17 #define DEBUG_TYPE "expand-isel-pseudos"
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;
26 namespace {
27 class ExpandISelPseudos : public MachineFunctionPass {
28 public:
29 static char ID; // Pass identification, replacement for typeid
30 ExpandISelPseudos() : MachineFunctionPass(ID) {}
32 private:
33 virtual bool runOnMachineFunction(MachineFunction &MF);
35 const char *getPassName() const {
36 return "Expand ISel Pseudo-instructions";
39 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
40 MachineFunctionPass::getAnalysisUsage(AU);
43 } // end anonymous namespace
45 char ExpandISelPseudos::ID = 0;
46 INITIALIZE_PASS(ExpandISelPseudos, "expand-isel-pseudos",
47 "Expand CodeGen Pseudo-instructions", false, false)
49 FunctionPass *llvm::createExpandISelPseudosPass() {
50 return new ExpandISelPseudos();
53 bool ExpandISelPseudos::runOnMachineFunction(MachineFunction &MF) {
54 bool Changed = false;
55 const TargetLowering *TLI = MF.getTarget().getTargetLowering();
57 // Iterate through each instruction in the function, looking for pseudos.
58 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
59 MachineBasicBlock *MBB = I;
60 for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
61 MBBI != MBBE; ) {
62 MachineInstr *MI = MBBI++;
64 // If MI is a pseudo, expand it.
65 const MCInstrDesc &MCID = MI->getDesc();
66 if (MCID.usesCustomInsertionHook()) {
67 Changed = true;
68 MachineBasicBlock *NewMBB =
69 TLI->EmitInstrWithCustomInserter(MI, MBB);
70 // The expansion may involve new basic blocks.
71 if (NewMBB != MBB) {
72 MBB = NewMBB;
73 I = NewMBB;
74 MBBI = NewMBB->begin();
75 MBBE = NewMBB->end();
81 return Changed;