blob: 2c3be3dbcd656ade01cc2df6ae5056695679fe90 [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
Chris Lattner0431c962005-06-25 02:48:37 +000057/// addPassesToEmitFile - Add passes to the specified pass manager to implement
58/// a static compiler for this target.
Andrew Lenharth304d0f32005-01-22 23:41:55 +000059///
Chris Lattner0431c962005-06-25 02:48:37 +000060bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
61 std::ostream &Out,
62 CodeGenFileType FileType) {
63 if (FileType != TargetMachine::AssemblyFile) return true;
Misha Brukman4633f1c2005-04-21 23:13:11 +000064
Andrew Lenharthf3f475e2005-03-03 19:03:21 +000065 if (EnableAlphaLSR) {
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000066 PM.add(createLoopStrengthReducePass());
Andrew Lenharthf3f475e2005-03-03 19:03:21 +000067 PM.add(createCFGSimplificationPass());
68 }
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000069
Andrew Lenharth304d0f32005-01-22 23:41:55 +000070 // FIXME: Implement efficient support for garbage collection intrinsics.
71 PM.add(createLowerGCPass());
72
73 // FIXME: Implement the invoke/unwind instructions!
74 PM.add(createLowerInvokePass());
75
76 // FIXME: Implement the switch instruction in the instruction selector!
77 PM.add(createLowerSwitchPass());
78
Andrew Lenharth304d0f32005-01-22 23:41:55 +000079 // Make sure that no unreachable blocks are instruction selected.
80 PM.add(createUnreachableBlockEliminationPass());
81
82 PM.add(createAlphaPatternInstructionSelector(*this));
83
84 if (PrintMachineCode)
85 PM.add(createMachineFunctionPrinterPass(&std::cerr));
86
87 PM.add(createRegisterAllocator());
88
89 if (PrintMachineCode)
90 PM.add(createMachineFunctionPrinterPass(&std::cerr));
91
92 PM.add(createPrologEpilogCodeInserter());
Misha Brukman4633f1c2005-04-21 23:13:11 +000093
Andrew Lenharth304d0f32005-01-22 23:41:55 +000094 // Must run branch selection immediately preceding the asm printer
95 //PM.add(createAlphaBranchSelectionPass());
Misha Brukman4633f1c2005-04-21 23:13:11 +000096
Andrew Lenharth304d0f32005-01-22 23:41:55 +000097 PM.add(createAlphaCodePrinterPass(Out, *this));
Misha Brukman4633f1c2005-04-21 23:13:11 +000098
Andrew Lenharth304d0f32005-01-22 23:41:55 +000099 PM.add(createMachineCodeDeleter());
100 return false;
101}