Revert "[MLIR][SPIRV] Support two memory access attributes in OpCopyMemory."

This reverts commit ef2f46e1f6a63040734c48ed53893298df14b6fa, which
likely triggers a compiler internal error for MSVC.

Differential Revision: https://reviews.llvm.org/D83075
This commit is contained in:
Lei Zhang 2020-07-02 15:42:10 -04:00
parent 286073484f
commit 08679af900
6 changed files with 27 additions and 239 deletions

View File

@ -198,7 +198,7 @@ def SPV_CopyMemoryOp : SPV_Op<"CopyMemory", []> {
``` ```
copy-memory-op ::= `spv.CopyMemory ` storage-class ssa-use copy-memory-op ::= `spv.CopyMemory ` storage-class ssa-use
storage-class ssa-use storage-class ssa-use
(`[` memory-access `]` (`, [` memory-access `]`)?)? (`[` memory-access `]`)?
` : ` spirv-element-type ` : ` spirv-element-type
``` ```
@ -215,16 +215,12 @@ def SPV_CopyMemoryOp : SPV_Op<"CopyMemory", []> {
SPV_AnyPtr:$target, SPV_AnyPtr:$target,
SPV_AnyPtr:$source, SPV_AnyPtr:$source,
OptionalAttr<SPV_MemoryAccessAttr>:$memory_access, OptionalAttr<SPV_MemoryAccessAttr>:$memory_access,
OptionalAttr<I32Attr>:$alignment, OptionalAttr<I32Attr>:$alignment
OptionalAttr<SPV_MemoryAccessAttr>:$source_memory_access,
OptionalAttr<I32Attr>:$source_alignment
); );
let results = (outs); let results = (outs);
let verifier = [{ return verifyCopyMemory(*this); }]; let verifier = [{ return verifyCopyMemory(*this); }];
let autogenSerialization = 0;
} }
// ----- // -----

View File

