blob: 2d7e467815daa3a5f9548921405be7318ad167fe [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)
Chris Lattnerc4fa3862006-09-03 18:44:02 +000057 : DataLayout("e"),
Andrew Lenharthdc7c0b82005-08-03 22:33:21 +000058 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenharth120ab482005-09-29 22:54:56 +000059 JITInfo(*this),
60 Subtarget(M, FS)
61{
62 DEBUG(std::cerr << "FS is " << FS << "\n");
63}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000064
Chris Lattner0431c962005-06-25 02:48:37 +000065/// addPassesToEmitFile - Add passes to the specified pass manager to implement
66/// a static compiler for this target.
Andrew Lenharth304d0f32005-01-22 23:41:55 +000067///
Chris Lattner0431c962005-06-25 02:48:37 +000068bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
69 std::ostream &Out,
Chris Lattnerce8eb0c2005-11-08 02:11:51 +000070 CodeGenFileType FileType,
71 bool Fast) {
Chris Lattner0431c962005-06-25 02:48:37 +000072 if (FileType != TargetMachine::AssemblyFile) return true;
Misha Brukman4633f1c2005-04-21 23:13:11 +000073
Andrew Lenharthea2fdf92005-11-12 19:21:08 +000074 PM.add(createLoopStrengthReducePass());
Andrew Lenharthf27b6142005-11-18 13:57:03 +000075 PM.add(createCFGSimplificationPass());
Andrew Lenharthe4f161c2005-03-02 17:21:38 +000076
Andrew Lenharthf27b6142005-11-18 13:57:03 +000077
Andrew Lenharth304d0f32005-01-22 23:41:55 +000078 // FIXME: Implement efficient support for garbage collection intrinsics.
79 PM.add(createLowerGCPass());
80
81 // FIXME: Implement the invoke/unwind instructions!
82 PM.add(createLowerInvokePass());
83
Andrew Lenharth304d0f32005-01-22 23:41:55 +000084 // Make sure that no unreachable blocks are instruction selected.
85 PM.add(createUnreachableBlockEliminationPass());
86
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +000087 PM.add(createAlphaISelDag(*this));
Andrew Lenharth304d0f32005-01-22 23:41:55 +000088
89 if (PrintMachineCode)
90 PM.add(createMachineFunctionPrinterPass(&std::cerr));
91
92 PM.add(createRegisterAllocator());
93
94 if (PrintMachineCode)
95 PM.add(createMachineFunctionPrinterPass(&std::cerr));
96
97 PM.add(createPrologEpilogCodeInserter());
Misha Brukman4633f1c2005-04-21 23:13:11 +000098
Andrew Lenharth304d0f32005-01-22 23:41:55 +000099 // Must run branch selection immediately preceding the asm printer
100 //PM.add(createAlphaBranchSelectionPass());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000101
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000102 PM.add(createAlphaCodePrinterPass(Out, *this));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000103
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000104 PM.add(createMachineCodeDeleter());
105 return false;
106}
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000107
108void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
109
Chris Lattner773a9592005-11-13 01:45:23 +0000110 PM.add(createLoopStrengthReducePass());
111 PM.add(createCFGSimplificationPass());
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000112
113 // FIXME: Implement efficient support for garbage collection intrinsics.
114 PM.add(createLowerGCPass());
115
116 // FIXME: Implement the invoke/unwind instructions!
117 PM.add(createLowerInvokePass());
118
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000119 // Make sure that no unreachable blocks are instruction selected.
120 PM.add(createUnreachableBlockEliminationPass());
121
Andrew Lenharthfabd5ba2006-01-23 21:56:07 +0000122 PM.add(createAlphaISelDag(TM));
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000123
124 if (PrintMachineCode)
125 PM.add(createMachineFunctionPrinterPass(&std::cerr));
126
127 PM.add(createRegisterAllocator());
128
129 if (PrintMachineCode)
130 PM.add(createMachineFunctionPrinterPass(&std::cerr));
131
132 PM.add(createPrologEpilogCodeInserter());
133
134 // Must run branch selection immediately preceding the asm printer
135 //PM.add(createAlphaBranchSelectionPass());
136
137}
138
139bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
140 MachineCodeEmitter &MCE) {
Evan Cheng55fc2802006-07-25 20:40:54 +0000141 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Andrew Lenharth0934ae02005-07-22 20:52:16 +0000142 // Delete machine code for this function
143 PM.add(createMachineCodeDeleter());
144 return false;
145}