blob: 40de5dff1b58c99bd54fd805e4ea3280b6a2a984 [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
Dan Gohman844731a2008-05-13 00:00:25 +000022// Register the target.
23static RegisterTarget<MipsTargetMachine> X("mips", " Mips");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000024
25const TargetAsmInfo *MipsTargetMachine::
26createTargetAsmInfo() const
27{
28 return new MipsTargetAsmInfo(*this);
29}
30
31// DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
Bruno Cardoso Lopes51195af2007-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
35// offset from the stack/frame pointer, so StackGrowsUp is used.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000036// When using CodeModel::Large the behaviour
37//
38//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000039MipsTargetMachine::
40MipsTargetMachine(const Module &M, const std::string &FS):
41 Subtarget(*this, M, FS), DataLayout("E-p:32:32:32"),
Bruno Cardoso Lopes51195af2007-08-28 05:13:42 +000042 InstrInfo(*this), FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0),
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +000043 TLInfo(*this)
44{
45 if (getRelocationModel() != Reloc::Static)
46 setRelocationModel(Reloc::PIC_);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000047 if (getCodeModel() == CodeModel::Default)
48 setCodeModel(CodeModel::Small);
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +000049}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000050
51// return 0 and must specify -march to gen MIPS code.
52unsigned MipsTargetMachine::
Bruno Cardoso Lopes758dcca2007-07-11 23:17:41 +000053getModuleMatchQuality(const Module &M)
54{
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000055 // We strongly match "mips-*".
56 std::string TT = M.getTargetTriple();
57 if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
58 return 20;
Bruno Cardoso Lopes758dcca2007-07-11 23:17:41 +000059
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000060 return 0;
61}
62
63// Install an instruction selector pass using
64// the ISelDag to gen Mips code.
65bool MipsTargetMachine::
Dan Gohmanbfae8312008-03-11 22:29:46 +000066addInstSelector(PassManagerBase &PM, bool Fast)
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000067{
68 PM.add(createMipsISelDag(*this));
69 return false;
70}
71
72// Implemented by targets that want to run passes immediately before
73// machine code is emitted. return true if -print-machineinstrs should
74// print out the code after the passes.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000075bool MipsTargetMachine::
Dan Gohmanbfae8312008-03-11 22:29:46 +000076addPreEmitPass(PassManagerBase &PM, bool Fast)
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000077{
Bruno Cardoso Lopesaff42dc2007-08-18 01:58:15 +000078 PM.add(createMipsDelaySlotFillerPass(*this));
79 return true;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000080}
81
82// Implements the AssemblyEmitter for the target. Must return
83// true if AssemblyEmitter is supported
84bool MipsTargetMachine::
Dan Gohmanbfae8312008-03-11 22:29:46 +000085addAssemblyEmitter(PassManagerBase &PM, bool Fast,
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000086 std::ostream &Out)
87{
88 // Output assembly language.
89 PM.add(createMipsCodePrinterPass(Out, *this));
90 return false;
91}