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 IsPIC(TM.getRelocationModel() == Reloc::PIC_),
54 ABI(TM.getSubtarget<MipsSubtarget>().getTargetABI()) {}
56 virtual const char *getPassName() const {
57 return "Mips Constant Islands";
60 bool runOnMachineFunction(MachineFunction &F);
63 const TargetMachine &TM;
68 char MipsConstantIslands::ID = 0;
69 } // end of anonymous namespace
71 /// createMipsLongBranchPass - Returns a pass that converts branches to long
73 FunctionPass *llvm::createMipsConstantIslandPass(MipsTargetMachine &tm) {
74 return new MipsConstantIslands(tm);
77 bool MipsConstantIslands::runOnMachineFunction(MachineFunction &F) {
78 // The intention is for this to be a mips16 only pass for now
80 // if (!TM.getSubtarget<MipsSubtarget>().inMips16Mode())