1 //===-- MipsTargetMachine.cpp - Define TargetMachine for Mips -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implements the info about Mips target spec.
12 //===----------------------------------------------------------------------===//
14 #include "MipsTargetMachine.h"
16 #include "MipsFrameLowering.h"
17 #include "MipsInstrInfo.h"
18 #include "llvm/CodeGen/Passes.h"
19 #include "llvm/PassManager.h"
20 #include "llvm/Support/TargetRegistry.h"
23 extern "C" void LLVMInitializeMipsTarget() {
24 // Register the target.
25 RegisterTargetMachine<MipsebTargetMachine> X(TheMipsTarget);
26 RegisterTargetMachine<MipselTargetMachine> Y(TheMipselTarget);
27 RegisterTargetMachine<MipsebTargetMachine> A(TheMips64Target);
28 RegisterTargetMachine<MipselTargetMachine> B(TheMips64elTarget);
31 // DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
32 // 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
35 // offset from the stack/frame pointer, using StackGrowsUp enables
36 // an easier handling.
37 // Using CodeModel::Large enables different CALL behavior.
39 MipsTargetMachine(const Target &T, StringRef TT,
40 StringRef CPU, StringRef FS, const TargetOptions &Options,
41 Reloc::Model RM, CodeModel::Model CM,
44 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
45 Subtarget(TT, CPU, FS, isLittle, RM),
47 (Subtarget.isABI_N64() ?
48 "e-p:64:64:64-i8:8:32-i16:16:32-i64:64:64-f128:128:128-"
50 "e-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32-S64") :
51 (Subtarget.isABI_N64() ?
52 "E-p:64:64:64-i8:8:32-i16:16:32-i64:64:64-f128:128:128-"
54 "E-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32-S64")),
55 InstrInfo(MipsInstrInfo::create(*this)),
56 FrameLowering(MipsFrameLowering::create(*this, Subtarget)),
57 TLInfo(*this), TSInfo(*this), JITInfo(),
58 STTI(&TLInfo), VTTI(&TLInfo) {
61 void MipsebTargetMachine::anchor() { }
64 MipsebTargetMachine(const Target &T, StringRef TT,
65 StringRef CPU, StringRef FS, const TargetOptions &Options,
66 Reloc::Model RM, CodeModel::Model CM,
68 : MipsTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
70 void MipselTargetMachine::anchor() { }
73 MipselTargetMachine(const Target &T, StringRef TT,
74 StringRef CPU, StringRef FS, const TargetOptions &Options,
75 Reloc::Model RM, CodeModel::Model CM,
77 : MipsTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
80 /// Mips Code Generator Pass Configuration Options.
81 class MipsPassConfig : public TargetPassConfig {
83 MipsPassConfig(MipsTargetMachine *TM, PassManagerBase &PM)
84 : TargetPassConfig(TM, PM) {}
86 MipsTargetMachine &getMipsTargetMachine() const {
87 return getTM<MipsTargetMachine>();
90 const MipsSubtarget &getMipsSubtarget() const {
91 return *getMipsTargetMachine().getSubtargetImpl();
94 virtual bool addInstSelector();
95 virtual bool addPreEmitPass();
99 TargetPassConfig *MipsTargetMachine::createPassConfig(PassManagerBase &PM) {
100 return new MipsPassConfig(this, PM);
103 // Install an instruction selector pass using
104 // the ISelDag to gen Mips code.
105 bool MipsPassConfig::addInstSelector() {
106 addPass(createMipsISelDag(getMipsTargetMachine()));
110 // Implemented by targets that want to run passes immediately before
111 // machine code is emitted. return true if -print-machineinstrs should
112 // print out the code after the passes.
113 bool MipsPassConfig::addPreEmitPass() {
114 MipsTargetMachine &TM = getMipsTargetMachine();
115 addPass(createMipsDelaySlotFillerPass(TM));
117 // NOTE: long branch has not been implemented for mips16.
118 if (TM.getSubtarget<MipsSubtarget>().hasStandardEncoding())
119 addPass(createMipsLongBranchPass(TM));
124 bool MipsTargetMachine::addCodeEmitter(PassManagerBase &PM,
125 JITCodeEmitter &JCE) {
126 // Machine code emitter pass for Mips.
127 PM.add(createMipsJITCodeEmitterPass(*this, JCE));