blob: 372e267d4629f99ddb20dba7183cf0434623a83d [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//
5// This file was developed by Bruno Cardoso Lopes and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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 Lopes972f5892007-06-06 07:42:06 +000038MipsTargetMachine::
39MipsTargetMachine(const Module &M, const std::string &FS):
40 Subtarget(*this, M, FS), DataLayout("E-p:32:32:32"),
Bruno Cardoso Lopes51195af2007-08-28 05:13:42 +000041 InstrInfo(*this), FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000042 TLInfo(*this) {}
43
44// return 0 and must specify -march to gen MIPS code.
45unsigned MipsTargetMachine::
Bruno Cardoso Lopes758dcca2007-07-11 23:17:41 +000046getModuleMatchQuality(const Module &M)
47{
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000048 // We strongly match "mips-*".
49 std::string TT = M.getTargetTriple();
50 if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
51 return 20;
Bruno Cardoso Lopes758dcca2007-07-11 23:17:41 +000052
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000053 return 0;
54}
55
56// Install an instruction selector pass using
57// the ISelDag to gen Mips code.
58bool MipsTargetMachine::
59addInstSelector(FunctionPassManager &PM, bool Fast)
60{
61 PM.add(createMipsISelDag(*this));
62 return false;
63}
64
65// Implemented by targets that want to run passes immediately before
66// machine code is emitted. return true if -print-machineinstrs should
67// print out the code after the passes.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000068bool MipsTargetMachine::
69addPreEmitPass(FunctionPassManager &PM, bool Fast)
70{
Bruno Cardoso Lopesaff42dc2007-08-18 01:58:15 +000071 PM.add(createMipsDelaySlotFillerPass(*this));
72 return true;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000073}
74
75// Implements the AssemblyEmitter for the target. Must return
76// true if AssemblyEmitter is supported
77bool MipsTargetMachine::
78addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
79 std::ostream &Out)
80{
81 // Output assembly language.
82 PM.add(createMipsCodePrinterPass(Out, *this));
83 return false;
84}