blob: f5bd484b0cfb869949d558bfd91a168174b56b19 [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 Lenharthe4f161c2005-03-02 17:21:38 +000031namespace llvm {
Misha Brukman4633f1c2005-04-21 23:13:11 +000032 cl::opt<bool> EnableAlphaLSR("enable-lsr-for-alpha",
33 cl::desc("Enable LSR for Alpha (beta option!)"),
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000034 cl::Hidden);
Andrew Lenharth4907d222005-10-20 00:28:31 +000035 cl::opt<bool> EnableAlphaDAG("enable-dag-isel-for-alpha",
36 cl::desc("Enable DAG ISEL for Alpha (beta option!)"),
37 cl::Hidden);
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000038}
39
Andrew Lenharth2f401632005-02-01 20:35:11 +000040unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
41 // We strongly match "alpha*".
42 std::string TT = M.getTargetTriple();
43 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
44 TT[3] == 'h' && TT[4] == 'a')
45 return 20;
46
47 if (M.getEndianness() == Module::LittleEndian &&
48 M.getPointerSize() == Module::Pointer64)
49 return 10; // Weak match
50 else if (M.getEndianness() != Module::AnyEndianness ||
51 M.getPointerSize() != Module::AnyPointerSize)
52 return 0; // Match for some other target
53
Chris Lattnerc1d6f672005-10-30 16:44:01 +000054 return getJITMatchQuality()/2;
Andrew Lenharth2f401632005-02-01 20:35:11 +000055}
56
Andrew Lenharth0934ae02005-07-22 20:52:16 +000057unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharth38396f82005-07-22 21:00:30 +000058#ifdef __alpha
Andrew Lenharth0934ae02005-07-22 20:52:16 +000059 return 10;
60#else
61 return 0;
62#endif
63}
64
Jim Laskeyb1e11802005-09-01 21:38:21 +000065AlphaTargetMachine::AlphaTargetMachine(const Module &M, IntrinsicLowering *IL,
66 const std::string &FS)
Misha Brukman4633f1c2005-04-21 23:13:11 +000067 : TargetMachine("alpha", IL, true),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000068 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000069 JITInfo(*this),
70 Subtarget(M, FS)
71{
72 DEBUG(std::cerr << "FS is " << FS << "\n");
73}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000074
Chris Lattner0431c962005-06-25 02:48:37 +000075/// addPassesToEmitFile - Add passes to the specified pass manager to implement
76/// a static compiler for this target.
Andrew Lenharth304d0f32005-01-22 23:41:55 +000077///
Chris Lattner0431c962005-06-25 02:48:37 +000078bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
79 std::ostream &Out,
Chris Lattnerce8eb0c2005-11-08 02:11:51 +000080 CodeGenFileType FileType,
81 bool Fast) {
Chris Lattner0431c962005-06-25 02:48:37 +000082 if (FileType != TargetMachine::AssemblyFile) return true;
Misha Brukman4633f1c2005-04-21 23:13:11 +000083
Andrew Lenharthf3f475e2005-03-03 19:03:21 +000084 if (EnableAlphaLSR) {
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000085 PM.add(createLoopStrengthReducePass());
Andrew Lenharthf3f475e2005-03-03 19:03:21 +000086 PM.add(createCFGSimplificationPass());
87 }
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000088
Andrew Lenharth304d0f32005-01-22 23:41:55 +000089 // FIXME: Implement efficient support for garbage collection intrinsics.
90 PM.add(createLowerGCPass());
91
92 // FIXME: Implement the invoke/unwind instructions!
93 PM.add(createLowerInvokePass());
94
95 // FIXME: Implement the switch instruction in the instruction selector!
96 PM.add(createLowerSwitchPass());
97
Andrew Lenharth304d0f32005-01-22 23:41:55 +000098 // Make sure that no unreachable blocks are instruction selected.
99 PM.add(createUnreachableBlockEliminationPass());
100
Andrew Lenharth4907d222005-10-20 00:28:31 +0000101 if (EnableAlphaDAG)
102 PM.add(createAlphaISelDag(*this));
103 else
104 PM.add(createAlphaPatternInstructionSelector(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000105
106 if (PrintMachineCode)
107 PM.add(createMachineFunctionPrinterPass(&std::cerr));
108
109 PM.add(createRegisterAllocator());
110
111 if (PrintMachineCode)
112 PM.add(createMachineFunctionPrinterPass(&std::cerr));
113
114 PM.add(createPrologEpilogCodeInserter());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000115
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000116 // Must run branch selection immediately preceding the asm printer
117 //PM.add(createAlphaBranchSelectionPass());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000118
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000119 PM.add(createAlphaCodePrinterPass(Out, *this));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000120
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000121 PM.add(createMachineCodeDeleter());
122 return false;
123}
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000124
125void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
126
127 if (EnableAlphaLSR) {
128 PM.add(createLoopStrengthReducePass());
129 PM.add(createCFGSimplificationPass());
130 }
131
132 // FIXME: Implement efficient support for garbage collection intrinsics.
133 PM.add(createLowerGCPass());
134
135 // FIXME: Implement the invoke/unwind instructions!
136 PM.add(createLowerInvokePass());
137
138 // FIXME: Implement the switch instruction in the instruction selector!
139 PM.add(createLowerSwitchPass());
140
141 // Make sure that no unreachable blocks are instruction selected.
142 PM.add(createUnreachableBlockEliminationPass());
143
144 PM.add(createAlphaPatternInstructionSelector(TM));
145
146 if (PrintMachineCode)
147 PM.add(createMachineFunctionPrinterPass(&std::cerr));
148
149 PM.add(createRegisterAllocator());
150
151 if (PrintMachineCode)
152 PM.add(createMachineFunctionPrinterPass(&std::cerr));
153
154 PM.add(createPrologEpilogCodeInserter());
155
156 // Must run branch selection immediately preceding the asm printer
157 //PM.add(createAlphaBranchSelectionPass());
158
159}
160
161bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
162 MachineCodeEmitter &MCE) {
163 PM.add(createAlphaCodeEmitterPass(MCE));
164 // Delete machine code for this function
165 PM.add(createMachineCodeDeleter());
166 return false;
167}