1 //===-- MipsConstantIslandPass.cpp - Emit Pc Relative loads----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
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.
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
26 #define DEBUG_TYPE "mips-constant-islands"
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"
44 typedef MachineBasicBlock::iterator Iter;
45 typedef MachineBasicBlock::reverse_iterator ReverseIter;
47 class MipsConstantIslands : public MachineFunctionPass {
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()) {}
57 virtual const char *getPassName() const {
58 return "Mips Constant Islands";
61 bool runOnMachineFunction(MachineFunction &F);
66 const TargetMachine &TM;
67 const MipsInstrInfo *TII;
73 char MipsConstantIslands::ID = 0;
74 } // end of anonymous namespace
76 /// createMipsLongBranchPass - Returns a pass that converts branches to long
78 FunctionPass *llvm::createMipsConstantIslandPass(MipsTargetMachine &tm) {
79 return new MipsConstantIslands(tm);
82 bool MipsConstantIslands::runOnMachineFunction(MachineFunction &F) {