Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 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 "MBlazeMCAsmInfo.h" |
| 16 | #include "MBlazeTargetMachine.h" |
| 17 | #include "llvm/PassManager.h" |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/Passes.h" |
| 19 | #include "llvm/Support/FormattedStream.h" |
| 20 | #include "llvm/Target/TargetOptions.h" |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetRegistry.h" |
| 22 | using namespace llvm; |
| 23 | |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 24 | static MCStreamer *createMCStreamer(const Target &T, const std::string &TT, |
| 25 | MCContext &Ctx, TargetAsmBackend &TAB, |
| 26 | raw_ostream &_OS, |
| 27 | MCCodeEmitter *_Emitter, |
| 28 | bool RelaxAll) { |
| 29 | Triple TheTriple(TT); |
| 30 | switch (TheTriple.getOS()) { |
| 31 | case Triple::Darwin: |
| 32 | llvm_unreachable("MBlaze does not support Darwin MACH-O format"); |
| 33 | return NULL; |
| 34 | case Triple::MinGW32: |
| 35 | case Triple::MinGW64: |
| 36 | case Triple::Cygwin: |
| 37 | case Triple::Win32: |
| 38 | llvm_unreachable("ARM does not support Windows COFF format"); |
| 39 | return NULL; |
| 40 | default: |
| 41 | return createELFStreamer(Ctx, TAB, _OS, _Emitter, RelaxAll); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 46 | extern "C" void LLVMInitializeMBlazeTarget() { |
| 47 | // Register the target. |
| 48 | RegisterTargetMachine<MBlazeTargetMachine> X(TheMBlazeTarget); |
| 49 | RegisterAsmInfo<MBlazeMCAsmInfo> A(TheMBlazeTarget); |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 50 | |
| 51 | // Register the MC code emitter |
| 52 | TargetRegistry::RegisterCodeEmitter(TheMBlazeTarget, |
| 53 | llvm::createMBlazeMCCodeEmitter); |
| 54 | |
| 55 | // Register the asm backend |
| 56 | TargetRegistry::RegisterAsmBackend(TheMBlazeTarget, |
| 57 | createMBlazeAsmBackend); |
| 58 | |
| 59 | // Register the object streamer |
| 60 | TargetRegistry::RegisterObjectStreamer(TheMBlazeTarget, |
| 61 | createMCStreamer); |
| 62 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // DataLayout --> Big-endian, 32-bit pointer/ABI/alignment |
| 66 | // The stack is always 8 byte aligned |
| 67 | // On function prologue, the stack is created by decrementing |
| 68 | // its pointer. Once decremented, all references are done with positive |
| 69 | // offset from the stack/frame pointer, using StackGrowsUp enables |
| 70 | // an easier handling. |
| 71 | MBlazeTargetMachine:: |
| 72 | MBlazeTargetMachine(const Target &T, const std::string &TT, |
| 73 | const std::string &FS): |
| 74 | LLVMTargetMachine(T, TT), |
| 75 | Subtarget(TT, FS), |
Wesley Peck | 4da992a | 2010-10-21 19:48:38 +0000 | [diff] [blame^] | 76 | DataLayout("E-p:32:32:32-i8:8:8-i16:16:16"), |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 77 | InstrInfo(*this), |
| 78 | FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0), |
Wesley Peck | 4e9141f | 2010-10-21 03:57:26 +0000 | [diff] [blame] | 79 | TLInfo(*this), TSInfo(*this), ELFWriterInfo(*this) { |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 80 | if (getRelocationModel() == Reloc::Default) { |
| 81 | setRelocationModel(Reloc::Static); |
| 82 | } |
| 83 | |
| 84 | if (getCodeModel() == CodeModel::Default) |
| 85 | setCodeModel(CodeModel::Small); |
| 86 | } |
| 87 | |
| 88 | // Install an instruction selector pass using |
| 89 | // the ISelDag to gen MBlaze code. |
| 90 | bool MBlazeTargetMachine:: |
| 91 | addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel) { |
| 92 | PM.add(createMBlazeISelDag(*this)); |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | // Implemented by targets that want to run passes immediately before |
| 97 | // machine code is emitted. return true if -print-machineinstrs should |
| 98 | // print out the code after the passes. |
| 99 | bool MBlazeTargetMachine:: |
| 100 | addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel) { |
| 101 | PM.add(createMBlazeDelaySlotFillerPass(*this)); |
| 102 | return true; |
| 103 | } |