Skip to content

Commit

Permalink
Changing size values to iree_host_size_t (size_t).
Browse files Browse the repository at this point in the history
  • Loading branch information
benvanik committed Aug 17, 2020
1 parent f5bd6fd commit 4bb6028
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 89 deletions.
4 changes: 4 additions & 0 deletions iree/base/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ typedef uint64_t iree_device_size_t;
// Whole length of the underlying buffer.
#define IREE_WHOLE_BUFFER (iree_device_size_t(-1))

//===----------------------------------------------------------------------===//
// Byte buffers and memory utilities
//===----------------------------------------------------------------------===//

// A span of mutable bytes (ala std::span of uint8_t).
typedef struct {
uint8_t* data;
Expand Down
10 changes: 5 additions & 5 deletions iree/vm/bytecode_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ iree_status_t iree_vm_bytecode_dispatch(
if (global < 0 || global >= module_state->global_ref_count) {
return iree_make_status(
IREE_STATUS_OUT_OF_RANGE,
"global ref ordinal out of range: %d (table=%d)", global,
"global ref ordinal out of range: %d (table=%zu)", global,
module_state->global_ref_count);
}
const iree_vm_type_def_t* type_def = VM_DecTypeOf("value");
Expand All @@ -170,7 +170,7 @@ iree_status_t iree_vm_bytecode_dispatch(
if (global < 0 || global >= module_state->global_ref_count) {
return iree_make_status(
IREE_STATUS_OUT_OF_RANGE,
"global ref ordinal out of range: %d (table=%d)", global,
"global ref ordinal out of range: %d (table=%zu)", global,
module_state->global_ref_count);
}
const iree_vm_type_def_t* type_def = VM_DecTypeOf("value");
Expand All @@ -186,7 +186,7 @@ iree_status_t iree_vm_bytecode_dispatch(
if (global < 0 || global >= module_state->global_ref_count) {
return iree_make_status(
IREE_STATUS_OUT_OF_RANGE,
"global ref ordinal out of range: %d (table=%d)", global,
"global ref ordinal out of range: %d (table=%zu)", global,
module_state->global_ref_count);
}
const iree_vm_type_def_t* type_def = VM_DecTypeOf("value");
Expand All @@ -202,7 +202,7 @@ iree_status_t iree_vm_bytecode_dispatch(
if (global < 0 || global >= module_state->global_ref_count) {
return iree_make_status(
IREE_STATUS_OUT_OF_RANGE,
"global ref ordinal out of range: %d (table=%d)", global,
"global ref ordinal out of range: %d (table=%zu)", global,
module_state->global_ref_count);
}
const iree_vm_type_def_t* type_def = VM_DecTypeOf("value");
Expand Down Expand Up @@ -240,7 +240,7 @@ iree_status_t iree_vm_bytecode_dispatch(
rodata_ordinal >= module_state->rodata_ref_count) {
return iree_make_status(
IREE_STATUS_OUT_OF_RANGE,
"rodata ref ordinal out of range: %d (table=%d)", rodata_ordinal,
"rodata ref ordinal out of range: %d (table=%zu)", rodata_ordinal,
module_state->rodata_ref_count);
}
bool result_is_move;
Expand Down
44 changes: 22 additions & 22 deletions iree/vm/bytecode_dispatch_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,29 @@ static const int kRegSize = sizeof(uint16_t);
// Bytecode data access macros for reading values of a given type from a byte
// offset within the current function.
#if defined(IREE_IS_LITTLE_ENDIAN)
#define OP_I8(i) bytecode_data[pc + i]
#define OP_I16(i) *((uint16_t*)&bytecode_data[pc + i])
#define OP_I32(i) *((uint32_t*)&bytecode_data[pc + i])
#define OP_I64(i) *((uint64_t*)&bytecode_data[pc + i])
#define OP_I8(i) bytecode_data[pc + (i)]
#define OP_I16(i) *((uint16_t*)&bytecode_data[pc + (i)])
#define OP_I32(i) *((uint32_t*)&bytecode_data[pc + (i)])
#define OP_I64(i) *((uint64_t*)&bytecode_data[pc + (i)])
#else
#define OP_I8(i) bytecode_data[pc + i]
#define OP_I16(i) \
((uint16_t)bytecode_data[pc + 0 + i]) | \
((uint16_t)bytecode_data[pc + 1 + i] << 8)
#define OP_I32(i) \
((uint32_t)bytecode_data[pc + 0 + i]) | \
((uint32_t)bytecode_data[pc + 1 + i] << 8) | \
((uint32_t)bytecode_data[pc + 2 + i] << 16) | \
((uint32_t)bytecode_data[pc + 3 + i] << 24)
#define OP_I64(i) \
((uint64_t)bytecode_data[pc + 0 + i]) | \
((uint64_t)bytecode_data[pc + 1 + i] << 8) | \
((uint64_t)bytecode_data[pc + 2 + i] << 16) | \
((uint64_t)bytecode_data[pc + 3 + i] << 24) | \
((uint64_t)bytecode_data[pc + 4 + i] << 32) | \
((uint64_t)bytecode_data[pc + 5 + i] << 40) | \
((uint64_t)bytecode_data[pc + 6 + i] << 48) | \
((uint64_t)bytecode_data[pc + 7 + i] << 56)
#define OP_I8(i) bytecode_data[pc + (i)]
#define OP_I16(i) \
((uint16_t)bytecode_data[pc + 0 + (i)]) | \
((uint16_t)bytecode_data[pc + 1 + (i)] << 8)
#define OP_I32(i) \
((uint32_t)bytecode_data[pc + 0 + (i)]) | \
((uint32_t)bytecode_data[pc + 1 + (i)] << 8) | \
((uint32_t)bytecode_data[pc + 2 + (i)] << 16) | \
((uint32_t)bytecode_data[pc + 3 + (i)] << 24)
#define OP_I64(i) \
((uint64_t)bytecode_data[pc + 0 + (i)]) | \
((uint64_t)bytecode_data[pc + 1 + (i)] << 8) | \
((uint64_t)bytecode_data[pc + 2 + (i)] << 16) | \
((uint64_t)bytecode_data[pc + 3 + (i)] << 24) | \
((uint64_t)bytecode_data[pc + 4 + (i)] << 32) | \
((uint64_t)bytecode_data[pc + 5 + (i)] << 40) | \
((uint64_t)bytecode_data[pc + 6 + (i)] << 48) | \
((uint64_t)bytecode_data[pc + 7 + (i)] << 56)
#endif // IREE_IS_LITTLE_ENDIAN

//===----------------------------------------------------------------------===//
Expand Down
65 changes: 29 additions & 36 deletions iree/vm/bytecode_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,13 @@ static iree_status_t iree_vm_bytecode_module_flatbuffer_verify(
return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
"exports[%zu] missing signature", i);
}
int32_t internal_ordinal =
iree_host_size_t internal_ordinal =
iree_vm_ExportFunctionDef_internal_ordinal(export_def);
if (internal_ordinal < 0 ||
internal_ordinal >=
iree_vm_InternalFunctionDef_vec_len(internal_functions)) {
if (internal_ordinal >=
iree_vm_InternalFunctionDef_vec_len(internal_functions)) {
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
"exports[%zu] internal_ordinal out of bounds (0 < %d < %zu)", i,
"exports[%zu] internal_ordinal out of bounds (0 < %zu < %zu)", i,
internal_ordinal,
iree_vm_InternalFunctionDef_vec_len(internal_functions));
}
Expand Down Expand Up @@ -280,7 +279,7 @@ static iree_vm_module_signature_t iree_vm_bytecode_module_signature(
}

static iree_status_t iree_vm_bytecode_module_get_function(
void* self, iree_vm_function_linkage_t linkage, int32_t ordinal,
void* self, iree_vm_function_linkage_t linkage, iree_host_size_t ordinal,
iree_vm_function_t* out_function, iree_string_view_t* out_name,
iree_vm_function_signature_t* out_signature) {
if (out_function) {
Expand All @@ -299,11 +298,10 @@ static iree_status_t iree_vm_bytecode_module_get_function(
if (linkage == IREE_VM_FUNCTION_LINKAGE_IMPORT) {
iree_vm_ImportFunctionDef_vec_t imported_functions =
iree_vm_BytecodeModuleDef_imported_functions(module->def);
if (ordinal < 0 ||
ordinal >= iree_vm_ImportFunctionDef_vec_len(imported_functions)) {
if (ordinal >= iree_vm_ImportFunctionDef_vec_len(imported_functions)) {
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
"import ordinal out of range (0 < %d < %zu)", ordinal,
"import ordinal out of range (0 < %zu < %zu)", ordinal,
iree_vm_ImportFunctionDef_vec_len(imported_functions));
}
iree_vm_ImportFunctionDef_table_t import_def =
Expand All @@ -313,16 +311,15 @@ static iree_status_t iree_vm_bytecode_module_get_function(
if (out_function) {
out_function->module = &module->interface;
out_function->linkage = linkage;
out_function->ordinal = ordinal;
out_function->ordinal = (uint16_t)ordinal;
}
} else if (linkage == IREE_VM_FUNCTION_LINKAGE_EXPORT) {
iree_vm_ExportFunctionDef_vec_t exported_functions =
iree_vm_BytecodeModuleDef_exported_functions(module->def);
if (ordinal < 0 ||
ordinal >= iree_vm_ExportFunctionDef_vec_len(exported_functions)) {
if (ordinal >= iree_vm_ExportFunctionDef_vec_len(exported_functions)) {
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
"export ordinal out of range (0 < %d < %zu)", ordinal,
"export ordinal out of range (0 < %zu < %zu)", ordinal,
iree_vm_ExportFunctionDef_vec_len(exported_functions));
}
iree_vm_ExportFunctionDef_table_t export_def =
Expand All @@ -345,11 +342,10 @@ static iree_status_t iree_vm_bytecode_module_get_function(
} else {
iree_vm_InternalFunctionDef_vec_t internal_functions =
iree_vm_BytecodeModuleDef_internal_functions(module->def);
if (ordinal < 0 ||
ordinal >= iree_vm_InternalFunctionDef_vec_len(internal_functions)) {
if (ordinal >= iree_vm_InternalFunctionDef_vec_len(internal_functions)) {
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
"function ordinal out of range (0 < %d < %zu)", ordinal,
"function ordinal out of range (0 < %zu < %zu)", ordinal,
iree_vm_InternalFunctionDef_vec_len(internal_functions));
}
iree_vm_InternalFunctionDef_table_t function_def =
Expand All @@ -359,7 +355,7 @@ static iree_status_t iree_vm_bytecode_module_get_function(
if (out_function) {
out_function->module = &module->interface;
out_function->linkage = IREE_VM_FUNCTION_LINKAGE_INTERNAL;
out_function->ordinal = ordinal;
out_function->ordinal = (uint16_t)ordinal;

const iree_vm_FunctionDescriptor_t* function_descriptor =
&module->function_descriptor_table[ordinal];
Expand All @@ -385,25 +381,24 @@ static iree_status_t iree_vm_bytecode_module_get_function(
}

static iree_status_t iree_vm_bytecode_module_get_function_reflection_attr(
void* self, iree_vm_function_linkage_t linkage, int32_t ordinal,
int32_t index, iree_string_view_t* key, iree_string_view_t* value) {
void* self, iree_vm_function_linkage_t linkage, iree_host_size_t ordinal,
iree_host_size_t index, iree_string_view_t* key,
iree_string_view_t* value) {
if (linkage != IREE_VM_FUNCTION_LINKAGE_INTERNAL) {
iree_vm_function_t internal_function;
IREE_RETURN_IF_ERROR(iree_vm_bytecode_module_get_function(
self, linkage, ordinal, &internal_function, NULL, NULL));
linkage = internal_function.linkage;
ordinal = internal_function.ordinal;
}

iree_vm_bytecode_module_t* module = (iree_vm_bytecode_module_t*)self;
iree_vm_InternalFunctionDef_vec_t internal_functions =
iree_vm_BytecodeModuleDef_internal_functions(module->def);

if (ordinal < 0 ||
ordinal >= iree_vm_InternalFunctionDef_vec_len(internal_functions)) {
if (ordinal >= iree_vm_InternalFunctionDef_vec_len(internal_functions)) {
return iree_make_status(
IREE_STATUS_INVALID_ARGUMENT,
"function ordinal out of range (0 < %d < %zu)", ordinal,
"function ordinal out of range (0 < %zu < %zu)", ordinal,
iree_vm_InternalFunctionDef_vec_len(internal_functions));
}

Expand All @@ -413,10 +408,9 @@ static iree_status_t iree_vm_bytecode_module_get_function_reflection_attr(
iree_vm_InternalFunctionDef_signature(function_def);
iree_vm_ReflectionAttrDef_vec_t reflection_attrs =
iree_vm_FunctionSignatureDef_reflection_attrs(signature);
if (index < 0 ||
index >= iree_vm_ReflectionAttrDef_vec_len(reflection_attrs)) {
if (index >= iree_vm_ReflectionAttrDef_vec_len(reflection_attrs)) {
return iree_make_status(IREE_STATUS_NOT_FOUND,
"reflection attribute at index %d not found",
"reflection attribute at index %zu not found",
index);
}
iree_vm_ReflectionAttrDef_table_t attr =
Expand Down Expand Up @@ -516,16 +510,16 @@ static iree_host_size_t iree_vm_bytecode_module_layout_state(
iree_vm_bytecode_module_state_t* state) {
iree_vm_ModuleStateDef_table_t module_state =
iree_vm_BytecodeModuleDef_module_state(module_def);
int rwdata_storage_capacity = 0;
int global_ref_count = 0;
iree_host_size_t rwdata_storage_capacity = 0;
iree_host_size_t global_ref_count = 0;
if (module_state) {
rwdata_storage_capacity =
iree_vm_ModuleStateDef_global_bytes_capacity(module_state);
global_ref_count = iree_vm_ModuleStateDef_global_ref_count(module_state);
}
int rodata_ref_count = iree_vm_RodataSegmentDef_vec_len(
iree_host_size_t rodata_ref_count = iree_vm_RodataSegmentDef_vec_len(
iree_vm_BytecodeModuleDef_rodata_segments(module_def));
int import_function_count = iree_vm_ImportFunctionDef_vec_len(
iree_host_size_t import_function_count = iree_vm_ImportFunctionDef_vec_len(
iree_vm_BytecodeModuleDef_imported_functions(module_def));

uint8_t* base_ptr = (uint8_t*)state;
Expand Down Expand Up @@ -614,14 +608,14 @@ static void iree_vm_bytecode_module_free_state(
}

static iree_status_t iree_vm_bytecode_module_resolve_import(
void* self, iree_vm_module_state_t* module_state, int32_t ordinal,
void* self, iree_vm_module_state_t* module_state, iree_host_size_t ordinal,
iree_vm_function_t function) {
IREE_ASSERT_ARGUMENT(module_state);
iree_vm_bytecode_module_state_t* state =
(iree_vm_bytecode_module_state_t*)module_state;
if (ordinal < 0 || ordinal >= state->import_count) {
if (ordinal >= state->import_count) {
return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
"import ordinal out of range (0 < %d < %d)",
"import ordinal out of range (0 < %zu < %zu)",
ordinal, state->import_count);
}
// TODO(benvanik): verify signature.
Expand All @@ -648,10 +642,9 @@ static iree_status_t iree_vm_bytecode_module_begin_call(
}

iree_vm_bytecode_module_t* module = (iree_vm_bytecode_module_t*)self;
if (function.ordinal < 0 ||
function.ordinal >= module->function_descriptor_count) {
if (function.ordinal >= module->function_descriptor_count) {
return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
"function ordinal out of range (0 < %d < %d)",
"function ordinal out of range (0 < %u < %zu)",
function.ordinal,
module->function_descriptor_count);
}
Expand Down
10 changes: 5 additions & 5 deletions iree/vm/bytecode_module_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef struct {
// Table of internal function bytecode descriptors.
// Mapped 1:1 with internal functions. Each defined bytecode span represents a
// range of bytes in |bytecode_data|.
int32_t function_descriptor_count;
iree_host_size_t function_descriptor_count;
const iree_vm_FunctionDescriptor_t* function_descriptor_table;

// A pointer to the bytecode data embedded within the module.
Expand All @@ -69,7 +69,7 @@ typedef struct {
iree_vm_BytecodeModuleDef_table_t def;

// Type table mapping module type IDs to registered VM types.
int32_t type_count;
iree_host_size_t type_count;
iree_vm_type_def_t* type_table;
} iree_vm_bytecode_module_t;

Expand All @@ -83,18 +83,18 @@ typedef struct {
iree_byte_span_t rwdata_storage;

// Global ref_ptr values, indexed by global ordinal.
int32_t global_ref_count;
iree_host_size_t global_ref_count;
iree_vm_ref_t* global_ref_table;

// TODO(benvanik): move to iree_vm_bytecode_module_t if always static.
// Initialized references to rodata segments.
// Right now these don't do much, however we can perform lazy caching and
// on-the-fly decompression using this information.
int32_t rodata_ref_count;
iree_host_size_t rodata_ref_count;
iree_vm_ro_byte_buffer_t* rodata_ref_table;

// Resolved function imports.
int32_t import_count;
iree_host_size_t import_count;
iree_vm_function_t* import_table;

// Allocator used for the state itself and any runtime allocations needed.
Expand Down
5 changes: 3 additions & 2 deletions iree/vm/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ iree_vm_module_lookup_function_by_name(const iree_vm_module_t* module,
IREE_API_EXPORT iree_status_t IREE_API_CALL
iree_vm_module_lookup_function_by_ordinal(const iree_vm_module_t* module,
iree_vm_function_linkage_t linkage,
int32_t ordinal,
iree_host_size_t ordinal,
iree_vm_function_t* out_function,
iree_string_view_t* linkage_name) {
return module->get_function(module->self, linkage, ordinal, out_function,
Expand Down Expand Up @@ -128,7 +128,8 @@ iree_vm_function_reflection_attr(const iree_vm_function_t* function,
}

IREE_API_EXPORT iree_status_t IREE_API_CALL
iree_vm_get_function_reflection_attr(iree_vm_function_t function, int32_t index,
iree_vm_get_function_reflection_attr(iree_vm_function_t function,
iree_host_size_t index,
iree_string_view_t* key,
iree_string_view_t* value) {
if (!function.module->get_function_reflection_attr) {
Expand Down
Loading

0 comments on commit 4bb6028

Please sign in to comment.