blob: f6e0ed1d3aa3219ee21d1ace8009fc0279605ea2 [file] [log] [blame]
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001//===-- IA64TargetMachine.cpp - Define TargetMachine for IA64 -------------===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00002//
Duraid Madina9b9d45f2005-03-17 18:17:03 +00003// 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.
Misha Brukman4633f1c2005-04-21 23:13:11 +00007//
Duraid Madina9b9d45f2005-03-17 18:17:03 +00008//===----------------------------------------------------------------------===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00009//
Duraid Madina9b9d45f2005-03-17 18:17:03 +000010// This file defines the IA64 specific subclass of TargetMachine.
11//
12//===----------------------------------------------------------------------===//
13
14#include "IA64TargetMachine.h"
15#include "IA64.h"
16#include "llvm/Module.h"
17#include "llvm/PassManager.h"
18#include "llvm/CodeGen/IntrinsicLowering.h"
19#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/Passes.h"
21#include "llvm/Target/TargetOptions.h"
22#include "llvm/Target/TargetMachineRegistry.h"
23#include "llvm/Transforms/Scalar.h"
24#include "llvm/Support/CommandLine.h"
25#include "llvm/ADT/Statistic.h"
26using namespace llvm;
27
28/// IA64TargetMachineModule - Note that this is used on hosts that cannot link
29/// in a library unless there are references into the library. In particular,
30/// it seems that it is not possible to get things to work on Win32 without
31/// this. Though it is unused, do not remove it.
32extern "C" int IA64TargetMachineModule;
33int IA64TargetMachineModule = 0;
34
35namespace {
36 cl::opt<bool> DisableOutput("disable-ia64-llc-output", cl::Hidden,
37 cl::desc("Disable the IA64 asm printer, for use "
38 "when profiling the code generator."));
39
40 // Register the target.
41 RegisterTarget<IA64TargetMachine> X("ia64", " IA-64 (Itanium)");
42}
43
44unsigned IA64TargetMachine::compileTimeMatchQuality() {
45#if defined(__ia64__) || defined(__IA64__)
46 return 50;
47#else
48 return 0;
49#endif
50}
51
52unsigned IA64TargetMachine::getModuleMatchQuality(const Module &M) {
53 // we match [iI][aA]*64
54 bool seenIA64=false;
55 std::string TT = M.getTargetTriple();
56
57 if (TT.size() >= 4) {
58 if( (TT[0]=='i' || TT[0]=='I') &&
59 (TT[1]=='a' || TT[1]=='A') ) {
60 for(unsigned int i=2; i<(TT.size()-1); i++)
61 if(TT[i]=='6' && TT[i+1]=='4')
62 seenIA64=true;
63 }
64
65 if(seenIA64)
66 return 50; // strong match
67 }
68
69 return compileTimeMatchQuality()/2;
70
71}
72
73/// IA64TargetMachine ctor - Create an LP64 architecture model
74///
75IA64TargetMachine::IA64TargetMachine(const Module &M, IntrinsicLowering *IL)
76 : TargetMachine("IA64", IL, true),
77 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0) { // FIXME? check this stuff
78}
79
80// addPassesToEmitAssembly - We currently use all of the same passes as the JIT
81// does to emit statically compiled machine code.
82bool IA64TargetMachine::addPassesToEmitAssembly(PassManager &PM,
83 std::ostream &Out) {
84 // FIXME: Implement efficient support for garbage collection intrinsics.
85 PM.add(createLowerGCPass());
86
87 // FIXME: Implement the invoke/unwind instructions!
88 PM.add(createLowerInvokePass());
89
90 // FIXME: Implement the switch instruction in the instruction selector!
91 PM.add(createLowerSwitchPass());
92
93 // Make sure that no unreachable blocks are instruction selected.
94 PM.add(createUnreachableBlockEliminationPass());
95
96 PM.add(createIA64PatternInstructionSelector(*this));
97
98/* XXX not yet. ;)
99 // Run optional SSA-based machine code optimizations next...
100 if (!NoSSAPeephole)
101 PM.add(createIA64SSAPeepholeOptimizerPass());
102*/
103
104 // Print the instruction selected machine code...
105 if (PrintMachineCode)
106 PM.add(createMachineFunctionPrinterPass(&std::cerr));
107
108 // Perform register allocation to convert to a concrete IA64 representation
109 PM.add(createRegisterAllocator());
110
111 if (PrintMachineCode)
112 PM.add(createMachineFunctionPrinterPass(&std::cerr));
113
114 if (PrintMachineCode)
115 PM.add(createMachineFunctionPrinterPass(&std::cerr));
116
117 // Insert prolog/epilog code. Eliminate abstract frame index references...
118 PM.add(createPrologEpilogCodeInserter());
119
120/* XXX no, not just yet */
121// PM.add(createIA64PeepholeOptimizerPass());
122
123 if (PrintMachineCode) // Print the register-allocated code
124 PM.add(createIA64CodePrinterPass(std::cerr, *this));
125
126 if (!DisableOutput)
127 PM.add(createIA64CodePrinterPass(Out, *this));
128
129 // Delete machine code for this function
130 PM.add(createMachineCodeDeleter());
131
132 return false; // success!
133}
134