Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ struct ExtendedBuiltin {

enum InstFlags {
// It is a half type
INST_PRINTER_WIDTH16 = 1
INST_PRINTER_WIDTH16 = 1,
// It is a 64-bit type
INST_PRINTER_WIDTH64 = INST_PRINTER_WIDTH16 << 1,

};
} // namespace SPIRV

Expand Down
29 changes: 29 additions & 0 deletions llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,35 @@ void SPIRVInstPrinter::printInst(const MCInst *MI, uint64_t Address,
MI, FirstVariableIndex, OS);
printRemainingVariableOps(MI, FirstVariableIndex + 1, OS);
break;
case SPIRV::OpSwitch:
if (MI->getFlags() & SPIRV::INST_PRINTER_WIDTH64) {
// In binary format 64-bit types are split into two 32-bit operands,
// but in text format combine these into a single 64-bit value as
// this is what tools such as spirv-as require.
const unsigned NumOps = MI->getNumOperands();
for (unsigned OpIdx = NumFixedOps; OpIdx < NumOps;) {
if (OpIdx + 1 >= NumOps || !MI->getOperand(OpIdx).isImm() ||
!MI->getOperand(OpIdx + 1).isImm()) {
continue;
}
OS << ' ';
uint64_t LowBits = MI->getOperand(OpIdx).getImm();
uint64_t HighBits = MI->getOperand(OpIdx + 1).getImm();
uint64_t CombinedValue = (HighBits << 32) | LowBits;
OS << formatImm(CombinedValue);
OpIdx += 2;

// Next should be the label
if (OpIdx < NumOps) {
OS << ' ';
printOperand(MI, OpIdx, OS);
OpIdx++;
}
}
} else {
printRemainingVariableOps(MI, NumFixedOps, OS);
}
break;
case SPIRV::OpImageSampleImplicitLod:
case SPIRV::OpImageSampleDrefImplicitLod:
case SPIRV::OpImageSampleProjImplicitLod:
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/SPIRV/SPIRVInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class SPIRVInstrInfo : public SPIRVGenInstrInfo {
namespace SPIRV {
enum AsmComments {
// It is a half type
ASM_PRINTER_WIDTH16 = MachineInstr::TAsmComments
ASM_PRINTER_WIDTH16 = MachineInstr::TAsmComments,
// It is a 64 bit type
ASM_PRINTER_WIDTH64 = ASM_PRINTER_WIDTH16 << 1,
};
} // namespace SPIRV

Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVMCInstLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ void SPIRVMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI,
// Propagate previously set flags
if (MI->getAsmPrinterFlags() & SPIRV::ASM_PRINTER_WIDTH16)
OutMI.setFlags(SPIRV::INST_PRINTER_WIDTH16);
if (MI->getAsmPrinterFlags() & SPIRV::ASM_PRINTER_WIDTH64)
OutMI.setFlags(SPIRV::INST_PRINTER_WIDTH64);
const MachineFunction *MF = MI->getMF();
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
const MachineOperand &MO = MI->getOperand(i);
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB) {
uint32_t LowBits = FullImm & 0xffffffff;
uint32_t HighBits = (FullImm >> 32) & 0xffffffff;
MIB.addImm(LowBits).addImm(HighBits);
// Asm Printer needs this info to print 64-bit operands correctly
MIB.getInstr()->setAsmPrinterFlag(SPIRV::ASM_PRINTER_WIDTH64);
return;
}
report_fatal_error("Unsupported constant bitwidth");
Expand Down
6 changes: 5 additions & 1 deletion llvm/test/CodeGen/SPIRV/branching/OpSwitch64.ll
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV

; CHECK-SPIRV: OpSwitch %[[#]] %[[#]] 0 0 %[[#]] 1 0 %[[#]] 1 5 %[[#]]
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=asm | spirv-as - -o /dev/null %}

; CHECK-SPIRV: OpSwitch %[[#]] %[[#]] 0 %[[#]] 1 %[[#]] 21474836481 %[[#]]

define spir_kernel void @test_64(i32 addrspace(1)* %res) {
entry:
Expand Down