Fixed some bugs.
[llvm/zpu.git] / lib / Target / Alpha / AlphaBranchSelector.cpp
blob37681170953698354b43a5cbdf09ef96ccc2879a
1 //===-- AlphaBranchSelector.cpp - Convert Pseudo branchs ----------*- 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 // Replace Pseudo COND_BRANCH_* with their appropriate real branch
11 // Simplified version of the PPC Branch Selector
13 //===----------------------------------------------------------------------===//
15 #include "Alpha.h"
16 #include "AlphaInstrInfo.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/Target/TargetMachine.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 using namespace llvm;
22 namespace {
23 struct AlphaBSel : public MachineFunctionPass {
24 static char ID;
25 AlphaBSel() : MachineFunctionPass(ID) {}
27 virtual bool runOnMachineFunction(MachineFunction &Fn);
29 virtual const char *getPassName() const {
30 return "Alpha Branch Selection";
33 char AlphaBSel::ID = 0;
36 /// createAlphaBranchSelectionPass - returns an instance of the Branch Selection
37 /// Pass
38 ///
39 FunctionPass *llvm::createAlphaBranchSelectionPass() {
40 return new AlphaBSel();
43 bool AlphaBSel::runOnMachineFunction(MachineFunction &Fn) {
45 for (MachineFunction::iterator MFI = Fn.begin(), E = Fn.end(); MFI != E;
46 ++MFI) {
47 MachineBasicBlock *MBB = MFI;
49 for (MachineBasicBlock::iterator MBBI = MBB->begin(), EE = MBB->end();
50 MBBI != EE; ++MBBI) {
51 if (MBBI->getOpcode() == Alpha::COND_BRANCH_I ||
52 MBBI->getOpcode() == Alpha::COND_BRANCH_F) {
54 // condbranch operands:
55 // 0. bc opcode
56 // 1. reg
57 // 2. target MBB
58 const TargetInstrInfo *TII = Fn.getTarget().getInstrInfo();
59 MBBI->setDesc(TII->get(MBBI->getOperand(0).getImm()));
64 return true;