MipsConstantIslandPass.cpp revision 41e632d9e1a55d36cb08b0551ad82a13d9137a5e
1//===-- MipsConstantIslandPass.cpp - Emit Pc Relative loads----------------===//
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
41using namespace llvm;
42
43namespace {
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        IsPIC(TM.getRelocationModel() == Reloc::PIC_),
54        ABI(TM.getSubtarget<MipsSubtarget>().getTargetABI()) {}
55
56    virtual const char *getPassName() const {
57      return "Mips Constant Islands";
58    }
59
60    bool runOnMachineFunction(MachineFunction &F);
61
62  private:
63    const TargetMachine &TM;
64    bool IsPIC;
65    unsigned ABI;
66  };
67
68  char MipsConstantIslands::ID = 0;
69} // end of anonymous namespace
70
71/// createMipsLongBranchPass - Returns a pass that converts branches to long
72/// branches.
73FunctionPass *llvm::createMipsConstantIslandPass(MipsTargetMachine &tm) {
74  return new MipsConstantIslands(tm);
75}
76
77bool MipsConstantIslands::runOnMachineFunction(MachineFunction &F) {
78  // The intention is for this to be a mips16 only pass for now
79  // FIXME:
80  // if (!TM.getSubtarget<MipsSubtarget>().inMips16Mode())
81  //  return false;
82  return false;
83}
84
85