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"),
58 DataLayout(std::string("alpha"), std::string("e")),
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 // Make sure that no unreachable blocks are instruction selected.
86 PM.add(createUnreachableBlockEliminationPass());
88 PM.add(createAlphaISelDag(*this));
91 PM.add(createMachineFunctionPrinterPass(&std::cerr));
93 PM.add(createRegisterAllocator());
96 PM.add(createMachineFunctionPrinterPass(&std::cerr));
98 PM.add(createPrologEpilogCodeInserter());
100 // Must run branch selection immediately preceding the asm printer
101 //PM.add(createAlphaBranchSelectionPass());
103 PM.add(createAlphaCodePrinterPass(Out, *this));
105 PM.add(createMachineCodeDeleter());
109 void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
111 PM.add(createLoopStrengthReducePass());
112 PM.add(createCFGSimplificationPass());
114 // FIXME: Implement efficient support for garbage collection intrinsics.
115 PM.add(createLowerGCPass());
117 // FIXME: Implement the invoke/unwind instructions!
118 PM.add(createLowerInvokePass());
120 // Make sure that no unreachable blocks are instruction selected.
121 PM.add(createUnreachableBlockEliminationPass());
123 PM.add(createAlphaISelDag(TM));
125 if (PrintMachineCode)
126 PM.add(createMachineFunctionPrinterPass(&std::cerr));
128 PM.add(createRegisterAllocator());
130 if (PrintMachineCode)
131 PM.add(createMachineFunctionPrinterPass(&std::cerr));
133 PM.add(createPrologEpilogCodeInserter());
135 // Must run branch selection immediately preceding the asm printer
136 //PM.add(createAlphaBranchSelectionPass());
140 bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
141 MachineCodeEmitter &MCE) {
142 PM.add(createAlphaCodeEmitterPass(MCE));
143 // Delete machine code for this function
144 PM.add(createMachineCodeDeleter());