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)");
32 cl::opt<bool> EnableAlphaDAG("enable-dag-isel-for-alpha",
33 cl::desc("Enable DAG ISEL for Alpha (beta option!)"),
37 unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
38 // We strongly match "alpha*".
39 std::string TT = M.getTargetTriple();
40 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
41 TT[3] == 'h' && TT[4] == 'a')
44 if (M.getEndianness() == Module::LittleEndian &&
45 M.getPointerSize() == Module::Pointer64)
46 return 10; // Weak match
47 else if (M.getEndianness() != Module::AnyEndianness ||
48 M.getPointerSize() != Module::AnyPointerSize)
49 return 0; // Match for some other target
51 return getJITMatchQuality()/2;
54 unsigned AlphaTargetMachine::getJITMatchQuality() {
62 AlphaTargetMachine::AlphaTargetMachine(const Module &M, IntrinsicLowering *IL,
63 const std::string &FS)
64 : TargetMachine("alpha", IL, true),
65 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
69 DEBUG(std::cerr << "FS is " << FS << "\n");
72 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
73 /// a static compiler for this target.
75 bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
77 CodeGenFileType FileType,
79 if (FileType != TargetMachine::AssemblyFile) return true;
81 PM.add(createLoopStrengthReducePass());
82 PM.add(createCFGSimplificationPass());
85 // FIXME: Implement efficient support for garbage collection intrinsics.
86 PM.add(createLowerGCPass());
88 // FIXME: Implement the invoke/unwind instructions!
89 PM.add(createLowerInvokePass());
91 // FIXME: Implement the switch instruction in the instruction selector!
92 PM.add(createLowerSwitchPass());
94 // Make sure that no unreachable blocks are instruction selected.
95 PM.add(createUnreachableBlockEliminationPass());
98 PM.add(createAlphaISelDag(*this));
100 PM.add(createAlphaPatternInstructionSelector(*this));
102 if (PrintMachineCode)
103 PM.add(createMachineFunctionPrinterPass(&std::cerr));
105 PM.add(createRegisterAllocator());
107 if (PrintMachineCode)
108 PM.add(createMachineFunctionPrinterPass(&std::cerr));
110 PM.add(createPrologEpilogCodeInserter());
112 // Must run branch selection immediately preceding the asm printer
113 //PM.add(createAlphaBranchSelectionPass());
115 PM.add(createAlphaCodePrinterPass(Out, *this));
117 PM.add(createMachineCodeDeleter());
121 void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
123 PM.add(createLoopStrengthReducePass());
124 PM.add(createCFGSimplificationPass());
126 // FIXME: Implement efficient support for garbage collection intrinsics.
127 PM.add(createLowerGCPass());
129 // FIXME: Implement the invoke/unwind instructions!
130 PM.add(createLowerInvokePass());
132 // FIXME: Implement the switch instruction in the instruction selector!
133 PM.add(createLowerSwitchPass());
135 // Make sure that no unreachable blocks are instruction selected.
136 PM.add(createUnreachableBlockEliminationPass());
138 PM.add(createAlphaPatternInstructionSelector(TM));
140 if (PrintMachineCode)
141 PM.add(createMachineFunctionPrinterPass(&std::cerr));
143 PM.add(createRegisterAllocator());
145 if (PrintMachineCode)
146 PM.add(createMachineFunctionPrinterPass(&std::cerr));
148 PM.add(createPrologEpilogCodeInserter());
150 // Must run branch selection immediately preceding the asm printer
151 //PM.add(createAlphaBranchSelectionPass());
155 bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
156 MachineCodeEmitter &MCE) {
157 PM.add(createAlphaCodeEmitterPass(MCE));
158 // Delete machine code for this function
159 PM.add(createMachineCodeDeleter());