blob: 8dbd2559864d2c6ae505ba54f5675d43ec156c52 [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,
Evan Chengefd9b422011-07-20 07:51:56 +000035 StringRef CPU, StringRef FS,
36 Reloc::Model RM, CodeModel::Model CM,
Akira Hatanakae2489122011-04-15 21:51:11 +000037 bool isLittle=false):
Evan Chengefd9b422011-07-20 07:51:56 +000038 LLVMTargetMachine(T, TT, CPU, FS, RM, CM),
Evan Chengfe6e4052011-06-30 01:53:36 +000039 Subtarget(TT, CPU, FS, isLittle),
Akira Hatanakad1465bd2011-05-19 17:21:09 +000040 DataLayout(isLittle ?
41 std::string("e-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32") :
42 std::string("E-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32")),
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000043 InstrInfo(*this),
Anton Korobeynikov2f931282011-01-10 12:39:04 +000044 FrameLowering(Subtarget),
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000045 TLInfo(*this), TSInfo(*this), JITInfo() {
Bruno Cardoso Lopes35d86e62007-10-09 03:01:19 +000046}
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000047
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +000048MipselTargetMachine::
Evan Cheng2129f592011-07-19 06:37:02 +000049MipselTargetMachine(const Target &T, StringRef TT,
Evan Chengefd9b422011-07-20 07:51:56 +000050 StringRef CPU, StringRef FS,
51 Reloc::Model RM, CodeModel::Model CM) :
52 MipsTargetMachine(T, TT, CPU, FS, RM, CM, true) {}
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +000053
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000054// Install an instruction selector pass using
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000055// the ISelDag to gen Mips code.
56bool MipsTargetMachine::
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000057addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel)
Chris Lattner2b4364f2010-01-20 06:34:14 +000058{
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000059 PM.add(createMipsISelDag(*this));
60 return false;
61}
62
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000063// Implemented by targets that want to run passes immediately before
64// machine code is emitted. return true if -print-machineinstrs should
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000065// print out the code after the passes.
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000066bool MipsTargetMachine::
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000067addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel)
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000068{
Bruno Cardoso Lopesa7465122007-08-18 01:58:15 +000069 PM.add(createMipsDelaySlotFillerPass(*this));
70 return true;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000071}
Akira Hatanaka27916972011-04-15 19:52:08 +000072
73bool MipsTargetMachine::
Akira Hatanaka23e8ecf2011-05-04 17:54:27 +000074addPreRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
75 PM.add(createMipsEmitGPRestorePass(*this));
76 return true;
77}
78
79bool MipsTargetMachine::
Akira Hatanaka27916972011-04-15 19:52:08 +000080addPostRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
81 PM.add(createMipsExpandPseudoPass(*this));
82 return true;
83}
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000084
85bool MipsTargetMachine::addCodeEmitter(PassManagerBase &PM,
86 CodeGenOpt::Level OptLevel,
87 JITCodeEmitter &JCE) {
88 // Machine code emitter pass for Mips.
89 PM.add(createMipsJITCodeEmitterPass(*this, JCE));
90 return false;
91}
92