mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-29 10:25:12 +00:00
Add the exit instruction to the PTX target.
Patch by Che-Liang Chiou <clchiou@gmail.com>! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114294 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -14,7 +14,11 @@
|
|||||||
|
|
||||||
#include "PTX.h"
|
#include "PTX.h"
|
||||||
#include "PTXTargetMachine.h"
|
#include "PTXTargetMachine.h"
|
||||||
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/CodeGen/AsmPrinter.h"
|
#include "llvm/CodeGen/AsmPrinter.h"
|
||||||
|
#include "llvm/CodeGen/MachineInstr.h"
|
||||||
|
#include "llvm/MC/MCStreamer.h"
|
||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@@ -25,11 +29,26 @@ namespace {
|
|||||||
explicit PTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) :
|
explicit PTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) :
|
||||||
AsmPrinter(TM, Streamer) {}
|
AsmPrinter(TM, Streamer) {}
|
||||||
const char *getPassName() const { return "PTX Assembly Printer"; }
|
const char *getPassName() const { return "PTX Assembly Printer"; }
|
||||||
|
|
||||||
|
virtual void EmitInstruction(const MachineInstr *MI);
|
||||||
|
|
||||||
|
// autogen'd.
|
||||||
|
void printInstruction(const MachineInstr *MI, raw_ostream &OS);
|
||||||
|
static const char *getRegisterName(unsigned RegNo);
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void PTXAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
||||||
|
SmallString<128> str;
|
||||||
|
raw_svector_ostream os(str);
|
||||||
|
printInstruction(MI, os);
|
||||||
|
os << ';';
|
||||||
|
OutStreamer.EmitRawText(os.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "PTXGenAsmWriter.inc"
|
||||||
|
|
||||||
// Force static initialization.
|
// Force static initialization.
|
||||||
extern "C" void LLVMInitializePTXAsmPrinter()
|
extern "C" void LLVMInitializePTXAsmPrinter() {
|
||||||
{
|
|
||||||
RegisterAsmPrinter<PTXAsmPrinter> X(ThePTXTarget);
|
RegisterAsmPrinter<PTXAsmPrinter> X(ThePTXTarget);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,22 @@
|
|||||||
set(LLVM_TARGET_DEFINITIONS PTX.td)
|
set(LLVM_TARGET_DEFINITIONS PTX.td)
|
||||||
|
|
||||||
|
tablegen(PTXGenAsmWriter.inc -gen-asm-writer)
|
||||||
|
tablegen(PTXGenDAGISel.inc -gen-dag-isel)
|
||||||
|
tablegen(PTXGenInstrInfo.inc -gen-instr-desc)
|
||||||
|
tablegen(PTXGenInstrNames.inc -gen-instr-enums)
|
||||||
|
tablegen(PTXGenRegisterInfo.inc -gen-register-desc)
|
||||||
|
tablegen(PTXGenRegisterInfo.h.inc -gen-register-desc-header)
|
||||||
|
tablegen(PTXGenRegisterNames.inc -gen-register-enums)
|
||||||
|
tablegen(PTXGenSubtarget.inc -gen-subtarget)
|
||||||
|
|
||||||
add_llvm_target(PTXCodeGen
|
add_llvm_target(PTXCodeGen
|
||||||
|
PTXISelDAGToDAG.cpp
|
||||||
|
PTXISelLowering.cpp
|
||||||
|
PTXInstrInfo.cpp
|
||||||
|
PTXMCAsmInfo.cpp
|
||||||
|
PTXRegisterInfo.cpp
|
||||||
|
PTXSubtarget.cpp
|
||||||
|
PTXTargetMachine.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries (LLVMPTXCodeGen LLVMSelectionDAG)
|
target_link_libraries (LLVMPTXCodeGen LLVMSelectionDAG)
|
||||||
|
@@ -12,7 +12,14 @@ LIBRARYNAME = LLVMPTXCodeGen
|
|||||||
TARGET = PTX
|
TARGET = PTX
|
||||||
|
|
||||||
# Make sure that tblgen is run, first thing.
|
# Make sure that tblgen is run, first thing.
|
||||||
BUILT_SOURCES =
|
BUILT_SOURCES = PTXGenAsmWriter.inc \
|
||||||
|
PTXGenDAGISel.inc \
|
||||||
|
PTXGenInstrInfo.inc \
|
||||||
|
PTXGenInstrNames.inc \
|
||||||
|
PTXGenRegisterInfo.inc \
|
||||||
|
PTXGenRegisterInfo.h.inc \
|
||||||
|
PTXGenRegisterNames.inc \
|
||||||
|
PTXGenSubtarget.inc
|
||||||
|
|
||||||
DIRS = AsmPrinter TargetInfo
|
DIRS = AsmPrinter TargetInfo
|
||||||
|
|
||||||
|
@@ -18,7 +18,19 @@
|
|||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class PTXTargetMachine;
|
||||||
|
class FunctionPass;
|
||||||
|
|
||||||
|
FunctionPass *createPTXISelDag(PTXTargetMachine &TM,
|
||||||
|
CodeGenOpt::Level OptLevel);
|
||||||
|
|
||||||
extern Target ThePTXTarget;
|
extern Target ThePTXTarget;
|
||||||
} // namespace llvm;
|
} // namespace llvm;
|
||||||
|
|
||||||
|
// Defines symbolic names for PTX registers.
|
||||||
|
#include "PTXGenRegisterNames.inc"
|
||||||
|
|
||||||
|
// Defines symbolic names for the PTX instructions.
|
||||||
|
#include "PTXGenInstrNames.inc"
|
||||||
|
|
||||||
#endif // PTX_H
|
#endif // PTX_H
|
||||||
|
@@ -8,3 +8,47 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// This is the top level entry point for the PTX target.
|
// This is the top level entry point for the PTX target.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Target-independent interfaces
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
include "llvm/Target/Target.td"
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Subtarget Features.
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
def FeatureSM20 : SubtargetFeature<"sm20", "is_sm20", "true",
|
||||||
|
"Enable sm_20 target architecture">;
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// PTX supported processors.
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
class Proc<string Name, list<SubtargetFeature> Features>
|
||||||
|
: Processor<Name, NoItineraries, Features>;
|
||||||
|
|
||||||
|
def : Proc<"generic", []>;
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Register File Description
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
include "PTXRegisterInfo.td"
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Instruction Descriptions
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
include "PTXInstrInfo.td"
|
||||||
|
|
||||||
|
def PTXInstrInfo : InstrInfo;
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Target Declaration
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
def PTX : Target {
|
||||||
|
let InstructionSet = PTXInstrInfo;
|
||||||
|
}
|
||||||
|
53
lib/Target/PTX/PTXISelDAGToDAG.cpp
Normal file
53
lib/Target/PTX/PTXISelDAGToDAG.cpp
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
//===-- PTXISelDAGToDAG.cpp - A dag to dag inst selector for PTX ----------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file defines an instruction selector for the PTX target.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "PTX.h"
|
||||||
|
#include "PTXTargetMachine.h"
|
||||||
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// PTXDAGToDAGISel - PTX specific code to select PTX machine
|
||||||
|
// instructions for SelectionDAG operations.
|
||||||
|
class PTXDAGToDAGISel : public SelectionDAGISel {
|
||||||
|
public:
|
||||||
|
PTXDAGToDAGISel(PTXTargetMachine &TM, CodeGenOpt::Level OptLevel);
|
||||||
|
|
||||||
|
virtual const char *getPassName() const {
|
||||||
|
return "PTX DAG->DAG Pattern Instruction Selection";
|
||||||
|
}
|
||||||
|
|
||||||
|
SDNode *Select(SDNode *Node);
|
||||||
|
|
||||||
|
// Include the pieces auto'gened from the target description
|
||||||
|
#include "PTXGenDAGISel.inc"
|
||||||
|
|
||||||
|
}; // class PTXDAGToDAGISel
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// createPTXISelDag - This pass converts a legalized DAG into a
|
||||||
|
// PTX-specific DAG, ready for instruction scheduling
|
||||||
|
FunctionPass *llvm::createPTXISelDag(PTXTargetMachine &TM,
|
||||||
|
CodeGenOpt::Level OptLevel) {
|
||||||
|
return new PTXDAGToDAGISel(TM, OptLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
PTXDAGToDAGISel::PTXDAGToDAGISel(PTXTargetMachine &TM,
|
||||||
|
CodeGenOpt::Level OptLevel)
|
||||||
|
: SelectionDAGISel(TM, OptLevel) {}
|
||||||
|
|
||||||
|
SDNode *PTXDAGToDAGISel::Select(SDNode *Node) {
|
||||||
|
// SelectCode() is auto'gened
|
||||||
|
return SelectCode(Node);
|
||||||
|
}
|
62
lib/Target/PTX/PTXISelLowering.cpp
Normal file
62
lib/Target/PTX/PTXISelLowering.cpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
//===-- PTXISelLowering.cpp - PTX DAG Lowering Implementation -------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file implements the PTXTargetLowering class.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "PTXISelLowering.h"
|
||||||
|
#include "PTXRegisterInfo.h"
|
||||||
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
|
#include "llvm/CodeGen/SelectionDAG.h"
|
||||||
|
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
PTXTargetLowering::PTXTargetLowering(TargetMachine &TM)
|
||||||
|
: TargetLowering(TM, new TargetLoweringObjectFileELF()) {
|
||||||
|
// Set up the register classes.
|
||||||
|
addRegisterClass(MVT::i1, PTX::PredsRegisterClass);
|
||||||
|
|
||||||
|
// Compute derived properties from the register classes
|
||||||
|
computeRegisterProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *PTXTargetLowering::getTargetNodeName(unsigned Opcode) const {
|
||||||
|
switch (Opcode) {
|
||||||
|
default: llvm_unreachable("Unknown opcode");
|
||||||
|
case PTXISD::EXIT: return "PTXISD::EXIT";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Calling Convention Implementation
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
SDValue PTXTargetLowering::
|
||||||
|
LowerFormalArguments(SDValue Chain,
|
||||||
|
CallingConv::ID CallConv,
|
||||||
|
bool isVarArg,
|
||||||
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
||||||
|
DebugLoc dl,
|
||||||
|
SelectionDAG &DAG,
|
||||||
|
SmallVectorImpl<SDValue> &InVals) const {
|
||||||
|
return Chain;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDValue PTXTargetLowering::
|
||||||
|
LowerReturn(SDValue Chain,
|
||||||
|
CallingConv::ID CallConv,
|
||||||
|
bool isVarArg,
|
||||||
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
||||||
|
const SmallVectorImpl<SDValue> &OutVals,
|
||||||
|
DebugLoc dl,
|
||||||
|
SelectionDAG &DAG) const {
|
||||||
|
return DAG.getNode(PTXISD::EXIT, dl, MVT::Other, Chain);
|
||||||
|
}
|
60
lib/Target/PTX/PTXISelLowering.h
Normal file
60
lib/Target/PTX/PTXISelLowering.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
//==-- PTXISelLowering.h - PTX DAG Lowering Interface ------------*- C++ -*-==//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file defines the interfaces that PTX uses to lower LLVM code into a
|
||||||
|
// selection DAG.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef PTX_ISEL_LOWERING_H
|
||||||
|
#define PTX_ISEL_LOWERING_H
|
||||||
|
|
||||||
|
#include "llvm/Target/TargetLowering.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
class PTXSubtarget;
|
||||||
|
class PTXTargetMachine;
|
||||||
|
|
||||||
|
namespace PTXISD {
|
||||||
|
enum NodeType {
|
||||||
|
FIRST_NUMBER = ISD::BUILTIN_OP_END,
|
||||||
|
EXIT
|
||||||
|
};
|
||||||
|
} // namespace PTXISD
|
||||||
|
|
||||||
|
class PTXTargetLowering : public TargetLowering {
|
||||||
|
public:
|
||||||
|
explicit PTXTargetLowering(TargetMachine &TM);
|
||||||
|
|
||||||
|
virtual const char *getTargetNodeName(unsigned Opcode) const;
|
||||||
|
|
||||||
|
virtual unsigned getFunctionAlignment(const Function *F) const {
|
||||||
|
return 2; }
|
||||||
|
|
||||||
|
virtual SDValue
|
||||||
|
LowerFormalArguments(SDValue Chain,
|
||||||
|
CallingConv::ID CallConv,
|
||||||
|
bool isVarArg,
|
||||||
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
||||||
|
DebugLoc dl,
|
||||||
|
SelectionDAG &DAG,
|
||||||
|
SmallVectorImpl<SDValue> &InVals) const;
|
||||||
|
|
||||||
|
virtual SDValue
|
||||||
|
LowerReturn(SDValue Chain,
|
||||||
|
CallingConv::ID CallConv,
|
||||||
|
bool isVarArg,
|
||||||
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
||||||
|
const SmallVectorImpl<SDValue> &OutVals,
|
||||||
|
DebugLoc dl,
|
||||||
|
SelectionDAG &DAG) const;
|
||||||
|
}; // class PTXTargetLowering
|
||||||
|
} // namespace llvm
|
||||||
|
|
||||||
|
#endif // PTX_ISEL_LOWERING_H
|
24
lib/Target/PTX/PTXInstrFormats.td
Normal file
24
lib/Target/PTX/PTXInstrFormats.td
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//===- PTXInstrFormats.td - PTX Instruction Formats ----------*- tblgen -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// PTX Predicate operand, default to (0, 0) = (zero-reg, always).
|
||||||
|
// Leave PrintMethod empty; predicate printing is defined elsewhere.
|
||||||
|
def pred : PredicateOperand<OtherVT, (ops Preds, i32imm),
|
||||||
|
(ops (i1 zero_reg), (i32 0))>;
|
||||||
|
|
||||||
|
let Namespace = "PTX" in {
|
||||||
|
class InstPTX<dag oops, dag iops, string asmstr, list<dag> pattern>
|
||||||
|
: Instruction {
|
||||||
|
dag OutOperandList = oops;
|
||||||
|
dag InOperandList = !con(iops, (ins pred:$_p));
|
||||||
|
let AsmString = asmstr; // Predicate printing is defined elsewhere.
|
||||||
|
let Pattern = pattern;
|
||||||
|
let isPredicable = 1;
|
||||||
|
}
|
||||||
|
}
|
22
lib/Target/PTX/PTXInstrInfo.cpp
Normal file
22
lib/Target/PTX/PTXInstrInfo.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
//===- PTXInstrInfo.cpp - PTX Instruction Information ---------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file contains the PTX implementation of the TargetInstrInfo class.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "PTXInstrInfo.h"
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
#include "PTXGenInstrInfo.inc"
|
||||||
|
|
||||||
|
PTXInstrInfo::PTXInstrInfo(PTXTargetMachine &_TM)
|
||||||
|
: TargetInstrInfoImpl(PTXInsts, array_lengthof(PTXInsts)),
|
||||||
|
RI(_TM, *this), TM(_TM) {}
|
35
lib/Target/PTX/PTXInstrInfo.h
Normal file
35
lib/Target/PTX/PTXInstrInfo.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//===- PTXInstrInfo.h - PTX Instruction Information -------------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file contains the PTX implementation of the TargetInstrInfo class.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef PTX_INSTR_INFO_H
|
||||||
|
#define PTX_INSTR_INFO_H
|
||||||
|
|
||||||
|
#include "PTXRegisterInfo.h"
|
||||||
|
#include "llvm/Target/TargetInstrInfo.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
class PTXTargetMachine;
|
||||||
|
|
||||||
|
class PTXInstrInfo : public TargetInstrInfoImpl {
|
||||||
|
private:
|
||||||
|
const PTXRegisterInfo RI;
|
||||||
|
PTXTargetMachine &TM;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit PTXInstrInfo(PTXTargetMachine &_TM);
|
||||||
|
|
||||||
|
virtual const PTXRegisterInfo &getRegisterInfo() const { return RI; }
|
||||||
|
}; // class PTXInstrInfo
|
||||||
|
} // namespace llvm
|
||||||
|
|
||||||
|
#endif // PTX_INSTR_INFO_H
|
33
lib/Target/PTX/PTXInstrInfo.td
Normal file
33
lib/Target/PTX/PTXInstrInfo.td
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
//===- PTXInstrInfo.td - PTX Instruction defs -----------------*- tblgen-*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file describes the PTX instructions in TableGen format.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Instruction format superclass
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
include "PTXInstrFormats.td"
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// PTX Specific Node Definitions
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
def PTXexit
|
||||||
|
: SDNode<"PTXISD::EXIT", SDTNone, [SDNPHasChain]>;
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Instructions
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
|
||||||
|
def EXIT : InstPTX<(outs), (ins), "exit", [(PTXexit)]>;
|
||||||
|
}
|
30
lib/Target/PTX/PTXMCAsmInfo.cpp
Normal file
30
lib/Target/PTX/PTXMCAsmInfo.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
//===-- PTXMCAsmInfo.cpp - PTX asm properties -----------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file contains the declarations of the PTXMCAsmInfo properties.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "PTXMCAsmInfo.h"
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
PTXMCAsmInfo::PTXMCAsmInfo(const Target &T, const StringRef &TT) {
|
||||||
|
CommentString = "//";
|
||||||
|
|
||||||
|
PrivateGlobalPrefix = "$L__";
|
||||||
|
|
||||||
|
AllowPeriodsInName = false;
|
||||||
|
|
||||||
|
HasSetDirective = false;
|
||||||
|
|
||||||
|
HasDotTypeDotSizeDirective = false;
|
||||||
|
|
||||||
|
HasSingleParameterDotFile = false;
|
||||||
|
}
|
28
lib/Target/PTX/PTXMCAsmInfo.h
Normal file
28
lib/Target/PTX/PTXMCAsmInfo.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
//=====-- PTXMCAsmInfo.h - PTX asm properties -----------------*- C++ -*--====//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file contains the declaration of the PTXMCAsmInfo class.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef PTX_MCASM_INFO_H
|
||||||
|
#define PTX_MCASM_INFO_H
|
||||||
|
|
||||||
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
class Target;
|
||||||
|
class StringRef;
|
||||||
|
|
||||||
|
struct PTXMCAsmInfo : public MCAsmInfo {
|
||||||
|
explicit PTXMCAsmInfo(const Target &T, const StringRef &TT);
|
||||||
|
};
|
||||||
|
} // namespace llvm
|
||||||
|
|
||||||
|
#endif // PTX_MCASM_INFO_H
|
19
lib/Target/PTX/PTXRegisterInfo.cpp
Normal file
19
lib/Target/PTX/PTXRegisterInfo.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//===- PTXRegisterInfo.cpp - PTX Register Information ---------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file contains the PTX implementation of the TargetRegisterInfo class.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "PTX.h"
|
||||||
|
#include "PTXRegisterInfo.h"
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
#include "PTXGenRegisterInfo.inc"
|
68
lib/Target/PTX/PTXRegisterInfo.h
Normal file
68
lib/Target/PTX/PTXRegisterInfo.h
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
//===- PTXRegisterInfo.h - PTX Register Information Impl --------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file contains the PTX implementation of the MRegisterInfo class.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef PTX_REGISTER_INFO_H
|
||||||
|
#define PTX_REGISTER_INFO_H
|
||||||
|
|
||||||
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
|
#include "llvm/ADT/BitVector.h"
|
||||||
|
|
||||||
|
#include "PTXGenRegisterInfo.h.inc"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
class PTXTargetMachine;
|
||||||
|
class MachineFunction;
|
||||||
|
|
||||||
|
struct PTXRegisterInfo : public PTXGenRegisterInfo {
|
||||||
|
PTXRegisterInfo(PTXTargetMachine &TM,
|
||||||
|
const TargetInstrInfo &TII) {}
|
||||||
|
|
||||||
|
virtual const unsigned
|
||||||
|
*getCalleeSavedRegs(const MachineFunction *MF = 0) const {
|
||||||
|
static const unsigned CalleeSavedRegs[] = { 0 };
|
||||||
|
return CalleeSavedRegs; // save nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual BitVector getReservedRegs(const MachineFunction &MF) const {
|
||||||
|
BitVector Reserved(getNumRegs());
|
||||||
|
return Reserved; // reserve no regs
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool hasFP(const MachineFunction &MF) const { return false; }
|
||||||
|
|
||||||
|
// FIXME: Given that PTX does not support stack frame, what should we do here?
|
||||||
|
virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI,
|
||||||
|
int SPAdj,
|
||||||
|
RegScavenger *RS = NULL) const {}
|
||||||
|
|
||||||
|
virtual void emitPrologue(MachineFunction &MF) const {}
|
||||||
|
virtual void emitEpilogue(MachineFunction &MF,
|
||||||
|
MachineBasicBlock &MBB) const {}
|
||||||
|
|
||||||
|
virtual unsigned getFrameRegister(const MachineFunction &MF) const {
|
||||||
|
llvm_unreachable("PTX does not have a frame register");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual unsigned getRARegister() const {
|
||||||
|
llvm_unreachable("PTX does not have a return address register");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int getDwarfRegNum(unsigned RegNum, bool isEH) const {
|
||||||
|
return PTXGenRegisterInfo::getDwarfRegNumFull(RegNum, 0);
|
||||||
|
}
|
||||||
|
}; // struct PTXRegisterInfo
|
||||||
|
} // namespace llvm
|
||||||
|
|
||||||
|
#endif // PTX_REGISTER_INFO_H
|
63
lib/Target/PTX/PTXRegisterInfo.td
Normal file
63
lib/Target/PTX/PTXRegisterInfo.td
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
//===- PTXRegisterInfo.td - PTX Register defs ----------------*- tblgen -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Declarations that describe the PTX register file
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
class PTXReg<string n> : Register<n> {
|
||||||
|
let Namespace = "PTX";
|
||||||
|
}
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Registers
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
def P0 : PTXReg<"p0">;
|
||||||
|
def P1 : PTXReg<"p1">;
|
||||||
|
def P2 : PTXReg<"p2">;
|
||||||
|
def P3 : PTXReg<"p3">;
|
||||||
|
def P4 : PTXReg<"p4">;
|
||||||
|
def P5 : PTXReg<"p5">;
|
||||||
|
def P6 : PTXReg<"p6">;
|
||||||
|
def P7 : PTXReg<"p7">;
|
||||||
|
def P8 : PTXReg<"p8">;
|
||||||
|
def P9 : PTXReg<"p9">;
|
||||||
|
def P10 : PTXReg<"p10">;
|
||||||
|
def P11 : PTXReg<"p11">;
|
||||||
|
def P12 : PTXReg<"p12">;
|
||||||
|
def P13 : PTXReg<"p13">;
|
||||||
|
def P14 : PTXReg<"p14">;
|
||||||
|
def P15 : PTXReg<"p15">;
|
||||||
|
def P16 : PTXReg<"p16">;
|
||||||
|
def P17 : PTXReg<"p17">;
|
||||||
|
def P18 : PTXReg<"p18">;
|
||||||
|
def P19 : PTXReg<"p19">;
|
||||||
|
def P20 : PTXReg<"p20">;
|
||||||
|
def P21 : PTXReg<"p21">;
|
||||||
|
def P22 : PTXReg<"p22">;
|
||||||
|
def P23 : PTXReg<"p23">;
|
||||||
|
def P24 : PTXReg<"p24">;
|
||||||
|
def P25 : PTXReg<"p25">;
|
||||||
|
def P26 : PTXReg<"p26">;
|
||||||
|
def P27 : PTXReg<"p27">;
|
||||||
|
def P28 : PTXReg<"p28">;
|
||||||
|
def P29 : PTXReg<"p29">;
|
||||||
|
def P30 : PTXReg<"p30">;
|
||||||
|
def P31 : PTXReg<"p31">;
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Register classes
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
def Preds : RegisterClass<"PTX", [i1], 8,
|
||||||
|
[P0, P1, P2, P3, P4, P5, P6, P7,
|
||||||
|
P8, P9, P10, P11, P12, P13, P14, P15,
|
||||||
|
P16, P17, P18, P19, P20, P21, P22, P23,
|
||||||
|
P24, P25, P26, P27, P28, P29, P30, P31]>;
|
23
lib/Target/PTX/PTXSubtarget.cpp
Normal file
23
lib/Target/PTX/PTXSubtarget.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
//===- PTXSubtarget.cpp - PTX Subtarget Information ---------------*- C++ -*-=//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file implements the PTX specific subclass of TargetSubtarget.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "PTXSubtarget.h"
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
PTXSubtarget::PTXSubtarget(const std::string &TT, const std::string &FS) {
|
||||||
|
std::string TARGET = "sm_20";
|
||||||
|
// TODO: call ParseSubtargetFeatures(FS, TARGET);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "PTXGenSubtarget.inc"
|
32
lib/Target/PTX/PTXSubtarget.h
Normal file
32
lib/Target/PTX/PTXSubtarget.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
//====-- PTXSubtarget.h - Define Subtarget for the PTX ---------*- C++ -*--===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This file declares the PTX specific subclass of TargetSubtarget.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef PTX_SUBTARGET_H
|
||||||
|
#define PTX_SUBTARGET_H
|
||||||
|
|
||||||
|
#include "llvm/Target/TargetSubtarget.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
class PTXSubtarget : public TargetSubtarget {
|
||||||
|
private:
|
||||||
|
bool is_sm20;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PTXSubtarget(const std::string &TT, const std::string &FS);
|
||||||
|
|
||||||
|
std::string ParseSubtargetFeatures(const std::string &FS,
|
||||||
|
const std::string &CPU);
|
||||||
|
}; // class PTXSubtarget
|
||||||
|
} // namespace llvm
|
||||||
|
|
||||||
|
#endif // PTX_SUBTARGET_H
|
@@ -12,20 +12,32 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "PTX.h"
|
#include "PTX.h"
|
||||||
|
#include "PTXMCAsmInfo.h"
|
||||||
#include "PTXTargetMachine.h"
|
#include "PTXTargetMachine.h"
|
||||||
|
#include "llvm/PassManager.h"
|
||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
extern "C" void LLVMInitializePTXTarget()
|
extern "C" void LLVMInitializePTXTarget() {
|
||||||
{
|
|
||||||
// Register the target
|
|
||||||
RegisterTargetMachine<PTXTargetMachine> X(ThePTXTarget);
|
RegisterTargetMachine<PTXTargetMachine> X(ThePTXTarget);
|
||||||
|
RegisterAsmInfo<PTXMCAsmInfo> Y(ThePTXTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DataLayout and FrameInfo are filled with dummy data
|
||||||
PTXTargetMachine::PTXTargetMachine(const Target &T,
|
PTXTargetMachine::PTXTargetMachine(const Target &T,
|
||||||
const std::string &TT,
|
const std::string &TT,
|
||||||
const std::string &FS) :
|
const std::string &FS)
|
||||||
LLVMTargetMachine(T, TT)
|
: LLVMTargetMachine(T, TT),
|
||||||
{
|
DataLayout("e-p:32:32-i64:32:32-f64:32:32-v128:32:128-v64:32:64-n32:64"),
|
||||||
|
FrameInfo(TargetFrameInfo::StackGrowsDown, 2, -2),
|
||||||
|
InstrInfo(*this),
|
||||||
|
TLInfo(*this),
|
||||||
|
Subtarget(TT, FS) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PTXTargetMachine::addInstSelector(PassManagerBase &PM,
|
||||||
|
CodeGenOpt::Level OptLevel) {
|
||||||
|
PM.add(createPTXISelDag(*this, OptLevel));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -14,14 +14,42 @@
|
|||||||
#ifndef PTX_TARGET_MACHINE_H
|
#ifndef PTX_TARGET_MACHINE_H
|
||||||
#define PTX_TARGET_MACHINE_H
|
#define PTX_TARGET_MACHINE_H
|
||||||
|
|
||||||
|
#include "PTXISelLowering.h"
|
||||||
|
#include "PTXInstrInfo.h"
|
||||||
|
#include "PTXSubtarget.h"
|
||||||
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#include "llvm/Target/TargetFrameInfo.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class PTXTargetMachine : public LLVMTargetMachine {
|
class PTXTargetMachine : public LLVMTargetMachine {
|
||||||
public:
|
private:
|
||||||
PTXTargetMachine(const Target &T, const std::string &TT,
|
const TargetData DataLayout;
|
||||||
const std::string &FS);
|
TargetFrameInfo FrameInfo;
|
||||||
}; // class PTXTargetMachine
|
PTXInstrInfo InstrInfo;
|
||||||
|
PTXTargetLowering TLInfo;
|
||||||
|
PTXSubtarget Subtarget;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PTXTargetMachine(const Target &T, const std::string &TT,
|
||||||
|
const std::string &FS);
|
||||||
|
|
||||||
|
virtual const TargetData *getTargetData() const { return &DataLayout; }
|
||||||
|
|
||||||
|
virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; }
|
||||||
|
|
||||||
|
virtual const PTXInstrInfo *getInstrInfo() const { return &InstrInfo; }
|
||||||
|
virtual const TargetRegisterInfo *getRegisterInfo() const {
|
||||||
|
return &InstrInfo.getRegisterInfo(); }
|
||||||
|
|
||||||
|
virtual const PTXTargetLowering *getTargetLowering() const {
|
||||||
|
return &TLInfo; }
|
||||||
|
|
||||||
|
virtual const PTXSubtarget *getSubtargetImpl() const { return &Subtarget; }
|
||||||
|
|
||||||
|
virtual bool addInstSelector(PassManagerBase &PM,
|
||||||
|
CodeGenOpt::Level OptLevel);
|
||||||
|
}; // class PTXTargetMachine
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
|
||||||
#endif // PTX_TARGET_MACHINE_H
|
#endif // PTX_TARGET_MACHINE_H
|
||||||
|
@@ -15,8 +15,7 @@ using namespace llvm;
|
|||||||
|
|
||||||
Target llvm::ThePTXTarget;
|
Target llvm::ThePTXTarget;
|
||||||
|
|
||||||
extern "C" void LLVMInitializePTXTargetInfo()
|
extern "C" void LLVMInitializePTXTargetInfo() {
|
||||||
{
|
|
||||||
// see llvm/ADT/Triple.h
|
// see llvm/ADT/Triple.h
|
||||||
RegisterTarget<Triple::ptx> X(ThePTXTarget, "ptx", "PTX");
|
RegisterTarget<Triple::ptx> X(ThePTXTarget, "ptx", "PTX");
|
||||||
}
|
}
|
||||||
|
5
test/CodeGen/PTX/dg.exp
Normal file
5
test/CodeGen/PTX/dg.exp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
load_lib llvm.exp
|
||||||
|
|
||||||
|
if { [llvm_supports_target PTX] } {
|
||||||
|
RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
|
||||||
|
}
|
6
test/CodeGen/PTX/exit.ll
Normal file
6
test/CodeGen/PTX/exit.ll
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
; RUN: llc < %s -march=ptx | FileCheck %s
|
||||||
|
|
||||||
|
define void @t1() {
|
||||||
|
;CHECK: exit;
|
||||||
|
ret void
|
||||||
|
}
|
Reference in New Issue
Block a user