2012-02-17 08:55:11 +00:00
|
|
|
//===-- MipsTargetMachine.cpp - Define TargetMachine for Mips -------------===//
|
2007-06-06 07:42:06 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-06 07:42:06 +00:00
|
|
|
//
|
2011-04-15 21:51:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 07:42:06 +00:00
|
|
|
//
|
|
|
|
// Implements the info about Mips target spec.
|
|
|
|
//
|
2011-04-15 21:51:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 07:42:06 +00:00
|
|
|
|
|
|
|
#include "MipsTargetMachine.h"
|
2012-03-17 18:46:09 +00:00
|
|
|
#include "Mips.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "Mips16FrameLowering.h"
|
|
|
|
#include "Mips16HardFloat.h"
|
|
|
|
#include "Mips16ISelDAGToDAG.h"
|
|
|
|
#include "Mips16ISelLowering.h"
|
|
|
|
#include "Mips16InstrInfo.h"
|
2012-08-02 18:21:47 +00:00
|
|
|
#include "MipsFrameLowering.h"
|
|
|
|
#include "MipsInstrInfo.h"
|
2013-04-09 19:46:01 +00:00
|
|
|
#include "MipsModuleISelDAGToDAG.h"
|
2013-04-10 16:58:04 +00:00
|
|
|
#include "MipsOs16.h"
|
2013-04-09 19:46:01 +00:00
|
|
|
#include "MipsSEFrameLowering.h"
|
|
|
|
#include "MipsSEISelDAGToDAG.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "MipsSEISelLowering.h"
|
|
|
|
#include "MipsSEInstrInfo.h"
|
2013-04-09 19:46:01 +00:00
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
2012-02-03 05:12:41 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/PassManager.h"
|
2013-04-09 19:46:01 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2011-08-24 18:08:43 +00:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2013-08-23 10:27:02 +00:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2007-06-06 07:42:06 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-21 22:55:11 +00:00
|
|
|
#define DEBUG_TYPE "mips"
|
|
|
|
|
2009-07-25 06:49:55 +00:00
|
|
|
extern "C" void LLVMInitializeMipsTarget() {
|
|
|
|
// Register the target.
|
2011-09-21 03:00:58 +00:00
|
|
|
RegisterTargetMachine<MipsebTargetMachine> X(TheMipsTarget);
|
2009-08-03 02:22:28 +00:00
|
|
|
RegisterTargetMachine<MipselTargetMachine> Y(TheMipselTarget);
|
2012-07-31 21:39:17 +00:00
|
|
|
RegisterTargetMachine<MipsebTargetMachine> A(TheMips64Target);
|
|
|
|
RegisterTargetMachine<MipselTargetMachine> B(TheMips64elTarget);
|
2007-06-06 07:42:06 +00:00
|
|
|
}
|
|
|
|
|
2007-08-28 05:13:42 +00:00
|
|
|
// On function prologue, the stack is created by decrementing
|
|
|
|
// its pointer. Once decremented, all references are done with positive
|
2010-11-15 00:06:54 +00:00
|
|
|
// offset from the stack/frame pointer, using StackGrowsUp enables
|
2008-08-06 06:14:43 +00:00
|
|
|
// an easier handling.
|
Several changes to Mips backend, experimental fp support being the most
important.
- Cleanup in the Subtarget info with addition of new features, not all support
yet, but they allow the future inclusion of features easier. Among new features,
we have : Arch family info (mips1, mips2, ...), ABI info (o32, eabi), 64-bit
integer
and float registers, allegrex vector FPU (VFPU), single float only support.
- TargetMachine now detects allegrex core.
- Added allegrex (Mips32r2) sext_inreg instructions.
- *Added Float Point Instructions*, handling single float only, and
aliased accesses for 32-bit FPUs.
- Some cleanup in FP instruction formats and FP register classes.
- Calling conventions improved to support mips 32-bit EABI.
- Added Asm Printer support for fp cond codes.
- Added support for sret copy to a return register.
- EABI support added into LowerCALL and FORMAL_ARGS.
- MipsFunctionInfo now keeps a virtual register per function to track the
sret on function entry until function ret.
- MipsInstrInfo FP support into methods (isMoveInstr, isLoadFromStackSlot, ...),
FP cond codes mapping and initial FP Branch Analysis.
- Two new Mips SDNode to handle fp branch and compare instructions : FPBrcond,
FPCmp
- MipsTargetLowering : handling different FP classes, Allegrex support, sret
return copy, no homing location within EABI, non 32-bit stack objects
arguments, and asm constraint for float.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53146 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-05 19:05:21 +00:00
|
|
|
// Using CodeModel::Large enables different CALL behavior.
|
2014-07-02 00:54:07 +00:00
|
|
|
MipsTargetMachine::MipsTargetMachine(const Target &T, StringRef TT,
|
|
|
|
StringRef CPU, StringRef FS,
|
|
|
|
const TargetOptions &Options,
|
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL, bool isLittle)
|
|
|
|
: LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
|
2014-07-18 23:41:32 +00:00
|
|
|
Subtarget(nullptr), DefaultSubtarget(TT, CPU, FS, isLittle, this),
|
|
|
|
NoMips16Subtarget(TT, CPU, FS.empty() ? "-mips16" : FS.str() + ",-mips16",
|
|
|
|
isLittle, this),
|
|
|
|
Mips16Subtarget(TT, CPU, FS.empty() ? "+mips16" : FS.str() + ",+mips16",
|
|
|
|
isLittle, this) {
|
|
|
|
Subtarget = &DefaultSubtarget;
|
2013-05-13 01:16:13 +00:00
|
|
|
initAsmInfo();
|
2013-04-09 19:46:01 +00:00
|
|
|
}
|
|
|
|
|
2011-12-20 02:50:00 +00:00
|
|
|
void MipsebTargetMachine::anchor() { }
|
|
|
|
|
2011-09-21 03:00:58 +00:00
|
|
|
MipsebTargetMachine::
|
|
|
|
MipsebTargetMachine(const Target &T, StringRef TT,
|
2011-12-02 22:16:29 +00:00
|
|
|
StringRef CPU, StringRef FS, const TargetOptions &Options,
|
2011-11-16 08:38:26 +00:00
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
2011-12-02 22:16:29 +00:00
|
|
|
CodeGenOpt::Level OL)
|
|
|
|
: MipsTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
|
2011-09-21 03:00:58 +00:00
|
|
|
|
2011-12-20 02:50:00 +00:00
|
|
|
void MipselTargetMachine::anchor() { }
|
|
|
|
|
2008-06-04 01:45:25 +00:00
|
|
|
MipselTargetMachine::
|
2011-07-19 06:37:02 +00:00
|
|
|
MipselTargetMachine(const Target &T, StringRef TT,
|
2011-12-02 22:16:29 +00:00
|
|
|
StringRef CPU, StringRef FS, const TargetOptions &Options,
|
2011-11-16 08:38:26 +00:00
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
2011-12-02 22:16:29 +00:00
|
|
|
CodeGenOpt::Level OL)
|
|
|
|
: MipsTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
|
2008-06-04 01:45:25 +00:00
|
|
|
|
2014-07-18 23:41:32 +00:00
|
|
|
void MipsTargetMachine::resetSubtarget(MachineFunction *MF) {
|
|
|
|
DEBUG(dbgs() << "resetSubtarget\n");
|
|
|
|
AttributeSet FnAttrs = MF->getFunction()->getAttributes();
|
|
|
|
bool Mips16Attr = FnAttrs.hasAttribute(AttributeSet::FunctionIndex, "mips16");
|
|
|
|
bool NoMips16Attr =
|
|
|
|
FnAttrs.hasAttribute(AttributeSet::FunctionIndex, "nomips16");
|
|
|
|
assert(!(Mips16Attr && NoMips16Attr) &&
|
|
|
|
"mips16 and nomips16 specified on the same function");
|
|
|
|
if (Mips16Attr)
|
|
|
|
Subtarget = &Mips16Subtarget;
|
|
|
|
else if (NoMips16Attr)
|
|
|
|
Subtarget = &NoMips16Subtarget;
|
|
|
|
else
|
|
|
|
Subtarget = &DefaultSubtarget;
|
2014-08-05 02:39:49 +00:00
|
|
|
MF->setSubtarget(Subtarget);
|
2014-07-18 23:41:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-03 05:12:41 +00:00
|
|
|
namespace {
|
|
|
|
/// Mips Code Generator Pass Configuration Options.
|
|
|
|
class MipsPassConfig : public TargetPassConfig {
|
|
|
|
public:
|
2012-02-04 02:56:59 +00:00
|
|
|
MipsPassConfig(MipsTargetMachine *TM, PassManagerBase &PM)
|
2013-10-07 19:13:53 +00:00
|
|
|
: TargetPassConfig(TM, PM) {
|
|
|
|
// The current implementation of long branch pass requires a scratch
|
|
|
|
// register ($at) to be available before branch instructions. Tail merging
|
|
|
|
// can break this requirement, so disable it when long branch pass is
|
|
|
|
// enabled.
|
|
|
|
EnableTailMerge = !getMipsSubtarget().enableLongBranchPass();
|
|
|
|
}
|
2012-02-03 05:12:41 +00:00
|
|
|
|
|
|
|
MipsTargetMachine &getMipsTargetMachine() const {
|
|
|
|
return getTM<MipsTargetMachine>();
|
|
|
|
}
|
|
|
|
|
|
|
|
const MipsSubtarget &getMipsSubtarget() const {
|
|
|
|
return *getMipsTargetMachine().getSubtargetImpl();
|
|
|
|
}
|
|
|
|
|
2014-04-29 07:58:02 +00:00
|
|
|
void addIRPasses() override;
|
|
|
|
bool addInstSelector() override;
|
|
|
|
void addMachineSSAOptimization() override;
|
|
|
|
bool addPreEmitPass() override;
|
2014-03-10 16:31:25 +00:00
|
|
|
|
2014-04-29 07:58:02 +00:00
|
|
|
bool addPreRegAlloc() override;
|
2014-03-10 16:31:25 +00:00
|
|
|
|
2012-02-03 05:12:41 +00:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2012-02-04 02:56:59 +00:00
|
|
|
TargetPassConfig *MipsTargetMachine::createPassConfig(PassManagerBase &PM) {
|
|
|
|
return new MipsPassConfig(this, PM);
|
2012-02-03 05:12:41 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 16:58:04 +00:00
|
|
|
void MipsPassConfig::addIRPasses() {
|
|
|
|
TargetPassConfig::addIRPasses();
|
|
|
|
if (getMipsSubtarget().os16())
|
|
|
|
addPass(createMipsOs16(getMipsTargetMachine()));
|
Checkin in of first of several patches to finish implementation of
mips16/mips32 floating point interoperability.
This patch fixes returns from mips16 functions so that if the function
was in fact called by a mips32 hard float routine, then values
that would have been returned in floating point registers are so returned.
Mips16 mode has no floating point instructions so there is no way to
load values into floating point registers.
This is needed when returning float, double, single complex, double complex
in the Mips ABI.
Helper functions in libc for mips16 are available to do this.
For efficiency purposes, these helper functions have a different calling
convention from normal Mips calls.
Registers v0,v1,a0,a1 are used to pass parameters instead of
a0,a1,a2,a3.
This is because v0,v1,a0,a1 are the natural registers used to return
floating point values in soft float. These values can then be moved
to the appropriate floating point registers with no extra cost.
The only register that is modified is ra in this call.
The helper functions make sure that the return values are in the floating
point registers that they would be in if soft float was not in effect
(which it is for mips16, though the soft float is implemented using a mips32
library that uses hard float).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181641 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-10 22:25:39 +00:00
|
|
|
if (getMipsSubtarget().inMips16HardFloat())
|
|
|
|
addPass(createMips16HardFloat(getMipsTargetMachine()));
|
2013-04-10 16:58:04 +00:00
|
|
|
}
|
2010-11-15 00:06:54 +00:00
|
|
|
// Install an instruction selector pass using
|
2007-06-06 07:42:06 +00:00
|
|
|
// the ISelDag to gen Mips code.
|
2012-05-01 08:27:43 +00:00
|
|
|
bool MipsPassConfig::addInstSelector() {
|
2014-07-18 20:29:02 +00:00
|
|
|
addPass(createMipsModuleISelDag(getMipsTargetMachine()));
|
|
|
|
addPass(createMips16ISelDag(getMipsTargetMachine()));
|
|
|
|
addPass(createMipsSEISelDag(getMipsTargetMachine()));
|
2007-06-06 07:42:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-27 23:38:42 +00:00
|
|
|
void MipsPassConfig::addMachineSSAOptimization() {
|
|
|
|
addPass(createMipsOptimizePICCallPass(getMipsTargetMachine()));
|
|
|
|
TargetPassConfig::addMachineSSAOptimization();
|
|
|
|
}
|
|
|
|
|
2014-03-10 16:31:25 +00:00
|
|
|
bool MipsPassConfig::addPreRegAlloc() {
|
|
|
|
if (getOptLevel() == CodeGenOpt::None) {
|
|
|
|
addPass(createMipsOptimizePICCallPass(getMipsTargetMachine()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-09 19:46:01 +00:00
|
|
|
void MipsTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
|
2014-07-18 23:41:32 +00:00
|
|
|
if (Subtarget->allowMixed16_32()) {
|
2013-04-09 19:46:01 +00:00
|
|
|
DEBUG(errs() << "No ");
|
|
|
|
//FIXME: The Basic Target Transform Info
|
|
|
|
// pass needs to become a function pass instead of
|
|
|
|
// being an immutable pass and then this method as it exists now
|
|
|
|
// would be unnecessary.
|
|
|
|
PM.add(createNoTargetTransformInfoPass());
|
|
|
|
} else
|
|
|
|
LLVMTargetMachine::addAnalysisPasses(PM);
|
|
|
|
DEBUG(errs() << "Target Transform Info Pass Added\n");
|
|
|
|
}
|
|
|
|
|
2010-11-15 00:06:54 +00:00
|
|
|
// Implemented by targets that want to run passes immediately before
|
|
|
|
// machine code is emitted. return true if -print-machineinstrs should
|
2007-06-06 07:42:06 +00:00
|
|
|
// print out the code after the passes.
|
2012-05-01 08:27:43 +00:00
|
|
|
bool MipsPassConfig::addPreEmitPass() {
|
2012-06-14 01:19:35 +00:00
|
|
|
MipsTargetMachine &TM = getMipsTargetMachine();
|
2012-07-02 19:48:31 +00:00
|
|
|
addPass(createMipsDelaySlotFillerPass(TM));
|
2014-07-18 20:29:02 +00:00
|
|
|
addPass(createMipsLongBranchPass(TM));
|
|
|
|
addPass(createMipsConstantIslandPass(TM));
|
2007-08-18 01:58:15 +00:00
|
|
|
return true;
|
2007-06-06 07:42:06 +00:00
|
|
|
}
|