4c830541f16a2a0f41f0f656200efb8d6303936e
[oota-llvm.git] / lib / Target / Alpha / AlphaTargetMachine.cpp
1 //===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
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 //
11 //===----------------------------------------------------------------------===//
12
13 #include "Alpha.h"
14 #include "AlphaJITInfo.h"
15 #include "AlphaTargetAsmInfo.h"
16 #include "AlphaTargetMachine.h"
17 #include "llvm/Module.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/Target/TargetMachineRegistry.h"
20 #include "llvm/Support/raw_ostream.h"
21
22 using namespace llvm;
23
24 /// AlphaTargetMachineModule - Note that this is used on hosts that cannot link
25 /// in a library unless there are references into the library.  In particular,
26 /// it seems that it is not possible to get things to work on Win32 without
27 /// this.  Though it is unused, do not remove it.
28 extern "C" int AlphaTargetMachineModule;
29 int AlphaTargetMachineModule = 0;
30
31 // Register the targets
32 static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]");
33
34 const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
35   return new AlphaTargetAsmInfo(*this);
36 }
37
38 unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
39   // We strongly match "alpha*".
40   std::string TT = M.getTargetTriple();
41   if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
42       TT[3] == 'h' && TT[4] == 'a')
43     return 20;
44   // If the target triple is something non-alpha, we don't match.
45   if (!TT.empty()) return 0;
46
47   if (M.getEndianness()  == Module::LittleEndian &&
48       M.getPointerSize() == Module::Pointer64)
49     return 10;                                   // Weak match
50   else if (M.getEndianness() != Module::AnyEndianness ||
51            M.getPointerSize() != Module::AnyPointerSize)
52     return 0;                                    // Match for some other target
53
54   return getJITMatchQuality()/2;
55 }
56
57 unsigned AlphaTargetMachine::getJITMatchQuality() {
58 #ifdef __alpha
59   return 10;
60 #else
61   return 0;
62 #endif
63 }
64
65 AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
66   : DataLayout("e-f128:128:128"),
67     FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
68     JITInfo(*this),
69     Subtarget(M, FS),
70     TLInfo(*this) {
71   setRelocationModel(Reloc::PIC_);
72 }
73
74
75 //===----------------------------------------------------------------------===//
76 // Pass Pipeline Configuration
77 //===----------------------------------------------------------------------===//
78
79 bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM,
80                                          CodeGenOpt::Level OptLevel) {
81   PM.add(createAlphaISelDag(*this));
82   return false;
83 }
84 bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM,
85                                         CodeGenOpt::Level OptLevel) {
86   // Must run branch selection immediately preceding the asm printer
87   PM.add(createAlphaBranchSelectionPass());
88   return false;
89 }
90 bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
91                                             CodeGenOpt::Level OptLevel,
92                                             bool Verbose,
93                                             raw_ostream &Out) {
94   PM.add(createAlphaLLRPPass(*this));
95   PM.add(createAlphaCodePrinterPass(Out, *this, OptLevel, Verbose));
96   return false;
97 }
98 bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
99                                         CodeGenOpt::Level OptLevel,
100                                         bool DumpAsm, MachineCodeEmitter &MCE) {
101   PM.add(createAlphaCodeEmitterPass(*this, MCE));
102   if (DumpAsm)
103     PM.add(createAlphaCodePrinterPass(errs(), *this, OptLevel, true));
104   return false;
105 }
106 bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM,
107                                         CodeGenOpt::Level OptLevel,
108                                         bool DumpAsm, JITCodeEmitter &JCE) {
109   PM.add(createAlphaJITCodeEmitterPass(*this, JCE));
110   if (DumpAsm)
111     PM.add(createAlphaCodePrinterPass(errs(), *this, OptLevel, true));
112   return false;
113 }
114 bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
115                                               CodeGenOpt::Level OptLevel,
116                                               bool DumpAsm,
117                                               MachineCodeEmitter &MCE) {
118   return addCodeEmitter(PM, OptLevel, DumpAsm, MCE);
119 }
120 bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
121                                               CodeGenOpt::Level OptLevel,
122                                               bool DumpAsm,
123                                               JITCodeEmitter &JCE) {
124   return addCodeEmitter(PM, OptLevel, DumpAsm, JCE);
125 }
126