]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/lib/Target/MBlaze/MBlazeTargetMachine.cpp
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / lib / Target / MBlaze / MBlazeTargetMachine.cpp
1 //===-- MBlazeTargetMachine.cpp - Define TargetMachine for MBlaze ---------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Implements the info about MBlaze target spec.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "MBlaze.h"
15 #include "MBlazeTargetMachine.h"
16 #include "llvm/PassManager.h"
17 #include "llvm/CodeGen/Passes.h"
18 #include "llvm/Support/FormattedStream.h"
19 #include "llvm/Target/TargetOptions.h"
20 #include "llvm/Target/TargetRegistry.h"
21 using namespace llvm;
22
23 static MCStreamer *createMCStreamer(const Target &T, const std::string &TT,
24                                     MCContext &Ctx, TargetAsmBackend &TAB,
25                                     raw_ostream &_OS,
26                                     MCCodeEmitter *_Emitter,
27                                     bool RelaxAll,
28                                     bool NoExecStack) {
29   Triple TheTriple(TT);
30
31   if (TheTriple.isOSDarwin()) {
32     llvm_unreachable("MBlaze does not support Darwin MACH-O format");
33     return NULL;
34   }
35
36   if (TheTriple.isOSWindows()) {
37     llvm_unreachable("MBlaze does not support Windows COFF format");
38     return NULL;
39   }
40
41   return createELFStreamer(Ctx, TAB, _OS, _Emitter, RelaxAll, NoExecStack);
42 }
43
44
45 extern "C" void LLVMInitializeMBlazeTarget() {
46   // Register the target.
47   RegisterTargetMachine<MBlazeTargetMachine> X(TheMBlazeTarget);
48
49   // Register the MC code emitter
50   TargetRegistry::RegisterCodeEmitter(TheMBlazeTarget,
51                                       llvm::createMBlazeMCCodeEmitter);
52
53   // Register the asm backend
54   TargetRegistry::RegisterAsmBackend(TheMBlazeTarget,
55                                      createMBlazeAsmBackend);
56
57   // Register the object streamer
58   TargetRegistry::RegisterObjectStreamer(TheMBlazeTarget,
59                                          createMCStreamer);
60
61 }
62
63 // DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
64 // The stack is always 8 byte aligned
65 // On function prologue, the stack is created by decrementing
66 // its pointer. Once decremented, all references are done with positive
67 // offset from the stack/frame pointer, using StackGrowsUp enables
68 // an easier handling.
69 MBlazeTargetMachine::
70 MBlazeTargetMachine(const Target &T, const std::string &TT,
71                     const std::string &CPU, const std::string &FS):
72   LLVMTargetMachine(T, TT, CPU, FS),
73   Subtarget(TT, CPU, FS),
74   DataLayout("E-p:32:32:32-i8:8:8-i16:16:16"),
75   InstrInfo(*this),
76   FrameLowering(Subtarget),
77   TLInfo(*this), TSInfo(*this), ELFWriterInfo(*this),
78   InstrItins(Subtarget.getInstrItineraryData()) {
79   if (getRelocationModel() == Reloc::Default) {
80       setRelocationModel(Reloc::Static);
81   }
82
83   if (getCodeModel() == CodeModel::Default)
84     setCodeModel(CodeModel::Small);
85 }
86
87 // Install an instruction selector pass using
88 // the ISelDag to gen MBlaze code.
89 bool MBlazeTargetMachine::addInstSelector(PassManagerBase &PM,
90                                           CodeGenOpt::Level OptLevel) {
91   PM.add(createMBlazeISelDag(*this));
92   return false;
93 }
94
95 // Implemented by targets that want to run passes immediately before
96 // machine code is emitted. return true if -print-machineinstrs should
97 // print out the code after the passes.
98 bool MBlazeTargetMachine::addPreEmitPass(PassManagerBase &PM,
99                                          CodeGenOpt::Level OptLevel) {
100   PM.add(createMBlazeDelaySlotFillerPass(*this));
101   return true;
102 }