blob: 7b17004da8523d5cd9f60d9396dbd0d8bcc5e0b6 [file] [log] [blame]
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001//===-- MipsTargetMachine.cpp - Define TargetMachine for Mips -------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Lopes972f5892007-06-06 07:42:06 +00007//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00009//
10// Implements the info about Mips target spec.
11//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000013
14#include "Mips.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000015#include "MipsTargetMachine.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000016#include "llvm/PassManager.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000017#include "llvm/Support/TargetRegistry.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000018using namespace llvm;
19
Daniel Dunbar0c795d62009-07-25 06:49:55 +000020extern "C" void LLVMInitializeMipsTarget() {
21 // Register the target.
Eli Friedmane2c74082009-08-03 02:22:28 +000022 RegisterTargetMachine<MipsTargetMachine> X(TheMipsTarget);
23 RegisterTargetMachine<MipselTargetMachine> Y(TheMipselTarget);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000024}
25
26// DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
Bruno Cardoso Lopes51195af2007-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 Korobeynikov33464912010-11-15 00:06:54 +000030// offset from the stack/frame pointer, using StackGrowsUp enables
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000031// an easier handling.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000032// Using CodeModel::Large enables different CALL behavior.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000033MipsTargetMachine::
Evan Cheng43966132011-07-19 06:37:02 +000034MipsTargetMachine(const Target &T, StringRef TT,
Evan Cheng34ad6db2011-07-20 07:51:56 +000035 StringRef CPU, StringRef FS,
36 Reloc::Model RM, CodeModel::Model CM,
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000037 bool isLittle=false):
Evan Cheng34ad6db2011-07-20 07:51:56 +000038 LLVMTargetMachine(T, TT, CPU, FS, RM, CM),
Evan Cheng276365d2011-06-30 01:53:36 +000039 Subtarget(TT, CPU, FS, isLittle),
Akira Hatanakad48cfae2011-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 Korobeynikov33464912010-11-15 00:06:54 +000043 InstrInfo(*this),
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000044 FrameLowering(Subtarget),
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000045 TLInfo(*this), TSInfo(*this), JITInfo() {
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +000046}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000047
Bruno Cardoso Lopesd2947ee2008-06-04 01:45:25 +000048MipselTargetMachine::
Evan Cheng43966132011-07-19 06:37:02 +000049MipselTargetMachine(const Target &T, StringRef TT,
Evan Cheng34ad6db2011-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 Lopesd2947ee2008-06-04 01:45:25 +000053
Anton Korobeynikov33464912010-11-15 00:06:54 +000054// Install an instruction selector pass using
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000055// the ISelDag to gen Mips code.
56bool MipsTargetMachine::
Anton Korobeynikov33464912010-11-15 00:06:54 +000057addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel)
Chris Lattner8eeba352010-01-20 06:34:14 +000058{
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000059 PM.add(createMipsISelDag(*this));
60 return false;
61}
62
Anton Korobeynikov33464912010-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 Lopes972f5892007-06-06 07:42:06 +000065// print out the code after the passes.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000066bool MipsTargetMachine::
Anton Korobeynikov33464912010-11-15 00:06:54 +000067addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel)
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000068{
Bruno Cardoso Lopesaff42dc2007-08-18 01:58:15 +000069 PM.add(createMipsDelaySlotFillerPass(*this));
70 return true;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000071}
Akira Hatanaka99a2e982011-04-15 19:52:08 +000072
73bool MipsTargetMachine::
Akira Hatanaka6b7588e2011-05-04 17:54:27 +000074addPreRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
75 PM.add(createMipsEmitGPRestorePass(*this));
76 return true;
77}
78
79bool MipsTargetMachine::
Akira Hatanaka99a2e982011-04-15 19:52:08 +000080addPostRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
81 PM.add(createMipsExpandPseudoPass(*this));
82 return true;
83}
Bruno Cardoso Lopesdca6cdd2011-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