<div dir="ltr">Should be fixed in r187829. Thanks for the report!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 6, 2013 at 5:10 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Aug 6, 2013 at 10:13 AM, Justin Holewinski<br>
<<a href="mailto:jholewinski@nvidia.com">jholewinski@nvidia.com</a>> wrote:<br>
> Author: jholewinski<br>
> Date: Tue Aug 6 09:13:27 2013<br>
> New Revision: 187798<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=187798&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=187798&view=rev</a><br>
> Log:<br>
> [NVPTX] Start conversion to MC infrastructure<br>
><br>
> This change converts the NVPTX target to use the MC infrastructure<br>
> instead of directly emitting MachineInstr instances. This brings<br>
> the target more up-to-date with LLVM TOT, and should fix PR15175<br>
> and PR15958 (libNVPTXInstPrinter is empty) as a side-effect.<br>
><br>
> Added:<br>
> llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.h<br>
> llvm/trunk/lib/Target/NVPTX/NVPTXMCExpr.cpp<br>
> llvm/trunk/lib/Target/NVPTX/NVPTXMCExpr.h<br>
> llvm/trunk/test/CodeGen/NVPTX/fp-literals.ll<br>
> Modified:<br>
> llvm/trunk/lib/Target/NVPTX/CMakeLists.txt<br>
> llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp<br>
> llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp<br>
> llvm/trunk/lib/Target/NVPTX/NVPTX.td<br>
> llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp<br>
> llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.h<br>
> llvm/trunk/lib/Target/NVPTX/NVPTXISelLowering.cpp<br>
><br>
> Modified: llvm/trunk/lib/Target/NVPTX/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/CMakeLists.txt?rev=187798&r1=187797&r2=187798&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/CMakeLists.txt?rev=187798&r1=187797&r2=187798&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Target/NVPTX/CMakeLists.txt (original)<br>
> +++ llvm/trunk/lib/Target/NVPTX/CMakeLists.txt Tue Aug 6 09:13:27 2013<br>
> @@ -25,6 +25,7 @@ set(NVPTXCodeGen_sources<br>
> NVVMReflect.cpp<br>
> NVPTXGenericToNVVM.cpp<br>
> NVPTXPrologEpilogPass.cpp<br>
> + NVPTXMCExpr.cpp<br>
> )<br>
><br>
> add_llvm_target(NVPTXCodeGen ${NVPTXCodeGen_sources})<br>
><br>
> Modified: llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp?rev=187798&r1=187797&r2=187798&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp?rev=187798&r1=187797&r2=187798&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp (original)<br>
> +++ llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp Tue Aug 6 09:13:27 2013<br>
> @@ -1 +1,274 @@<br>
> -// Placeholder<br>
> +//===-- NVPTXInstPrinter.cpp - PTX assembly instruction printing ----------===//<br>
> +//<br>
> +// The LLVM Compiler Infrastructure<br>
> +//<br>
> +// This file is distributed under the University of Illinois Open Source<br>
> +// License. See LICENSE.TXT for details.<br>
> +//<br>
> +//===----------------------------------------------------------------------===//<br>
> +//<br>
> +// Print MCInst instructions to .ptx format.<br>
> +//<br>
> +//===----------------------------------------------------------------------===//<br>
> +<br>
> +#define DEBUG_TYPE "asm-printer"<br>
> +#include "InstPrinter/NVPTXInstPrinter.h"<br>
> +#include "NVPTX.h"<br>
> +#include "MCTargetDesc/NVPTXBaseInfo.h"<br>
> +#include "llvm/MC/MCExpr.h"<br>
> +#include "llvm/MC/MCInst.h"<br>
> +#include "llvm/MC/MCInstrInfo.h"<br>
> +#include "llvm/MC/MCSubtargetInfo.h"<br>
> +#include "llvm/Support/ErrorHandling.h"<br>
> +#include "llvm/Support/FormattedStream.h"<br>
> +#include <cctype><br>
> +using namespace llvm;<br>
> +<br>
> +#include "NVPTXGenAsmWriter.inc"<br>
> +<br>
> +<br>
> +NVPTXInstPrinter::NVPTXInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,<br>
> + const MCRegisterInfo &MRI,<br>
> + const MCSubtargetInfo &STI)<br>
> + : MCInstPrinter(MAI, MII, MRI) {<br>
> + setAvailableFeatures(STI.getFeatureBits());<br>
> +}<br>
> +<br>
> +void NVPTXInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {<br>
> + // Decode the virtual register<br>
> + // Must be kept in sync with NVPTXAsmPrinter::encodeVirtualRegister<br>
> + unsigned RCId = (RegNo >> 28);<br>
> + switch (RCId) {<br>
> + default: report_fatal_error("Bad virtual register encoding");<br>
> + case 0:<br>
> + OS << "%p";<br>
> + break;<br>
> + case 1:<br>
> + OS << "%rs";<br>
> + break;<br>
> + case 2:<br>
> + OS << "%r";<br>
> + break;<br>
> + case 3:<br>
> + OS << "%rl";<br>
> + break;<br>
> + case 4:<br>
> + OS << "%f";<br>
> + break;<br>
> + case 5:<br>
> + OS << "%fl";<br>
> + break;<br>
> + }<br>
> +<br>
> + unsigned VReg = RegNo & 0x0FFFFFFF;<br>
> + OS << VReg;<br>
> +}<br>
> +<br>
> +void NVPTXInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,<br>
> + StringRef Annot) {<br>
> + printInstruction(MI, OS);<br>
> +<br>
> + // Next always print the annotation.<br>
> + printAnnotation(OS, Annot);<br>
> +}<br>
> +<br>
> +void NVPTXInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,<br>
> + raw_ostream &O) {<br>
> + const MCOperand &Op = MI->getOperand(OpNo);<br>
> + if (Op.isReg()) {<br>
> + unsigned Reg = Op.getReg();<br>
> + printRegName(O, Reg);<br>
> + } else if (Op.isImm()) {<br>
> + O << markup("<imm:") << formatImm(Op.getImm()) << markup(">");<br>
> + } else {<br>
> + assert(Op.isExpr() && "Unknown operand kind in printOperand");<br>
> + O << *Op.getExpr();<br>
> + }<br>
> +}<br>
> +<br>
> +void NVPTXInstPrinter::printCvtMode(const MCInst *MI, int OpNum, raw_ostream &O,<br>
> + const char *Modifier) {<br>
> + const MCOperand &MO = MI->getOperand(OpNum);<br>
> + int64_t Imm = MO.getImm();<br>
> +<br>
> + if (strcmp(Modifier, "ftz") == 0) {<br>
> + // FTZ flag<br>
> + if (Imm & NVPTX::PTXCvtMode::FTZ_FLAG)<br>
> + O << ".ftz";<br>
> + } else if (strcmp(Modifier, "sat") == 0) {<br>
> + // SAT flag<br>
> + if (Imm & NVPTX::PTXCvtMode::SAT_FLAG)<br>
> + O << ".sat";<br>
> + } else if (strcmp(Modifier, "base") == 0) {<br>
> + // Default operand<br>
> + switch (Imm & NVPTX::PTXCvtMode::BASE_MASK) {<br>
> + default:<br>
> + return;<br>
> + case NVPTX::PTXCvtMode::NONE:<br>
> + break;<br>
> + case NVPTX::PTXCvtMode::RNI:<br>
> + O << ".rni";<br>
> + break;<br>
> + case NVPTX::PTXCvtMode::RZI:<br>
> + O << ".rzi";<br>
> + break;<br>
> + case NVPTX::PTXCvtMode::RMI:<br>
> + O << ".rmi";<br>
> + break;<br>
> + case NVPTX::PTXCvtMode::RPI:<br>
> + O << ".rpi";<br>
> + break;<br>
> + case NVPTX::PTXCvtMode::RN:<br>
> + O << ".rn";<br>
> + break;<br>
> + case NVPTX::PTXCvtMode::RZ:<br>
> + O << ".rz";<br>
> + break;<br>
> + case NVPTX::PTXCvtMode::RM:<br>
> + O << ".rm";<br>
> + break;<br>
> + case NVPTX::PTXCvtMode::RP:<br>
> + O << ".rp";<br>
> + break;<br>
> + }<br>
> + } else {<br>
> + llvm_unreachable("Invalid conversion modifier");<br>
> + }<br>
> +}<br>
> +<br>
> +void NVPTXInstPrinter::printCmpMode(const MCInst *MI, int OpNum, raw_ostream &O,<br>
> + const char *Modifier) {<br>
> + const MCOperand &MO = MI->getOperand(OpNum);<br>
> + int64_t Imm = MO.getImm();<br>
> +<br>
> + if (strcmp(Modifier, "ftz") == 0) {<br>
> + // FTZ flag<br>
> + if (Imm & NVPTX::PTXCmpMode::FTZ_FLAG)<br>
> + O << ".ftz";<br>
> + } else if (strcmp(Modifier, "base") == 0) {<br>
> + switch (Imm & NVPTX::PTXCmpMode::BASE_MASK) {<br>
> + default:<br>
> + return;<br>
> + case NVPTX::PTXCmpMode::EQ:<br>
> + O << ".eq";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::NE:<br>
> + O << ".ne";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::LT:<br>
> + O << ".lt";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::LE:<br>
> + O << ".le";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::GT:<br>
> + O << ".gt";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::GE:<br>
> + O << ".ge";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::LO:<br>
> + O << ".lo";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::LS:<br>
> + O << ".ls";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::HI:<br>
> + O << ".hi";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::HS:<br>
> + O << ".hs";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::EQU:<br>
> + O << ".equ";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::NEU:<br>
> + O << ".neu";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::LTU:<br>
> + O << ".ltu";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::LEU:<br>
> + O << ".leu";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::GTU:<br>
> + O << ".gtu";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::GEU:<br>
> + O << ".geu";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::NUM:<br>
> + O << ".num";<br>
> + break;<br>
> + case NVPTX::PTXCmpMode::NotANumber:<br>
> + O << ".nan";<br>
> + break;<br>
> + }<br>
> + } else {<br>
> + llvm_unreachable("Empty Modifier");<br>
> + }<br>
> +}<br>
> +<br>
> +void NVPTXInstPrinter::printLdStCode(const MCInst *MI, int OpNum,<br>
> + raw_ostream &O, const char *Modifier) {<br>
> + if (Modifier) {<br>
> + const MCOperand &MO = MI->getOperand(OpNum);<br>
> + int Imm = (int) MO.getImm();<br>
> + if (!strcmp(Modifier, "volatile")) {<br>
> + if (Imm)<br>
> + O << ".volatile";<br>
> + } else if (!strcmp(Modifier, "addsp")) {<br>
> + switch (Imm) {<br>
> + case NVPTX::PTXLdStInstCode::GLOBAL:<br>
> + O << ".global";<br>
> + break;<br>
> + case NVPTX::PTXLdStInstCode::SHARED:<br>
> + O << ".shared";<br>
> + break;<br>
> + case NVPTX::PTXLdStInstCode::LOCAL:<br>
> + O << ".local";<br>
> + break;<br>
> + case NVPTX::PTXLdStInstCode::PARAM:<br>
> + O << ".param";<br>
> + break;<br>
> + case NVPTX::PTXLdStInstCode::CONSTANT:<br>
> + O << ".const";<br>
> + break;<br>
> + case NVPTX::PTXLdStInstCode::GENERIC:<br>
> + break;<br>
> + default:<br>
> + llvm_unreachable("Wrong Address Space");<br>
> + }<br>
> + } else if (!strcmp(Modifier, "sign")) {<br>
> + if (Imm == NVPTX::PTXLdStInstCode::Signed)<br>
> + O << "s";<br>
> + else if (Imm == NVPTX::PTXLdStInstCode::Unsigned)<br>
> + O << "u";<br>
> + else<br>
> + O << "f";<br>
> + } else if (!strcmp(Modifier, "vec")) {<br>
> + if (Imm == NVPTX::PTXLdStInstCode::V2)<br>
> + O << ".v2";<br>
> + else if (Imm == NVPTX::PTXLdStInstCode::V4)<br>
> + O << ".v4";<br>
> + } else<br>
> + llvm_unreachable("Unknown Modifier");<br>
> + } else<br>
> + llvm_unreachable("Empty Modifier");<br>
> +}<br>
> +<br>
> +void NVPTXInstPrinter::printMemOperand(const MCInst *MI, int OpNum,<br>
> + raw_ostream &O, const char *Modifier) {<br>
> + printOperand(MI, OpNum, O);<br>
> +<br>
> + if (Modifier && !strcmp(Modifier, "add")) {<br>
> + O << ", ";<br>
> + printOperand(MI, OpNum + 1, O);<br>
> + } else {<br>
> + if (MI->getOperand(OpNum + 1).isImm() &&<br>
> + MI->getOperand(OpNum + 1).getImm() == 0)<br>
> + return; // don't print ',0' or '+0'<br>
> + O << "+";<br>
> + printOperand(MI, OpNum + 1, O);<br>
> + }<br>
> +}<br>
><br>
> Added: llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.h?rev=187798&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.h?rev=187798&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.h (added)<br>
> +++ llvm/trunk/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.h Tue Aug 6 09:13:27 2013<br>
> @@ -0,0 +1,52 @@<br>
> +//= NVPTXInstPrinter.h - Convert NVPTX MCInst to assembly syntax --*- C++ -*-=//<br>
> +//<br>
> +// The LLVM Compiler Infrastructure<br>
> +//<br>
> +// This file is distributed under the University of Illinois Open Source<br>
> +// License. See LICENSE.TXT for details.<br>
> +//<br>
> +//===----------------------------------------------------------------------===//<br>
> +//<br>
> +// This class prints an NVPTX MCInst to .ptx file syntax.<br>
> +//<br>
> +//===----------------------------------------------------------------------===//<br>
> +<br>
> +#ifndef NVPTX_INST_PRINTER_H<br>
> +#define NVPTX_INST_PRINTER_H<br>
> +<br>
> +#include "llvm/MC/MCInstPrinter.h"<br>
> +#include "llvm/Support/raw_ostream.h"<br>
> +<br>
> +namespace llvm {<br>
> +<br>
> +class MCOperand;<br>
> +class MCSubtargetInfo;<br>
> +<br>
> +class NVPTXInstPrinter : public MCInstPrinter {<br>
> +public:<br>
> + NVPTXInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,<br>
> + const MCRegisterInfo &MRI, const MCSubtargetInfo &STI);<br>
> +<br>
> + virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;<br>
> + virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot);<br>
> +<br>
> + // Autogenerated by tblgen.<br>
> + void printInstruction(const MCInst *MI, raw_ostream &O);<br>
> + static const char *getRegisterName(unsigned RegNo);<br>
> + // End<br>
> +<br>
> + void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);<br>
> + void printCvtMode(const MCInst *MI, int OpNum, raw_ostream &O,<br>
> + const char *Modifier = 0);<br>
> + void printCmpMode(const MCInst *MI, int OpNum, raw_ostream &O,<br>
> + const char *Modifier = 0);<br>
> + void printLdStCode(const MCInst *MI, int OpNum,<br>
> + raw_ostream &O, const char *Modifier = 0);<br>
> + void printMemOperand(const MCInst *MI, int OpNum,<br>
> + raw_ostream &O, const char *Modifier = 0);<br>
> +<br>
> +};<br>
> +<br>
> +}<br>
> +<br>
> +#endif<br>
><br>
> Modified: llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp?rev=187798&r1=187797&r2=187798&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp?rev=187798&r1=187797&r2=187798&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp (original)<br>
> +++ llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp Tue Aug 6 09:13:27 2013<br>
> @@ -13,6 +13,7 @@<br>
><br>
> #include "NVPTXMCTargetDesc.h"<br>
> #include "NVPTXMCAsmInfo.h"<br>
> +#include "InstPrinter/NVPTXInstPrinter.h"<br>
> #include "llvm/MC/MCCodeGenInfo.h"<br>
> #include "llvm/MC/MCInstrInfo.h"<br>
> #include "llvm/MC/MCRegisterInfo.h"<br>
> @@ -57,6 +58,17 @@ static MCCodeGenInfo *createNVPTXMCCodeG<br>
> return X;<br>
> }<br>
><br>
> +static MCInstPrinter *createNVPTXMCInstPrinter(const Target &T,<br>
> + unsigned SyntaxVariant,<br>
> + const MCAsmInfo &MAI,<br>
> + const MCInstrInfo &MII,<br>
> + const MCRegisterInfo &MRI,<br>
> + const MCSubtargetInfo &STI) {<br>
> + if (SyntaxVariant == 0)<br>
> + return new NVPTXInstPrinter(MAI, MII, MRI, STI);<br>
> + return 0;<br>
> +}<br>
> +<br>
> // Force static initialization.<br>
> extern "C" void LLVMInitializeNVPTXTargetMC() {<br>
> // Register the MC asm info.<br>
> @@ -85,4 +97,9 @@ extern "C" void LLVMInitializeNVPTXTarge<br>
> TargetRegistry::RegisterMCSubtargetInfo(TheNVPTXTarget64,<br>
> createNVPTXMCSubtargetInfo);<br>
><br>
> + // Register the MCInstPrinter.<br>
> + TargetRegistry::RegisterMCInstPrinter(TheNVPTXTarget32,<br>
> + createNVPTXMCInstPrinter);<br>
> + TargetRegistry::RegisterMCInstPrinter(TheNVPTXTarget64,<br>
> + createNVPTXMCInstPrinter);<br>
> }<br>
><br>
> Modified: llvm/trunk/lib/Target/NVPTX/NVPTX.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTX.td?rev=187798&r1=187797&r2=187798&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTX.td?rev=187798&r1=187797&r2=187798&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Target/NVPTX/NVPTX.td (original)<br>
> +++ llvm/trunk/lib/Target/NVPTX/NVPTX.td Tue Aug 6 09:13:27 2013<br>
> @@ -57,6 +57,12 @@ def : Proc<"sm_35", [SM35]>;<br>
> def NVPTXInstrInfo : InstrInfo {<br>
> }<br>
><br>
> +def NVPTXAsmWriter : AsmWriter {<br>
> + bit isMCAsmWriter = 1;<br>
> + string AsmWriterClassName = "InstPrinter";<br>
> +}<br>
> +<br>
> def NVPTX : Target {<br>
> let InstructionSet = NVPTXInstrInfo;<br>
> + let AssemblyWriters = [NVPTXAsmWriter];<br>
> }<br>
><br>
> Modified: llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp?rev=187798&r1=187797&r2=187798&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp?rev=187798&r1=187797&r2=187798&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (original)<br>
> +++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Tue Aug 6 09:13:27 2013<br>
> @@ -16,6 +16,7 @@<br>
> #include "MCTargetDesc/NVPTXMCAsmInfo.h"<br>
> #include "NVPTX.h"<br>
> #include "NVPTXInstrInfo.h"<br>
> +#include "NVPTXMCExpr.h"<br>
> #include "NVPTXRegisterInfo.h"<br>
> #include "NVPTXTargetMachine.h"<br>
> #include "NVPTXUtilities.h"<br>
> @@ -46,8 +47,6 @@<br>
> #include <sstream><br>
> using namespace llvm;<br>
><br>
> -#include "NVPTXGenAsmWriter.inc"<br>
> -<br>
> bool RegAllocNilUsed = true;<br>
><br>
> #define DEPOTNAME "__local_depot"<br>
> @@ -309,8 +308,106 @@ void NVPTXAsmPrinter::EmitInstruction(co<br>
> raw_svector_ostream OS(Str);<br>
> if (nvptxSubtarget.getDrvInterface() == NVPTX::CUDA)<br>
> emitLineNumberAsDotLoc(*MI);<br>
> - printInstruction(MI, OS);<br>
> - OutStreamer.EmitRawText(OS.str());<br>
> +<br>
> + MCInst Inst;<br>
> + lowerToMCInst(MI, Inst);<br>
> + OutStreamer.EmitInstruction(Inst);<br>
> +}<br>
> +<br>
> +void NVPTXAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {<br>
> + OutMI.setOpcode(MI->getOpcode());<br>
> +<br>
> + for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {<br>
> + const MachineOperand &MO = MI->getOperand(i);<br>
> +<br>
> + MCOperand MCOp;<br>
> + if (lowerOperand(MO, MCOp))<br>
> + OutMI.addOperand(MCOp);<br>
> + }<br>
> +}<br>
> +<br>
> +bool NVPTXAsmPrinter::lowerOperand(const MachineOperand &MO,<br>
> + MCOperand &MCOp) {<br>
> + switch (MO.getType()) {<br>
> + default: llvm_unreachable("unknown operand type");<br>
> + case MachineOperand::MO_Register:<br>
> + MCOp = MCOperand::CreateReg(encodeVirtualRegister(MO.getReg()));<br>
> + break;<br>
> + case MachineOperand::MO_Immediate:<br>
> + MCOp = MCOperand::CreateImm(MO.getImm());<br>
> + break;<br>
> + case MachineOperand::MO_MachineBasicBlock:<br>
> + MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(<br>
> + MO.getMBB()->getSymbol(), OutContext));<br>
> + break;<br>
> + case MachineOperand::MO_ExternalSymbol:<br>
> + MCOp = GetSymbolRef(MO, GetExternalSymbolSymbol(MO.getSymbolName()));<br>
> + break;<br>
> + case MachineOperand::MO_GlobalAddress:<br>
> + MCOp = GetSymbolRef(MO, Mang->getSymbol(MO.getGlobal()));<br>
> + break;<br>
> + case MachineOperand::MO_FPImmediate: {<br>
> + const ConstantFP *Cnt = MO.getFPImm();<br>
> + APFloat Val = Cnt->getValueAPF();<br>
> +<br>
> + switch (Cnt->getType()->getTypeID()) {<br>
> + default: report_fatal_error("Unsupported FP type"); break;<br>
> + case Type::FloatTyID:<br>
> + MCOp = MCOperand::CreateExpr(<br>
> + NVPTXFloatMCExpr::CreateConstantFPSingle(Val, OutContext));<br>
> + break;<br>
> + case Type::DoubleTyID:<br>
> + MCOp = MCOperand::CreateExpr(<br>
> + NVPTXFloatMCExpr::CreateConstantFPDouble(Val, OutContext));<br>
> + break;<br>
> + }<br>
> + break;<br>
> + }<br>
> + }<br>
> + return true;<br>
> +}<br>
> +<br>
> +unsigned NVPTXAsmPrinter::encodeVirtualRegister(unsigned Reg) {<br>
> + const TargetRegisterClass *RC = MRI->getRegClass(Reg);<br>
> +<br>
> + DenseMap<unsigned, unsigned> &RegMap = VRegMapping[RC];<br>
> + unsigned RegNum = RegMap[Reg];<br>
> +<br>
> + // Encode the register class in the upper 4 bits<br>
> + // Must be kept in sync with NVPTXInstPrinter::printRegName<br>
> + unsigned Ret = 0;<br>
> + if (RC == &NVPTX::Int1RegsRegClass) {<br>
> + Ret = 0;<br>
> + } else if (RC == &NVPTX::Int16RegsRegClass) {<br>
> + Ret = (1 << 28);<br>
> + } else if (RC == &NVPTX::Int32RegsRegClass) {<br>
> + Ret = (2 << 28);<br>
> + } else if (RC == &NVPTX::Int64RegsRegClass) {<br>
> + Ret = (3 << 28);<br>
> + } else if (RC == &NVPTX::Float32RegsRegClass) {<br>
> + Ret = (4 << 28);<br>
> + } else if (RC == &NVPTX::Float64RegsRegClass) {<br>
> + Ret = (5 << 28);<br>
> + } else {<br>
> + report_fatal_error("Bad register class");<br>
> + }<br>
> +<br>
> + // Insert the vreg number<br>
> + Ret |= (RegNum & 0x0FFFFFFF);<br>
> + return Ret;<br>
> +}<br>
> +<br>
> +MCOperand NVPTXAsmPrinter::GetSymbolRef(const MachineOperand &MO,<br>
> + const MCSymbol *Symbol) {<br>
> + const MCExpr *Expr;<br>
> + switch (MO.getTargetFlags()) {<br>
> + default: {<br>
> + Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None,<br>
> + OutContext);<br>
> + break;<br>
> + }<br>
<br>
</div></div>This has introduced a new warning in MSVC:<br>
<br>
E:\bb-win7\ninja-clang-i686-msc17-R\llvm-project\llvm\lib\Target\NVPTX\NVPTXAsmPrinter.cpp(415)<br>
: warning C4065: switch statement contains 'default' but no 'case'<br>
labels<br>
<br>
Can you please rectify?<br>
<br>
Thanks!<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div>
</div>