blob: 427094c9553a0ff5572b0d6dba2e58da14d0f349 [file] [log] [blame]
Andrew Lenharth3c127722005-01-24 18:45:41 +00001//===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
Misha Brukman89b8c8d2005-04-21 23:13:11 +00002//
Andrew Lenhartha1b5ca22005-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 Brukman89b8c8d2005-04-21 23:13:11 +00007//
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +00008//===----------------------------------------------------------------------===//
Misha Brukman89b8c8d2005-04-21 23:13:11 +00009//
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000010//
11//===----------------------------------------------------------------------===//
12
13#include "Alpha.h"
Andrew Lenharth55d04512005-07-22 20:52:16 +000014#include "AlphaJITInfo.h"
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000015#include "AlphaTargetMachine.h"
Andrew Lenharth8fb0d502005-02-01 20:35:11 +000016#include "llvm/Module.h"
Andrew Lenhartha1b5ca22005-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 Lenhartha7a83b92005-09-29 22:54:56 +000021#include "llvm/Support/Debug.h"
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000022#include <iostream>
Andrew Lenharth8fb0d502005-02-01 20:35:11 +000023
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000024using namespace llvm;
25
26namespace {
27 // Register the targets
28 RegisterTarget<AlphaTargetMachine> X("alpha", " Alpha (incomplete)");
29}
30
Andrew Lenharth8fb0d502005-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 Lattner5c7d7312005-10-30 16:44:01 +000045 return getJITMatchQuality()/2;
Andrew Lenharth8fb0d502005-02-01 20:35:11 +000046}
47
Andrew Lenharth55d04512005-07-22 20:52:16 +000048unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharthc32843e2005-07-22 21:00:30 +000049#ifdef __alpha
Andrew Lenharth55d04512005-07-22 20:52:16 +000050 return 10;
51#else
52 return 0;
53#endif
54}
55
Chris Lattner6f95ab72006-03-23 05:43:16 +000056AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Chris Lattnerf3b5b922006-06-16 18:22:52 +000057 : TargetMachine("alpha"), DataLayout("e"),
Andrew Lenharth3a18a392005-08-03 22:33:21 +000058 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenhartha7a83b92005-09-29 22:54:56 +000059 JITInfo(*this),
60 Subtarget(M, FS)
61{
62 DEBUG(std::cerr << "FS is " << FS << "\n");
63}
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000064
Chris Lattnerf11f48b2005-06-25 02:48:37 +000065/// addPassesToEmitFile - Add passes to the specified pass manager to implement
66/// a static compiler for this target.
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000067///
Chris Lattnerf11f48b2005-06-25 02:48:37 +000068bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
69 std::ostream &Out,
Chris Lattnerb28f2142005-11-08 02:11:51 +000070 CodeGenFileType FileType,
71 bool Fast) {
Chris Lattnerf11f48b2005-06-25 02:48:37 +000072 if (FileType != TargetMachine::AssemblyFile) return true;
Misha Brukman89b8c8d2005-04-21 23:13:11 +000073
Andrew Lenharthab724242005-11-12 19:21:08 +000074 PM.add(createLoopStrengthReducePass());
Andrew Lenharth6bc51c62005-11-18 13:57:03 +000075 PM.add(createCFGSimplificationPass());
Andrew Lenharthed4b6482005-03-02 17:21:38 +000076
Andrew Lenharth6bc51c62005-11-18 13:57:03 +000077
Andrew Lenhartha1b5ca22005-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 Lenhartha1b5ca22005-01-22 23:41:55 +000084 // Make sure that no unreachable blocks are instruction selected.
85 PM.add(createUnreachableBlockEliminationPass());
86
Andrew Lenharthc0bf3772006-01-23 21:56:07 +000087 PM.add(createAlphaISelDag(*this));
Andrew Lenhartha1b5ca22005-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 Brukman89b8c8d2005-04-21 23:13:11 +000098
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000099 // Must run branch selection immediately preceding the asm printer
100 //PM.add(createAlphaBranchSelectionPass());
Misha Brukman89b8c8d2005-04-21 23:13:11 +0000101
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +0000102 PM.add(createAlphaCodePrinterPass(Out, *this));
Misha Brukman89b8c8d2005-04-21 23:13:11 +0000103
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +0000104 PM.add(createMachineCodeDeleter());
105 return false;
106}
Andrew Lenharth55d04512005-07-22 20:52:16 +0000107
108void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
109
Chris Lattner54c8fcf2005-11-13 01:45:23 +0000110 PM.add(createLoopStrengthReducePass());
111 PM.add(createCFGSimplificationPass());
Andrew Lenharth55d04512005-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 Lenharth55d04512005-07-22 20:52:16 +0000119 // Make sure that no unreachable blocks are instruction selected.
120 PM.add(createUnreachableBlockEliminationPass());
121
Andrew Lenharthc0bf3772006-01-23 21:56:07 +0000122 PM.add(createAlphaISelDag(TM));
Andrew Lenharth55d04512005-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 Chengf6acb342006-07-25 20:40:54 +0000141 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Andrew Lenharth55d04512005-07-22 20:52:16 +0000142 // Delete machine code for this function
143 PM.add(createMachineCodeDeleter());
144 return false;
145}