Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 1 | //===-- 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 Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 15 | #include "PTXMCAsmInfo.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 16 | #include "PTXTargetMachine.h" |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 17 | #include "llvm/PassManager.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetRegistry.h" |
Che-Liang Chiou | f48817c | 2011-03-02 07:36:48 +0000 | [diff] [blame^] | 19 | #include "llvm/Support/raw_ostream.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace llvm; |
| 22 | |
Rafael Espindola | a484f2c | 2010-11-28 14:48:34 +0000 | [diff] [blame] | 23 | namespace llvm { |
| 24 | MCStreamer *createPTXAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 25 | bool isVerboseAsm, bool useLoc, |
Rafael Espindola | a484f2c | 2010-11-28 14:48:34 +0000 | [diff] [blame] | 26 | MCInstPrinter *InstPrint, |
| 27 | MCCodeEmitter *CE, |
Daniel Dunbar | 745dacc | 2010-12-16 03:05:59 +0000 | [diff] [blame] | 28 | TargetAsmBackend *TAB, |
Rafael Espindola | a484f2c | 2010-11-28 14:48:34 +0000 | [diff] [blame] | 29 | bool ShowInst); |
| 30 | } |
| 31 | |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 32 | extern "C" void LLVMInitializePTXTarget() { |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 33 | RegisterTargetMachine<PTXTargetMachine> X(ThePTXTarget); |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 34 | RegisterAsmInfo<PTXMCAsmInfo> Y(ThePTXTarget); |
Che-Liang Chiou | d77f2a4 | 2010-11-08 02:58:44 +0000 | [diff] [blame] | 35 | TargetRegistry::RegisterAsmStreamer(ThePTXTarget, createPTXAsmStreamer); |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Che-Liang Chiou | f48817c | 2011-03-02 07:36:48 +0000 | [diff] [blame^] | 38 | namespace { |
| 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 Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 43 | // DataLayout and FrameLowering are filled with dummy data |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 44 | PTXTargetMachine::PTXTargetMachine(const Target &T, |
| 45 | const std::string &TT, |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 46 | const std::string &FS) |
Che-Liang Chiou | f48817c | 2011-03-02 07:36:48 +0000 | [diff] [blame^] | 47 | : 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 Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 53 | FrameLowering(Subtarget), |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 54 | TLInfo(*this), |
Che-Liang Chiou | f48817c | 2011-03-02 07:36:48 +0000 | [diff] [blame^] | 55 | InstrInfo(*this) { |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | bool PTXTargetMachine::addInstSelector(PassManagerBase &PM, |
| 59 | CodeGenOpt::Level OptLevel) { |
| 60 | PM.add(createPTXISelDag(*this, OptLevel)); |
Che-Liang Chiou | ad83c1d | 2011-01-01 10:50:37 +0000 | [diff] [blame] | 61 | return false; |
| 62 | } |
| 63 | |
| 64 | bool PTXTargetMachine::addPostRegAlloc(PassManagerBase &PM, |
| 65 | CodeGenOpt::Level OptLevel) { |
| 66 | // PTXMFInfoExtract must after register allocation! |
Che-Liang Chiou | 3278c42 | 2010-11-08 03:00:52 +0000 | [diff] [blame] | 67 | PM.add(createPTXMFInfoExtract(*this, OptLevel)); |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 68 | return false; |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 69 | } |