blob: 55140e34e432ba58a41377eea2d8cdf4fa7d7a37 [file] [log] [blame]
Andrew Lenharthf81173f2006-10-31 16:49:55 +00001//===-- 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"
21using namespace llvm;
22
23namespace {
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///
37FunctionPass *llvm::createAlphaBranchSelectionPass() {
38 return new AlphaBSel();
39}
40
41bool 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 MBBI->setOpcode(MBBI->getOperand(0).getImm());
57 }
58 }
59 }
60
61 return true;
62}
63