You've already forked linux-packaging-mono
Imported Upstream version 5.18.0.167
Former-commit-id: 289509151e0fee68a1b591a20c9f109c3c789d3a
This commit is contained in:
parent
e19d552987
commit
b084638f15
41
external/llvm/lib/Target/NVPTX/CMakeLists.txt
vendored
41
external/llvm/lib/Target/NVPTX/CMakeLists.txt
vendored
@ -1,41 +0,0 @@
|
||||
set(LLVM_TARGET_DEFINITIONS NVPTX.td)
|
||||
|
||||
|
||||
tablegen(LLVM NVPTXGenRegisterInfo.inc -gen-register-info)
|
||||
tablegen(LLVM NVPTXGenInstrInfo.inc -gen-instr-info)
|
||||
tablegen(LLVM NVPTXGenAsmWriter.inc -gen-asm-writer)
|
||||
tablegen(LLVM NVPTXGenDAGISel.inc -gen-dag-isel)
|
||||
tablegen(LLVM NVPTXGenSubtargetInfo.inc -gen-subtarget)
|
||||
add_public_tablegen_target(NVPTXCommonTableGen)
|
||||
|
||||
set(NVPTXCodeGen_sources
|
||||
NVPTXAllocaHoisting.cpp
|
||||
NVPTXAsmPrinter.cpp
|
||||
NVPTXAssignValidGlobalNames.cpp
|
||||
NVPTXFrameLowering.cpp
|
||||
NVPTXGenericToNVVM.cpp
|
||||
NVPTXISelDAGToDAG.cpp
|
||||
NVPTXISelLowering.cpp
|
||||
NVPTXImageOptimizer.cpp
|
||||
NVPTXInstrInfo.cpp
|
||||
NVPTXLowerAggrCopies.cpp
|
||||
NVPTXLowerArgs.cpp
|
||||
NVPTXLowerAlloca.cpp
|
||||
NVPTXPeephole.cpp
|
||||
NVPTXMCExpr.cpp
|
||||
NVPTXPrologEpilogPass.cpp
|
||||
NVPTXRegisterInfo.cpp
|
||||
NVPTXReplaceImageHandles.cpp
|
||||
NVPTXSubtarget.cpp
|
||||
NVPTXTargetMachine.cpp
|
||||
NVPTXTargetTransformInfo.cpp
|
||||
NVPTXUtilities.cpp
|
||||
NVVMIntrRange.cpp
|
||||
NVVMReflect.cpp
|
||||
)
|
||||
|
||||
add_llvm_target(NVPTXCodeGen ${NVPTXCodeGen_sources})
|
||||
|
||||
add_subdirectory(TargetInfo)
|
||||
add_subdirectory(InstPrinter)
|
||||
add_subdirectory(MCTargetDesc)
|
@ -1,3 +0,0 @@
|
||||
add_llvm_library(LLVMNVPTXAsmPrinter
|
||||
NVPTXInstPrinter.cpp
|
||||
)
|
@ -1,23 +0,0 @@
|
||||
;===- ./lib/Target/NVPTX/InstPrinter/LLVMBuild.txt -------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
;
|
||||
; This is an LLVMBuild description file for the components in this subdirectory.
|
||||
;
|
||||
; For more information on the LLVMBuild system, please see:
|
||||
;
|
||||
; http://llvm.org/docs/LLVMBuild.html
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[component_0]
|
||||
type = Library
|
||||
name = NVPTXAsmPrinter
|
||||
parent = NVPTX
|
||||
required_libraries = MC Support
|
||||
add_to_library_groups = NVPTX
|
@ -1,296 +0,0 @@
|
||||
//===-- NVPTXInstPrinter.cpp - PTX assembly instruction printing ----------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Print MCInst instructions to .ptx format.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "InstPrinter/NVPTXInstPrinter.h"
|
||||
#include "MCTargetDesc/NVPTXBaseInfo.h"
|
||||
#include "NVPTX.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "llvm/MC/MCInstrInfo.h"
|
||||
#include "llvm/MC/MCSubtargetInfo.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include <cctype>
|
||||
using namespace llvm;
|
||||
|
||||
#define DEBUG_TYPE "asm-printer"
|
||||
|
||||
#include "NVPTXGenAsmWriter.inc"
|
||||
|
||||
NVPTXInstPrinter::NVPTXInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
|
||||
const MCRegisterInfo &MRI)
|
||||
: MCInstPrinter(MAI, MII, MRI) {}
|
||||
|
||||
void NVPTXInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
|
||||
// Decode the virtual register
|
||||
// Must be kept in sync with NVPTXAsmPrinter::encodeVirtualRegister
|
||||
unsigned RCId = (RegNo >> 28);
|
||||
switch (RCId) {
|
||||
default: report_fatal_error("Bad virtual register encoding");
|
||||
case 0:
|
||||
// This is actually a physical register, so defer to the autogenerated
|
||||
// register printer
|
||||
OS << getRegisterName(RegNo);
|
||||
return;
|
||||
case 1:
|
||||
OS << "%p";
|
||||
break;
|
||||
case 2:
|
||||
OS << "%rs";
|
||||
break;
|
||||
case 3:
|
||||
OS << "%r";
|
||||
break;
|
||||
case 4:
|
||||
OS << "%rd";
|
||||
break;
|
||||
case 5:
|
||||
OS << "%f";
|
||||
break;
|
||||
case 6:
|
||||
OS << "%fd";
|
||||
break;
|
||||
case 7:
|
||||
OS << "%h";
|
||||
break;
|
||||
case 8:
|
||||
OS << "%hh";
|
||||
break;
|
||||
}
|
||||
|
||||
unsigned VReg = RegNo & 0x0FFFFFFF;
|
||||
OS << VReg;
|
||||
}
|
||||
|
||||
void NVPTXInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
|
||||
StringRef Annot, const MCSubtargetInfo &STI) {
|
||||
printInstruction(MI, OS);
|
||||
|
||||
// Next always print the annotation.
|
||||
printAnnotation(OS, Annot);
|
||||
}
|
||||
|
||||
void NVPTXInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
||||
raw_ostream &O) {
|
||||
const MCOperand &Op = MI->getOperand(OpNo);
|
||||
if (Op.isReg()) {
|
||||
unsigned Reg = Op.getReg();
|
||||
printRegName(O, Reg);
|
||||
} else if (Op.isImm()) {
|
||||
O << markup("<imm:") << formatImm(Op.getImm()) << markup(">");
|
||||
} else {
|
||||
assert(Op.isExpr() && "Unknown operand kind in printOperand");
|
||||
Op.getExpr()->print(O, &MAI);
|
||||
}
|
||||
}
|
||||
|
||||
void NVPTXInstPrinter::printCvtMode(const MCInst *MI, int OpNum, raw_ostream &O,
|
||||
const char *Modifier) {
|
||||
const MCOperand &MO = MI->getOperand(OpNum);
|
||||
int64_t Imm = MO.getImm();
|
||||
|
||||
if (strcmp(Modifier, "ftz") == 0) {
|
||||
// FTZ flag
|
||||
if (Imm & NVPTX::PTXCvtMode::FTZ_FLAG)
|
||||
O << ".ftz";
|
||||
} else if (strcmp(Modifier, "sat") == 0) {
|
||||
// SAT flag
|
||||
if (Imm & NVPTX::PTXCvtMode::SAT_FLAG)
|
||||
O << ".sat";
|
||||
} else if (strcmp(Modifier, "base") == 0) {
|
||||
// Default operand
|
||||
switch (Imm & NVPTX::PTXCvtMode::BASE_MASK) {
|
||||
default:
|
||||
return;
|
||||
case NVPTX::PTXCvtMode::NONE:
|
||||
break;
|
||||
case NVPTX::PTXCvtMode::RNI:
|
||||
O << ".rni";
|
||||
break;
|
||||
case NVPTX::PTXCvtMode::RZI:
|
||||
O << ".rzi";
|
||||
break;
|
||||
case NVPTX::PTXCvtMode::RMI:
|
||||
O << ".rmi";
|
||||
break;
|
||||
case NVPTX::PTXCvtMode::RPI:
|
||||
O << ".rpi";
|
||||
break;
|
||||
case NVPTX::PTXCvtMode::RN:
|
||||
O << ".rn";
|
||||
break;
|
||||
case NVPTX::PTXCvtMode::RZ:
|
||||
O << ".rz";
|
||||
break;
|
||||
case NVPTX::PTXCvtMode::RM:
|
||||
O << ".rm";
|
||||
break;
|
||||
case NVPTX::PTXCvtMode::RP:
|
||||
O << ".rp";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
llvm_unreachable("Invalid conversion modifier");
|
||||
}
|
||||
}
|
||||
|
||||
void NVPTXInstPrinter::printCmpMode(const MCInst *MI, int OpNum, raw_ostream &O,
|
||||
const char *Modifier) {
|
||||
const MCOperand &MO = MI->getOperand(OpNum);
|
||||
int64_t Imm = MO.getImm();
|
||||
|
||||
if (strcmp(Modifier, "ftz") == 0) {
|
||||
// FTZ flag
|
||||
if (Imm & NVPTX::PTXCmpMode::FTZ_FLAG)
|
||||
O << ".ftz";
|
||||
} else if (strcmp(Modifier, "base") == 0) {
|
||||
switch (Imm & NVPTX::PTXCmpMode::BASE_MASK) {
|
||||
default:
|
||||
return;
|
||||
case NVPTX::PTXCmpMode::EQ:
|
||||
O << ".eq";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::NE:
|
||||
O << ".ne";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::LT:
|
||||
O << ".lt";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::LE:
|
||||
O << ".le";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::GT:
|
||||
O << ".gt";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::GE:
|
||||
O << ".ge";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::LO:
|
||||
O << ".lo";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::LS:
|
||||
O << ".ls";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::HI:
|
||||
O << ".hi";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::HS:
|
||||
O << ".hs";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::EQU:
|
||||
O << ".equ";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::NEU:
|
||||
O << ".neu";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::LTU:
|
||||
O << ".ltu";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::LEU:
|
||||
O << ".leu";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::GTU:
|
||||
O << ".gtu";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::GEU:
|
||||
O << ".geu";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::NUM:
|
||||
O << ".num";
|
||||
break;
|
||||
case NVPTX::PTXCmpMode::NotANumber:
|
||||
O << ".nan";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
llvm_unreachable("Empty Modifier");
|
||||
}
|
||||
}
|
||||
|
||||
void NVPTXInstPrinter::printLdStCode(const MCInst *MI, int OpNum,
|
||||
raw_ostream &O, const char *Modifier) {
|
||||
if (Modifier) {
|
||||
const MCOperand &MO = MI->getOperand(OpNum);
|
||||
int Imm = (int) MO.getImm();
|
||||
if (!strcmp(Modifier, "volatile")) {
|
||||
if (Imm)
|
||||
O << ".volatile";
|
||||
} else if (!strcmp(Modifier, "addsp")) {
|
||||
switch (Imm) {
|
||||
case NVPTX::PTXLdStInstCode::GLOBAL:
|
||||
O << ".global";
|
||||
break;
|
||||
case NVPTX::PTXLdStInstCode::SHARED:
|
||||
O << ".shared";
|
||||
break;
|
||||
case NVPTX::PTXLdStInstCode::LOCAL:
|
||||
O << ".local";
|
||||
break;
|
||||
case NVPTX::PTXLdStInstCode::PARAM:
|
||||
O << ".param";
|
||||
break;
|
||||
case NVPTX::PTXLdStInstCode::CONSTANT:
|
||||
O << ".const";
|
||||
break;
|
||||
case NVPTX::PTXLdStInstCode::GENERIC:
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Wrong Address Space");
|
||||
}
|
||||
} else if (!strcmp(Modifier, "sign")) {
|
||||
if (Imm == NVPTX::PTXLdStInstCode::Signed)
|
||||
O << "s";
|
||||
else if (Imm == NVPTX::PTXLdStInstCode::Unsigned)
|
||||
O << "u";
|
||||
else if (Imm == NVPTX::PTXLdStInstCode::Untyped)
|
||||
O << "b";
|
||||
else if (Imm == NVPTX::PTXLdStInstCode::Float)
|
||||
O << "f";
|
||||
else
|
||||
llvm_unreachable("Unknown register type");
|
||||
} else if (!strcmp(Modifier, "vec")) {
|
||||
if (Imm == NVPTX::PTXLdStInstCode::V2)
|
||||
O << ".v2";
|
||||
else if (Imm == NVPTX::PTXLdStInstCode::V4)
|
||||
O << ".v4";
|
||||
} else
|
||||
llvm_unreachable("Unknown Modifier");
|
||||
} else
|
||||
llvm_unreachable("Empty Modifier");
|
||||
}
|
||||
|
||||
void NVPTXInstPrinter::printMemOperand(const MCInst *MI, int OpNum,
|
||||
raw_ostream &O, const char *Modifier) {
|
||||
printOperand(MI, OpNum, O);
|
||||
|
||||
if (Modifier && !strcmp(Modifier, "add")) {
|
||||
O << ", ";
|
||||
printOperand(MI, OpNum + 1, O);
|
||||
} else {
|
||||
if (MI->getOperand(OpNum + 1).isImm() &&
|
||||
MI->getOperand(OpNum + 1).getImm() == 0)
|
||||
return; // don't print ',0' or '+0'
|
||||
O << "+";
|
||||
printOperand(MI, OpNum + 1, O);
|
||||
}
|
||||
}
|
||||
|
||||
void NVPTXInstPrinter::printProtoIdent(const MCInst *MI, int OpNum,
|
||||
raw_ostream &O, const char *Modifier) {
|
||||
const MCOperand &Op = MI->getOperand(OpNum);
|
||||
assert(Op.isExpr() && "Call prototype is not an MCExpr?");
|
||||
const MCExpr *Expr = Op.getExpr();
|
||||
const MCSymbol &Sym = cast<MCSymbolRefExpr>(Expr)->getSymbol();
|
||||
O << Sym.getName();
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
//= NVPTXInstPrinter.h - Convert NVPTX MCInst to assembly syntax --*- C++ -*-=//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This class prints an NVPTX MCInst to .ptx file syntax.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_TARGET_NVPTX_INSTPRINTER_NVPTXINSTPRINTER_H
|
||||
#define LLVM_LIB_TARGET_NVPTX_INSTPRINTER_NVPTXINSTPRINTER_H
|
||||
|
||||
#include "llvm/MC/MCInstPrinter.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class MCSubtargetInfo;
|
||||
|
||||
class NVPTXInstPrinter : public MCInstPrinter {
|
||||
public:
|
||||
NVPTXInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
|
||||
const MCRegisterInfo &MRI);
|
||||
|
||||
void printRegName(raw_ostream &OS, unsigned RegNo) const override;
|
||||
void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot,
|
||||
const MCSubtargetInfo &STI) override;
|
||||
|
||||
// Autogenerated by tblgen.
|
||||
void printInstruction(const MCInst *MI, raw_ostream &O);
|
||||
static const char *getRegisterName(unsigned RegNo);
|
||||
// End
|
||||
|
||||
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
|
||||
void printCvtMode(const MCInst *MI, int OpNum, raw_ostream &O,
|
||||
const char *Modifier = nullptr);
|
||||
void printCmpMode(const MCInst *MI, int OpNum, raw_ostream &O,
|
||||
const char *Modifier = nullptr);
|
||||
void printLdStCode(const MCInst *MI, int OpNum,
|
||||
raw_ostream &O, const char *Modifier = nullptr);
|
||||
void printMemOperand(const MCInst *MI, int OpNum,
|
||||
raw_ostream &O, const char *Modifier = nullptr);
|
||||
void printProtoIdent(const MCInst *MI, int OpNum,
|
||||
raw_ostream &O, const char *Modifier = nullptr);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
32
external/llvm/lib/Target/NVPTX/LLVMBuild.txt
vendored
32
external/llvm/lib/Target/NVPTX/LLVMBuild.txt
vendored
@ -1,32 +0,0 @@
|
||||
;===- ./lib/Target/NVPTX/LLVMBuild.txt -------------------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
;
|
||||
; This is an LLVMBuild description file for the components in this subdirectory.
|
||||
;
|
||||
; For more information on the LLVMBuild system, please see:
|
||||
;
|
||||
; http://llvm.org/docs/LLVMBuild.html
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[common]
|
||||
subdirectories = InstPrinter MCTargetDesc TargetInfo
|
||||
|
||||
[component_0]
|
||||
type = TargetGroup
|
||||
name = NVPTX
|
||||
parent = Target
|
||||
has_asmprinter = 1
|
||||
|
||||
[component_1]
|
||||
type = Library
|
||||
name = NVPTXCodeGen
|
||||
parent = NVPTX
|
||||
required_libraries = Analysis AsmPrinter CodeGen Core IPO MC NVPTXAsmPrinter NVPTXDesc NVPTXInfo Scalar SelectionDAG Support Target TransformUtils Vectorize
|
||||
add_to_library_groups = NVPTX
|
@ -1,4 +0,0 @@
|
||||
add_llvm_library(LLVMNVPTXDesc
|
||||
NVPTXMCAsmInfo.cpp
|
||||
NVPTXMCTargetDesc.cpp
|
||||
)
|
@ -1,23 +0,0 @@
|
||||
;===- ./lib/Target/NVPTX/MCTargetDesc/LLVMBuild.txt ------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
;
|
||||
; This is an LLVMBuild description file for the components in this subdirectory.
|
||||
;
|
||||
; For more information on the LLVMBuild system, please see:
|
||||
;
|
||||
; http://llvm.org/docs/LLVMBuild.html
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[component_0]
|
||||
type = Library
|
||||
name = NVPTXDesc
|
||||
parent = NVPTX
|
||||
required_libraries = MC NVPTXAsmPrinter NVPTXInfo Support
|
||||
add_to_library_groups = NVPTX
|
@ -1,46 +0,0 @@
|
||||
//===-- NVPTXBaseInfo.h - Top-level definitions for NVPTX -------*- 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 small standalone helper functions and enum definitions for
|
||||
// the NVPTX target useful for the compiler back-end and the MC libraries.
|
||||
// As such, it deliberately does not include references to LLVM core
|
||||
// code gen types, passes, etc..
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXBASEINFO_H
|
||||
#define LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXBASEINFO_H
|
||||
|
||||
namespace llvm {
|
||||
|
||||
enum AddressSpace {
|
||||
ADDRESS_SPACE_GENERIC = 0,
|
||||
ADDRESS_SPACE_GLOBAL = 1,
|
||||
ADDRESS_SPACE_SHARED = 3,
|
||||
ADDRESS_SPACE_CONST = 4,
|
||||
ADDRESS_SPACE_LOCAL = 5,
|
||||
|
||||
// NVVM Internal
|
||||
ADDRESS_SPACE_PARAM = 101
|
||||
};
|
||||
|
||||
namespace NVPTXII {
|
||||
enum {
|
||||
// These must be kept in sync with TSFlags in NVPTXInstrFormats.td
|
||||
IsTexFlag = 0x80,
|
||||
IsSuldMask = 0x300,
|
||||
IsSuldShift = 8,
|
||||
IsSustFlag = 0x400,
|
||||
IsSurfTexQueryFlag = 0x800,
|
||||
IsTexModeUnifiedFlag = 0x1000
|
||||
};
|
||||
} // namespace NVPTXII
|
||||
|
||||
} // namespace llvm
|
||||
#endif
|
@ -1,59 +0,0 @@
|
||||
//===-- NVPTXMCAsmInfo.cpp - NVPTX 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 NVPTXMCAsmInfo properties.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "NVPTXMCAsmInfo.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
// -debug-compile - Command line option to inform opt and llc passes to
|
||||
// compile for debugging
|
||||
static cl::opt<bool> CompileForDebugging("debug-compile",
|
||||
cl::desc("Compile for debugging"),
|
||||
cl::Hidden, cl::init(false));
|
||||
|
||||
void NVPTXMCAsmInfo::anchor() {}
|
||||
|
||||
NVPTXMCAsmInfo::NVPTXMCAsmInfo(const Triple &TheTriple) {
|
||||
if (TheTriple.getArch() == Triple::nvptx64) {
|
||||
CodePointerSize = CalleeSaveStackSlotSize = 8;
|
||||
}
|
||||
|
||||
CommentString = "//";
|
||||
|
||||
HasSingleParameterDotFile = false;
|
||||
|
||||
InlineAsmStart = " begin inline asm";
|
||||
InlineAsmEnd = " end inline asm";
|
||||
|
||||
SupportsDebugInformation = CompileForDebugging;
|
||||
// PTX does not allow .align on functions.
|
||||
HasFunctionAlignment = false;
|
||||
HasDotTypeDotSizeDirective = false;
|
||||
// PTX does not allow .hidden or .protected
|
||||
HiddenDeclarationVisibilityAttr = HiddenVisibilityAttr = MCSA_Invalid;
|
||||
ProtectedVisibilityAttr = MCSA_Invalid;
|
||||
|
||||
Data8bitsDirective = " .b8 ";
|
||||
Data16bitsDirective = " .b16 ";
|
||||
Data32bitsDirective = " .b32 ";
|
||||
Data64bitsDirective = " .b64 ";
|
||||
ZeroDirective = " .b8";
|
||||
AsciiDirective = " .b8";
|
||||
AscizDirective = " .b8";
|
||||
|
||||
// @TODO: Can we just disable this?
|
||||
WeakDirective = "\t// .weak\t";
|
||||
GlobalDirective = "\t// .globl\t";
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
//===-- NVPTXMCAsmInfo.h - NVPTX 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 NVPTXMCAsmInfo class.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXMCASMINFO_H
|
||||
#define LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXMCASMINFO_H
|
||||
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
|
||||
namespace llvm {
|
||||
class Target;
|
||||
class Triple;
|
||||
|
||||
class NVPTXMCAsmInfo : public MCAsmInfo {
|
||||
virtual void anchor();
|
||||
|
||||
public:
|
||||
explicit NVPTXMCAsmInfo(const Triple &TheTriple);
|
||||
};
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
@ -1,79 +0,0 @@
|
||||
//===-- NVPTXMCTargetDesc.cpp - NVPTX Target Descriptions -------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file provides NVPTX specific target descriptions.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "NVPTXMCTargetDesc.h"
|
||||
#include "InstPrinter/NVPTXInstPrinter.h"
|
||||
#include "NVPTXMCAsmInfo.h"
|
||||
#include "llvm/MC/MCInstrInfo.h"
|
||||
#include "llvm/MC/MCRegisterInfo.h"
|
||||
#include "llvm/MC/MCSubtargetInfo.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
#define GET_INSTRINFO_MC_DESC
|
||||
#include "NVPTXGenInstrInfo.inc"
|
||||
|
||||
#define GET_SUBTARGETINFO_MC_DESC
|
||||
#include "NVPTXGenSubtargetInfo.inc"
|
||||
|
||||
#define GET_REGINFO_MC_DESC
|
||||
#include "NVPTXGenRegisterInfo.inc"
|
||||
|
||||
static MCInstrInfo *createNVPTXMCInstrInfo() {
|
||||
MCInstrInfo *X = new MCInstrInfo();
|
||||
InitNVPTXMCInstrInfo(X);
|
||||
return X;
|
||||
}
|
||||
|
||||
static MCRegisterInfo *createNVPTXMCRegisterInfo(const Triple &TT) {
|
||||
MCRegisterInfo *X = new MCRegisterInfo();
|
||||
// PTX does not have a return address register.
|
||||
InitNVPTXMCRegisterInfo(X, 0);
|
||||
return X;
|
||||
}
|
||||
|
||||
static MCSubtargetInfo *
|
||||
createNVPTXMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
|
||||
return createNVPTXMCSubtargetInfoImpl(TT, CPU, FS);
|
||||
}
|
||||
|
||||
static MCInstPrinter *createNVPTXMCInstPrinter(const Triple &T,
|
||||
unsigned SyntaxVariant,
|
||||
const MCAsmInfo &MAI,
|
||||
const MCInstrInfo &MII,
|
||||
const MCRegisterInfo &MRI) {
|
||||
if (SyntaxVariant == 0)
|
||||
return new NVPTXInstPrinter(MAI, MII, MRI);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Force static initialization.
|
||||
extern "C" void LLVMInitializeNVPTXTargetMC() {
|
||||
for (Target *T : {&getTheNVPTXTarget32(), &getTheNVPTXTarget64()}) {
|
||||
// Register the MC asm info.
|
||||
RegisterMCAsmInfo<NVPTXMCAsmInfo> X(*T);
|
||||
|
||||
// Register the MC instruction info.
|
||||
TargetRegistry::RegisterMCInstrInfo(*T, createNVPTXMCInstrInfo);
|
||||
|
||||
// Register the MC register info.
|
||||
TargetRegistry::RegisterMCRegInfo(*T, createNVPTXMCRegisterInfo);
|
||||
|
||||
// Register the MC subtarget info.
|
||||
TargetRegistry::RegisterMCSubtargetInfo(*T, createNVPTXMCSubtargetInfo);
|
||||
|
||||
// Register the MCInstPrinter.
|
||||
TargetRegistry::RegisterMCInstPrinter(*T, createNVPTXMCInstPrinter);
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
//===-- NVPTXMCTargetDesc.h - NVPTX Target Descriptions ---------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file provides NVPTX specific target descriptions.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXMCTARGETDESC_H
|
||||
#define LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXMCTARGETDESC_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace llvm {
|
||||
class Target;
|
||||
|
||||
Target &getTheNVPTXTarget32();
|
||||
Target &getTheNVPTXTarget64();
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
// Defines symbolic names for PTX registers.
|
||||
#define GET_REGINFO_ENUM
|
||||
#include "NVPTXGenRegisterInfo.inc"
|
||||
|
||||
// Defines symbolic names for the PTX instructions.
|
||||
#define GET_INSTRINFO_ENUM
|
||||
#include "NVPTXGenInstrInfo.inc"
|
||||
|
||||
#define GET_SUBTARGETINFO_ENUM
|
||||
#include "NVPTXGenSubtargetInfo.inc"
|
||||
|
||||
#endif
|
@ -1,49 +0,0 @@
|
||||
//===-- ManagedStringPool.h - Managed String Pool ---------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The strings allocated from a managed string pool are owned by the string
|
||||
// pool and will be deleted together with the managed string pool.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
|
||||
#define LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include <string>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
/// ManagedStringPool - The strings allocated from a managed string pool are
|
||||
/// owned by the string pool and will be deleted together with the managed
|
||||
/// string pool.
|
||||
class ManagedStringPool {
|
||||
SmallVector<std::string *, 8> Pool;
|
||||
|
||||
public:
|
||||
ManagedStringPool() = default;
|
||||
|
||||
~ManagedStringPool() {
|
||||
SmallVectorImpl<std::string *>::iterator Current = Pool.begin();
|
||||
while (Current != Pool.end()) {
|
||||
delete *Current;
|
||||
Current++;
|
||||
}
|
||||
}
|
||||
|
||||
std::string *getManagedString(const char *S) {
|
||||
std::string *Str = new std::string(S);
|
||||
Pool.push_back(Str);
|
||||
return Str;
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
|
177
external/llvm/lib/Target/NVPTX/NVPTX.h
vendored
177
external/llvm/lib/Target/NVPTX/NVPTX.h
vendored
@ -1,177 +0,0 @@
|
||||
//===-- NVPTX.h - Top-level interface for NVPTX representation --*- 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 entry points for global functions defined in
|
||||
// the LLVM NVPTX back-end.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_TARGET_NVPTX_NVPTX_H
|
||||
#define LLVM_LIB_TARGET_NVPTX_NVPTX_H
|
||||
|
||||
#include "MCTargetDesc/NVPTXBaseInfo.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/Value.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include <cassert>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace llvm {
|
||||
class NVPTXTargetMachine;
|
||||
class FunctionPass;
|
||||
class MachineFunctionPass;
|
||||
class formatted_raw_ostream;
|
||||
|
||||
namespace NVPTXCC {
|
||||
enum CondCodes {
|
||||
EQ,
|
||||
NE,
|
||||
LT,
|
||||
LE,
|
||||
GT,
|
||||
GE
|
||||
};
|
||||
}
|
||||
|
||||
FunctionPass *createNVPTXISelDag(NVPTXTargetMachine &TM,
|
||||
llvm::CodeGenOpt::Level OptLevel);
|
||||
ModulePass *createNVPTXAssignValidGlobalNamesPass();
|
||||
ModulePass *createGenericToNVVMPass();
|
||||
FunctionPass *createNVVMIntrRangePass(unsigned int SmVersion);
|
||||
FunctionPass *createNVVMReflectPass();
|
||||
MachineFunctionPass *createNVPTXPrologEpilogPass();
|
||||
MachineFunctionPass *createNVPTXReplaceImageHandlesPass();
|
||||
FunctionPass *createNVPTXImageOptimizerPass();
|
||||
FunctionPass *createNVPTXLowerArgsPass(const NVPTXTargetMachine *TM);
|
||||
BasicBlockPass *createNVPTXLowerAllocaPass();
|
||||
MachineFunctionPass *createNVPTXPeephole();
|
||||
|
||||
Target &getTheNVPTXTarget32();
|
||||
Target &getTheNVPTXTarget64();
|
||||
|
||||
namespace NVPTX {
|
||||
enum DrvInterface {
|
||||
NVCL,
|
||||
CUDA
|
||||
};
|
||||
|
||||
// A field inside TSFlags needs a shift and a mask. The usage is
|
||||
// always as follows :
|
||||
// ((TSFlags & fieldMask) >> fieldShift)
|
||||
// The enum keeps the mask, the shift, and all valid values of the
|
||||
// field in one place.
|
||||
enum VecInstType {
|
||||
VecInstTypeShift = 0,
|
||||
VecInstTypeMask = 0xF,
|
||||
|
||||
VecNOP = 0,
|
||||
VecLoad = 1,
|
||||
VecStore = 2,
|
||||
VecBuild = 3,
|
||||
VecShuffle = 4,
|
||||
VecExtract = 5,
|
||||
VecInsert = 6,
|
||||
VecDest = 7,
|
||||
VecOther = 15
|
||||
};
|
||||
|
||||
enum SimpleMove {
|
||||
SimpleMoveMask = 0x10,
|
||||
SimpleMoveShift = 4
|
||||
};
|
||||
enum LoadStore {
|
||||
isLoadMask = 0x20,
|
||||
isLoadShift = 5,
|
||||
isStoreMask = 0x40,
|
||||
isStoreShift = 6
|
||||
};
|
||||
|
||||
namespace PTXLdStInstCode {
|
||||
enum AddressSpace {
|
||||
GENERIC = 0,
|
||||
GLOBAL = 1,
|
||||
CONSTANT = 2,
|
||||
SHARED = 3,
|
||||
PARAM = 4,
|
||||
LOCAL = 5
|
||||
};
|
||||
enum FromType {
|
||||
Unsigned = 0,
|
||||
Signed,
|
||||
Float,
|
||||
Untyped
|
||||
};
|
||||
enum VecType {
|
||||
Scalar = 1,
|
||||
V2 = 2,
|
||||
V4 = 4
|
||||
};
|
||||
}
|
||||
|
||||
/// PTXCvtMode - Conversion code enumeration
|
||||
namespace PTXCvtMode {
|
||||
enum CvtMode {
|
||||
NONE = 0,
|
||||
RNI,
|
||||
RZI,
|
||||
RMI,
|
||||
RPI,
|
||||
RN,
|
||||
RZ,
|
||||
RM,
|
||||
RP,
|
||||
|
||||
BASE_MASK = 0x0F,
|
||||
FTZ_FLAG = 0x10,
|
||||
SAT_FLAG = 0x20
|
||||
};
|
||||
}
|
||||
|
||||
/// PTXCmpMode - Comparison mode enumeration
|
||||
namespace PTXCmpMode {
|
||||
enum CmpMode {
|
||||
EQ = 0,
|
||||
NE,
|
||||
LT,
|
||||
LE,
|
||||
GT,
|
||||
GE,
|
||||
LO,
|
||||
LS,
|
||||
HI,
|
||||
HS,
|
||||
EQU,
|
||||
NEU,
|
||||
LTU,
|
||||
LEU,
|
||||
GTU,
|
||||
GEU,
|
||||
NUM,
|
||||
// NAN is a MACRO
|
||||
NotANumber,
|
||||
|
||||
BASE_MASK = 0xFF,
|
||||
FTZ_FLAG = 0x100
|
||||
};
|
||||
}
|
||||
}
|
||||
} // end namespace llvm;
|
||||
|
||||
// Defines symbolic names for NVPTX registers. This defines a mapping from
|
||||
// register name to register number.
|
||||
#define GET_REGINFO_ENUM
|
||||
#include "NVPTXGenRegisterInfo.inc"
|
||||
|
||||
// Defines symbolic names for the NVPTX instructions.
|
||||
#define GET_INSTRINFO_ENUM
|
||||
#include "NVPTXGenInstrInfo.inc"
|
||||
|
||||
#endif
|
101
external/llvm/lib/Target/NVPTX/NVPTX.td
vendored
101
external/llvm/lib/Target/NVPTX/NVPTX.td
vendored
@ -1,101 +0,0 @@
|
||||
//===- NVPTX.td - Describe the NVPTX Target Machine -----------*- tblgen -*-==//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// This is the top level entry point for the NVPTX target.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Target-independent interfaces
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
include "llvm/Target/Target.td"
|
||||
|
||||
include "NVPTXRegisterInfo.td"
|
||||
include "NVPTXInstrInfo.td"
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Subtarget Features.
|
||||
// - We use the SM version number instead of explicit feature table.
|
||||
// - Need at least one feature to avoid generating zero sized array by
|
||||
// TableGen in NVPTXGenSubtarget.inc.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// SM Versions
|
||||
def SM20 : SubtargetFeature<"sm_20", "SmVersion", "20",
|
||||
"Target SM 2.0">;
|
||||
def SM21 : SubtargetFeature<"sm_21", "SmVersion", "21",
|
||||
"Target SM 2.1">;
|
||||
def SM30 : SubtargetFeature<"sm_30", "SmVersion", "30",
|
||||
"Target SM 3.0">;
|
||||
def SM32 : SubtargetFeature<"sm_32", "SmVersion", "32",
|
||||
"Target SM 3.2">;
|
||||
def SM35 : SubtargetFeature<"sm_35", "SmVersion", "35",
|
||||
"Target SM 3.5">;
|
||||
def SM37 : SubtargetFeature<"sm_37", "SmVersion", "37",
|
||||
"Target SM 3.7">;
|
||||
def SM50 : SubtargetFeature<"sm_50", "SmVersion", "50",
|
||||
"Target SM 5.0">;
|
||||
def SM52 : SubtargetFeature<"sm_52", "SmVersion", "52",
|
||||
"Target SM 5.2">;
|
||||
def SM53 : SubtargetFeature<"sm_53", "SmVersion", "53",
|
||||
"Target SM 5.3">;
|
||||
def SM60 : SubtargetFeature<"sm_60", "SmVersion", "60",
|
||||
"Target SM 6.0">;
|
||||
def SM61 : SubtargetFeature<"sm_61", "SmVersion", "61",
|
||||
"Target SM 6.1">;
|
||||
def SM62 : SubtargetFeature<"sm_62", "SmVersion", "62",
|
||||
"Target SM 6.2">;
|
||||
def SM70 : SubtargetFeature<"sm_70", "SmVersion", "70",
|
||||
"Target SM 7.0">;
|
||||
|
||||
def SATOM : SubtargetFeature<"satom", "HasAtomScope", "true",
|
||||
"Atomic operations with scope">;
|
||||
|
||||
// PTX Versions
|
||||
def PTX32 : SubtargetFeature<"ptx32", "PTXVersion", "32",
|
||||
"Use PTX version 3.2">;
|
||||
def PTX40 : SubtargetFeature<"ptx40", "PTXVersion", "40",
|
||||
"Use PTX version 4.0">;
|
||||
def PTX41 : SubtargetFeature<"ptx41", "PTXVersion", "41",
|
||||
"Use PTX version 4.1">;
|
||||
def PTX42 : SubtargetFeature<"ptx42", "PTXVersion", "42",
|
||||
"Use PTX version 4.2">;
|
||||
def PTX43 : SubtargetFeature<"ptx43", "PTXVersion", "43",
|
||||
"Use PTX version 4.3">;
|
||||
def PTX50 : SubtargetFeature<"ptx50", "PTXVersion", "50",
|
||||
"Use PTX version 5.0">;
|
||||
def PTX60 : SubtargetFeature<"ptx60", "PTXVersion", "60",
|
||||
"Use PTX version 6.0">;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// NVPTX supported processors.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
class Proc<string Name, list<SubtargetFeature> Features>
|
||||
: Processor<Name, NoItineraries, Features>;
|
||||
|
||||
def : Proc<"sm_20", [SM20]>;
|
||||
def : Proc<"sm_21", [SM21]>;
|
||||
def : Proc<"sm_30", [SM30]>;
|
||||
def : Proc<"sm_32", [SM32, PTX40]>;
|
||||
def : Proc<"sm_35", [SM35]>;
|
||||
def : Proc<"sm_37", [SM37, PTX41]>;
|
||||
def : Proc<"sm_50", [SM50, PTX40]>;
|
||||
def : Proc<"sm_52", [SM52, PTX41]>;
|
||||
def : Proc<"sm_53", [SM53, PTX42]>;
|
||||
def : Proc<"sm_60", [SM60, PTX50, SATOM]>;
|
||||
def : Proc<"sm_61", [SM61, PTX50, SATOM]>;
|
||||
def : Proc<"sm_62", [SM62, PTX50, SATOM]>;
|
||||
def : Proc<"sm_70", [SM70, PTX60, SATOM]>;
|
||||
|
||||
def NVPTXInstrInfo : InstrInfo {
|
||||
}
|
||||
|
||||
def NVPTX : Target {
|
||||
let InstructionSet = NVPTXInstrInfo;
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
//===-- AllocaHoisting.cpp - Hoist allocas to the entry block --*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Hoist the alloca instructions in the non-entry blocks to the entry blocks.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "NVPTXAllocaHoisting.h"
|
||||
#include "llvm/CodeGen/StackProtector.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
// Hoisting the alloca instructions in the non-entry blocks to the entry
|
||||
// block.
|
||||
class NVPTXAllocaHoisting : public FunctionPass {
|
||||
public:
|
||||
static char ID; // Pass ID
|
||||
NVPTXAllocaHoisting() : FunctionPass(ID) {}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addPreserved<StackProtector>();
|
||||
}
|
||||
|
||||
StringRef getPassName() const override {
|
||||
return "NVPTX specific alloca hoisting";
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &function) override;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
bool NVPTXAllocaHoisting::runOnFunction(Function &function) {
|
||||
bool functionModified = false;
|
||||
Function::iterator I = function.begin();
|
||||
TerminatorInst *firstTerminatorInst = (I++)->getTerminator();
|
||||
|
||||
for (Function::iterator E = function.end(); I != E; ++I) {
|
||||
for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE;) {
|
||||
AllocaInst *allocaInst = dyn_cast<AllocaInst>(BI++);
|
||||
if (allocaInst && isa<ConstantInt>(allocaInst->getArraySize())) {
|
||||
allocaInst->moveBefore(firstTerminatorInst);
|
||||
functionModified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return functionModified;
|
||||
}
|
||||
|
||||
char NVPTXAllocaHoisting::ID = 0;
|
||||
|
||||
namespace llvm {
|
||||
void initializeNVPTXAllocaHoistingPass(PassRegistry &);
|
||||
}
|
||||
|
||||
INITIALIZE_PASS(
|
||||
NVPTXAllocaHoisting, "alloca-hoisting",
|
||||
"Hoisting alloca instructions in non-entry blocks to the entry block",
|
||||
false, false)
|
||||
|
||||
FunctionPass *llvm::createAllocaHoisting() { return new NVPTXAllocaHoisting; }
|
@ -1,23 +0,0 @@
|
||||
//===-- AllocaHoisting.h - Hosist allocas to the entry block ----*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Hoist the alloca instructions in the non-entry blocks to the entry blocks.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXALLOCAHOISTING_H
|
||||
#define LLVM_LIB_TARGET_NVPTX_NVPTXALLOCAHOISTING_H
|
||||
|
||||
namespace llvm {
|
||||
class FunctionPass;
|
||||
|
||||
extern FunctionPass *createAllocaHoisting();
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
2453
external/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
vendored
2453
external/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
vendored
File diff suppressed because it is too large
Load Diff
367
external/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
vendored
367
external/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
vendored
@ -1,367 +0,0 @@
|
||||
//===-- NVPTXAsmPrinter.h - NVPTX LLVM assembly writer ----------*- 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 a printer that converts from our internal representation
|
||||
// of machine-dependent LLVM code to NVPTX assembly language.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H
|
||||
#define LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H
|
||||
|
||||
#include "NVPTX.h"
|
||||
#include "NVPTXSubtarget.h"
|
||||
#include "NVPTXTargetMachine.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/CodeGen/AsmPrinter.h"
|
||||
#include "llvm/CodeGen/MachineFunction.h"
|
||||
#include "llvm/CodeGen/MachineLoopInfo.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/DebugLoc.h"
|
||||
#include "llvm/IR/DerivedTypes.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/GlobalValue.h"
|
||||
#include "llvm/IR/Value.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/PassAnalysisSupport.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// The ptx syntax and format is very different from that usually seem in a .s
|
||||
// file,
|
||||
// therefore we are not able to use the MCAsmStreamer interface here.
|
||||
//
|
||||
// We are handcrafting the output method here.
|
||||
//
|
||||
// A better approach is to clone the MCAsmStreamer to a MCPTXAsmStreamer
|
||||
// (subclass of MCStreamer).
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class MCOperand;
|
||||
|
||||
class LineReader {
|
||||
private:
|
||||
unsigned theCurLine;
|
||||
std::ifstream fstr;
|
||||
char buff[512];
|
||||
std::string theFileName;
|
||||
SmallVector<unsigned, 32> lineOffset;
|
||||
|
||||
public:
|
||||
LineReader(std::string filename) {
|
||||
theCurLine = 0;
|
||||
fstr.open(filename.c_str());
|
||||
theFileName = filename;
|
||||
}
|
||||
|
||||
~LineReader() { fstr.close(); }
|
||||
|
||||
std::string fileName() { return theFileName; }
|
||||
std::string readLine(unsigned line);
|
||||
};
|
||||
|
||||
class LLVM_LIBRARY_VISIBILITY NVPTXAsmPrinter : public AsmPrinter {
|
||||
|
||||
class AggBuffer {
|
||||
// Used to buffer the emitted string for initializing global
|
||||
// aggregates.
|
||||
//
|
||||
// Normally an aggregate (array, vector or structure) is emitted
|
||||
// as a u8[]. However, if one element/field of the aggregate
|
||||
// is a non-NULL address, then the aggregate is emitted as u32[]
|
||||
// or u64[].
|
||||
//
|
||||
// We first layout the aggregate in 'buffer' in bytes, except for
|
||||
// those symbol addresses. For the i-th symbol address in the
|
||||
//aggregate, its corresponding 4-byte or 8-byte elements in 'buffer'
|
||||
// are filled with 0s. symbolPosInBuffer[i-1] records its position
|
||||
// in 'buffer', and Symbols[i-1] records the Value*.
|
||||
//
|
||||
// Once we have this AggBuffer setup, we can choose how to print
|
||||
// it out.
|
||||
public:
|
||||
unsigned numSymbols; // number of symbol addresses
|
||||
|
||||
private:
|
||||
const unsigned size; // size of the buffer in bytes
|
||||
std::vector<unsigned char> buffer; // the buffer
|
||||
SmallVector<unsigned, 4> symbolPosInBuffer;
|
||||
SmallVector<const Value *, 4> Symbols;
|
||||
// SymbolsBeforeStripping[i] is the original form of Symbols[i] before
|
||||
// stripping pointer casts, i.e.,
|
||||
// Symbols[i] == SymbolsBeforeStripping[i]->stripPointerCasts().
|
||||
//
|
||||
// We need to keep these values because AggBuffer::print decides whether to
|
||||
// emit a "generic()" cast for Symbols[i] depending on the address space of
|
||||
// SymbolsBeforeStripping[i].
|
||||
SmallVector<const Value *, 4> SymbolsBeforeStripping;
|
||||
unsigned curpos;
|
||||
raw_ostream &O;
|
||||
NVPTXAsmPrinter &AP;
|
||||
bool EmitGeneric;
|
||||
|
||||
public:
|
||||
AggBuffer(unsigned size, raw_ostream &O, NVPTXAsmPrinter &AP)
|
||||
: size(size), buffer(size), O(O), AP(AP) {
|
||||
curpos = 0;
|
||||
numSymbols = 0;
|
||||
EmitGeneric = AP.EmitGeneric;
|
||||
}
|
||||
|
||||
unsigned addBytes(unsigned char *Ptr, int Num, int Bytes) {
|
||||
assert((curpos + Num) <= size);
|
||||
assert((curpos + Bytes) <= size);
|
||||
for (int i = 0; i < Num; ++i) {
|
||||
buffer[curpos] = Ptr[i];
|
||||
curpos++;
|
||||
}
|
||||
for (int i = Num; i < Bytes; ++i) {
|
||||
buffer[curpos] = 0;
|
||||
curpos++;
|
||||
}
|
||||
return curpos;
|
||||
}
|
||||
|
||||
unsigned addZeros(int Num) {
|
||||
assert((curpos + Num) <= size);
|
||||
for (int i = 0; i < Num; ++i) {
|
||||
buffer[curpos] = 0;
|
||||
curpos++;
|
||||
}
|
||||
return curpos;
|
||||
}
|
||||
|
||||
void addSymbol(const Value *GVar, const Value *GVarBeforeStripping) {
|
||||
symbolPosInBuffer.push_back(curpos);
|
||||
Symbols.push_back(GVar);
|
||||
SymbolsBeforeStripping.push_back(GVarBeforeStripping);
|
||||
numSymbols++;
|
||||
}
|
||||
|
||||
void print() {
|
||||
if (numSymbols == 0) {
|
||||
// print out in bytes
|
||||
for (unsigned i = 0; i < size; i++) {
|
||||
if (i)
|
||||
O << ", ";
|
||||
O << (unsigned int) buffer[i];
|
||||
}
|
||||
} else {
|
||||
// print out in 4-bytes or 8-bytes
|
||||
unsigned int pos = 0;
|
||||
unsigned int nSym = 0;
|
||||
unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
|
||||
unsigned int nBytes = 4;
|
||||
if (static_cast<const NVPTXTargetMachine &>(AP.TM).is64Bit())
|
||||
nBytes = 8;
|
||||
for (pos = 0; pos < size; pos += nBytes) {
|
||||
if (pos)
|
||||
O << ", ";
|
||||
if (pos == nextSymbolPos) {
|
||||
const Value *v = Symbols[nSym];
|
||||
const Value *v0 = SymbolsBeforeStripping[nSym];
|
||||
if (const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
|
||||
MCSymbol *Name = AP.getSymbol(GVar);
|
||||
PointerType *PTy = dyn_cast<PointerType>(v0->getType());
|
||||
bool IsNonGenericPointer = false; // Is v0 a non-generic pointer?
|
||||
if (PTy && PTy->getAddressSpace() != 0) {
|
||||
IsNonGenericPointer = true;
|
||||
}
|
||||
if (EmitGeneric && !isa<Function>(v) && !IsNonGenericPointer) {
|
||||
O << "generic(";
|
||||
Name->print(O, AP.MAI);
|
||||
O << ")";
|
||||
} else {
|
||||
Name->print(O, AP.MAI);
|
||||
}
|
||||
} else if (const ConstantExpr *CExpr = dyn_cast<ConstantExpr>(v0)) {
|
||||
const MCExpr *Expr =
|
||||
AP.lowerConstantForGV(cast<Constant>(CExpr), false);
|
||||
AP.printMCExpr(*Expr, O);
|
||||
} else
|
||||
llvm_unreachable("symbol type unknown");
|
||||
nSym++;
|
||||
if (nSym >= numSymbols)
|
||||
nextSymbolPos = size + 1;
|
||||
else
|
||||
nextSymbolPos = symbolPosInBuffer[nSym];
|
||||
} else if (nBytes == 4)
|
||||
O << *(unsigned int *)(&buffer[pos]);
|
||||
else
|
||||
O << *(unsigned long long *)(&buffer[pos]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
friend class AggBuffer;
|
||||
|
||||
void emitSrcInText(StringRef filename, unsigned line);
|
||||
|
||||
private:
|
||||
StringRef getPassName() const override { return "NVPTX Assembly Printer"; }
|
||||
|
||||
const Function *F;
|
||||
std::string CurrentFnName;
|
||||
|
||||
void EmitBasicBlockStart(const MachineBasicBlock &MBB) const override;
|
||||
void EmitFunctionEntryLabel() override;
|
||||
void EmitFunctionBodyStart() override;
|
||||
void EmitFunctionBodyEnd() override;
|
||||
void emitImplicitDef(const MachineInstr *MI) const override;
|
||||
|
||||
void EmitInstruction(const MachineInstr *) override;
|
||||
void lowerToMCInst(const MachineInstr *MI, MCInst &OutMI);
|
||||
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
|
||||
MCOperand GetSymbolRef(const MCSymbol *Symbol);
|
||||
unsigned encodeVirtualRegister(unsigned Reg);
|
||||
|
||||
void printVecModifiedImmediate(const MachineOperand &MO, const char *Modifier,
|
||||
raw_ostream &O);
|
||||
void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
|
||||
const char *Modifier = nullptr);
|
||||
void printModuleLevelGV(const GlobalVariable *GVar, raw_ostream &O,
|
||||
bool = false);
|
||||
void printParamName(Function::const_arg_iterator I, int paramIndex,
|
||||
raw_ostream &O);
|
||||
void emitGlobals(const Module &M);
|
||||
void emitHeader(Module &M, raw_ostream &O, const NVPTXSubtarget &STI);
|
||||
void emitKernelFunctionDirectives(const Function &F, raw_ostream &O) const;
|
||||
void emitVirtualRegister(unsigned int vr, raw_ostream &);
|
||||
void emitFunctionParamList(const Function *, raw_ostream &O);
|
||||
void emitFunctionParamList(const MachineFunction &MF, raw_ostream &O);
|
||||
void setAndEmitFunctionVirtualRegisters(const MachineFunction &MF);
|
||||
void printReturnValStr(const Function *, raw_ostream &O);
|
||||
void printReturnValStr(const MachineFunction &MF, raw_ostream &O);
|
||||
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
||||
unsigned AsmVariant, const char *ExtraCode,
|
||||
raw_ostream &) override;
|
||||
void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
|
||||
const char *Modifier = nullptr);
|
||||
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
||||
unsigned AsmVariant, const char *ExtraCode,
|
||||
raw_ostream &) override;
|
||||
|
||||
const MCExpr *lowerConstantForGV(const Constant *CV, bool ProcessingGeneric);
|
||||
void printMCExpr(const MCExpr &Expr, raw_ostream &OS);
|
||||
|
||||
protected:
|
||||
bool doInitialization(Module &M) override;
|
||||
bool doFinalization(Module &M) override;
|
||||
|
||||
private:
|
||||
std::string CurrentBankselLabelInBasicBlock;
|
||||
|
||||
bool GlobalsEmitted;
|
||||
|
||||
// This is specific per MachineFunction.
|
||||
const MachineRegisterInfo *MRI;
|
||||
// The contents are specific for each
|
||||
// MachineFunction. But the size of the
|
||||
// array is not.
|
||||
typedef DenseMap<unsigned, unsigned> VRegMap;
|
||||
typedef DenseMap<const TargetRegisterClass *, VRegMap> VRegRCMap;
|
||||
VRegRCMap VRegMapping;
|
||||
|
||||
// Cache the subtarget here.
|
||||
const NVPTXSubtarget *nvptxSubtarget;
|
||||
|
||||
// Build the map between type name and ID based on module's type
|
||||
// symbol table.
|
||||
std::map<Type *, std::string> TypeNameMap;
|
||||
|
||||
// List of variables demoted to a function scope.
|
||||
std::map<const Function *, std::vector<const GlobalVariable *>> localDecls;
|
||||
|
||||
// To record filename to ID mapping
|
||||
std::map<std::string, unsigned> filenameMap;
|
||||
void recordAndEmitFilenames(Module &);
|
||||
|
||||
void emitPTXGlobalVariable(const GlobalVariable *GVar, raw_ostream &O);
|
||||
void emitPTXAddressSpace(unsigned int AddressSpace, raw_ostream &O) const;
|
||||
std::string getPTXFundamentalTypeStr(Type *Ty, bool = true) const;
|
||||
void printScalarConstant(const Constant *CPV, raw_ostream &O);
|
||||
void printFPConstant(const ConstantFP *Fp, raw_ostream &O);
|
||||
void bufferLEByte(const Constant *CPV, int Bytes, AggBuffer *aggBuffer);
|
||||
void bufferAggregateConstant(const Constant *CV, AggBuffer *aggBuffer);
|
||||
|
||||
void emitLinkageDirective(const GlobalValue *V, raw_ostream &O);
|
||||
void emitDeclarations(const Module &, raw_ostream &O);
|
||||
void emitDeclaration(const Function *, raw_ostream &O);
|
||||
void emitDemotedVars(const Function *, raw_ostream &);
|
||||
|
||||
bool lowerImageHandleOperand(const MachineInstr *MI, unsigned OpNo,
|
||||
MCOperand &MCOp);
|
||||
void lowerImageHandleSymbol(unsigned Index, MCOperand &MCOp);
|
||||
|
||||
bool isLoopHeaderOfNoUnroll(const MachineBasicBlock &MBB) const;
|
||||
|
||||
LineReader *reader = nullptr;
|
||||
|
||||
LineReader *getReader(const std::string &);
|
||||
|
||||
// Used to control the need to emit .generic() in the initializer of
|
||||
// module scope variables.
|
||||
// Although ptx supports the hybrid mode like the following,
|
||||
// .global .u32 a;
|
||||
// .global .u32 b;
|
||||
// .global .u32 addr[] = {a, generic(b)}
|
||||
// we have difficulty representing the difference in the NVVM IR.
|
||||
//
|
||||
// Since the address value should always be generic in CUDA C and always
|
||||
// be specific in OpenCL, we use this simple control here.
|
||||
//
|
||||
bool EmitGeneric;
|
||||
|
||||
public:
|
||||
NVPTXAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
|
||||
: AsmPrinter(TM, std::move(Streamer)),
|
||||
EmitGeneric(static_cast<NVPTXTargetMachine &>(TM).getDrvInterface() ==
|
||||
NVPTX::CUDA) {}
|
||||
|
||||
~NVPTXAsmPrinter() override {
|
||||
delete reader;
|
||||
}
|
||||
|
||||
bool runOnMachineFunction(MachineFunction &F) override {
|
||||
nvptxSubtarget = &F.getSubtarget<NVPTXSubtarget>();
|
||||
return AsmPrinter::runOnMachineFunction(F);
|
||||
}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<MachineLoopInfo>();
|
||||
AsmPrinter::getAnalysisUsage(AU);
|
||||
}
|
||||
|
||||
bool ignoreLoc(const MachineInstr &);
|
||||
|
||||
std::string getVirtualRegisterName(unsigned) const;
|
||||
|
||||
DebugLoc prevDebugLoc;
|
||||
void emitLineNumberAsDotLoc(const MachineInstr &);
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user