@ -28,11 +28,7 @@
using namespace mlir; using namespace mlir;
// TODO(antiagainst): generate these strings using ODS. // TODO(antiagainst): generate these strings using ODS.
static constexpr const char kMemoryAccessAttrName[] = "memory_access";
static constexpr const char kSourceMemoryAccessAttrName[] =
"source_memory_access";
static constexpr const char kAlignmentAttrName[] = "alignment"; static constexpr const char kAlignmentAttrName[] = "alignment";
static constexpr const char kSourceAlignmentAttrName[] = "source_alignment";
static constexpr const char kBranchWeightAttrName[] = "branch_weights"; static constexpr const char kBranchWeightAttrName[] = "branch_weights";
static constexpr const char kCallee[] = "callee"; static constexpr const char kCallee[] = "callee";
static constexpr const char kClusterSize[] = "cluster_size"; static constexpr const char kClusterSize[] = "cluster_size";
@ -161,8 +157,6 @@ parseEnumKeywordAttr(EnumClass &value, OpAsmParser &parser,
return success(); return success();
} }
template <const char memoryAccessAttrName[] = kMemoryAccessAttrName,
const char alignmentAttrName[] = kAlignmentAttrName>
static ParseResult parseMemoryAccessAttributes(OpAsmParser &parser, static ParseResult parseMemoryAccessAttributes(OpAsmParser &parser,
OperationState &state) { OperationState &state) {
// Parse an optional list of attributes staring with '[' // Parse an optional list of attributes staring with '['
@ -172,7 +166,7 @@ static ParseResult parseMemoryAccessAttributes(OpAsmParser &parser,
} }
spirv::MemoryAccess memoryAccessAttr; spirv::MemoryAccess memoryAccessAttr;
if (parseEnumStrAttr(memoryAccessAttr, parser, state, memoryAccessAttrName)) { if (parseEnumStrAttr(memoryAccessAttr, parser, state)) {
return failure(); return failure();
} }
@ -181,7 +175,7 @@ static ParseResult parseMemoryAccessAttributes(OpAsmParser &parser,
Attribute alignmentAttr; Attribute alignmentAttr;
Type i32Type = parser.getBuilder().getIntegerType(32); Type i32Type = parser.getBuilder().getIntegerType(32);
if (parser.parseComma() || if (parser.parseComma() ||
parser.parseAttribute(alignmentAttr, i32Type, alignmentAttrName, parser.parseAttribute(alignmentAttr, i32Type, kAlignmentAttrName,
state.attributes)) { state.attributes)) {
return failure(); return failure();
} }
@ -189,33 +183,19 @@ static ParseResult parseMemoryAccessAttributes(OpAsmParser &parser,
return parser.parseRSquare(); return parser.parseRSquare();
} }
template <typename MemoryOpTy, template <typename MemoryOpTy>
const char memoryAccessAttrName[] = kMemoryAccessAttrName, static void
const char alignmentAttrName[] = kAlignmentAttrName, printMemoryAccessAttribute(MemoryOpTy memoryOp, OpAsmPrinter &printer,
bool first = true> SmallVectorImpl<StringRef> &elidedAttrs) {
static void printMemoryAccessAttribute(
MemoryOpTy memoryOp, OpAsmPrinter &printer,
SmallVectorImpl<StringRef> &elidedAttrs,
Optional<spirv::MemoryAccess> memoryAccessAtrrValue = None,
Optional<llvm::APInt> alignmentAttrValue = None) {
// Print optional memory access attribute. // Print optional memory access attribute.
if (auto memAccess = (memoryAccessAtrrValue ? memoryAccessAtrrValue if (auto memAccess = memoryOp.memory_access()) {
: memoryOp.memory_access())) { elidedAttrs.push_back(spirv::attributeName<spirv::MemoryAccess>());
elidedAttrs.push_back(memoryAccessAttrName);
if (!first) {
printer << ", ";
}
printer << " [\"" << stringifyMemoryAccess(*memAccess) << "\""; printer << " [\"" << stringifyMemoryAccess(*memAccess) << "\"";
if (spirv::bitEnumContains(*memAccess, spirv::MemoryAccess::Aligned)) { // Print integer alignment attribute.
// Print integer alignment attribute. if (auto alignment = memoryOp.alignment()) {
if (auto alignment = (alignmentAttrValue ? alignmentAttrValue elidedAttrs.push_back(kAlignmentAttrName);
: memoryOp.alignment())) { printer << ", " << alignment;
elidedAttrs.push_back(alignmentAttrName);
printer << ", " << alignment;
}
} }
printer << "]"; printer << "]";
} }
@ -263,19 +243,17 @@ static LogicalResult verifyCastOp(Operation *op,
return success(); return success();
} }
template <typename MemoryOpTy, template <typename MemoryOpTy>
const char memoryAccessAttrName[] = kMemoryAccessAttrName,
const char alignmentAttrName[] = kAlignmentAttrName>
static LogicalResult verifyMemoryAccessAttribute(MemoryOpTy memoryOp) { static LogicalResult verifyMemoryAccessAttribute(MemoryOpTy memoryOp) {
// ODS checks for attributes values. Just need to verify that if the // ODS checks for attributes values. Just need to verify that if the
// memory-access attribute is Aligned, then the alignment attribute must be // memory-access attribute is Aligned, then the alignment attribute must be
// present. // present.
auto *op = memoryOp.getOperation(); auto *op = memoryOp.getOperation();
auto memAccessAttr = op->getAttr(memoryAccessAttrName); auto memAccessAttr = op->getAttr(spirv::attributeName<spirv::MemoryAccess>());
if (!memAccessAttr) { if (!memAccessAttr) {
// Alignment attribute shouldn't be present if memory access attribute is // Alignment attribute shouldn't be present if memory access attribute is
// not present. // not present.
if (op->getAttr(alignmentAttrName)) { if (op->getAttr(kAlignmentAttrName)) {
return memoryOp.emitOpError( return memoryOp.emitOpError(
"invalid alignment specification without aligned memory access " "invalid alignment specification without aligned memory access "
"specification"); "specification");
@ -292,11 +270,11 @@ static LogicalResult verifyMemoryAccessAttribute(MemoryOpTy memoryOp) {
} }
if (spirv::bitEnumContains(*memAccess, spirv::MemoryAccess::Aligned)) { if (spirv::bitEnumContains(*memAccess, spirv::MemoryAccess::Aligned)) {
if (!op->getAttr(alignmentAttrName)) { if (!op->getAttr(kAlignmentAttrName)) {
return memoryOp.emitOpError("missing alignment value"); return memoryOp.emitOpError("missing alignment value");
} }
} else { } else {
if (op->getAttr(alignmentAttrName)) { if (op->getAttr(kAlignmentAttrName)) {
return memoryOp.emitOpError( return memoryOp.emitOpError(
"invalid alignment specification with non-aligned memory access " "invalid alignment specification with non-aligned memory access "
"specification"); "specification");
@ -2861,10 +2839,6 @@ static void print(spirv::CopyMemoryOp copyMemory, OpAsmPrinter &printer) {
SmallVector<StringRef, 4> elidedAttrs; SmallVector<StringRef, 4> elidedAttrs;
printMemoryAccessAttribute(copyMemory, printer, elidedAttrs); printMemoryAccessAttribute(copyMemory, printer, elidedAttrs);
printMemoryAccessAttribute<decltype(copyMemory), kSourceMemoryAccessAttrName,
kSourceAlignmentAttrName, false>(
copyMemory, printer, elidedAttrs, copyMemory.source_memory_access(),
copyMemory.source_alignment());
printer.printOptionalAttrDict(op->getAttrs(), elidedAttrs); printer.printOptionalAttrDict(op->getAttrs(), elidedAttrs);
@ -2887,23 +2861,9 @@ static ParseResult parseCopyMemoryOp(OpAsmParser &parser,
parser.parseOperand(targetPtrInfo) || parser.parseComma() || parser.parseOperand(targetPtrInfo) || parser.parseComma() ||
parseEnumStrAttr(sourceStorageClass, parser) || parseEnumStrAttr(sourceStorageClass, parser) ||
parser.parseOperand(sourcePtrInfo) || parser.parseOperand(sourcePtrInfo) ||
parseMemoryAccessAttributes(parser, state)) { parseMemoryAccessAttributes(parser, state) ||
return failure(); parser.parseOptionalAttrDict(state.attributes) || parser.parseColon() ||
} parser.parseType(elementType)) {
if (!parser.parseOptionalComma()) {
// Parse 2nd memory access attributes.
if (parseMemoryAccessAttributes<kSourceMemoryAccessAttrName,
kSourceAlignmentAttrName>(parser, state)) {
return failure();
}
}
if (parser.parseColon() || parser.parseType(elementType)) {
return failure();
}
if (parser.parseOptionalAttrDict(state.attributes)) {
return failure(); return failure();
} }
@ -2930,21 +2890,7 @@ static LogicalResult verifyCopyMemory(spirv::CopyMemoryOp copyMemory) {
"both operands must be pointers to the same type"); "both operands must be pointers to the same type");
} }
if (failed(verifyMemoryAccessAttribute(copyMemory))) { return verifyMemoryAccessAttribute(copyMemory);
return failure();
}
// TODO (ergawy): According to the spec:
//
// If two masks are present, the first applies to Target and cannot include
// MakePointerVisible, and the second applies to Source and cannot include
// MakePointerAvailable.
//
// Add such verification here.
return verifyMemoryAccessAttribute<decltype(copyMemory),
kSourceMemoryAccessAttrName,
kSourceAlignmentAttrName>(copyMemory);
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -2510,76 +2510,6 @@ Deserializer::processOp<spirv::MemoryBarrierOp>(ArrayRef<uint32_t> operands) {
return success(); return success();
} }
template <>
LogicalResult
Deserializer::processOp<spirv::CopyMemoryOp>(ArrayRef<uint32_t> words) {
SmallVector<Type, 1> resultTypes;
size_t wordIndex = 0;
SmallVector<Value, 4> operands;
SmallVector<NamedAttribute, 4> attributes;
if (wordIndex < words.size()) {
auto arg = getValue(words[wordIndex]);
if (!arg) {
return emitError(unknownLoc, "unknown result <id> : ")
<< words[wordIndex];
}
operands.push_back(arg);
wordIndex++;
}
if (wordIndex < words.size()) {
auto arg = getValue(words[wordIndex]);
if (!arg) {
return emitError(unknownLoc, "unknown result <id> : ")
<< words[wordIndex];
}
operands.push_back(arg);
wordIndex++;
}
bool isAlignedAttr = false;
if (wordIndex < words.size()) {
auto attrValue = words[wordIndex++];
attributes.push_back(opBuilder.getNamedAttr(
"memory_access", opBuilder.getI32IntegerAttr(attrValue)));
isAlignedAttr = (attrValue == 2);
}
if (isAlignedAttr && wordIndex < words.size()) {
attributes.push_back(opBuilder.getNamedAttr(
"alignment", opBuilder.getI32IntegerAttr(words[wordIndex++])));
}
if (wordIndex < words.size()) {
attributes.push_back(opBuilder.getNamedAttr(
"source_memory_access",
opBuilder.getI32IntegerAttr(words[wordIndex++])));
}
if (wordIndex < words.size()) {
attributes.push_back(opBuilder.getNamedAttr(
"source_alignment", opBuilder.getI32IntegerAttr(words[wordIndex++])));
}
if (wordIndex != words.size()) {
return emitError(unknownLoc,
"found more operands than expected when deserializing "
"spirv::CopyMemoryOp, only ")
<< wordIndex << " of " << words.size() << " processed";
}
Location loc = createFileLineColLoc(opBuilder);
opBuilder.create<spirv::CopyMemoryOp>(loc, resultTypes, operands, attributes);
return success();
}
// Pull in auto-generated Deserializer::dispatchToAutogenDeserialization() and // Pull in auto-generated Deserializer::dispatchToAutogenDeserialization() and
// various Deserializer::processOp<...>() specializations. // various Deserializer::processOp<...>() specializations.
#define GET_DESERIALIZATION_FNS #define GET_DESERIALIZATION_FNS

View File

@ -364,8 +364,7 @@ private:
/// Method to serialize an operation in the SPIR-V dialect that is a mirror of /// Method to serialize an operation in the SPIR-V dialect that is a mirror of
/// an instruction in the SPIR-V spec. This is auto generated if hasOpcode == /// an instruction in the SPIR-V spec. This is auto generated if hasOpcode ==
/// 1 and autogenSerialization == 1 in ODS. /// 1 and autogenSerialization == 1 in ODS.
template <typename OpTy> template <typename OpTy> LogicalResult processOp(OpTy op) {
LogicalResult processOp(OpTy op) {
return op.emitError("unsupported op serialization"); return op.emitError("unsupported op serialization");
} }
@ -1905,51 +1904,6 @@ Serializer::processOp<spirv::FunctionCallOp>(spirv::FunctionCallOp op) {
operands); operands);
} }
template <>
LogicalResult
Serializer::processOp<spirv::CopyMemoryOp>(spirv::CopyMemoryOp op) {
SmallVector<uint32_t, 4> operands;
SmallVector<StringRef, 2> elidedAttrs;
for (Value operand : op.getOperation()->getOperands()) {
auto id = getValueID(operand);
assert(id && "use before def!");
operands.push_back(id);
}
if (auto attr = op.getAttr("memory_access")) {
operands.push_back(static_cast<uint32_t>(
attr.cast<IntegerAttr>().getValue().getZExtValue()));
}
elidedAttrs.push_back("memory_access");
if (auto attr = op.getAttr("alignment")) {
operands.push_back(static_cast<uint32_t>(
attr.cast<IntegerAttr>().getValue().getZExtValue()));
}
elidedAttrs.push_back("alignment");
if (auto attr = op.getAttr("source_memory_access")) {
operands.push_back(static_cast<uint32_t>(
attr.cast<IntegerAttr>().getValue().getZExtValue()));
}
elidedAttrs.push_back("source_memory_access");
if (auto attr = op.getAttr("source_alignment")) {
operands.push_back(static_cast<uint32_t>(
attr.cast<IntegerAttr>().getValue().getZExtValue()));
}
elidedAttrs.push_back("source_alignment");
emitDebugLine(functionBody, op.getLoc());
encodeInstructionInto(functionBody, spirv::Opcode::OpCopyMemory, operands);
return success();
}
// Pull in auto-generated Serializer::dispatchToAutogenSerialization() and // Pull in auto-generated Serializer::dispatchToAutogenSerialization() and
// various Serializer::processOp<...>() specializations. // various Serializer::processOp<...>() specializations.
#define GET_SERIALIZATION_FNS #define GET_SERIALIZATION_FNS

View File

@ -93,18 +93,6 @@ spv.module Logical GLSL450 requires #spv.vce<v1.0, [Shader], []> {
// CHECK: spv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Volatile"] : f32 // CHECK: spv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Volatile"] : f32
spv.CopyMemory "Function" %0, "Function" %1 ["Volatile"] : f32 spv.CopyMemory "Function" %0, "Function" %1 ["Volatile"] : f32
// CHECK: spv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Volatile"], ["Volatile"] : f32
spv.CopyMemory "Function" %0, "Function" %1 ["Volatile"], ["Volatile"] : f32
// CHECK: spv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 4], ["Volatile"] : f32
spv.CopyMemory "Function" %0, "Function" %1 ["Aligned", 4], ["Volatile"] : f32
// CHECK: spv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Volatile"], ["Aligned", 4] : f32
spv.CopyMemory "Function" %0, "Function" %1 ["Volatile"], ["Aligned", 4] : f32
// CHECK: spv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 8], ["Aligned", 4] : f32
spv.CopyMemory "Function" %0, "Function" %1 ["Aligned", 8], ["Aligned", 4] : f32
spv.Return spv.Return
} }
} }

