More templatization.
[oota-llvm.git] / lib / Target / IA64 / IA64TargetMachine.cpp
1 //===-- IA64TargetMachine.cpp - Define TargetMachine for IA64 -------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Duraid Madina and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the IA64 specific subclass of TargetMachine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "IA64TargetAsmInfo.h"
15 #include "IA64TargetMachine.h"
16 #include "IA64.h"
17 #include "llvm/Module.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/Target/TargetMachineRegistry.h"
20 using namespace llvm;
21
22 /// IA64TargetMachineModule - Note that this is used on hosts that cannot link
23 /// in a library unless there are references into the library.  In particular,
24 /// it seems that it is not possible to get things to work on Win32 without
25 /// this.  Though it is unused, do not remove it.
26 extern "C" int IA64TargetMachineModule;
27 int IA64TargetMachineModule = 0;
28
29 namespace {
30   RegisterTarget<IA64TargetMachine> X("ia64", "  IA-64 (Itanium)");
31 }
32
33 const TargetAsmInfo *IA64TargetMachine::createTargetAsmInfo() const {
34   return new IA64TargetAsmInfo(*this);
35 }
36
37 unsigned IA64TargetMachine::getModuleMatchQuality(const Module &M) {
38   // we match [iI][aA]*64
39   bool seenIA64=false;
40   std::string TT = M.getTargetTriple();
41
42   if (TT.size() >= 4) {
43     if( (TT[0]=='i' || TT[0]=='I') &&
44         (TT[1]=='a' || TT[1]=='A') ) {
45       for(unsigned int i=2; i<(TT.size()-1); i++)
46         if(TT[i]=='6' && TT[i+1]=='4')
47           seenIA64=true;
48     }
49
50     if (seenIA64)
51       return 20; // strong match
52   }
53   // If the target triple is something non-ia64, we don't match.
54   if (!TT.empty()) return 0;
55
56 #if defined(__ia64__) || defined(__IA64__)
57   return 5;
58 #else
59   return 0;
60 #endif
61 }
62
63 /// IA64TargetMachine ctor - Create an LP64 architecture model
64 ///
65 IA64TargetMachine::IA64TargetMachine(const Module &M, const std::string &FS)
66   : DataLayout("e-f80:128:128"),
67     FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
68     TLInfo(*this) { // FIXME? check this stuff
69 }
70
71
72 //===----------------------------------------------------------------------===//
73 // Pass Pipeline Configuration
74 //===----------------------------------------------------------------------===//
75
76 bool IA64TargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
77   PM.add(createIA64DAGToDAGInstructionSelector(*this));
78   return false;
79 }
80
81 bool IA64TargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
82   // Make sure everything is bundled happily
83   PM.add(createIA64BundlingPass(*this));
84   return true;
85 }
86 bool IA64TargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 
87                                            std::ostream &Out) {
88   PM.add(createIA64CodePrinterPass(Out, *this));
89   return false;
90 }
91