Changeset View
Standalone View
mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
Show First 20 Lines • Show All 305 Lines • ▼ Show 20 Lines | if (spirv::bitEnumContains(*memAccess, spirv::MemoryAccess::Aligned)) { | ||||
printer << ", " << alignment; | printer << ", " << alignment; | ||||
} | } | ||||
} | } | ||||
printer << "]"; | printer << "]"; | ||||
} | } | ||||
elidedAttrs.push_back(spirv::attributeName<spirv::StorageClass>()); | elidedAttrs.push_back(spirv::attributeName<spirv::StorageClass>()); | ||||
} | } | ||||
static ParseResult parseImageOperands(OpAsmParser &parser, | |||||
spirv::ImageOperandsAttr &attr) { | |||||
// Expect image operands | |||||
if (parser.parseOptionalLSquare()) | |||||
return success(); | |||||
spirv::ImageOperands imageOperands; | |||||
if (parseEnumStrAttr(imageOperands, parser)) | |||||
return failure(); | |||||
attr = spirv::ImageOperandsAttr::get(parser.getBuilder().getContext(), | |||||
imageOperands); | |||||
return parser.parseRSquare(); | |||||
} | |||||
static void printImageOperands(OpAsmPrinter &printer, Operation *imageOp, | |||||
spirv::ImageOperandsAttr attr) { | |||||
if (attr) { | |||||
auto strImageOperands = stringifyImageOperands(attr.getValue()); | |||||
printer << "[\"" << strImageOperands << "\"]"; | |||||
} | |||||
return; | |||||
antiagainst: This isn't necessary? | |||||
} | |||||
template <typename Op> | |||||
static LogicalResult verifyImageOperands(Op imageOp, | |||||
spirv::ImageOperandsAttr attr, | |||||
If attr is null but values isn't empty, that should be a validation error? antiagainst: If attr is null but values isn't empty, that should be a validation error? | |||||
Operation::operand_range operands) { | |||||
if (!attr) { | |||||
if (operands.empty()) | |||||
Nit: In MLIR we prefer early return when it simplifies code. So here if (!attr) return success(). antiagainst: Nit: In MLIR we prefer early return when it simplifies code. So here `if (!attr) return success… | |||||
Not Done ReplyInline ActionsThis else isn't necesary. antiagainst: This `else` isn't necesary. | |||||
return success(); | |||||
else | |||||
return imageOp.emitError("the Image Operands should encode what operands " | |||||
FYI: we have bitEnumContains utility functions generated for probing whether a bit is set. antiagainst: FYI: we have `bitEnumContains` utility functions generated for probing whether a bit is set. | |||||
And also operator| and operator&. antiagainst: And also `operator|` and `operator&`. | |||||
Thanks for pointing it out. :) Weiwei-2021: Thanks for pointing it out. :) | |||||
"follow, as per Image Operands"); | |||||
} | |||||
I assume this part needs to be rewritten? Not sure I follow what's verified here.. antiagainst: I assume this part needs to be rewritten? Not sure I follow what's verified here.. | |||||
Sorry about the confusion. Initially, I want to check the "Bias" and "Lod" will have one following operand for each. And after reading the detail, I realized that they cannot show up at the same time. :( Weiwei-2021: Sorry about the confusion. Initially, I want to check the "Bias" and "Lod" will have one… | |||||
Ping @antiagainst to check whether this versino is ok. Weiwei-2021: Ping @antiagainst to check whether this versino is ok. | |||||
// TODO: Add the validation rules for the following Image Operands. | |||||
spirv::ImageOperands noSupportOperands = | |||||
spirv::ImageOperands::Bias | spirv::ImageOperands::Lod | | |||||
spirv::ImageOperands::Grad | spirv::ImageOperands::ConstOffset | | |||||
spirv::ImageOperands::Offset | spirv::ImageOperands::ConstOffsets | | |||||
spirv::ImageOperands::Sample | spirv::ImageOperands::MinLod | | |||||
spirv::ImageOperands::MakeTexelAvailable | | |||||
spirv::ImageOperands::MakeTexelVisible | | |||||
spirv::ImageOperands::SignExtend | spirv::ImageOperands::ZeroExtend; | |||||
if (spirv::bitEnumContains(attr.getValue(), noSupportOperands)) | |||||
llvm_unreachable("unimplemented operands of Image Operands"); | |||||
return success(); | |||||
} | |||||
static LogicalResult verifyCastOp(Operation *op, | static LogicalResult verifyCastOp(Operation *op, | ||||
bool requireSameBitWidth = true, | bool requireSameBitWidth = true, | ||||
bool skipBitWidthCheck = false) { | bool skipBitWidthCheck = false) { | ||||
// Some CastOps have no limit on bit widths for result and operand type. | // Some CastOps have no limit on bit widths for result and operand type. | ||||
if (skipBitWidthCheck) | if (skipBitWidthCheck) | ||||
return success(); | return success(); | ||||
Type operandType = op->getOperand(0).getType(); | Type operandType = op->getOperand(0).getType(); | ||||
▲ Show 20 Lines • Show All 3,347 Lines • ▼ Show 20 Lines | static LogicalResult verify(spirv::GLSLLdexpOp ldexpOp) { | ||||
return success(); | return success(); | ||||
} | } | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// spv.ImageDrefGather | // spv.ImageDrefGather | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
static LogicalResult verify(spirv::ImageDrefGatherOp imageDrefGatherOp) { | static LogicalResult verify(spirv::ImageDrefGatherOp imageDrefGatherOp) { | ||||
// TODO: Support optional operands. | |||||
VectorType resultType = | VectorType resultType = | ||||
imageDrefGatherOp.result().getType().cast<VectorType>(); | imageDrefGatherOp.result().getType().cast<VectorType>(); | ||||
auto sampledImageType = imageDrefGatherOp.sampledimage() | auto sampledImageType = imageDrefGatherOp.sampledimage() | ||||
.getType() | .getType() | ||||
.cast<spirv::SampledImageType>(); | .cast<spirv::SampledImageType>(); | ||||
auto imageType = sampledImageType.getImageType().cast<spirv::ImageType>(); | auto imageType = sampledImageType.getImageType().cast<spirv::ImageType>(); | ||||
if (resultType.getNumElements() != 4) | if (resultType.getNumElements() != 4) | ||||
Show All 15 Lines | if (imageDim != spirv::Dim::Dim2D && imageDim != spirv::Dim::Cube && | ||||
return imageDrefGatherOp.emitOpError( | return imageDrefGatherOp.emitOpError( | ||||
"the Dim operand of the underlying image type must be 2D, Cube, or " | "the Dim operand of the underlying image type must be 2D, Cube, or " | ||||
"Rect"); | "Rect"); | ||||
if (imageMS != spirv::ImageSamplingInfo::SingleSampled) | if (imageMS != spirv::ImageSamplingInfo::SingleSampled) | ||||
return imageDrefGatherOp.emitOpError( | return imageDrefGatherOp.emitOpError( | ||||
"the MS operand of the underlying image type must be 0"); | "the MS operand of the underlying image type must be 0"); | ||||
return success(); | spirv::ImageOperandsAttr attr = imageDrefGatherOp.imageoperandsAttr(); | ||||
auto operandArguments = imageDrefGatherOp.operand_arguments(); | |||||
return verifyImageOperands(imageDrefGatherOp, attr, operandArguments); | |||||
} | } | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// spv.ImageQuerySize | // spv.ImageQuerySize | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
static LogicalResult verify(spirv::ImageQuerySizeOp imageQuerySizeOp) { | static LogicalResult verify(spirv::ImageQuerySizeOp imageQuerySizeOp) { | ||||
spirv::ImageType imageType = | spirv::ImageType imageType = | ||||
▲ Show 20 Lines • Show All 182 Lines • Show Last 20 Lines |
This isn't necessary?