mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-23 15:29:51 +00:00
a430cb613b
and mips16 on a per function basis. Because this patch is somewhat involved I have provide an overview of the key pieces of it. The patch is written so as to not change the behavior of the non mixed mode. We have tested this a lot but it is something new to switch subtargets so we don't want any chance of regression in the mainline compiler until we have more confidence in this. Mips32/64 are very different from Mip16 as is the case of ARM vs Thumb1. For that reason there are derived versions of the register info, frame info, instruction info and instruction selection classes. Now we register three separate passes for instruction selection. One which is used to switch subtargets (MipsModuleISelDAGToDAG.cpp) and then one for each of the current subtargets (Mips16ISelDAGToDAG.cpp and MipsSEISelDAGToDAG.cpp). When the ModuleISel pass runs, it determines if there is a need to switch subtargets and if so, the owning pointers in MipsTargetMachine are appropriately changed. When 16Isel or SEIsel is run, they will return immediately without doing any work if the current subtarget mode does not apply to them. In addition, MipsAsmPrinter needs to be reset on a function basis. The pass BasicTargetTransformInfo is substituted with a null pass since the pass is immutable and really needs to be a function pass for it to be used with changing subtargets. This will be fixed in a follow on patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179118 91177308-0d34-0410-b5e6-96231b3b80d8
90 lines
2.7 KiB
C++
90 lines
2.7 KiB
C++
//===-- MipsConstantIslandPass.cpp - Emit Pc Relative loads----------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
//
|
|
// This pass is used to make Pc relative loads of constants.
|
|
// For now, only Mips16 will use this. While it has the same name and
|
|
// uses many ideas from the LLVM ARM Constant Island Pass, it's not intended
|
|
// to reuse any of the code from the ARM version.
|
|
//
|
|
// Loading constants inline is expensive on Mips16 and it's in general better
|
|
// to place the constant nearby in code space and then it can be loaded with a
|
|
// simple 16 bit load instruction.
|
|
//
|
|
// The constants can be not just numbers but addresses of functions and labels.
|
|
// This can be particularly helpful in static relocation mode for embedded
|
|
// non linux targets.
|
|
//
|
|
//
|
|
|
|
#define DEBUG_TYPE "mips-constant-islands"
|
|
|
|
#include "Mips.h"
|
|
#include "MCTargetDesc/MipsBaseInfo.h"
|
|
#include "MipsTargetMachine.h"
|
|
#include "llvm/ADT/Statistic.h"
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/MathExtras.h"
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
#include "llvm/Target/TargetMachine.h"
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
typedef MachineBasicBlock::iterator Iter;
|
|
typedef MachineBasicBlock::reverse_iterator ReverseIter;
|
|
|
|
class MipsConstantIslands : public MachineFunctionPass {
|
|
|
|
public:
|
|
static char ID;
|
|
MipsConstantIslands(TargetMachine &tm)
|
|
: MachineFunctionPass(ID), TM(tm),
|
|
TII(static_cast<const MipsInstrInfo*>(tm.getInstrInfo())),
|
|
IsPIC(TM.getRelocationModel() == Reloc::PIC_),
|
|
ABI(TM.getSubtarget<MipsSubtarget>().getTargetABI()) {}
|
|
|
|
virtual const char *getPassName() const {
|
|
return "Mips Constant Islands";
|
|
}
|
|
|
|
bool runOnMachineFunction(MachineFunction &F);
|
|
|
|
private:
|
|
|
|
|
|
const TargetMachine &TM;
|
|
const MipsInstrInfo *TII;
|
|
bool IsPIC;
|
|
unsigned ABI;
|
|
|
|
};
|
|
|
|
char MipsConstantIslands::ID = 0;
|
|
} // end of anonymous namespace
|
|
|
|
/// createMipsLongBranchPass - Returns a pass that converts branches to long
|
|
/// branches.
|
|
FunctionPass *llvm::createMipsConstantIslandPass(MipsTargetMachine &tm) {
|
|
return new MipsConstantIslands(tm);
|
|
}
|
|
|
|
bool MipsConstantIslands::runOnMachineFunction(MachineFunction &F) {
|
|
// The intention is for this to be a mips16 only pass for now
|
|
// FIXME:
|
|
// if (!TM.getSubtarget<MipsSubtarget>().inMips16Mode())
|
|
// return false;
|
|
return false;
|
|
}
|
|
|