Andrew Lenharth | f81173f | 2006-10-31 16:49:55 +0000 | [diff] [blame] | 1 | //===-- AlphaBranchSelector.cpp - Convert Pseudo branchs ----------*- C++ -*-=// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Andrew Lenharth | f81173f | 2006-10-31 16:49:55 +0000 | [diff] [blame] | 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" |
Andrew Lenharth | f81173f | 2006-10-31 16:49:55 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCAsmInfo.h" |
Andrew Lenharth | f81173f | 2006-10-31 16:49:55 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
| 22 | namespace { |
Nick Lewycky | 6726b6d | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 23 | struct AlphaBSel : public MachineFunctionPass { |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 24 | static char ID; |
Dan Gohman | ae73dc1 | 2008-09-04 17:05:41 +0000 | [diff] [blame] | 25 | AlphaBSel() : MachineFunctionPass(&ID) {} |
Andrew Lenharth | f81173f | 2006-10-31 16:49:55 +0000 | [diff] [blame] | 26 | |
| 27 | virtual bool runOnMachineFunction(MachineFunction &Fn); |
| 28 | |
| 29 | virtual const char *getPassName() const { |
| 30 | return "Alpha Branch Selection"; |
| 31 | } |
| 32 | }; |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 33 | char AlphaBSel::ID = 0; |
Andrew Lenharth | f81173f | 2006-10-31 16:49:55 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /// createAlphaBranchSelectionPass - returns an instance of the Branch Selection |
| 37 | /// Pass |
| 38 | /// |
| 39 | FunctionPass *llvm::createAlphaBranchSelectionPass() { |
| 40 | return new AlphaBSel(); |
| 41 | } |
| 42 | |
| 43 | bool AlphaBSel::runOnMachineFunction(MachineFunction &Fn) { |
| 44 | |
| 45 | for (MachineFunction::iterator MFI = Fn.begin(), E = Fn.end(); MFI != E; |
| 46 | ++MFI) { |
| 47 | MachineBasicBlock *MBB = MFI; |
| 48 | |
| 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) { |
| 53 | |
| 54 | // condbranch operands: |
| 55 | // 0. bc opcode |
| 56 | // 1. reg |
| 57 | // 2. target MBB |
Evan Cheng | 12a4478 | 2006-11-30 07:12:03 +0000 | [diff] [blame] | 58 | const TargetInstrInfo *TII = Fn.getTarget().getInstrInfo(); |
Chris Lattner | 5080f4d | 2008-01-11 18:10:50 +0000 | [diff] [blame] | 59 | MBBI->setDesc(TII->get(MBBI->getOperand(0).getImm())); |
Andrew Lenharth | f81173f | 2006-10-31 16:49:55 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |