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