Remove some redundant checks, add a couple of new ones. This allows us to
[oota-llvm.git] / lib / Target / Alpha / AlphaTargetMachine.cpp
1 //===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 // 
8 //===----------------------------------------------------------------------===//
9 // 
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "Alpha.h"
14 #include "AlphaTargetMachine.h"
15 #include "llvm/Module.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/Target/TargetOptions.h"
18 #include "llvm/Target/TargetMachineRegistry.h"
19 #include "llvm/Transforms/Scalar.h"
20 #include <iostream>
21
22 using namespace llvm;
23
24 namespace {
25   // Register the targets
26   RegisterTarget<AlphaTargetMachine> X("alpha", "  Alpha (incomplete)");
27 }
28
29 namespace llvm {
30   cl::opt<bool> EnableAlphaLSR("enable-lsr-for-alpha", 
31                              cl::desc("Enable LSR for Alpha (beta option!)"), 
32                              cl::Hidden);
33 }
34
35 unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
36   // We strongly match "alpha*".
37   std::string TT = M.getTargetTriple();
38   if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
39       TT[3] == 'h' && TT[4] == 'a')
40     return 20;
41
42   if (M.getEndianness()  == Module::LittleEndian &&
43       M.getPointerSize() == Module::Pointer64)
44     return 10;                                   // Weak match
45   else if (M.getEndianness() != Module::AnyEndianness ||
46            M.getPointerSize() != Module::AnyPointerSize)
47     return 0;                                    // Match for some other target
48
49   return 0;
50 }
51
52 AlphaTargetMachine::AlphaTargetMachine( const Module &M, IntrinsicLowering *IL)
53   : TargetMachine("alpha", IL, true), 
54     FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) //TODO: check these
55 {}
56
57 /// addPassesToEmitAssembly - Add passes to the specified pass manager
58 /// to implement a static compiler for this target.
59 ///
60 bool AlphaTargetMachine::addPassesToEmitAssembly(PassManager &PM,
61                                                    std::ostream &Out) {
62   
63   if (EnableAlphaLSR) {
64     PM.add(createLoopStrengthReducePass());
65     PM.add(createCFGSimplificationPass());
66   }
67
68   // FIXME: Implement efficient support for garbage collection intrinsics.
69   PM.add(createLowerGCPass());
70
71   // FIXME: Implement the invoke/unwind instructions!
72   PM.add(createLowerInvokePass());
73
74   // FIXME: Implement the switch instruction in the instruction selector!
75   PM.add(createLowerSwitchPass());
76
77   // Make sure that no unreachable blocks are instruction selected.
78   PM.add(createUnreachableBlockEliminationPass());
79
80   PM.add(createAlphaPatternInstructionSelector(*this));
81
82   if (PrintMachineCode)
83     PM.add(createMachineFunctionPrinterPass(&std::cerr));
84
85   PM.add(createRegisterAllocator());
86
87   if (PrintMachineCode)
88     PM.add(createMachineFunctionPrinterPass(&std::cerr));
89
90   PM.add(createPrologEpilogCodeInserter());
91   
92   // Must run branch selection immediately preceding the asm printer
93   //PM.add(createAlphaBranchSelectionPass());
94   
95   PM.add(createAlphaCodePrinterPass(Out, *this));
96     
97   PM.add(createMachineCodeDeleter());
98   return false;
99 }