1 //===-- MBlazeTargetMachine.cpp - Define TargetMachine for MBlaze ---------===//
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 MBlaze target spec.
12 //===----------------------------------------------------------------------===//
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"
23 static MCStreamer *createMCStreamer(const Target &T, const std::string &TT,
24 MCContext &Ctx, TargetAsmBackend &TAB,
26 MCCodeEmitter *_Emitter,
31 if (TheTriple.isOSDarwin()) {
32 llvm_unreachable("MBlaze does not support Darwin MACH-O format");
36 if (TheTriple.isOSWindows()) {
37 llvm_unreachable("MBlaze does not support Windows COFF format");
41 return createELFStreamer(Ctx, TAB, _OS, _Emitter, RelaxAll, NoExecStack);
45 extern "C" void LLVMInitializeMBlazeTarget() {
46 // Register the target.
47 RegisterTargetMachine<MBlazeTargetMachine> X(TheMBlazeTarget);
49 // Register the MC code emitter
50 TargetRegistry::RegisterCodeEmitter(TheMBlazeTarget,
51 llvm::createMBlazeMCCodeEmitter);
53 // Register the asm backend
54 TargetRegistry::RegisterAsmBackend(TheMBlazeTarget,
55 createMBlazeAsmBackend);
57 // Register the object streamer
58 TargetRegistry::RegisterObjectStreamer(TheMBlazeTarget,
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.
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"),
76 FrameLowering(Subtarget),
77 TLInfo(*this), TSInfo(*this), ELFWriterInfo(*this),
78 InstrItins(Subtarget.getInstrItineraryData()) {
79 if (getRelocationModel() == Reloc::Default) {
80 setRelocationModel(Reloc::Static);
83 if (getCodeModel() == CodeModel::Default)
84 setCodeModel(CodeModel::Small);
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));
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));