#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "SPIRVParsingUtils.h"
#include "mlir/IR/TypeUtilities.h"
namespace mlir::spirv {
static bool isNestedInFunctionOpInterface(Operation *op) {
if (!op)
return false;
if (op->hasTrait<OpTrait::SymbolTable>())
return false;
if (isa<FunctionOpInterface>(op))
return true;
return isNestedInFunctionOpInterface(op->getParentOp());
}
static bool isDirectInModuleLikeOp(Operation *op) {
return op && op->hasTrait<OpTrait::SymbolTable>();
}
static Type getUnaryOpResultType(Type operandType) {
Builder builder(operandType.getContext());
Type resultType = builder.getIntegerType(1);
if (auto vecType = llvm::dyn_cast<VectorType>(operandType))
return VectorType::get(vecType.getNumElements(), resultType);
return resultType;
}
static ParseResult parseImageOperands(OpAsmParser &parser,
spirv::ImageOperandsAttr &attr) {
if (parser.parseOptionalLSquare())
return success();
spirv::ImageOperands imageOperands;
if (parseEnumStrAttr(imageOperands, parser))
return failure();
attr = spirv::ImageOperandsAttr::get(parser.getContext(), imageOperands);
return parser.parseRSquare();
}
static void printImageOperands(OpAsmPrinter &printer, Operation *imageOp,
spirv::ImageOperandsAttr attr) {
if (attr) {
auto strImageOperands = stringifyImageOperands(attr.getValue());
printer << "[\"" << strImageOperands << "\"]";
}
}
}
#define GET_OP_CLASSES
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.cpp.inc"