blob: 80a88662a12e745eb52b0545ef6782d7b8c57990 [file] [log] [blame]
Andrew Lenharth886470e2005-01-24 18:45:41 +00001//===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002//
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"
Andrew Lenharth2f401632005-02-01 20:35:11 +000015#include "llvm/Module.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000016#include "llvm/CodeGen/Passes.h"
17#include "llvm/Target/TargetOptions.h"
18#include "llvm/Target/TargetMachineRegistry.h"
19#include "llvm/Transforms/Scalar.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000020#include <iostream>
Andrew Lenharth2f401632005-02-01 20:35:11 +000021
Andrew Lenharth304d0f32005-01-22 23:41:55 +000022using namespace llvm;
23
24namespace {
25 // Register the targets
26 RegisterTarget<AlphaTargetMachine> X("alpha", " Alpha (incomplete)");
27}
28
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000029namespace llvm {
30 cl::opt<bool> EnableAlphaLSR("enable-lsr-for-alpha",
31 cl::desc("Enable LSR for Alpha (beta option!)"),
32 cl::Hidden);
33}
34
Andrew Lenharth2f401632005-02-01 20:35:11 +000035unsigned 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
Andrew Lenharth304d0f32005-01-22 23:41:55 +000052AlphaTargetMachine::AlphaTargetMachine( const Module &M, IntrinsicLowering *IL)
53 : TargetMachine("alpha", IL, true),
54 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) //TODO: check these
Andrew Lenharth304d0f32005-01-22 23:41:55 +000055{}
56
Andrew Lenharth304d0f32005-01-22 23:41:55 +000057/// addPassesToEmitAssembly - Add passes to the specified pass manager
58/// to implement a static compiler for this target.
59///
60bool AlphaTargetMachine::addPassesToEmitAssembly(PassManager &PM,
61 std::ostream &Out) {
62
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000063 if (EnableAlphaLSR)
64 PM.add(createLoopStrengthReducePass());
65
Andrew Lenharth304d0f32005-01-22 23:41:55 +000066 // FIXME: Implement efficient support for garbage collection intrinsics.
67 PM.add(createLowerGCPass());
68
69 // FIXME: Implement the invoke/unwind instructions!
70 PM.add(createLowerInvokePass());
71
72 // FIXME: Implement the switch instruction in the instruction selector!
73 PM.add(createLowerSwitchPass());
74
Andrew Lenharth304d0f32005-01-22 23:41:55 +000075 // Make sure that no unreachable blocks are instruction selected.
76 PM.add(createUnreachableBlockEliminationPass());
77
78 PM.add(createAlphaPatternInstructionSelector(*this));
79
80 if (PrintMachineCode)
81 PM.add(createMachineFunctionPrinterPass(&std::cerr));
82
83 PM.add(createRegisterAllocator());
84
85 if (PrintMachineCode)
86 PM.add(createMachineFunctionPrinterPass(&std::cerr));
87
88 PM.add(createPrologEpilogCodeInserter());
89
90 // Must run branch selection immediately preceding the asm printer
91 //PM.add(createAlphaBranchSelectionPass());
92
93 PM.add(createAlphaCodePrinterPass(Out, *this));
94
95 PM.add(createMachineCodeDeleter());
96 return false;
97}