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" |
| 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 { |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 25 | static char ID; |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 26 | AlphaBSel() : MachineFunctionPass((intptr_t)&ID) {} |
Andrew Lenharth | f81173f | 2006-10-31 16:49:55 +0000 | [diff] [blame] | 27 | |
| 28 | virtual bool runOnMachineFunction(MachineFunction &Fn); |
| 29 | |
| 30 | virtual const char *getPassName() const { |
| 31 | return "Alpha Branch Selection"; |
| 32 | } |
| 33 | }; |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 34 | char AlphaBSel::ID = 0; |
Andrew Lenharth | f81173f | 2006-10-31 16:49:55 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /// createAlphaBranchSelectionPass - returns an instance of the Branch Selection |
| 38 | /// Pass |
| 39 | /// |
| 40 | FunctionPass *llvm::createAlphaBranchSelectionPass() { |
| 41 | return new AlphaBSel(); |
| 42 | } |
| 43 | |
| 44 | bool AlphaBSel::runOnMachineFunction(MachineFunction &Fn) { |
| 45 | |
| 46 | for (MachineFunction::iterator MFI = Fn.begin(), E = Fn.end(); MFI != E; |
| 47 | ++MFI) { |
| 48 | MachineBasicBlock *MBB = MFI; |
| 49 | |
| 50 | for (MachineBasicBlock::iterator MBBI = MBB->begin(), EE = MBB->end(); |
| 51 | MBBI != EE; ++MBBI) { |
| 52 | if (MBBI->getOpcode() == Alpha::COND_BRANCH_I || |
| 53 | MBBI->getOpcode() == Alpha::COND_BRANCH_F) { |
| 54 | |
| 55 | // condbranch operands: |
| 56 | // 0. bc opcode |
| 57 | // 1. reg |
| 58 | // 2. target MBB |
Evan Cheng | 12a4478 | 2006-11-30 07:12:03 +0000 | [diff] [blame] | 59 | const TargetInstrInfo *TII = Fn.getTarget().getInstrInfo(); |
| 60 | MBBI->setInstrDescriptor(TII->get(MBBI->getOperand(0).getImm())); |
Andrew Lenharth | f81173f | 2006-10-31 16:49:55 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return true; |
| 66 | } |
| 67 | |