blob: dd593d1c0bcce76717435bbf2ec7a00727516b75 [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
Jim Laskeyb1e11802005-09-01 21:38:21 +000056AlphaTargetMachine::AlphaTargetMachine(const Module &M, IntrinsicLowering *IL,
57 const std::string &FS)
Misha Brukman4633f1c2005-04-21 23:13:11 +000058 : TargetMachine("alpha", IL, 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
85 // FIXME: Implement the switch instruction in the instruction selector!
86 PM.add(createLowerSwitchPass());
87
Andrew Lenharth304d0f32005-01-22 23:41:55 +000088 // Make sure that no unreachable blocks are instruction selected.
89 PM.add(createUnreachableBlockEliminationPass());
90
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +000091 PM.add(createAlphaISelDag(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +000092
93 if (PrintMachineCode)
94 PM.add(createMachineFunctionPrinterPass(&std::cerr));
95
96 PM.add(createRegisterAllocator());
97
98 if (PrintMachineCode)
99 PM.add(createMachineFunctionPrinterPass(&std::cerr));
100
101 PM.add(createPrologEpilogCodeInserter());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000102
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000103 // Must run branch selection immediately preceding the asm printer
104 //PM.add(createAlphaBranchSelectionPass());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000105
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000106 PM.add(createAlphaCodePrinterPass(Out, *this));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000107
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000108 PM.add(createMachineCodeDeleter());
109 return false;
110}
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000111
112void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
113
Chris Lattner773a9592005-11-13 01:45:23 +0000114 PM.add(createLoopStrengthReducePass());
115 PM.add(createCFGSimplificationPass());
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000116
117 // FIXME: Implement efficient support for garbage collection intrinsics.
118 PM.add(createLowerGCPass());
119
120 // FIXME: Implement the invoke/unwind instructions!
121 PM.add(createLowerInvokePass());
122
123 // FIXME: Implement the switch instruction in the instruction selector!
124 PM.add(createLowerSwitchPass());
125
126 // Make sure that no unreachable blocks are instruction selected.
127 PM.add(createUnreachableBlockEliminationPass());
128
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +0000129 PM.add(createAlphaISelDag(TM));
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000130
131 if (PrintMachineCode)
132 PM.add(createMachineFunctionPrinterPass(&std::cerr));
133
134 PM.add(createRegisterAllocator());
135
136 if (PrintMachineCode)
137 PM.add(createMachineFunctionPrinterPass(&std::cerr));
138
139 PM.add(createPrologEpilogCodeInserter());
140
141 // Must run branch selection immediately preceding the asm printer
142 //PM.add(createAlphaBranchSelectionPass());
143
144}
145
146bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
147 MachineCodeEmitter &MCE) {
148 PM.add(createAlphaCodeEmitterPass(MCE));
149 // Delete machine code for this function
150 PM.add(createMachineCodeDeleter());
151 return false;
152}