blob: 03a024a361d5dfdf95cc1592689dcb5b5108c020 [file] [log] [blame]
Jia Liu9f610112012-02-17 08:55: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
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000014#include "MipsTargetMachine.h"
Craig Topperb25fda92012-03-17 18:46:09 +000015#include "Mips.h"
Akira Hatanakafab89292012-08-02 18:21:47 +000016#include "MipsFrameLowering.h"
17#include "MipsInstrInfo.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000018#include "llvm/PassManager.h"
Andrew Trickccb67362012-02-03 05:12:41 +000019#include "llvm/CodeGen/Passes.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000020#include "llvm/Support/TargetRegistry.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000021using namespace llvm;
22
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000023extern "C" void LLVMInitializeMipsTarget() {
24 // Register the target.
Akira Hatanaka3d673cc2011-09-21 03:00:58 +000025 RegisterTargetMachine<MipsebTargetMachine> X(TheMipsTarget);
Eli Friedman57c11da2009-08-03 02:22:28 +000026 RegisterTargetMachine<MipselTargetMachine> Y(TheMipselTarget);
Akira Hatanaka30651802012-07-31 21:39:17 +000027 RegisterTargetMachine<MipsebTargetMachine> A(TheMips64Target);
28 RegisterTargetMachine<MipselTargetMachine> B(TheMips64elTarget);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000029}
30
31// DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
Bruno Cardoso Lopes43318832007-08-28 05:13:42 +000032// The stack is always 8 byte aligned
33// On function prologue, the stack is created by decrementing
34// its pointer. Once decremented, all references are done with positive
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000035// offset from the stack/frame pointer, using StackGrowsUp enables
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +000036// an easier handling.
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000037// Using CodeModel::Large enables different CALL behavior.
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000038MipsTargetMachine::
Evan Cheng2129f592011-07-19 06:37:02 +000039MipsTargetMachine(const Target &T, StringRef TT,
Nick Lewycky50f02cb2011-12-02 22:16:29 +000040 StringRef CPU, StringRef FS, const TargetOptions &Options,
Evan Chengefd9b422011-07-20 07:51:56 +000041 Reloc::Model RM, CodeModel::Model CM,
Evan Chengecb29082011-11-16 08:38:26 +000042 CodeGenOpt::Level OL,
Nick Lewycky50f02cb2011-12-02 22:16:29 +000043 bool isLittle)
44 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
45 Subtarget(TT, CPU, FS, isLittle),
46 DataLayout(isLittle ?
47 (Subtarget.isABI_N64() ?
48 "e-p:64:64:64-i8:8:32-i16:16:32-i64:64:64-f128:128:128-n32" :
49 "e-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32") :
50 (Subtarget.isABI_N64() ?
51 "E-p:64:64:64-i8:8:32-i16:16:32-i64:64:64-f128:128:128-n32" :
52 "E-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32")),
Akira Hatanakafab89292012-08-02 18:21:47 +000053 InstrInfo(MipsInstrInfo::create(*this)),
54 FrameLowering(MipsFrameLowering::create(*this, Subtarget)),
Nick Lewycky50f02cb2011-12-02 22:16:29 +000055 TLInfo(*this), TSInfo(*this), JITInfo() {
Bruno Cardoso Lopes35d86e62007-10-09 03:01:19 +000056}
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000057
David Blaikiea379b1812011-12-20 02:50:00 +000058void MipsebTargetMachine::anchor() { }
59
Akira Hatanaka3d673cc2011-09-21 03:00:58 +000060MipsebTargetMachine::
61MipsebTargetMachine(const Target &T, StringRef TT,
Nick Lewycky50f02cb2011-12-02 22:16:29 +000062 StringRef CPU, StringRef FS, const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +000063 Reloc::Model RM, CodeModel::Model CM,
Nick Lewycky50f02cb2011-12-02 22:16:29 +000064 CodeGenOpt::Level OL)
65 : MipsTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
Akira Hatanaka3d673cc2011-09-21 03:00:58 +000066
David Blaikiea379b1812011-12-20 02:50:00 +000067void MipselTargetMachine::anchor() { }
68
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +000069MipselTargetMachine::
Evan Cheng2129f592011-07-19 06:37:02 +000070MipselTargetMachine(const Target &T, StringRef TT,
Nick Lewycky50f02cb2011-12-02 22:16:29 +000071 StringRef CPU, StringRef FS, const TargetOptions &Options,
Evan Chengecb29082011-11-16 08:38:26 +000072 Reloc::Model RM, CodeModel::Model CM,
Nick Lewycky50f02cb2011-12-02 22:16:29 +000073 CodeGenOpt::Level OL)
74 : MipsTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
Bruno Cardoso Lopes326a0372008-06-04 01:45:25 +000075
Andrew Trickccb67362012-02-03 05:12:41 +000076namespace {
77/// Mips Code Generator Pass Configuration Options.
78class MipsPassConfig : public TargetPassConfig {
79public:
Andrew Trickf8ea1082012-02-04 02:56:59 +000080 MipsPassConfig(MipsTargetMachine *TM, PassManagerBase &PM)
81 : TargetPassConfig(TM, PM) {}
Andrew Trickccb67362012-02-03 05:12:41 +000082
83 MipsTargetMachine &getMipsTargetMachine() const {
84 return getTM<MipsTargetMachine>();
85 }
86
87 const MipsSubtarget &getMipsSubtarget() const {
88 return *getMipsTargetMachine().getSubtargetImpl();
89 }
90
91 virtual bool addInstSelector();
Andrew Trickccb67362012-02-03 05:12:41 +000092 virtual bool addPreEmitPass();
93};
94} // namespace
95
Andrew Trickf8ea1082012-02-04 02:56:59 +000096TargetPassConfig *MipsTargetMachine::createPassConfig(PassManagerBase &PM) {
97 return new MipsPassConfig(this, PM);
Andrew Trickccb67362012-02-03 05:12:41 +000098}
99
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +0000100// Install an instruction selector pass using
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000101// the ISelDag to gen Mips code.
Bill Wendlingb12f16e2012-05-01 08:27:43 +0000102bool MipsPassConfig::addInstSelector() {
Bob Wilsonbbd38dd2012-07-02 19:48:31 +0000103 addPass(createMipsISelDag(getMipsTargetMachine()));
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000104 return false;
105}
106
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +0000107// Implemented by targets that want to run passes immediately before
108// machine code is emitted. return true if -print-machineinstrs should
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000109// print out the code after the passes.
Bill Wendlingb12f16e2012-05-01 08:27:43 +0000110bool MipsPassConfig::addPreEmitPass() {
Akira Hatanakaeb365222012-06-14 01:19:35 +0000111 MipsTargetMachine &TM = getMipsTargetMachine();
Bob Wilsonbbd38dd2012-07-02 19:48:31 +0000112 addPass(createMipsDelaySlotFillerPass(TM));
Akira Hatanakaeb365222012-06-14 01:19:35 +0000113
114 // NOTE: long branch has not been implemented for mips16.
115 if (TM.getSubtarget<MipsSubtarget>().hasStandardEncoding())
Bob Wilsonbbd38dd2012-07-02 19:48:31 +0000116 addPass(createMipsLongBranchPass(TM));
Akira Hatanakaeb365222012-06-14 01:19:35 +0000117
Bruno Cardoso Lopesa7465122007-08-18 01:58:15 +0000118 return true;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000119}
Akira Hatanaka27916972011-04-15 19:52:08 +0000120
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +0000121bool MipsTargetMachine::addCodeEmitter(PassManagerBase &PM,
Evan Chengecb29082011-11-16 08:38:26 +0000122 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +0000123 // Machine code emitter pass for Mips.
124 PM.add(createMipsJITCodeEmitterPass(*this, JCE));
125 return false;
126}