MachineInstr::setOpcode -> MachineInstr::setInstrDescriptor
[oota-llvm.git] / lib / Target / Alpha / AlphaBranchSelector.cpp
1 //===-- AlphaBranchSelector.cpp - Convert Pseudo branchs ----------*- C++ -*-=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Andrew Lenharth and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Replace Pseudo COND_BRANCH_* with their appropriate real branch
11 // Simplified version of the PPC Branch Selector
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "Alpha.h"
16 #include "AlphaInstrInfo.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/Target/TargetAsmInfo.h"
21 using namespace llvm;
22
23 namespace {
24   struct VISIBILITY_HIDDEN AlphaBSel : public MachineFunctionPass {
25
26     virtual bool runOnMachineFunction(MachineFunction &Fn);
27
28     virtual const char *getPassName() const {
29       return "Alpha Branch Selection";
30     }
31   };
32 }
33
34 /// createAlphaBranchSelectionPass - returns an instance of the Branch Selection
35 /// Pass
36 ///
37 FunctionPass *llvm::createAlphaBranchSelectionPass() {
38   return new AlphaBSel();
39 }
40
41 bool AlphaBSel::runOnMachineFunction(MachineFunction &Fn) {
42
43   for (MachineFunction::iterator MFI = Fn.begin(), E = Fn.end(); MFI != E;
44        ++MFI) {
45     MachineBasicBlock *MBB = MFI;
46     
47     for (MachineBasicBlock::iterator MBBI = MBB->begin(), EE = MBB->end();
48          MBBI != EE; ++MBBI) {
49       if (MBBI->getOpcode() == Alpha::COND_BRANCH_I ||
50           MBBI->getOpcode() == Alpha::COND_BRANCH_F) {
51         
52         // condbranch operands:
53         // 0. bc opcode
54         // 1. reg
55         // 2. target MBB
56         const TargetInstrInfo *TII = Fn.getTarget().getInstrInfo();
57         MBBI->setInstrDescriptor(TII->get(MBBI->getOperand(0).getImm()));
58       }
59     }
60   }
61   
62   return true;
63 }
64