blob: 7493bb527eb60157e226c2eac3c68a75d2393cb0 [file] [log] [blame]
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001//===-- MipsTargetMachine.cpp - Define TargetMachine for Mips -------------===//
2//
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//
8//===----------------------------------------------------------------------===//
9//
10// Implements the info about Mips target spec.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Mips.h"
15#include "MipsTargetAsmInfo.h"
16#include "MipsTargetMachine.h"
17#include "llvm/Module.h"
18#include "llvm/PassManager.h"
19#include "llvm/Target/TargetMachineRegistry.h"
20using namespace llvm;
21
22namespace {
23 // Register the target.
24 RegisterTarget<MipsTargetMachine> X("mips", " Mips");
25}
26
27const TargetAsmInfo *MipsTargetMachine::
28createTargetAsmInfo() const
29{
30 return new MipsTargetAsmInfo(*this);
31}
32
33// DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
Bruno Cardoso Lopes51195af2007-08-28 05:13:42 +000034// The stack is always 8 byte aligned
35// On function prologue, the stack is created by decrementing
36// its pointer. Once decremented, all references are done with positive
37// offset from the stack/frame pointer, so StackGrowsUp is used.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000038// When using CodeModel::Large the behaviour
39//
40//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000041MipsTargetMachine::
42MipsTargetMachine(const Module &M, const std::string &FS):
43 Subtarget(*this, M, FS), DataLayout("E-p:32:32:32"),
Bruno Cardoso Lopes51195af2007-08-28 05:13:42 +000044 InstrInfo(*this), FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0),
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +000045 TLInfo(*this)
46{
47 if (getRelocationModel() != Reloc::Static)
48 setRelocationModel(Reloc::PIC_);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000049 if (getCodeModel() == CodeModel::Default)
50 setCodeModel(CodeModel::Small);
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +000051}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000052
53// return 0 and must specify -march to gen MIPS code.
54unsigned MipsTargetMachine::
Bruno Cardoso Lopes758dcca2007-07-11 23:17:41 +000055getModuleMatchQuality(const Module &M)
56{
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000057 // We strongly match "mips-*".
58 std::string TT = M.getTargetTriple();
59 if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
60 return 20;
Bruno Cardoso Lopes758dcca2007-07-11 23:17:41 +000061
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000062 return 0;
63}
64
65// Install an instruction selector pass using
66// the ISelDag to gen Mips code.
67bool MipsTargetMachine::
68addInstSelector(FunctionPassManager &PM, bool Fast)
69{
70 PM.add(createMipsISelDag(*this));
71 return false;
72}
73
74// Implemented by targets that want to run passes immediately before
75// machine code is emitted. return true if -print-machineinstrs should
76// print out the code after the passes.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000077bool MipsTargetMachine::
78addPreEmitPass(FunctionPassManager &PM, bool Fast)
79{
Bruno Cardoso Lopesaff42dc2007-08-18 01:58:15 +000080 PM.add(createMipsDelaySlotFillerPass(*this));
81 return true;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000082}
83
84// Implements the AssemblyEmitter for the target. Must return
85// true if AssemblyEmitter is supported
86bool MipsTargetMachine::
87addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
88 std::ostream &Out)
89{
90 // Output assembly language.
91 PM.add(createMipsCodePrinterPass(Out, *this));
92 return false;
93}