blob: a195a48961a23c223b9a5d8a5acd02205fa32c68 [file] [log] [blame]
Akira Hatanakae2489122011-04-15 21:51:11 +00001//===-- MipsTargetMachine.cpp - Define TargetMachine for Mips -------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00009//
10// Implements the info about Mips target spec.
11//
Akira Hatanakae2489122011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000013
14#include "Mips.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000015#include "MipsTargetMachine.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000016#include "llvm/PassManager.h"
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000017#include "llvm/Target/TargetRegistry.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000018using namespace llvm;
19
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000020extern "C" void LLVMInitializeMipsTarget() {
21 // Register the target.
Eli Friedman57c11da2009-08-03 02:22:28 +000022 RegisterTargetMachine<MipsTargetMachine> X(TheMipsTarget);
23 RegisterTargetMachine<MipselTargetMachine> Y(TheMipselTarget);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000024}
25
26// DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
Bruno Cardoso Lopes43318832007-08-28 05:13:42 +000027// The stack is always 8 byte aligned
28// On function prologue, the stack is created by decrementing
29// its pointer. Once decremented, all references are done with positive
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000030// offset from the stack/frame pointer, using StackGrowsUp enables
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +000031// an easier handling.
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000032// Using CodeModel::Large enables different CALL behavior.
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000033MipsTargetMachine::
Evan Cheng2129f592011-07-19 06:37:02 +000034MipsTargetMachine(const Target &T, StringRef TT,
35 StringRef CPU, StringRef FS, Reloc::Model RM,
Akira Hatanakae2489122011-04-15 21:51:11 +000036 bool isLittle=false):
Evan Cheng2129f592011-07-19 06:37:02 +000037 LLVMTargetMachine(T, TT, CPU, FS, RM),
Evan Chengfe6e4052011-06-30 01:53:36 +000038 Subtarget(TT, CPU, FS, isLittle),
Akira Hatanakad1465bd2011-05-19 17:21:09 +000039 DataLayout(isLittle ?
40 std::string("e-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32") :
41 std::string("E-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32")),
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000042 InstrInfo(*this),
Anton Korobeynikov2f931282011-01-10 12:39:04 +000043 FrameLowering(Subtarget),
Dan Gohmanbb919df2010-05-11 17:31:57 +000044 TLInfo(*this), TSInfo(*this) {
Bruno Cardoso Lopes35d86e62007-10-09 03:01:19 +000045}
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000046
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +000047MipselTargetMachine::
Evan Cheng2129f592011-07-19 06:37:02 +000048MipselTargetMachine(const Target &T, StringRef TT,
49 StringRef CPU, StringRef FS, Reloc::Model RM) :
50 MipsTargetMachine(T, TT, CPU, FS, RM, true) {}
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +000051
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000052// Install an instruction selector pass using
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000053// the ISelDag to gen Mips code.
54bool MipsTargetMachine::
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000055addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel)
Chris Lattner2b4364f2010-01-20 06:34:14 +000056{
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000057 PM.add(createMipsISelDag(*this));
58 return false;
59}
60
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000061// Implemented by targets that want to run passes immediately before
62// machine code is emitted. return true if -print-machineinstrs should
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000063// print out the code after the passes.
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000064bool MipsTargetMachine::
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000065addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel)
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000066{
Bruno Cardoso Lopesa7465122007-08-18 01:58:15 +000067 PM.add(createMipsDelaySlotFillerPass(*this));
68 return true;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000069}
Akira Hatanaka27916972011-04-15 19:52:08 +000070
71bool MipsTargetMachine::
Akira Hatanaka23e8ecf2011-05-04 17:54:27 +000072addPreRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
73 PM.add(createMipsEmitGPRestorePass(*this));
74 return true;
75}
76
77bool MipsTargetMachine::
Akira Hatanaka27916972011-04-15 19:52:08 +000078addPostRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
79 PM.add(createMipsExpandPseudoPass(*this));
80 return true;
81}