blob: 001656e0121a783b58ea780dce140f91c25d64b6 [file] [log] [blame]
Andrew Lenharthf81173f2006-10-31 16:49:55 +00001//===-- AlphaBranchSelector.cpp - Convert Pseudo branchs ----------*- C++ -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Andrew Lenharthf81173f2006-10-31 16:49:55 +00007//
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 Lenharthf81173f2006-10-31 16:49:55 +000018#include "llvm/Target/TargetMachine.h"
Chris Lattneraf76e592009-08-22 20:48:53 +000019#include "llvm/MC/MCAsmInfo.h"
Andrew Lenharthf81173f2006-10-31 16:49:55 +000020using namespace llvm;
21
22namespace {
Nick Lewycky6726b6d2009-10-25 06:33:48 +000023 struct AlphaBSel : public MachineFunctionPass {
Devang Patel19974732007-05-03 01:11:54 +000024 static char ID;
Dan Gohmanae73dc12008-09-04 17:05:41 +000025 AlphaBSel() : MachineFunctionPass(&ID) {}
Andrew Lenharthf81173f2006-10-31 16:49:55 +000026
27 virtual bool runOnMachineFunction(MachineFunction &Fn);
28
29 virtual const char *getPassName() const {
30 return "Alpha Branch Selection";
31 }
32 };
Devang Patel19974732007-05-03 01:11:54 +000033 char AlphaBSel::ID = 0;
Andrew Lenharthf81173f2006-10-31 16:49:55 +000034}
35
36/// createAlphaBranchSelectionPass - returns an instance of the Branch Selection
37/// Pass
38///
39FunctionPass *llvm::createAlphaBranchSelectionPass() {
40 return new AlphaBSel();
41}
42
43bool 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 Cheng12a44782006-11-30 07:12:03 +000058 const TargetInstrInfo *TII = Fn.getTarget().getInstrInfo();
Chris Lattner5080f4d2008-01-11 18:10:50 +000059 MBBI->setDesc(TII->get(MBBI->getOperand(0).getImm()));
Andrew Lenharthf81173f2006-10-31 16:49:55 +000060 }
61 }
62 }
63
64 return true;
65}
66