1 //===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
14 #include "AlphaJITInfo.h"
15 #include "AlphaTargetMachine.h"
16 #include "llvm/Module.h"
17 #include "llvm/CodeGen/Passes.h"
18 #include "llvm/Target/TargetOptions.h"
19 #include "llvm/Target/TargetMachineRegistry.h"
20 #include "llvm/Transforms/Scalar.h"
21 #include "llvm/Support/Debug.h"
27 // Register the targets
28 RegisterTarget<AlphaTargetMachine> X("alpha", " Alpha (incomplete)");
31 unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
32 // We strongly match "alpha*".
33 std::string TT = M.getTargetTriple();
34 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
35 TT[3] == 'h' && TT[4] == 'a')
38 if (M.getEndianness() == Module::LittleEndian &&
39 M.getPointerSize() == Module::Pointer64)
40 return 10; // Weak match
41 else if (M.getEndianness() != Module::AnyEndianness ||
42 M.getPointerSize() != Module::AnyPointerSize)
43 return 0; // Match for some other target
45 return getJITMatchQuality()/2;
48 unsigned AlphaTargetMachine::getJITMatchQuality() {
56 AlphaTargetMachine::AlphaTargetMachine(const Module &M, IntrinsicLowering *IL,
57 const std::string &FS)
58 : TargetMachine("alpha", IL, true),
59 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
63 DEBUG(std::cerr << "FS is " << FS << "\n");
66 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
67 /// a static compiler for this target.
69 bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
71 CodeGenFileType FileType,
73 if (FileType != TargetMachine::AssemblyFile) return true;
75 PM.add(createLoopStrengthReducePass());
76 PM.add(createCFGSimplificationPass());
79 // FIXME: Implement efficient support for garbage collection intrinsics.
80 PM.add(createLowerGCPass());
82 // FIXME: Implement the invoke/unwind instructions!
83 PM.add(createLowerInvokePass());
85 // FIXME: Implement the switch instruction in the instruction selector!
86 PM.add(createLowerSwitchPass());
88 // Make sure that no unreachable blocks are instruction selected.
89 PM.add(createUnreachableBlockEliminationPass());
91 PM.add(createAlphaISelDag(*this));
94 PM.add(createMachineFunctionPrinterPass(&std::cerr));
96 PM.add(createRegisterAllocator());
99 PM.add(createMachineFunctionPrinterPass(&std::cerr));
101 PM.add(createPrologEpilogCodeInserter());
103 // Must run branch selection immediately preceding the asm printer
104 //PM.add(createAlphaBranchSelectionPass());
106 PM.add(createAlphaCodePrinterPass(Out, *this));
108 PM.add(createMachineCodeDeleter());
112 void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
114 PM.add(createLoopStrengthReducePass());
115 PM.add(createCFGSimplificationPass());
117 // FIXME: Implement efficient support for garbage collection intrinsics.
118 PM.add(createLowerGCPass());
120 // FIXME: Implement the invoke/unwind instructions!
121 PM.add(createLowerInvokePass());
123 // FIXME: Implement the switch instruction in the instruction selector!
124 PM.add(createLowerSwitchPass());
126 // Make sure that no unreachable blocks are instruction selected.
127 PM.add(createUnreachableBlockEliminationPass());
129 PM.add(createAlphaISelDag(TM));
131 if (PrintMachineCode)
132 PM.add(createMachineFunctionPrinterPass(&std::cerr));
134 PM.add(createRegisterAllocator());
136 if (PrintMachineCode)
137 PM.add(createMachineFunctionPrinterPass(&std::cerr));
139 PM.add(createPrologEpilogCodeInserter());
141 // Must run branch selection immediately preceding the asm printer
142 //PM.add(createAlphaBranchSelectionPass());
146 bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
147 MachineCodeEmitter &MCE) {
148 PM.add(createAlphaCodeEmitterPass(MCE));
149 // Delete machine code for this function
150 PM.add(createMachineCodeDeleter());