blob: cb4dd3ea1fa7df680b8434d6461ae256be96f33a [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//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// 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"
Jim Laskeyae92ce82006-09-07 23:39:26 +000015#include "AlphaTargetAsmInfo.h"
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000016#include "AlphaTargetMachine.h"
Andrew Lenharth8fb0d502005-02-01 20:35:11 +000017#include "llvm/Module.h"
Chris Lattner12e97302006-09-04 04:14:57 +000018#include "llvm/PassManager.h"
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000019#include "llvm/Target/TargetMachineRegistry.h"
Owen Anderson93719642008-08-21 00:14:44 +000020#include "llvm/Support/raw_ostream.h"
Andrew Lenharth8fb0d502005-02-01 20:35:11 +000021
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000022using namespace llvm;
23
Dan Gohmand78c4002008-05-13 00:00:25 +000024// Register the targets
Chris Lattner122c9b12008-10-16 06:16:50 +000025static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]");
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000026
Jim Laskeyae92ce82006-09-07 23:39:26 +000027const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
28 return new AlphaTargetAsmInfo(*this);
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;
Chris Lattner517290a2007-07-09 17:25:29 +000037 // If the target triple is something non-alpha, we don't match.
38 if (!TT.empty()) return 0;
Andrew Lenharth8fb0d502005-02-01 20:35:11 +000039
40 if (M.getEndianness() == Module::LittleEndian &&
41 M.getPointerSize() == Module::Pointer64)
42 return 10; // Weak match
43 else if (M.getEndianness() != Module::AnyEndianness ||
44 M.getPointerSize() != Module::AnyPointerSize)
45 return 0; // Match for some other target
46
Chris Lattner5c7d7312005-10-30 16:44:01 +000047 return getJITMatchQuality()/2;
Andrew Lenharth8fb0d502005-02-01 20:35:11 +000048}
49
Andrew Lenharth55d04512005-07-22 20:52:16 +000050unsigned AlphaTargetMachine::getJITMatchQuality() {
Andrew Lenharthc32843e2005-07-22 21:00:30 +000051#ifdef __alpha
Andrew Lenharth55d04512005-07-22 20:52:16 +000052 return 10;
53#else
54 return 0;
55#endif
56}
57
Chris Lattner6f95ab72006-03-23 05:43:16 +000058AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS)
Dale Johannesenc5283ec2007-08-03 20:20:50 +000059 : DataLayout("e-f128:128:128"),
Andrew Lenharth3a18a392005-08-03 22:33:21 +000060 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
Andrew Lenhartha7a83b92005-09-29 22:54:56 +000061 JITInfo(*this),
Andrew Lenhartha6bbf332006-10-11 04:29:42 +000062 Subtarget(M, FS),
63 TLInfo(*this) {
Andrew Lenharth5e2bacd2006-09-24 19:46:56 +000064 setRelocationModel(Reloc::PIC_);
Andrew Lenhartha7a83b92005-09-29 22:54:56 +000065}
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000066
Misha Brukman89b8c8d2005-04-21 23:13:11 +000067
Chris Lattner12e97302006-09-04 04:14:57 +000068//===----------------------------------------------------------------------===//
69// Pass Pipeline Configuration
70//===----------------------------------------------------------------------===//
Andrew Lenharthed4b6482005-03-02 17:21:38 +000071
Dan Gohman24570832008-03-11 22:29:46 +000072bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
Andrew Lenharthc0bf3772006-01-23 21:56:07 +000073 PM.add(createAlphaISelDag(*this));
Andrew Lenhartha1b5ca22005-01-22 23:41:55 +000074 return false;
75}
Dan Gohman24570832008-03-11 22:29:46 +000076bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
Andrew Lenharth55d04512005-07-22 20:52:16 +000077 // Must run branch selection immediately preceding the asm printer
Andrew Lenharth692e4152006-10-31 16:49:55 +000078 PM.add(createAlphaBranchSelectionPass());
Chris Lattner12e97302006-09-04 04:14:57 +000079 return false;
Andrew Lenharth55d04512005-07-22 20:52:16 +000080}
Dan Gohman24570832008-03-11 22:29:46 +000081bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
Owen Anderson93719642008-08-21 00:14:44 +000082 raw_ostream &Out) {
Andrew Lenharthf23e3bf2006-09-18 19:44:29 +000083 PM.add(createAlphaLLRPPass(*this));
Chris Lattner12e97302006-09-04 04:14:57 +000084 PM.add(createAlphaCodePrinterPass(Out, *this));
85 return false;
86}
Dan Gohman24570832008-03-11 22:29:46 +000087bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
Evan Cheng9d5df0a2007-07-20 21:56:13 +000088 bool DumpAsm, MachineCodeEmitter &MCE) {
Evan Chengf6acb342006-07-25 20:40:54 +000089 PM.add(createAlphaCodeEmitterPass(*this, MCE));
Evan Cheng9d5df0a2007-07-20 21:56:13 +000090 if (DumpAsm)
Owen Anderson93719642008-08-21 00:14:44 +000091 PM.add(createAlphaCodePrinterPass(errs(), *this));
Andrew Lenharth55d04512005-07-22 20:52:16 +000092 return false;
93}
Dan Gohman24570832008-03-11 22:29:46 +000094bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
Evan Cheng9d5df0a2007-07-20 21:56:13 +000095 bool Fast, bool DumpAsm,
Bill Wendling59889ae2007-02-08 01:38:33 +000096 MachineCodeEmitter &MCE) {
Evan Cheng9d5df0a2007-07-20 21:56:13 +000097 return addCodeEmitter(PM, Fast, DumpAsm, MCE);
Bill Wendling59889ae2007-02-08 01:38:33 +000098}