Skip to content

Commit c656326

Browse files
authored
Runtime API Changes (#164)
1 parent 3b4038a commit c656326

23 files changed

+301
-218
lines changed

cmake/typeartToolchainOptions.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ mark_as_advanced(TYPEART_CONFIG_DIR_IS_SHARE)
9494
option(TYPEART_USE_LEGACY_WRAPPER "Use the old TypeART compiler wrapper" OFF)
9595
# mark_as_advanced(TYPEART_USE_NEW_PASSMANAGER)
9696

97-
if(LLVM_VERSION_MAJOR VERSION_GREATER_EQUAL "18")
98-
set(TYPEART_USE_NEW_PASSMANAGER ON CACHE BOOL ON FORCE)
99-
endif()
97+
# if(LLVM_VERSION_MAJOR VERSION_GREATER_EQUAL "18")
98+
# set(TYPEART_USE_NEW_PASSMANAGER ON CACHE BOOL ON FORCE)
99+
# endif()
100100

101101
set(warning_guard "")
102102
if(NOT TYPEART_IS_TOP_LEVEL)

demo/tool.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ void analyseBuffer(const void* buf, int count, MPI_Datatype type) {
5151

5252
printf("Basetype(%s, addr=%p, size=%i , count=%i)\n", type_name, buf, size, count);
5353

54-
int type_id;
55-
size_t count_check;
56-
typeart_status status = typeart_get_type(buf, &type_id, &count_check);
54+
typeart_type_info info;
55+
typeart_status status = typeart_get_type(buf, &info);
5756

5857
if (status == TYPEART_OK) {
58+
int type_id;
59+
size_t count_check;
60+
type_id = info.type_id;
61+
count_check = info.count;
5962
// If the address corresponds to a struct, fetch the type of the first member
6063
while (type_id >= TYPEART_NUM_RESERVED_IDS) {
6164
typeart_struct_layout struct_layout;

externals/dimeta/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ FetchContent_Declare(
55
GIT_SHALLOW 1
66
)
77

8-
FetchContent_MakeAvailable(llvm-dimeta)
8+
#FetchContent_MakeAvailable(llvm-dimeta)
9+
10+
# TODO need exclude to not install llvm-dimeta with TypeART
11+
FetchContent_GetProperties(llvm-dimeta)
12+
if(NOT llvm-dimeta_POPULATED)
13+
FetchContent_Populate(llvm-dimeta)
14+
add_subdirectory(${llvm-dimeta_SOURCE_DIR} ${llvm-dimeta_BINARY_DIR} EXCLUDE_FROM_ALL)
15+
endif()
916

1017
mark_as_advanced(
1118
DIMETA_USE_HEAPALLOCSITE

lib/mpi_interceptor/InterceptorFunctions.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ int ta_check_buffer(const char* mpi_name, const void* called_from, const void* b
9898
ta_print_loc(called_from);
9999
return -1;
100100
}
101-
int typeId;
102-
size_t count = 0;
103-
typeart_status typeart_status_v = typeart_get_type(buf, &typeId, &count);
101+
// int typeId;
102+
// size_t count = 0;
103+
typeart_type_info info;
104+
typeart_status typeart_status_v = typeart_get_type(buf, &info);
104105
if (typeart_status_v != TYPEART_OK) {
105106
++mcounter.error;
106107
const char* msg = ta_get_error_message(typeart_status_v);

lib/passes/TypeARTPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class TypeArtPass : public llvm::PassInfoMixin<TypeArtPass> {
309309
bool runOnFunc(llvm::Function& f) {
310310
using namespace typeart;
311311

312-
if (f.isDeclaration() || util::starts_with_any_of(f.getName(), "__typeart")) {
312+
if (f.isDeclaration() || util::starts_with_any_of(f.getName(), "__typeart", "typeart")) {
313313
return false;
314314
}
315315

lib/passes/typegen/dimeta/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ set_target_properties(
4141
typeart_target_coverage_options(${TYPEART_PREFIX}_TypeGenDimetaStatic)
4242

4343
target_link_libraries(${TYPEART_PREFIX}_TypeGenDimetaStatic PUBLIC typeart::TypesStatic)
44-
target_link_libraries(${TYPEART_PREFIX}_TypeGenDimetaStatic PUBLIC dimeta::Types)
44+
target_link_libraries(${TYPEART_PREFIX}_TypeGenDimetaStatic PRIVATE dimeta::Types)
4545

4646
target_include_directories(
4747
${TYPEART_PREFIX}_TypeGenDimetaStatic ${warning_guard}

lib/runtime/RuntimeInterface.h

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,24 @@ typedef struct typeart_struct_layout_t { // NOLINT
4646
const size_t* count;
4747
} typeart_struct_layout;
4848

49+
typedef struct typeart_base_type_info_t {
50+
const void* address;
51+
int type_id;
52+
size_t count;
53+
} typeart_base_type_info;
54+
55+
typedef struct typeart_type_info_t {
56+
const void* address;
57+
int type_id;
58+
size_t count;
59+
typeart_base_type_info base_type_info; // API dependent
60+
} typeart_type_info;
61+
4962
/**
5063
* Determines the type and array element count at the given address.
5164
* For nested types with classes/structs, the containing type is resolved recursively, until an exact with the address
5265
* is found.
53-
* See typeart_get_type_length and typeart_get_type_id for resolving only one such parameter
54-
*
55-
* Note that this function will always return the outermost type lining up with the address.
56-
* Given a pointer to the start of a struct, the returned type will therefore be that of the struct, not of the first
57-
* member.
66+
* base_type_info is the outermost type and array element count at the given address.
5867
*
5968
* Code example:
6069
* {
@@ -68,20 +77,15 @@ typedef struct typeart_struct_layout_t { // NOLINT
6877
* }
6978
*
7079
* \param[in] addr The address.
71-
* \param[out] type_id Type ID
72-
* \param[out] count Allocation size
80+
* \param[out] base_type allocation info at the address addr. The address equals [in] param addr.
7381
*
7482
* \return A status code:
7583
* - TYPEART_OK: The query was successful and the contents of type and count are valid.
7684
* - TYPEART_UNKNOWN_ADDRESS: The given address is either not allocated, or was not correctly recorded by the runtime.
7785
* - TYPEART_BAD_ALIGNMENT: The given address does not line up with the start of the atomic type at that location.
7886
* - TYPEART_INVALID_ID: Encountered unregistered ID during lookup.
7987
*/
80-
typeart_status typeart_get_type(const void* addr, int* type_id, size_t* count);
81-
82-
typeart_status typeart_get_type_length(const void* addr, size_t* count);
83-
84-
typeart_status typeart_get_type_id(const void* addr, int* type_id);
88+
typeart_status typeart_get_type(const void* addr, typeart_type_info* type_info);
8589

8690
/**
8791
* Determines the outermost type and array element count at the given address.
@@ -117,17 +121,18 @@ typeart_status typeart_get_type_id(const void* addr, int* type_id);
117121
* to &data[0])
118122
* }
119123
*
120-
* \param[in] addr The address.
121-
* \param[out] type_id Type ID of the containing type
122-
* \param[out] count Number of elements in the containing buffer, not counting elements before the given address.
123-
* \param[out] base_address Address of the containing buffer.
124+
* \param[in] type The result of a `typeart_get_type` call on some address.
125+
* \param[out] containing_type Type information of the containing type.
124126
* \param[out] byte_offset The byte offset within that buffer element.
125127
*
126128
* \return A status code.
127129
* - TYPEART_OK: The query was successful.
128130
* - TYPEART_UNKNOWN_ADDRESS: The given address is either not allocated, or was not correctly recorded by the runtime.
129131
*/
130-
typeart_status typeart_get_containing_type(const void* addr, int* type_id, size_t* count, const void** base_address,
132+
// typeart_status typeart_get_containing_type(const void* addr, int* type_id, size_t* count, const void** base_address,
133+
// size_t* byte_offset);
134+
135+
typeart_status typeart_get_containing_type(typeart_type_info type_info, typeart_base_type_info* containing_type,
131136
size_t* byte_offset);
132137

133138
/**
@@ -156,24 +161,20 @@ typeart_status typeart_get_containing_type(const void* addr, int* type_id, size_
156161
* -> subtype_count: 1 (length of member float[2] at offset 20)
157162
* }
158163
*
164+
* \param[in] container_layout typeart_struct_layout corresponding to the containing type
159165
* \param[in] baseAddr Pointer to the start of the containing type.
160166
* \param[in] offset Byte offset within the containing type.
161-
* \param[in] container_layout typeart_struct_layout corresponding to the containing type
162-
* \param[out] subtype_id The type ID corresponding to the subtype.
163-
* \param[out] subtype_base_addr Pointer to the start of the subtype.
167+
* \param[out] subtype_info The type container to the subtype.
164168
* \param[out] subtype_byte_offset Byte offset within the subtype.
165-
* \param[out] subtype_count Number of elements in subarray.
166169
*
167170
* \return One of the following status codes:
168171
* - TYPEART_OK: Success.
169172
* - TYPEART_BAD_ALIGNMENT: Address corresponds to location inside an atomic type or padding.
170173
* - TYPEART_BAD_OFFSET: The provided offset is invalid.
171174
* - TYPEART_ERROR: The typeart_struct_layout is invalid.
172175
*/
173-
typeart_status typeart_get_subtype(const void* base_addr, size_t offset, const typeart_struct_layout* container_layout,
174-
int* subtype_id, const void** subtype_base_addr, size_t* subtype_byte_offset,
175-
size_t* subtype_count);
176-
176+
typeart_status typeart_get_subtype(const typeart_struct_layout* container_layout, const void* base_addr, size_t offset,
177+
typeart_base_type_info* subtype_info, size_t* subtype_byte_offset);
177178
/**
178179
* Returns the stored debug address generated by __builtin_return_address(0).
179180
*
@@ -204,22 +205,6 @@ typeart_status typeart_get_return_address(const void* addr, const void** return_
204205
*/
205206
typeart_status typeart_get_source_location(const void* addr, char** file, char** function, char** line);
206207

207-
/**
208-
* Given an address, this function provides information about the corresponding struct type.
209-
* This is more expensive than the below version, since the pointer addr must be resolved.
210-
*
211-
* \param[in] addr The pointer address
212-
* \param[out] struct_layout Data layout of the struct.
213-
*
214-
* \return One of the following status codes:
215-
* - TYPEART_OK: Success.
216-
* - TYPEART_WRONG_KIND: ID does not correspond to a struct type.
217-
* - TYPEART_UNKNOWN_ADDRESS: The given address is either not allocated, or was not correctly recorded by the runtime.
218-
* - TYPEART_BAD_ALIGNMENT: The given address does not line up with the start of the atomic type at that location.
219-
* - TYPEART_INVALID_ID: Encountered unregistered ID during lookup.
220-
*/
221-
typeart_status typeart_resolve_type_addr(const void* addr, typeart_struct_layout* struct_layout);
222-
223208
/**
224209
* Given a type ID, this function provides information about the corresponding struct type.
225210
*

lib/runtime/TypeResolution.cpp

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,23 @@ inline typeart_status query_type(const void* addr, int* type, size_t* count) {
287287
return TYPEART_UNKNOWN_ADDRESS;
288288
}
289289

290+
inline typeart_status query_type(const void* addr, typeart_type_info& info) {
291+
auto alloc = typeart::RuntimeSystem::get().allocTracker.findBaseAlloc(addr);
292+
typeart::RuntimeSystem::get().recorder.incUsedInRequest(addr);
293+
if (alloc) {
294+
typeart_base_type_info base;
295+
base.address = alloc->first;
296+
base.type_id = alloc->second.typeId;
297+
base.count = alloc->second.count;
298+
info.base_type_info = base;
299+
info.address = addr;
300+
const auto result = typeart::RuntimeSystem::get().typeResolution.getTypeInfo(addr, alloc->first, alloc->second,
301+
&info.type_id, &info.count);
302+
return result;
303+
}
304+
return TYPEART_UNKNOWN_ADDRESS;
305+
}
306+
290307
inline typeart_status query_struct_layout(int type_id, typeart_struct_layout* struct_layout) {
291308
const typeart::StructTypeInfo* struct_info;
292309
typeart_status status = typeart::RuntimeSystem::get().typeResolution.getStructInfo(type_id, &struct_info);
@@ -295,9 +312,9 @@ inline typeart_status query_struct_layout(int type_id, typeart_struct_layout* st
295312
struct_layout->name = struct_info->name.c_str();
296313
struct_layout->num_members = struct_info->num_members;
297314
struct_layout->extent = struct_info->extent;
298-
struct_layout->offsets = &struct_info->offsets[0];
299-
struct_layout->member_types = &struct_info->member_types[0];
300-
struct_layout->count = &struct_info->array_sizes[0];
315+
struct_layout->offsets = (struct_info->offsets).data();
316+
struct_layout->member_types = (struct_info->member_types).data();
317+
struct_layout->count = (struct_info->array_sizes).data();
301318
} else {
302319
struct_layout->type_id = std::numeric_limits<decltype(typeart_struct_layout::type_id)>::min();
303320
struct_layout->name = "";
@@ -334,57 +351,33 @@ char* string2char(std::string_view src) {
334351
*
335352
*/
336353

337-
typeart_status typeart_get_type(const void* addr, int* type_id, size_t* count) {
338-
typeart::RTGuard guard;
339-
return typeart::detail::query_type(addr, type_id, count);
340-
}
341-
342-
typeart_status typeart_get_type_length(const void* addr, size_t* count) {
343-
typeart::RTGuard guard;
344-
int type{0};
345-
return typeart::detail::query_type(addr, &type, count);
346-
}
347-
348-
typeart_status typeart_get_type_id(const void* addr, int* type_id) {
354+
typeart_status typeart_get_type(const void* addr, typeart_type_info* base_type) {
349355
typeart::RTGuard guard;
350-
size_t count{0};
351-
return typeart::detail::query_type(addr, type_id, &count);
356+
return typeart::detail::query_type(addr, *base_type);
352357
}
353358

354-
typeart_status typeart_get_containing_type(const void* addr, int* type_id, size_t* count, const void** base_address,
359+
typeart_status typeart_get_containing_type(typeart_type_info type, typeart_base_type_info* containing_type,
355360
size_t* byte_offset) {
356361
typeart::RTGuard guard;
357-
auto alloc = typeart::RuntimeSystem::get().allocTracker.findBaseAlloc(addr);
358-
if (alloc) {
359-
// auto& allocVal = alloc.value();
360-
*type_id = alloc->second.typeId;
361-
*base_address = alloc->first;
362-
return typeart::RuntimeSystem::get().typeResolution.getContainingTypeInfo(addr, alloc->first, alloc->second, count,
363-
byte_offset);
364-
}
365-
return TYPEART_UNKNOWN_ADDRESS;
362+
containing_type->type_id = type.base_type_info.type_id;
363+
containing_type->count = type.base_type_info.count;
364+
containing_type->address = type.base_type_info.address;
365+
const typeart::PointerInfo info{type.base_type_info.type_id, type.base_type_info.count};
366+
const auto result = typeart::RuntimeSystem::get().typeResolution.getContainingTypeInfo(
367+
type.address, containing_type->address, info, &containing_type->count, byte_offset);
368+
369+
return result;
366370
}
367371

368-
typeart_status typeart_get_subtype(const void* base_addr, size_t offset, const typeart_struct_layout* container_layout,
369-
int* subtype_id, const void** subtype_base_addr, size_t* subtype_byte_offset,
370-
size_t* subtype_count) {
372+
typeart_status typeart_get_subtype(const typeart_struct_layout* container_layout, const void* base_addr, size_t offset,
373+
typeart_base_type_info* subtype_info, size_t* subtype_byte_offset) {
371374
typeart::RTGuard guard;
372375
auto status = typeart::RuntimeSystem::get().typeResolution.getSubTypeInfo(
373-
base_addr, offset, *container_layout, subtype_id, subtype_base_addr, subtype_byte_offset, subtype_count);
376+
base_addr, offset, *container_layout, &subtype_info->type_id, &subtype_info->address, subtype_byte_offset,
377+
&subtype_info->count);
374378
return status;
375379
}
376380

377-
typeart_status typeart_resolve_type_addr(const void* addr, typeart_struct_layout* struct_layout) {
378-
typeart::RTGuard guard;
379-
int type_id{0};
380-
size_t size{0};
381-
auto status = typeart::detail::query_type(addr, &type_id, &size);
382-
if (status != TYPEART_OK) {
383-
return status;
384-
}
385-
return typeart::detail::query_struct_layout(type_id, struct_layout);
386-
}
387-
388381
typeart_status typeart_resolve_type_id(int type_id, typeart_struct_layout* struct_layout) {
389382
typeart::RTGuard guard;
390383
return typeart::detail::query_struct_layout(type_id, struct_layout);

scripts/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ function(typeart_configure_script input output)
3131
set(TYPEART_PASS_DIR ${LIBRARY_OUTPUT_PATH})
3232
set(TYPEART_ANALYSIS_PASS_DIR ${LIBRARY_OUTPUT_PATH})
3333
else()
34-
set(TYPEART_MPI_INTERCEPT_DIR ${CMAKE_BINARY_DIR}/lib/mpi_interceptor)
35-
set(TYPEART_RT_DIR ${CMAKE_BINARY_DIR}/lib/runtime)
36-
set(TYPEART_PASS_DIR ${CMAKE_BINARY_DIR}/lib/passes)
34+
set(TYPEART_MPI_INTERCEPT_DIR ${CMAKE_CURRENT_BINARY_DIR}/../lib/mpi_interceptor)
35+
set(TYPEART_RT_DIR ${CMAKE_CURRENT_BINARY_DIR}/../lib/runtime)
36+
set(TYPEART_PASS_DIR ${CMAKE_CURRENT_BINARY_DIR}/../lib/passes)
3737
set(TYPEART_ANALYSIS_PASS_DIR ${TYPEART_PASS_DIR}/analysis)
3838
endif()
3939

4040
if(EXECUTABLE_OUTPUT_PATH)
4141
set(TYPEART_BINARY_DIR ${EXECUTABLE_OUTPUT_PATH})
4242
else()
43-
set(TYPEART_BINARY_DIR ${CMAKE_BINARY_DIR})
43+
set(TYPEART_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/..)
4444
endif()
4545

4646
set(TYPEART_RELOCATABLE 0)

scripts/typeart-tmpl.sh.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ function toolchain_init() {
185185
}
186186

187187
function source_to_llvm() {
188-
$compiler ${omp_flags} ${typeart_includes} ${typeart_san_flags} \
188+
# flag errors with implicit conversions when changing API
189+
local error_flags="-Werror=incompatible-pointer-types"
190+
$compiler ${error_flags} ${omp_flags} ${typeart_includes} ${typeart_san_flags} \
189191
-O1 -g ${compile_flags} -Xclang -disable-llvm-passes -S -emit-llvm "${source_file}" -o -
190192
}
191193

0 commit comments

Comments
 (0)