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, const std::string &FS)
57 : TargetMachine("alpha"), DataLayout("e"),
58 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
62 DEBUG(std::cerr << "FS is " << FS << "\n");
65 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
66 /// a static compiler for this target.
68 bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
70 CodeGenFileType FileType,
72 if (FileType != TargetMachine::AssemblyFile) return true;
74 PM.add(createLoopStrengthReducePass());
75 PM.add(createCFGSimplificationPass());
78 // FIXME: Implement efficient support for garbage collection intrinsics.
79 PM.add(createLowerGCPass());
81 // FIXME: Implement the invoke/unwind instructions!
82 PM.add(createLowerInvokePass());
84 // Make sure that no unreachable blocks are instruction selected.
85 PM.add(createUnreachableBlockEliminationPass());
87 PM.add(createAlphaISelDag(*this));
90 PM.add(createMachineFunctionPrinterPass(&std::cerr));
92 PM.add(createRegisterAllocator());
95 PM.add(createMachineFunctionPrinterPass(&std::cerr));
97 PM.add(createPrologEpilogCodeInserter());
99 // Must run branch selection immediately preceding the asm printer
100 //PM.add(createAlphaBranchSelectionPass());
102 PM.add(createAlphaCodePrinterPass(Out, *this));
104 PM.add(createMachineCodeDeleter());
108 void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
110 PM.add(createLoopStrengthReducePass());
111 PM.add(createCFGSimplificationPass());
113 // FIXME: Implement efficient support for garbage collection intrinsics.
114 PM.add(createLowerGCPass());
116 // FIXME: Implement the invoke/unwind instructions!
117 PM.add(createLowerInvokePass());
119 // Make sure that no unreachable blocks are instruction selected.
120 PM.add(createUnreachableBlockEliminationPass());
122 PM.add(createAlphaISelDag(TM));
124 if (PrintMachineCode)
125 PM.add(createMachineFunctionPrinterPass(&std::cerr));
127 PM.add(createRegisterAllocator());
129 if (PrintMachineCode)
130 PM.add(createMachineFunctionPrinterPass(&std::cerr));
132 PM.add(createPrologEpilogCodeInserter());
134 // Must run branch selection immediately preceding the asm printer
135 //PM.add(createAlphaBranchSelectionPass());
139 bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
140 MachineCodeEmitter &MCE) {
141 PM.add(createAlphaCodeEmitterPass(MCE));
142 // Delete machine code for this function
143 PM.add(createMachineCodeDeleter());