blob: 83e95a7cb30ff0cb00cfbf9f218253ae01f904be [file] [log] [blame]
Andrew Lenharth886470e2005-01-24 18:45:41 +00001//===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00002//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00003// 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.
Misha Brukman4633f1c2005-04-21 23:13:11 +00007//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00008//===----------------------------------------------------------------------===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00009//
Andrew Lenharth304d0f32005-01-22 23:41:55 +000010//
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 {
Misha Brukman4633f1c2005-04-21 23:13:11 +000030 cl::opt<bool> EnableAlphaLSR("enable-lsr-for-alpha",
31 cl::desc("Enable LSR for Alpha (beta option!)"),
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000032 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)
Misha Brukman4633f1c2005-04-21 23:13:11 +000053 : TargetMachine("alpha", IL, true),
Andrew Lenharth304d0f32005-01-22 23:41:55 +000054 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) {
Misha Brukman4633f1c2005-04-21 23:13:11 +000062
Andrew Lenharthf3f475e2005-03-03 19:03:21 +000063 if (EnableAlphaLSR) {
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000064 PM.add(createLoopStrengthReducePass());
Andrew Lenharthf3f475e2005-03-03 19:03:21 +000065 PM.add(createCFGSimplificationPass());
66 }
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000067
Andrew Lenharth304d0f32005-01-22 23:41:55 +000068 // 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
Andrew Lenharth304d0f32005-01-22 23:41:55 +000077 // 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());
Misha Brukman4633f1c2005-04-21 23:13:11 +000091
Andrew Lenharth304d0f32005-01-22 23:41:55 +000092 // Must run branch selection immediately preceding the asm printer
93 //PM.add(createAlphaBranchSelectionPass());
Misha Brukman4633f1c2005-04-21 23:13:11 +000094
Andrew Lenharth304d0f32005-01-22 23:41:55 +000095 PM.add(createAlphaCodePrinterPass(Out, *this));
Misha Brukman4633f1c2005-04-21 23:13:11 +000096
Andrew Lenharth304d0f32005-01-22 23:41:55 +000097 PM.add(createMachineCodeDeleter());
98 return false;
99}