blob: 2970f8201b27945b79cf043dee24cbf4cbbab6ef [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"
Andrew Lenharth0934ae02005-07-22 20:52:16 +000014#include "AlphaJITInfo.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000015#include "AlphaTargetMachine.h"
Andrew Lenharth2f401632005-02-01 20:35:11 +000016#include "llvm/Module.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000017#include "llvm/CodeGen/Passes.h"
18#include "llvm/Target/TargetOptions.h"
19#include "llvm/Target/TargetMachineRegistry.h"
20#include "llvm/Transforms/Scalar.h"
Andrew Lenharth120ab482005-09-29 22:54:56 +000021#include "llvm/Support/Debug.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000022#include <iostream>
Andrew Lenharth2f401632005-02-01 20:35:11 +000023
Andrew Lenharth304d0f32005-01-22 23:41:55 +000024using namespace llvm;
25
26namespace {
27 // Register the targets
28 RegisterTarget<AlphaTargetMachine> X("alpha", " Alpha (incomplete)");
29}
30
Andrew Lenharth2f401632005-02-01 20:35:11 +000031unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
32 // We strongly match "alpha*".
33 std::string TT = M.getTargetTriple();
34 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
35 TT[3] == 'h' && TT[4] == 'a')
36 return 20;
37
38 if (M.getEndianness() == Module::LittleEndian &&
39 M.getPointerSize() == Module::Pointer64)
40 return 10; // Weak match
41 else if (M.getEndianness() != Module::AnyEndianness ||
42 M.getPointerSize() != Module::AnyPointerSize)
43 return 0; // Match for some other target
44
Chris Lattnerc1d6f672005-10-30 16:44:01 +000045 return getJITMatchQuality()/2;
Andrew Lenharth2f401632005-02-01 20:35:11 +000046}
47
Andrew Lenharth0934ae02005-07-22 20:52:16 +000048unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharth38396f82005-07-22 21:00:30 +000049#ifdef __alpha
Andrew Lenharth0934ae02005-07-22 20:52:16 +000050 return 10;
51#else
52 return 0;
53#endif
54}
55
Chris Lattnerbc641b92006-03-23 05:43:16 +000056AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Owen Andersona69571c2006-05-03 01:29:57 +000057 : TargetMachine("alpha"),
58 DataLayout("alpha", true),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000059 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000060 JITInfo(*this),
61 Subtarget(M, FS)
62{
63 DEBUG(std::cerr << "FS is " << FS << "\n");
64}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000065
Chris Lattner0431c962005-06-25 02:48:37 +000066/// addPassesToEmitFile - Add passes to the specified pass manager to implement
67/// a static compiler for this target.
Andrew Lenharth304d0f32005-01-22 23:41:55 +000068///
Chris Lattner0431c962005-06-25 02:48:37 +000069bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
70 std::ostream &Out,
Chris Lattnerce8eb0c2005-11-08 02:11:51 +000071 CodeGenFileType FileType,
72 bool Fast) {
Chris Lattner0431c962005-06-25 02:48:37 +000073 if (FileType != TargetMachine::AssemblyFile) return true;
Misha Brukman4633f1c2005-04-21 23:13:11 +000074
Andrew Lenharthea2fdf92005-11-12 19:21:08 +000075 PM.add(createLoopStrengthReducePass());
Andrew Lenharthf27b6142005-11-18 13:57:03 +000076 PM.add(createCFGSimplificationPass());
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000077
Andrew Lenharthf27b6142005-11-18 13:57:03 +000078
Andrew Lenharth304d0f32005-01-22 23:41:55 +000079 // FIXME: Implement efficient support for garbage collection intrinsics.
80 PM.add(createLowerGCPass());
81
82 // FIXME: Implement the invoke/unwind instructions!
83 PM.add(createLowerInvokePass());
84
Andrew Lenharth304d0f32005-01-22 23:41:55 +000085 // Make sure that no unreachable blocks are instruction selected.
86 PM.add(createUnreachableBlockEliminationPass());
87
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +000088 PM.add(createAlphaISelDag(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +000089
90 if (PrintMachineCode)
91 PM.add(createMachineFunctionPrinterPass(&std::cerr));
92
93 PM.add(createRegisterAllocator());
94
95 if (PrintMachineCode)
96 PM.add(createMachineFunctionPrinterPass(&std::cerr));
97
98 PM.add(createPrologEpilogCodeInserter());
Misha Brukman4633f1c2005-04-21 23:13:11 +000099
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000100 // Must run branch selection immediately preceding the asm printer
101 //PM.add(createAlphaBranchSelectionPass());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000102
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000103 PM.add(createAlphaCodePrinterPass(Out, *this));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000104
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000105 PM.add(createMachineCodeDeleter());
106 return false;
107}
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000108
109void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
110
Chris Lattner773a9592005-11-13 01:45:23 +0000111 PM.add(createLoopStrengthReducePass());
112 PM.add(createCFGSimplificationPass());
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000113
114 // FIXME: Implement efficient support for garbage collection intrinsics.
115 PM.add(createLowerGCPass());
116
117 // FIXME: Implement the invoke/unwind instructions!
118 PM.add(createLowerInvokePass());
119
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000120 // Make sure that no unreachable blocks are instruction selected.
121 PM.add(createUnreachableBlockEliminationPass());
122
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +0000123 PM.add(createAlphaISelDag(TM));
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000124
125 if (PrintMachineCode)
126 PM.add(createMachineFunctionPrinterPass(&std::cerr));
127
128 PM.add(createRegisterAllocator());
129
130 if (PrintMachineCode)
131 PM.add(createMachineFunctionPrinterPass(&std::cerr));
132
133 PM.add(createPrologEpilogCodeInserter());
134
135 // Must run branch selection immediately preceding the asm printer
136 //PM.add(createAlphaBranchSelectionPass());
137
138}
139
140bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
141 MachineCodeEmitter &MCE) {
142 PM.add(createAlphaCodeEmitterPass(MCE));
143 // Delete machine code for this function
144 PM.add(createMachineCodeDeleter());
145 return false;
146}