LLVM API Documentation
00001 //===-- AlphaBranchSelector.cpp - Convert Pseudo branchs ----------*- C++ -*-=// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Replace Pseudo COND_BRANCH_* with their appropriate real branch 00011 // Simplified version of the PPC Branch Selector 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "Alpha.h" 00016 #include "AlphaInstrInfo.h" 00017 #include "llvm/CodeGen/MachineFunctionPass.h" 00018 #include "llvm/Support/Compiler.h" 00019 #include "llvm/Target/TargetMachine.h" 00020 #include "llvm/Target/TargetAsmInfo.h" 00021 using namespace llvm; 00022 00023 namespace { 00024 struct VISIBILITY_HIDDEN AlphaBSel : public MachineFunctionPass { 00025 static char ID; 00026 AlphaBSel() : MachineFunctionPass(&ID) {} 00027 00028 virtual bool runOnMachineFunction(MachineFunction &Fn); 00029 00030 virtual const char *getPassName() const { 00031 return "Alpha Branch Selection"; 00032 } 00033 }; 00034 char AlphaBSel::ID = 0; 00035 } 00036 00037 /// createAlphaBranchSelectionPass - returns an instance of the Branch Selection 00038 /// Pass 00039 /// 00040 FunctionPass *llvm::createAlphaBranchSelectionPass() { 00041 return new AlphaBSel(); 00042 } 00043 00044 bool AlphaBSel::runOnMachineFunction(MachineFunction &Fn) { 00045 00046 for (MachineFunction::iterator MFI = Fn.begin(), E = Fn.end(); MFI != E; 00047 ++MFI) { 00048 MachineBasicBlock *MBB = MFI; 00049 00050 for (MachineBasicBlock::iterator MBBI = MBB->begin(), EE = MBB->end(); 00051 MBBI != EE; ++MBBI) { 00052 if (MBBI->getOpcode() == Alpha::COND_BRANCH_I || 00053 MBBI->getOpcode() == Alpha::COND_BRANCH_F) { 00054 00055 // condbranch operands: 00056 // 0. bc opcode 00057 // 1. reg 00058 // 2. target MBB 00059 const TargetInstrInfo *TII = Fn.getTarget().getInstrInfo(); 00060 MBBI->setDesc(TII->get(MBBI->getOperand(0).getImm())); 00061 } 00062 } 00063 } 00064 00065 return true; 00066 } 00067