Reed Kotler | c1a2caf | 2013-02-27 04:20:14 +0000 | [diff] [blame] | 1 | //===-- MipsConstantIslandPass.cpp - Emit Pc Relative loads----------------===// |
Reed Kotler | d056dc0 | 2013-02-27 03:33:58 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // |
| 11 | // This pass is used to make Pc relative loads of constants. |
| 12 | // For now, only Mips16 will use this. While it has the same name and |
| 13 | // uses many ideas from the LLVM ARM Constant Island Pass, it's not intended |
| 14 | // to reuse any of the code from the ARM version. |
| 15 | // |
| 16 | // Loading constants inline is expensive on Mips16 and it's in general better |
| 17 | // to place the constant nearby in code space and then it can be loaded with a |
| 18 | // simple 16 bit load instruction. |
| 19 | // |
| 20 | // The constants can be not just numbers but addresses of functions and labels. |
| 21 | // This can be particularly helpful in static relocation mode for embedded |
| 22 | // non linux targets. |
| 23 | // |
| 24 | // |
| 25 | |
| 26 | #define DEBUG_TYPE "mips-constant-islands" |
| 27 | |
| 28 | #include "Mips.h" |
| 29 | #include "MCTargetDesc/MipsBaseInfo.h" |
| 30 | #include "MipsTargetMachine.h" |
| 31 | #include "llvm/ADT/Statistic.h" |
| 32 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 33 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 34 | #include "llvm/IR/Function.h" |
| 35 | #include "llvm/Support/CommandLine.h" |
| 36 | #include "llvm/Support/MathExtras.h" |
| 37 | #include "llvm/Target/TargetInstrInfo.h" |
| 38 | #include "llvm/Target/TargetMachine.h" |
| 39 | #include "llvm/Target/TargetRegisterInfo.h" |
| 40 | |
| 41 | using namespace llvm; |
| 42 | |
| 43 | namespace { |
| 44 | typedef MachineBasicBlock::iterator Iter; |
| 45 | typedef MachineBasicBlock::reverse_iterator ReverseIter; |
| 46 | |
| 47 | class MipsConstantIslands : public MachineFunctionPass { |
| 48 | |
| 49 | public: |
| 50 | static char ID; |
| 51 | MipsConstantIslands(TargetMachine &tm) |
| 52 | : MachineFunctionPass(ID), TM(tm), |
| 53 | TII(static_cast<const MipsInstrInfo*>(tm.getInstrInfo())), |
| 54 | IsPIC(TM.getRelocationModel() == Reloc::PIC_), |
| 55 | ABI(TM.getSubtarget<MipsSubtarget>().getTargetABI()) {} |
| 56 | |
| 57 | virtual const char *getPassName() const { |
| 58 | return "Mips Constant Islands"; |
| 59 | } |
| 60 | |
| 61 | bool runOnMachineFunction(MachineFunction &F); |
| 62 | |
| 63 | private: |
| 64 | |
| 65 | |
| 66 | const TargetMachine &TM; |
| 67 | const MipsInstrInfo *TII; |
| 68 | bool IsPIC; |
| 69 | unsigned ABI; |
| 70 | |
| 71 | }; |
| 72 | |
| 73 | char MipsConstantIslands::ID = 0; |
| 74 | } // end of anonymous namespace |
| 75 | |
| 76 | /// createMipsLongBranchPass - Returns a pass that converts branches to long |
| 77 | /// branches. |
| 78 | FunctionPass *llvm::createMipsConstantIslandPass(MipsTargetMachine &tm) { |
| 79 | return new MipsConstantIslands(tm); |
| 80 | } |
| 81 | |
| 82 | bool MipsConstantIslands::runOnMachineFunction(MachineFunction &F) { |
| 83 | return true; |
| 84 | } |
| 85 | |