blob: 0c5ae0d67c64474610bff2a51c0a79a71a198af3 [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"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000018#include "llvm/CodeGen/MachineFunction.h"
19#include "llvm/CodeGen/Passes.h"
20#include "llvm/Target/TargetOptions.h"
21#include "llvm/Target/TargetMachineRegistry.h"
22#include "llvm/Transforms/Scalar.h"
23#include "llvm/Support/CommandLine.h"
24#include "llvm/ADT/Statistic.h"
Chris Lattner2c2c6c62006-01-22 23:41:00 +000025#include <iostream>
Duraid Madina9b9d45f2005-03-17 18:17:03 +000026using 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
Duraid Madinaf2db9b82005-10-28 17:46:35 +000040 cl::opt<bool> EnableDAGIsel("enable-ia64-dag-isel", cl::Hidden,
41 cl::desc("Enable the IA64 DAG->DAG isel"));
42
Duraid Madina9b9d45f2005-03-17 18:17:03 +000043 // Register the target.
44 RegisterTarget<IA64TargetMachine> X("ia64", " IA-64 (Itanium)");
45}
46
47unsigned IA64TargetMachine::compileTimeMatchQuality() {
48#if defined(__ia64__) || defined(__IA64__)
49 return 50;
50#else
51 return 0;
52#endif
53}
54
55unsigned IA64TargetMachine::getModuleMatchQuality(const Module &M) {
56 // we match [iI][aA]*64
57 bool seenIA64=false;
58 std::string TT = M.getTargetTriple();
59
60 if (TT.size() >= 4) {
61 if( (TT[0]=='i' || TT[0]=='I') &&
Misha Brukman7847fca2005-04-22 17:54:37 +000062 (TT[1]=='a' || TT[1]=='A') ) {
Duraid Madina9b9d45f2005-03-17 18:17:03 +000063 for(unsigned int i=2; i<(TT.size()-1); i++)
Misha Brukman7847fca2005-04-22 17:54:37 +000064 if(TT[i]=='6' && TT[i+1]=='4')
65 seenIA64=true;
Duraid Madina9b9d45f2005-03-17 18:17:03 +000066 }
67
68 if(seenIA64)
69 return 50; // strong match
70 }
71
72 return compileTimeMatchQuality()/2;
73
74}
75
76/// IA64TargetMachine ctor - Create an LP64 architecture model
77///
Chris Lattnerbc641b92006-03-23 05:43:16 +000078IA64TargetMachine::IA64TargetMachine(const Module &M, const std::string &FS)
Chris Lattner1790d442006-06-16 18:22:52 +000079 : TargetMachine("IA64"), DataLayout("e"),
Evan Chengc4c62572006-03-13 23:20:37 +000080 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
81 TLInfo(*this) { // FIXME? check this stuff
Duraid Madina9b9d45f2005-03-17 18:17:03 +000082}
83
Chris Lattner0431c962005-06-25 02:48:37 +000084// addPassesToEmitFile - We currently use all of the same passes as the JIT
Duraid Madina9b9d45f2005-03-17 18:17:03 +000085// does to emit statically compiled machine code.
Chris Lattner0431c962005-06-25 02:48:37 +000086bool IA64TargetMachine::addPassesToEmitFile(PassManager &PM,
87 std::ostream &Out,
Chris Lattnerce8eb0c2005-11-08 02:11:51 +000088 CodeGenFileType FileType,
89 bool Fast) {
Chris Lattner0431c962005-06-25 02:48:37 +000090 if (FileType != TargetMachine::AssemblyFile) return true;
91
Duraid Madina9b9d45f2005-03-17 18:17:03 +000092 // FIXME: Implement efficient support for garbage collection intrinsics.
93 PM.add(createLowerGCPass());
94
95 // FIXME: Implement the invoke/unwind instructions!
Duraid Madina21687e82005-11-06 04:29:30 +000096 PM.add(createLowerInvokePass(704, 16)); // on ia64 linux, jmpbufs are 704
97 // bytes and must be 16byte aligned
Duraid Madina9b9d45f2005-03-17 18:17:03 +000098
Duraid Madina9b9d45f2005-03-17 18:17:03 +000099 // Make sure that no unreachable blocks are instruction selected.
100 PM.add(createUnreachableBlockEliminationPass());
101
Duraid Madinaf2db9b82005-10-28 17:46:35 +0000102 // Add an instruction selector
Duraid Madinac5f24702006-01-19 14:13:11 +0000103// FIXME: reap this option one day: if(EnableDAGIsel)
104 PM.add(createIA64DAGToDAGInstructionSelector(*this));
Duraid Madinabadf0d92006-01-25 02:23:38 +0000105
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000106/* XXX not yet. ;)
107 // Run optional SSA-based machine code optimizations next...
108 if (!NoSSAPeephole)
109 PM.add(createIA64SSAPeepholeOptimizerPass());
110*/
111
112 // Print the instruction selected machine code...
113 if (PrintMachineCode)
114 PM.add(createMachineFunctionPrinterPass(&std::cerr));
115
116 // Perform register allocation to convert to a concrete IA64 representation
117 PM.add(createRegisterAllocator());
118
119 if (PrintMachineCode)
120 PM.add(createMachineFunctionPrinterPass(&std::cerr));
121
122 if (PrintMachineCode)
123 PM.add(createMachineFunctionPrinterPass(&std::cerr));
124
125 // Insert prolog/epilog code. Eliminate abstract frame index references...
126 PM.add(createPrologEpilogCodeInserter());
127
128/* XXX no, not just yet */
129// PM.add(createIA64PeepholeOptimizerPass());
130
Duraid Madinabadf0d92006-01-25 02:23:38 +0000131 // Make sure everything is bundled happily
132 PM.add(createIA64BundlingPass(*this));
133
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000134 if (PrintMachineCode) // Print the register-allocated code
135 PM.add(createIA64CodePrinterPass(std::cerr, *this));
136
137 if (!DisableOutput)
138 PM.add(createIA64CodePrinterPass(Out, *this));
139
140 // Delete machine code for this function
141 PM.add(createMachineCodeDeleter());
142
143 return false; // success!
144}
145