1 //===-- IA64TargetMachine.cpp - Define TargetMachine for IA64 -------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file defines the IA64 specific subclass of TargetMachine.
12 //===----------------------------------------------------------------------===//
14 #include "IA64TargetMachine.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"
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.
32 extern "C" int IA64TargetMachineModule;
33 int IA64TargetMachineModule = 0;
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."));
40 cl::opt<bool> EnableDAGIsel("enable-ia64-dag-isel", cl::Hidden,
41 cl::desc("Enable the IA64 DAG->DAG isel"));
43 // Register the target.
44 RegisterTarget<IA64TargetMachine> X("ia64", " IA-64 (Itanium)");
47 unsigned IA64TargetMachine::compileTimeMatchQuality() {
48 #if defined(__ia64__) || defined(__IA64__)
55 unsigned IA64TargetMachine::getModuleMatchQuality(const Module &M) {
56 // we match [iI][aA]*64
58 std::string TT = M.getTargetTriple();
61 if( (TT[0]=='i' || TT[0]=='I') &&
62 (TT[1]=='a' || TT[1]=='A') ) {
63 for(unsigned int i=2; i<(TT.size()-1); i++)
64 if(TT[i]=='6' && TT[i+1]=='4')
69 return 50; // strong match
72 return compileTimeMatchQuality()/2;
76 /// IA64TargetMachine ctor - Create an LP64 architecture model
78 IA64TargetMachine::IA64TargetMachine(const Module &M, IntrinsicLowering *IL,
79 const std::string &FS)
80 : TargetMachine("IA64", IL, true),
81 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0) { // FIXME? check this stuff
84 // addPassesToEmitFile - We currently use all of the same passes as the JIT
85 // does to emit statically compiled machine code.
86 bool IA64TargetMachine::addPassesToEmitFile(PassManager &PM,
88 CodeGenFileType FileType) {
89 if (FileType != TargetMachine::AssemblyFile) return true;
91 // FIXME: Implement efficient support for garbage collection intrinsics.
92 PM.add(createLowerGCPass());
94 // FIXME: Implement the invoke/unwind instructions!
95 PM.add(createLowerInvokePass());
97 // FIXME: Implement the switch instruction in the instruction selector!
98 PM.add(createLowerSwitchPass());
100 // Make sure that no unreachable blocks are instruction selected.
101 PM.add(createUnreachableBlockEliminationPass());
103 // Add an instruction selector
105 PM.add(createIA64DAGToDAGInstructionSelector(*this));
107 PM.add(createIA64PatternInstructionSelector(*this));
110 // Run optional SSA-based machine code optimizations next...
112 PM.add(createIA64SSAPeepholeOptimizerPass());
115 // Print the instruction selected machine code...
116 if (PrintMachineCode)
117 PM.add(createMachineFunctionPrinterPass(&std::cerr));
119 // Perform register allocation to convert to a concrete IA64 representation
120 PM.add(createRegisterAllocator());
122 if (PrintMachineCode)
123 PM.add(createMachineFunctionPrinterPass(&std::cerr));
125 if (PrintMachineCode)
126 PM.add(createMachineFunctionPrinterPass(&std::cerr));
128 // Insert prolog/epilog code. Eliminate abstract frame index references...
129 PM.add(createPrologEpilogCodeInserter());
131 /* XXX no, not just yet */
132 // PM.add(createIA64PeepholeOptimizerPass());
134 if (PrintMachineCode) // Print the register-allocated code
135 PM.add(createIA64CodePrinterPass(std::cerr, *this));
138 PM.add(createIA64CodePrinterPass(Out, *this));
140 // Delete machine code for this function
141 PM.add(createMachineCodeDeleter());
143 return false; // success!