Adding the MicroBlaze backend.
[oota-llvm.git] / 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 "MBlazeMCAsmInfo.h"
16 #include "MBlazeTargetMachine.h"
17 #include "llvm/PassManager.h"
18 #include "llvm/Target/TargetRegistry.h"
19 using namespace llvm;
20
21 extern "C" void LLVMInitializeMBlazeTarget() {
22   // Register the target.
23   RegisterTargetMachine<MBlazeTargetMachine> X(TheMBlazeTarget);
24   RegisterAsmInfo<MBlazeMCAsmInfo> A(TheMBlazeTarget);
25 }
26
27 // DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
28 // The stack is always 8 byte aligned
29 // On function prologue, the stack is created by decrementing
30 // its pointer. Once decremented, all references are done with positive
31 // offset from the stack/frame pointer, using StackGrowsUp enables
32 // an easier handling.
33 MBlazeTargetMachine::
34 MBlazeTargetMachine(const Target &T, const std::string &TT,
35                     const std::string &FS):
36   LLVMTargetMachine(T, TT),
37   Subtarget(TT, FS),
38   DataLayout("E-p:32:32-i8:8:8-i16:16:16-i64:32:32-"
39              "f64:32:32-v64:32:32-v128:32:32-n32"),
40   InstrInfo(*this),
41   FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0),
42   TLInfo(*this) {
43   if (getRelocationModel() == Reloc::Default) {
44       setRelocationModel(Reloc::Static);
45   }
46
47   if (getCodeModel() == CodeModel::Default)
48     setCodeModel(CodeModel::Small);
49 }
50
51 // Install an instruction selector pass using
52 // the ISelDag to gen MBlaze code.
53 bool MBlazeTargetMachine::
54 addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
55   PM.add(createMBlazeISelDag(*this));
56   return false;
57 }
58
59 // Implemented by targets that want to run passes immediately before
60 // machine code is emitted. return true if -print-machineinstrs should
61 // print out the code after the passes.
62 bool MBlazeTargetMachine::
63 addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
64   PM.add(createMBlazeDelaySlotFillerPass(*this));
65   return true;
66 }