build(builder, state, var.type(), builder->getSymbolRefAttr(var));
}
-static ParseResult parseAddressOfOp(OpAsmParser &parser,
- OperationState &state) {
- FlatSymbolRefAttr varRefAttr;
- Type type;
- if (parser.parseAttribute(varRefAttr, Type(), kVariableAttrName,
- state.attributes) ||
- parser.parseColonType(type)) {
- return failure();
- }
- auto ptrType = type.dyn_cast<spirv::PointerType>();
- if (!ptrType) {
- return parser.emitError(parser.getCurrentLocation(),
- "expected spv.ptr type");
- }
- state.addTypes(ptrType);
- return success();
-}
-
-static void print(spirv::AddressOfOp addressOfOp, OpAsmPrinter &printer) {
- SmallVector<StringRef, 4> elidedAttrs;
- printer << spirv::AddressOfOp::getOperationName();
-
- // Print symbol name.
- printer << ' ';
- printer.printSymbolName(addressOfOp.variable());
-
- // Print the type.
- printer << " : " << addressOfOp.pointer().getType();
-}
-
static LogicalResult verify(spirv::AddressOfOp addressOfOp) {
auto varOp = dyn_cast_or_null<spirv::GlobalVariableOp>(
SymbolTable::lookupNearestSymbolFrom(addressOfOp.getParentOp(),
// spv.FunctionCall
//===----------------------------------------------------------------------===//
-static ParseResult parseFunctionCallOp(OpAsmParser &parser,
- OperationState &state) {
- FlatSymbolRefAttr calleeAttr;
- FunctionType type;
- SmallVector<OpAsmParser::OperandType, 4> operands;
- auto loc = parser.getNameLoc();
- if (parser.parseAttribute(calleeAttr, kCallee, state.attributes) ||
- parser.parseOperandList(operands, OpAsmParser::Delimiter::Paren) ||
- parser.parseColonType(type)) {
- return failure();
- }
-
- auto funcType = type.dyn_cast<FunctionType>();
- if (!funcType) {
- return parser.emitError(loc, "expected function type, but provided ")
- << type;
- }
-
- if (funcType.getNumResults() > 1) {
- return parser.emitError(loc, "expected callee function to have 0 or 1 "
- "result, but provided ")
- << funcType.getNumResults();
- }
-
- return failure(parser.addTypesToList(funcType.getResults(), state.types) ||
- parser.resolveOperands(operands, funcType.getInputs(), loc,
- state.operands));
-}
-
-static void print(spirv::FunctionCallOp functionCallOp, OpAsmPrinter &printer) {
- SmallVector<Type, 4> argTypes(functionCallOp.getOperandTypes());
- Type functionType = FunctionType::get(
- argTypes, functionCallOp.getResultTypes(), functionCallOp.getContext());
-
- printer << spirv::FunctionCallOp::getOperationName() << ' '
- << functionCallOp.getAttr(kCallee) << '('
- << functionCallOp.arguments() << ") : " << functionType;
-}
-
static LogicalResult verify(spirv::FunctionCallOp functionCallOp) {
auto fnName = functionCallOp.callee();
// spv._reference_of
//===----------------------------------------------------------------------===//
-static ParseResult parseReferenceOfOp(OpAsmParser &parser,
- OperationState &state) {
- FlatSymbolRefAttr constRefAttr;
- Type type;
- if (parser.parseAttribute(constRefAttr, Type(), kSpecConstAttrName,
- state.attributes) ||
- parser.parseColonType(type)) {
- return failure();
- }
- return parser.addTypeToList(type, state.types);
-}
-
-static void print(spirv::ReferenceOfOp referenceOfOp, OpAsmPrinter &printer) {
- printer << spirv::ReferenceOfOp::getOperationName() << ' ';
- printer.printSymbolName(referenceOfOp.spec_const());
- printer << " : " << referenceOfOp.reference().getType();
-}
-
static LogicalResult verify(spirv::ReferenceOfOp referenceOfOp) {
auto specConstOp = dyn_cast_or_null<spirv::SpecConstantOp>(
SymbolTable::lookupNearestSymbolFrom(referenceOfOp.getParentOp(),
// spv.ReturnValue
//===----------------------------------------------------------------------===//
-static ParseResult parseReturnValueOp(OpAsmParser &parser,
- OperationState &state) {
- OpAsmParser::OperandType retValInfo;
- Type retValType;
- return failure(parser.parseOperand(retValInfo) ||
- parser.parseColonType(retValType) ||
- parser.resolveOperand(retValInfo, retValType, state.operands));
-}
-
-static void print(spirv::ReturnValueOp retValOp, OpAsmPrinter &printer) {
- printer << spirv::ReturnValueOp::getOperationName() << ' ' << retValOp.value()
- << " : " << retValOp.value().getType();
-}
-
static LogicalResult verify(spirv::ReturnValueOp retValOp) {
auto funcOp = retValOp.getParentOfType<FuncOp>();
auto numFnResults = funcOp.getType().getNumResults();
}
//===----------------------------------------------------------------------===//
-// spv.SubgroupBallotKHROp
-//===----------------------------------------------------------------------===//
-
-static ParseResult parseSubgroupBallotKHROp(OpAsmParser &parser,
- OperationState &state) {
- OpAsmParser::OperandType operandInfo;
- Type resultType;
- IntegerType i1Type = parser.getBuilder().getI1Type();
- if (parser.parseOperand(operandInfo) || parser.parseColonType(resultType) ||
- parser.resolveOperand(operandInfo, i1Type, state.operands))
- return failure();
-
- return parser.addTypeToList(resultType, state.types);
-}
-
-static void print(spirv::SubgroupBallotKHROp ballotOp, OpAsmPrinter &printer) {
- printer << spirv::SubgroupBallotKHROp::getOperationName() << ' '
- << ballotOp.predicate() << " : " << ballotOp.getType();
-}
-
-//===----------------------------------------------------------------------===//
-// spv.Undef
-//===----------------------------------------------------------------------===//
-
-static ParseResult parseUndefOp(OpAsmParser &parser, OperationState &state) {
- Type type;
- if (parser.parseColonType(type)) {
- return failure();
- }
- state.addTypes(type);
- return success();
-}
-
-static void print(spirv::UndefOp undefOp, OpAsmPrinter &printer) {
- printer << spirv::UndefOp::getOperationName() << " : " << undefOp.getType();
-}
-
-//===----------------------------------------------------------------------===//
// spv.Unreachable
//===----------------------------------------------------------------------===//