blob: 8f263294052099a5d377bd95b43a2d9b326da2f0 [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);
35}
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
51 return 0;
52}
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,
77 CodeGenFileType FileType) {
78 if (FileType != TargetMachine::AssemblyFile) return true;
Misha Brukman4633f1c2005-04-21 23:13:11 +000079
Andrew Lenharthf3f475e2005-03-03 19:03:21 +000080 if (EnableAlphaLSR) {
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000081 PM.add(createLoopStrengthReducePass());
Andrew Lenharthf3f475e2005-03-03 19:03:21 +000082 PM.add(createCFGSimplificationPass());
83 }
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000084
Andrew Lenharth304d0f32005-01-22 23:41:55 +000085 // FIXME: Implement efficient support for garbage collection intrinsics.
86 PM.add(createLowerGCPass());
87
88 // FIXME: Implement the invoke/unwind instructions!
89 PM.add(createLowerInvokePass());
90
91 // FIXME: Implement the switch instruction in the instruction selector!
92 PM.add(createLowerSwitchPass());
93
Andrew Lenharth304d0f32005-01-22 23:41:55 +000094 // Make sure that no unreachable blocks are instruction selected.
95 PM.add(createUnreachableBlockEliminationPass());
96
97 PM.add(createAlphaPatternInstructionSelector(*this));
98
99 if (PrintMachineCode)
100 PM.add(createMachineFunctionPrinterPass(&std::cerr));
101
102 PM.add(createRegisterAllocator());
103
104 if (PrintMachineCode)
105 PM.add(createMachineFunctionPrinterPass(&std::cerr));
106
107 PM.add(createPrologEpilogCodeInserter());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000108
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000109 // Must run branch selection immediately preceding the asm printer
110 //PM.add(createAlphaBranchSelectionPass());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000111
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000112 PM.add(createAlphaCodePrinterPass(Out, *this));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000113
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000114 PM.add(createMachineCodeDeleter());
115 return false;
116}
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000117
118void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
119
120 if (EnableAlphaLSR) {
121 PM.add(createLoopStrengthReducePass());
122 PM.add(createCFGSimplificationPass());
123 }
124
125 // FIXME: Implement efficient support for garbage collection intrinsics.
126 PM.add(createLowerGCPass());
127
128 // FIXME: Implement the invoke/unwind instructions!
129 PM.add(createLowerInvokePass());
130
131 // FIXME: Implement the switch instruction in the instruction selector!
132 PM.add(createLowerSwitchPass());
133
134 // Make sure that no unreachable blocks are instruction selected.
135 PM.add(createUnreachableBlockEliminationPass());
136
137 PM.add(createAlphaPatternInstructionSelector(TM));
138
139 if (PrintMachineCode)
140 PM.add(createMachineFunctionPrinterPass(&std::cerr));
141
142 PM.add(createRegisterAllocator());
143
144 if (PrintMachineCode)
145 PM.add(createMachineFunctionPrinterPass(&std::cerr));
146
147 PM.add(createPrologEpilogCodeInserter());
148
149 // Must run branch selection immediately preceding the asm printer
150 //PM.add(createAlphaBranchSelectionPass());
151
152}
153
154bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
155 MachineCodeEmitter &MCE) {
156 PM.add(createAlphaCodeEmitterPass(MCE));
157 // Delete machine code for this function
158 PM.add(createMachineCodeDeleter());
159 return false;
160}