View File

@ -1247,7 +1247,7 @@ func @cannot_be_generic_storage_class(%arg0: f32) -> () {
// ----- // -----
func @copy_memory_incompatible_ptrs() { func @copy_memory_incompatible_ptrs() -> () {
%0 = spv.Variable : !spv.ptr<f32, Function> %0 = spv.Variable : !spv.ptr<f32, Function>
%1 = spv.Variable : !spv.ptr<i32, Function> %1 = spv.Variable : !spv.ptr<i32, Function>
// expected-error @+1 {{both operands must be pointers to the same type}} // expected-error @+1 {{both operands must be pointers to the same type}}
@ -1257,7 +1257,7 @@ func @copy_memory_incompatible_ptrs() {
// ----- // -----
func @copy_memory_invalid_maa() { func @copy_memory_invalid_maa() -> () {
%0 = spv.Variable : !spv.ptr<f32, Function> %0 = spv.Variable : !spv.ptr<f32, Function>
%1 = spv.Variable : !spv.ptr<f32, Function> %1 = spv.Variable : !spv.ptr<f32, Function>
// expected-error @+1 {{missing alignment value}} // expected-error @+1 {{missing alignment value}}
@ -1267,27 +1267,7 @@ func @copy_memory_invalid_maa() {
// ----- // -----
func @copy_memory_invalid_source_maa() { func @copy_memory_print_maa() -> () {
%0 = spv.Variable : !spv.ptr<f32, Function>
%1 = spv.Variable : !spv.ptr<f32, Function>
// expected-error @+1 {{invalid alignment specification with non-aligned memory access specification}}
"spv.CopyMemory"(%0, %1) {source_memory_access=0x0001 : i32, memory_access=0x0002 : i32, source_alignment=8 : i32, alignment=4 : i32} : (!spv.ptr<f32, Function>, !spv.ptr<f32, Function>) -> ()
spv.Return
}
// -----
func @copy_memory_invalid_source_maa2() {
%0 = spv.Variable : !spv.ptr<f32, Function>
%1 = spv.Variable : !spv.ptr<f32, Function>
// expected-error @+1 {{missing alignment value}}
"spv.CopyMemory"(%0, %1) {source_memory_access=0x0002 : i32, memory_access=0x0002 : i32, alignment=4 : i32} : (!spv.ptr<f32, Function>, !spv.ptr<f32, Function>) -> ()
spv.Return
}
// -----
func @copy_memory_print_maa() {
%0 = spv.Variable : !spv.ptr<f32, Function> %0 = spv.Variable : !spv.ptr<f32, Function>
%1 = spv.Variable : !spv.ptr<f32, Function> %1 = spv.Variable : !spv.ptr<f32, Function>
@ -1297,11 +1277,5 @@ func @copy_memory_print_maa() {
// CHECK: spv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 4] : f32 // CHECK: spv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 4] : f32
"spv.CopyMemory"(%0, %1) {memory_access=0x0002 : i32, alignment=4 : i32} : (!spv.ptr<f32, Function>, !spv.ptr<f32, Function>) -> () "spv.CopyMemory"(%0, %1) {memory_access=0x0002 : i32, alignment=4 : i32} : (!spv.ptr<f32, Function>, !spv.ptr<f32, Function>) -> ()
// CHECK: spv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 4], ["Volatile"] : f32
"spv.CopyMemory"(%0, %1) {source_memory_access=0x0001 : i32, memory_access=0x0002 : i32, alignment=4 : i32} : (!spv.ptr<f32, Function>, !spv.ptr<f32, Function>) -> ()
// CHECK: spv.CopyMemory "Function" %{{.*}}, "Function" %{{.*}} ["Aligned", 4], ["Aligned", 8] : f32
"spv.CopyMemory"(%0, %1) {source_memory_access=0x0002 : i32, memory_access=0x0002 : i32, source_alignment=8 : i32, alignment=4 : i32} : (!spv.ptr<f32, Function>, !spv.ptr<f32, Function>) -> ()
spv.Return spv.Return
} }