blob: a318f81352af76f1016e25378dda495a192d7e04 [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.
Akira Hatanaka24648102011-09-21 03:00:58 +000022 RegisterTargetMachine<MipsebTargetMachine> X(TheMipsTarget);
Eli Friedmane2c74082009-08-03 02:22:28 +000023 RegisterTargetMachine<MipselTargetMachine> Y(TheMipselTarget);
Akira Hatanaka24648102011-09-21 03:00:58 +000024 RegisterTargetMachine<Mips64ebTargetMachine> A(TheMips64Target);
25 RegisterTargetMachine<Mips64elTargetMachine> B(TheMips64elTarget);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000026}
27
28// DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
Bruno Cardoso Lopes51195af2007-08-28 05:13:42 +000029// The stack is always 8 byte aligned
30// On function prologue, the stack is created by decrementing
31// its pointer. Once decremented, all references are done with positive
Anton Korobeynikov33464912010-11-15 00:06:54 +000032// offset from the stack/frame pointer, using StackGrowsUp enables
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000033// an easier handling.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000034// Using CodeModel::Large enables different CALL behavior.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000035MipsTargetMachine::
Evan Cheng43966132011-07-19 06:37:02 +000036MipsTargetMachine(const Target &T, StringRef TT,
Evan Cheng34ad6db2011-07-20 07:51:56 +000037 StringRef CPU, StringRef FS,
38 Reloc::Model RM, CodeModel::Model CM,
Akira Hatanaka24648102011-09-21 03:00:58 +000039 bool isLittle):
Evan Cheng34ad6db2011-07-20 07:51:56 +000040 LLVMTargetMachine(T, TT, CPU, FS, RM, CM),
Evan Cheng276365d2011-06-30 01:53:36 +000041 Subtarget(TT, CPU, FS, isLittle),
Akira Hatanaka24648102011-09-21 03:00:58 +000042 DataLayout(isLittle ?
43 (Subtarget.isABI_N64() ?
44 "e-p:64:64:64-i8:8:32-i16:16:32-i64:64:64-n32" :
45 "e-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32") :
46 (Subtarget.isABI_N64() ?
47 "E-p:64:64:64-i8:8:32-i16:16:32-i64:64:64-n32" :
48 "E-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32")),
Anton Korobeynikov33464912010-11-15 00:06:54 +000049 InstrInfo(*this),
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000050 FrameLowering(Subtarget),
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000051 TLInfo(*this), TSInfo(*this), JITInfo() {
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +000052}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000053
Akira Hatanaka24648102011-09-21 03:00:58 +000054MipsebTargetMachine::
55MipsebTargetMachine(const Target &T, StringRef TT,
56 StringRef CPU, StringRef FS,
57 Reloc::Model RM, CodeModel::Model CM) :
58 MipsTargetMachine(T, TT, CPU, FS, RM, CM, false) {}
59
Bruno Cardoso Lopesd2947ee2008-06-04 01:45:25 +000060MipselTargetMachine::
Evan Cheng43966132011-07-19 06:37:02 +000061MipselTargetMachine(const Target &T, StringRef TT,
Evan Cheng34ad6db2011-07-20 07:51:56 +000062 StringRef CPU, StringRef FS,
63 Reloc::Model RM, CodeModel::Model CM) :
64 MipsTargetMachine(T, TT, CPU, FS, RM, CM, true) {}
Bruno Cardoso Lopesd2947ee2008-06-04 01:45:25 +000065
Akira Hatanaka24648102011-09-21 03:00:58 +000066Mips64ebTargetMachine::
67Mips64ebTargetMachine(const Target &T, StringRef TT,
68 StringRef CPU, StringRef FS,
69 Reloc::Model RM, CodeModel::Model CM) :
70 MipsTargetMachine(T, TT, CPU, FS, RM, CM, false) {}
71
72Mips64elTargetMachine::
73Mips64elTargetMachine(const Target &T, StringRef TT,
74 StringRef CPU, StringRef FS,
75 Reloc::Model RM, CodeModel::Model CM) :
76 MipsTargetMachine(T, TT, CPU, FS, RM, CM, true) {}
77
Anton Korobeynikov33464912010-11-15 00:06:54 +000078// Install an instruction selector pass using
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000079// the ISelDag to gen Mips code.
80bool MipsTargetMachine::
Anton Korobeynikov33464912010-11-15 00:06:54 +000081addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel)
Chris Lattner8eeba352010-01-20 06:34:14 +000082{
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000083 PM.add(createMipsISelDag(*this));
84 return false;
85}
86
Anton Korobeynikov33464912010-11-15 00:06:54 +000087// Implemented by targets that want to run passes immediately before
88// machine code is emitted. return true if -print-machineinstrs should
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000089// print out the code after the passes.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000090bool MipsTargetMachine::
Anton Korobeynikov33464912010-11-15 00:06:54 +000091addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel)
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000092{
Bruno Cardoso Lopesaff42dc2007-08-18 01:58:15 +000093 PM.add(createMipsDelaySlotFillerPass(*this));
94 return true;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000095}
Akira Hatanaka99a2e982011-04-15 19:52:08 +000096
97bool MipsTargetMachine::
Akira Hatanaka6b7588e2011-05-04 17:54:27 +000098addPreRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
Akira Hatanaka78fec582011-09-27 16:58:43 +000099 // Do not restore $gp if target is Mips64.
100 // In N32/64, $gp is a callee-saved register.
101 if (!Subtarget.hasMips64())
102 PM.add(createMipsEmitGPRestorePass(*this));
Akira Hatanaka6b7588e2011-05-04 17:54:27 +0000103 return true;
104}
105
106bool MipsTargetMachine::
Akira Hatanaka99a2e982011-04-15 19:52:08 +0000107addPostRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
108 PM.add(createMipsExpandPseudoPass(*this));
109 return true;
110}
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +0000111
112bool MipsTargetMachine::addCodeEmitter(PassManagerBase &PM,
113 CodeGenOpt::Level OptLevel,
114 JITCodeEmitter &JCE) {
115 // Machine code emitter pass for Mips.
116 PM.add(createMipsJITCodeEmitterPass(*this, JCE));
117 return false;
118}
119