Skip to content

Commit 09630d6

Browse files
benvanikSimon Camphausen
andauthored
Finally moving VM type registration to iree_vm_instance_t. (#12650)
This allows for thread-safe type registration scoped to instances and unregistration of types as required by types in dynamically loaded modules that may wink out of existence at some point. The main trick here was changing the type ID from an ordinal in the type table to just the pointer of the type descriptor. This requires an extra 4 bytes per ref on 64-bit systems but who cares - now there's no round-tripping through the type table for common operations. As part of simplifying the way types are referenced VM type descriptors are now hidden behind iree_vm_ref_type_t. This makes refs much easier to work with as there's only one way to reference types and it always bottoms out on the registered descriptor handle. It also allows us to remove some type descriptor indirection we'd previously required in order to get reference counter offsets as we can share the same packed type identifier in type defs, refs, or lists. Thanks to @simon-camp for the required EmitC changes! --------- Co-authored-by: Simon Camphausen <simon.camphausen@iml.fraunhofer.de>
1 parent 8be370c commit 09630d6

File tree

89 files changed

+1677
-1057
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1677
-1057
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ cmake_dependent_option(IREE_OUTPUT_FORMAT_C "Enables the 'vm-c' output format, u
361361
if(IREE_BUILD_COMPILER)
362362
message(STATUS "IREE compiler output formats:")
363363
if(IREE_OUTPUT_FORMAT_C)
364-
message(STATUS " - C source module")
364+
message(STATUS " - 'vm-c': textual C source module")
365365
endif()
366366
# The 'vm-bytecode' and 'vm-asm' formats are always enabled.
367-
message(STATUS " - VM Bytecode")
368-
message(STATUS " - VM MLIR Assembly")
367+
message(STATUS " - 'vm-bytecode': VM bytecode")
368+
message(STATUS " - 'vm-asm': VM MLIR assembly")
369369
endif()
370370

371371
#-------------------------------------------------------------------------------

compiler/src/iree/compiler/ConstEval/Runtime.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ static Attribute createAttributeFromRawData(Location loc,
8383

8484
} // namespace
8585

86-
CompiledBinary::CompiledBinary() {}
86+
CompiledBinary::CompiledBinary() = default;
8787

88-
CompiledBinary::~CompiledBinary() {}
88+
CompiledBinary::~CompiledBinary() = default;
8989

9090
void CompiledBinary::deinitialize() {
9191
hal_module.reset();
@@ -106,10 +106,10 @@ LogicalResult CompiledBinary::invokeNullary(Location loc, StringRef name,
106106
}
107107

108108
iree::vm::ref<iree_vm_list_t> inputs;
109-
IREE_CHECK_OK(iree_vm_list_create(/*element_type=*/nullptr, 0,
109+
IREE_CHECK_OK(iree_vm_list_create(iree_vm_make_undefined_type_def(), 0,
110110
iree_allocator_system(), &inputs));
111111
iree::vm::ref<iree_vm_list_t> outputs;
112-
IREE_CHECK_OK(iree_vm_list_create(/*element_type=*/nullptr, 1,
112+
IREE_CHECK_OK(iree_vm_list_create(iree_vm_make_undefined_type_def(), 1,
113113
iree_allocator_system(), &outputs));
114114

115115
if (auto status =
@@ -188,7 +188,7 @@ Attribute CompiledBinary::convertVariantToAttribute(
188188
auto context = loc.getContext();
189189
Builder builder(context);
190190
if (iree_vm_variant_is_value(variant)) {
191-
switch (variant.type.value_type) {
191+
switch (iree_vm_type_def_as_value(variant.type)) {
192192
case IREE_VM_VALUE_TYPE_I8:
193193
return builder.getI8IntegerAttr(variant.i8);
194194
case IREE_VM_VALUE_TYPE_I16:
@@ -203,7 +203,8 @@ Attribute CompiledBinary::convertVariantToAttribute(
203203
return builder.getF64FloatAttr(variant.f64);
204204
default:
205205
emitError(loc) << "unrecognized evaluated value type: "
206-
<< static_cast<int>(variant.type.value_type);
206+
<< static_cast<int>(
207+
iree_vm_type_def_as_value(variant.type));
207208
return {};
208209
}
209210
}
@@ -248,7 +249,7 @@ Attribute CompiledBinary::convertVariantToAttribute(
248249
return convertedAttr;
249250
} else {
250251
iree_string_view_t typeName =
251-
iree_vm_ref_type_name(variant.type.ref_type);
252+
iree_vm_ref_type_name(iree_vm_type_def_as_ref(variant.type));
252253
emitError(loc) << "unrecognized evaluated ref type: "
253254
<< StringRef(typeName.data, typeName.size);
254255
return {};
@@ -311,7 +312,8 @@ Runtime::Runtime() {
311312
IREE_CHECK_OK(
312313
iree_hal_driver_registry_allocate(iree_allocator_system(), &registry));
313314
IREE_CHECK_OK(iree_hal_local_task_driver_module_register(registry));
314-
IREE_CHECK_OK(iree_vm_instance_create(iree_allocator_system(), &instance));
315+
IREE_CHECK_OK(iree_vm_instance_create(IREE_VM_TYPE_CAPACITY_DEFAULT,
316+
iree_allocator_system(), &instance));
315317
IREE_CHECK_OK(iree_hal_module_register_all_types(instance.get()));
316318
}
317319

compiler/src/iree/compiler/Dialect/VM/Conversion/VMToEmitC/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ iree_compiler_cc_library(
4141
"//compiler/src/iree/compiler/Dialect/VM/Analysis",
4242
"//compiler/src/iree/compiler/Dialect/VM/IR",
4343
"//compiler/src/iree/compiler/Dialect/VM/Utils:CallingConvention",
44+
"//compiler/src/iree/compiler/Dialect/VM/Utils:TypeTable",
4445
"@llvm-project//llvm:Support",
4546
"@llvm-project//mlir:ArithDialect",
4647
"@llvm-project//mlir:ControlFlowDialect",

compiler/src/iree/compiler/Dialect/VM/Conversion/VMToEmitC/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ iree_cc_library(
4343
iree::compiler::Dialect::VM::Analysis
4444
iree::compiler::Dialect::VM::IR
4545
iree::compiler::Dialect::VM::Utils::CallingConvention
46+
iree::compiler::Dialect::VM::Utils::TypeTable
4647
PUBLIC
4748
)
4849

0 commit comments

Comments
 (0)