Skip to content

Commit

Permalink
Ensuring rodata names and mime types can go from util->vm. (iree-org#…
Browse files Browse the repository at this point in the history
  • Loading branch information
benvanik authored Aug 6, 2022
1 parent eaffd37 commit aff200e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,9 @@ class PackConstantsPass : public PackConstantsBase<PackConstantsPass> {
SmallVector<Value> storageBuffers;
for (auto &storageResource : storageResources) {
auto rodataOp = builder.create<IREE::Util::BufferConstantOp>(
storageResource.loc, builder.getType<IREE::Util::BufferType>(),
storageResource.data,
builder.getIndexAttr(resourceConfig.getMinBufferOffsetAlignment()));
storageResource.loc, /*name=*/nullptr, storageResource.data,
builder.getIndexAttr(resourceConfig.getMinBufferOffsetAlignment()),
/*mimeType=*/nullptr);
storageBuffers.push_back(rodataOp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ struct ConvertMemRefGlobalOp : public OpConversionPattern<memref::GlobalOp> {
globalOp.getAlignmentAttr().getInt())
: IntegerAttr{};
auto constantOp = initializerBuilder.create<IREE::Util::BufferConstantOp>(
globalOp.getLoc(), initializerBuilder.getType<IREE::Util::BufferType>(),
globalOp.getInitialValueAttr(), alignmentAttr);
globalOp.getLoc(), /*name=*/nullptr, globalOp.getInitialValueAttr(),
alignmentAttr, /*mimeType=*/nullptr);
initializerBuilder.create<IREE::Util::GlobalStoreOp>(
globalOp.getLoc(), constantOp.getResult(), newOp.getName());
initializerBuilder.create<IREE::Util::InitializerReturnOp>(
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/iree/compiler/Dialect/Util/IR/UtilOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ LogicalResult ListSetOp::verify() {

void BufferConstantOp::getAsmResultNames(
function_ref<void(Value, StringRef)> setNameFn) {
setNameFn(getResult(), "buffer_cst");
setNameFn(getResult(), getName().value_or("buffer_cst"));
}

LogicalResult BufferConstantOp::verify() {
Expand Down
20 changes: 13 additions & 7 deletions compiler/src/iree/compiler/Dialect/Util/IR/UtilOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,17 @@ def Util_BufferConstantOp : Util_PureOp<"buffer.constant", [
}];

let arguments = (ins
AnyAttr:$value,
OptionalAttr<IndexAttr>:$alignment
OptionalAttr<StrAttr>:$name,
Util_AnySerializableAttr:$value,
OptionalAttr<IndexAttr>:$alignment,
OptionalAttr<StrAttr>:$mime_type
);
let results = (outs
Util_BufferType:$result
);

let assemblyFormat = [{
attr-dict `:`
type($result)
`=` $value
($name^)? attr-dict `:` type($result) `=` $value
}];

let hasVerifier = 1;
Expand Down Expand Up @@ -861,9 +861,15 @@ def Util_BufferSubspanOp : Util_PureOp<"buffer.subspan", [
"getTiedResultOperandIndices",
]>,
]> {
let summary = [{returns the buffer storage size in bytes}];
let summary = [{returns a reference to a subrange of a buffer}];
let description = [{
Returns the length of the buffer in bytes from its base offset.
Returns a logical view into an underlying source buffer. This induces
aliasing and multiple SSA values may allow access to the same underlying
buffer storage.

Subspans are a compiler-only concept and are propagated by an analysis pass
to result in absolute offsets on accesses any place the subrange would have
been used.
}];

let arguments = (ins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct BufferConstantOpConversion
op,
IREE::VM::RefType::get(
IREE::VM::BufferType::get(rewriter.getContext())),
/*name=*/nullptr, op.getValue(), alignmentAttr);
op.getNameAttr(), op.getValue(), alignmentAttr, op.getMimeTypeAttr());
return success();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

// CHECK-LABEL: @buffer_constant
func.func @buffer_constant() -> !util.buffer {
// CHECK-64: %[[BUFFER:.+]] = vm.rodata.inline {alignment = 64 : i64} : !vm.buffer = dense<[1, 2, 3]> : tensor<3xi32>
%0 = util.buffer.constant {alignment = 64 : index} : !util.buffer = dense<[1, 2, 3]> : tensor<3xi32>
// CHECK-64: %[[BUFFER:.+]] = vm.rodata.inline "name" {alignment = 64 : i64, mime_type = "text/plain"} : !vm.buffer = dense<[1, 2, 3]> : tensor<3xi32>
%0 = util.buffer.constant "name" {alignment = 64 : index, mime_type = "text/plain"} : !util.buffer = dense<[1, 2, 3]> : tensor<3xi32>
// CHECK-64: return %[[BUFFER]]
return %0 : !util.buffer
}
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/iree/compiler/Dialect/VM/IR/VMOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,9 @@ void RodataInlineOp::build(OpBuilder &builder, OperationState &result,
auto safeIdentifier = makeSafeIdentifier(value.getValue());
build(builder, result,
IREE::VM::RefType::get(IREE::VM::BufferType::get(builder.getContext())),
builder.getStringAttr(safeIdentifier), value,
/*alignment=*/builder.getI64IntegerAttr(1));
/*name=*/builder.getStringAttr(safeIdentifier), /*data=*/value,
/*alignment=*/builder.getI64IntegerAttr(1),
/*mimeType=*/nullptr);
}

//===----------------------------------------------------------------------===//
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/iree/compiler/Dialect/VM/IR/VMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,8 @@ def VM_RodataInlineOp : VM_PureOp<"rodata.inline", [
let arguments = (ins
OptionalAttr<StrAttr>:$name,
Util_AnySerializableAttr:$value,
OptionalAttr<I64Attr>:$alignment
OptionalAttr<I64Attr>:$alignment,
OptionalAttr<StrAttr>:$mime_type
);

let results = (outs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class HoistInlinedRodataPass
if (auto alignmentAttr = inlineOp.getAlignmentAttr()) {
rodataOp.setAlignmentAttr(alignmentAttr);
}
if (auto mimeTypeAttr = inlineOp.getMimeTypeAttr()) {
rodataOp.setMimeTypeAttr(mimeTypeAttr);
}
moduleSymbolTable.insert(rodataOp);
rodataOp.setPrivate();
replaceInlineOpWithRodataRef(inlineOp, rodataOp);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// RUN: iree-opt --split-input-file --iree-vm-hoist-inlined-rodata %s | FileCheck %s

vm.module @module {
// CHECK: vm.rodata private @fn_const dense<[1, 2, 3]> : tensor<3xi32>
// Here to check the symbol deduplication logic:
vm.func @name() { vm.return }
// CHECK: vm.rodata private @name_0 {alignment = 64 : i64, mime_type = "text/plain"} dense<[1, 2, 3]> : tensor<3xi32>
// CHECK-LABEL: vm.func @fn
vm.func @fn() {
// CHECK: = vm.const.ref.rodata @fn_const : !vm.buffer
%0 = vm.rodata.inline : !vm.buffer = dense<[1, 2, 3]> : tensor<3xi32>
// CHECK: = vm.const.ref.rodata @name_0 : !vm.buffer
%0 = vm.rodata.inline "name" {alignment = 64 : i64, mime_type = "text/plain"} : !vm.buffer = dense<[1, 2, 3]> : tensor<3xi32>
vm.return
}
}
Expand Down

0 comments on commit aff200e

Please sign in to comment.