blob: 371510fe3250fb86a551e49774929ba1760d6b9c [file] [log] [blame]
Nick Lewyckyf7a3c502010-09-07 18:14:24 +00001//===-- PTXTargetMachine.cpp - Define TargetMachine for PTX ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Top-level implementation for the PTX target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PTX.h"
Eric Christopher50880d02010-09-18 18:52:28 +000015#include "PTXMCAsmInfo.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000016#include "PTXTargetMachine.h"
Eric Christopher50880d02010-09-18 18:52:28 +000017#include "llvm/PassManager.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000018#include "llvm/Target/TargetRegistry.h"
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000019#include "llvm/Support/raw_ostream.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000020
21using namespace llvm;
22
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000023namespace llvm {
24 MCStreamer *createPTXAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
Rafael Espindola89b93722010-12-10 07:39:47 +000025 bool isVerboseAsm, bool useLoc,
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000026 MCInstPrinter *InstPrint,
27 MCCodeEmitter *CE,
Daniel Dunbar745dacc2010-12-16 03:05:59 +000028 TargetAsmBackend *TAB,
Rafael Espindolaa484f2c2010-11-28 14:48:34 +000029 bool ShowInst);
30}
31
Eric Christopher50880d02010-09-18 18:52:28 +000032extern "C" void LLVMInitializePTXTarget() {
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000033 RegisterTargetMachine<PTXTargetMachine> X(ThePTXTarget);
Eric Christopher50880d02010-09-18 18:52:28 +000034 RegisterAsmInfo<PTXMCAsmInfo> Y(ThePTXTarget);
Che-Liang Chioud77f2a42010-11-08 02:58:44 +000035 TargetRegistry::RegisterAsmStreamer(ThePTXTarget, createPTXAsmStreamer);
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000036}
37
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000038namespace {
39 const char* DataLayout32 = "e-p:32:32-i64:32:32-f64:32:32-v128:32:128-v64:32:64-n32:64";
40 const char* DataLayout64 = "e-p:64:64-i64:32:32-f64:32:32-v128:32:128-v64:32:64-n32:64";
41}
42
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000043// DataLayout and FrameLowering are filled with dummy data
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000044PTXTargetMachine::PTXTargetMachine(const Target &T,
45 const std::string &TT,
Eric Christopher50880d02010-09-18 18:52:28 +000046 const std::string &FS)
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000047 : Subtarget(TT, FS),
48 // FIXME: This feels like a dirty hack, but Subtarget does not appear to be
49 // initialized at this point, and we need to finish initialization of
50 // DataLayout.
51 DataLayout((FS.find("64bit") != FS.npos) ? DataLayout64 : DataLayout32),
52 LLVMTargetMachine(T, TT),
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000053 FrameLowering(Subtarget),
Eric Christopher50880d02010-09-18 18:52:28 +000054 TLInfo(*this),
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000055 InstrInfo(*this) {
Eric Christopher50880d02010-09-18 18:52:28 +000056}
57
58bool PTXTargetMachine::addInstSelector(PassManagerBase &PM,
59 CodeGenOpt::Level OptLevel) {
60 PM.add(createPTXISelDag(*this, OptLevel));
Che-Liang Chiouad83c1d2011-01-01 10:50:37 +000061 return false;
62}
63
64bool PTXTargetMachine::addPostRegAlloc(PassManagerBase &PM,
65 CodeGenOpt::Level OptLevel) {
66 // PTXMFInfoExtract must after register allocation!
Che-Liang Chiou3278c422010-11-08 03:00:52 +000067 PM.add(createPTXMFInfoExtract(*this, OptLevel));
Eric Christopher50880d02010-09-18 18:52:28 +000068 return false;
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000069}