blob: fd9cbe59bc52c71168e8de5a98c4fec9af8e2635 [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 {
Andrew Lenharth4907d222005-10-20 00:28:31 +000032 cl::opt<bool> EnableAlphaDAG("enable-dag-isel-for-alpha",
33 cl::desc("Enable DAG ISEL for Alpha (beta option!)"),
34 cl::Hidden);
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000035}
36
Andrew Lenharth2f401632005-02-01 20:35:11 +000037unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
38 // We strongly match "alpha*".
39 std::string TT = M.getTargetTriple();
40 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
41 TT[3] == 'h' && TT[4] == 'a')
42 return 20;
43
44 if (M.getEndianness() == Module::LittleEndian &&
45 M.getPointerSize() == Module::Pointer64)
46 return 10; // Weak match
47 else if (M.getEndianness() != Module::AnyEndianness ||
48 M.getPointerSize() != Module::AnyPointerSize)
49 return 0; // Match for some other target
50
Chris Lattnerc1d6f672005-10-30 16:44:01 +000051 return getJITMatchQuality()/2;
Andrew Lenharth2f401632005-02-01 20:35:11 +000052}
53
Andrew Lenharth0934ae02005-07-22 20:52:16 +000054unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharth38396f82005-07-22 21:00:30 +000055#ifdef __alpha
Andrew Lenharth0934ae02005-07-22 20:52:16 +000056 return 10;
57#else
58 return 0;
59#endif
60}
61
Jim Laskeyb1e11802005-09-01 21:38:21 +000062AlphaTargetMachine::AlphaTargetMachine(const Module &M, IntrinsicLowering *IL,
63 const std::string &FS)
Misha Brukman4633f1c2005-04-21 23:13:11 +000064 : TargetMachine("alpha", IL, true),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000065 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000066 JITInfo(*this),
67 Subtarget(M, FS)
68{
69 DEBUG(std::cerr << "FS is " << FS << "\n");
70}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000071
Chris Lattner0431c962005-06-25 02:48:37 +000072/// addPassesToEmitFile - Add passes to the specified pass manager to implement
73/// a static compiler for this target.
Andrew Lenharth304d0f32005-01-22 23:41:55 +000074///
Chris Lattner0431c962005-06-25 02:48:37 +000075bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
76 std::ostream &Out,
Chris Lattnerce8eb0c2005-11-08 02:11:51 +000077 CodeGenFileType FileType,
78 bool Fast) {
Chris Lattner0431c962005-06-25 02:48:37 +000079 if (FileType != TargetMachine::AssemblyFile) return true;
Misha Brukman4633f1c2005-04-21 23:13:11 +000080
Andrew Lenharthea2fdf92005-11-12 19:21:08 +000081 PM.add(createLoopStrengthReducePass());
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000082
Andrew Lenharth304d0f32005-01-22 23:41:55 +000083 // FIXME: Implement efficient support for garbage collection intrinsics.
84 PM.add(createLowerGCPass());
85
86 // FIXME: Implement the invoke/unwind instructions!
87 PM.add(createLowerInvokePass());
88
89 // FIXME: Implement the switch instruction in the instruction selector!
90 PM.add(createLowerSwitchPass());
91
Andrew Lenharth304d0f32005-01-22 23:41:55 +000092 // Make sure that no unreachable blocks are instruction selected.
93 PM.add(createUnreachableBlockEliminationPass());
94
Andrew Lenharthea2fdf92005-11-12 19:21:08 +000095 PM.add(createCFGSimplificationPass());
96
Andrew Lenharth4907d222005-10-20 00:28:31 +000097 if (EnableAlphaDAG)
98 PM.add(createAlphaISelDag(*this));
99 else
100 PM.add(createAlphaPatternInstructionSelector(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000101
102 if (PrintMachineCode)
103 PM.add(createMachineFunctionPrinterPass(&std::cerr));
104
105 PM.add(createRegisterAllocator());
106
107 if (PrintMachineCode)
108 PM.add(createMachineFunctionPrinterPass(&std::cerr));
109
110 PM.add(createPrologEpilogCodeInserter());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000111
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000112 // Must run branch selection immediately preceding the asm printer
113 //PM.add(createAlphaBranchSelectionPass());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000114
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000115 PM.add(createAlphaCodePrinterPass(Out, *this));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000116
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000117 PM.add(createMachineCodeDeleter());
118 return false;
119}
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000120
121void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
122
Chris Lattner773a9592005-11-13 01:45:23 +0000123 PM.add(createLoopStrengthReducePass());
124 PM.add(createCFGSimplificationPass());
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000125
126 // FIXME: Implement efficient support for garbage collection intrinsics.
127 PM.add(createLowerGCPass());
128
129 // FIXME: Implement the invoke/unwind instructions!
130 PM.add(createLowerInvokePass());
131
132 // FIXME: Implement the switch instruction in the instruction selector!
133 PM.add(createLowerSwitchPass());
134
135 // Make sure that no unreachable blocks are instruction selected.
136 PM.add(createUnreachableBlockEliminationPass());
137
138 PM.add(createAlphaPatternInstructionSelector(TM));
139
140 if (PrintMachineCode)
141 PM.add(createMachineFunctionPrinterPass(&std::cerr));
142
143 PM.add(createRegisterAllocator());
144
145 if (PrintMachineCode)
146 PM.add(createMachineFunctionPrinterPass(&std::cerr));
147
148 PM.add(createPrologEpilogCodeInserter());
149
150 // Must run branch selection immediately preceding the asm printer
151 //PM.add(createAlphaBranchSelectionPass());
152
153}
154
155bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
156 MachineCodeEmitter &MCE) {
157 PM.add(createAlphaCodeEmitterPass(MCE));
158 // Delete machine code for this function
159 PM.add(createMachineCodeDeleter());
160 return false;
161}