Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmake/typeartToolchainOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ mark_as_advanced(TYPEART_CONFIG_DIR_IS_SHARE)
option(TYPEART_USE_LEGACY_WRAPPER "Use the old TypeART compiler wrapper" OFF)
# mark_as_advanced(TYPEART_USE_NEW_PASSMANAGER)

if(LLVM_VERSION_MAJOR VERSION_GREATER_EQUAL "18")
set(TYPEART_USE_NEW_PASSMANAGER ON CACHE BOOL ON FORCE)
endif()
# if(LLVM_VERSION_MAJOR VERSION_GREATER_EQUAL "18")
# set(TYPEART_USE_NEW_PASSMANAGER ON CACHE BOOL ON FORCE)
# endif()

set(warning_guard "")
if(NOT TYPEART_IS_TOP_LEVEL)
Expand Down
9 changes: 6 additions & 3 deletions demo/tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ void analyseBuffer(const void* buf, int count, MPI_Datatype type) {

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

int type_id;
size_t count_check;
typeart_status status = typeart_get_type(buf, &type_id, &count_check);
typeart_type_info info;
typeart_status status = typeart_get_type(buf, &info);

if (status == TYPEART_OK) {
int type_id;
size_t count_check;
type_id = info.type_id;
count_check = info.count;
// If the address corresponds to a struct, fetch the type of the first member
while (type_id >= TYPEART_NUM_RESERVED_IDS) {
typeart_struct_layout struct_layout;
Expand Down
9 changes: 8 additions & 1 deletion externals/dimeta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ FetchContent_Declare(
GIT_SHALLOW 1
)

FetchContent_MakeAvailable(llvm-dimeta)
#FetchContent_MakeAvailable(llvm-dimeta)

# TODO need exclude to not install llvm-dimeta with TypeART
FetchContent_GetProperties(llvm-dimeta)
if(NOT llvm-dimeta_POPULATED)
FetchContent_Populate(llvm-dimeta)
add_subdirectory(${llvm-dimeta_SOURCE_DIR} ${llvm-dimeta_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

mark_as_advanced(
DIMETA_USE_HEAPALLOCSITE
Expand Down
7 changes: 4 additions & 3 deletions lib/mpi_interceptor/InterceptorFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ int ta_check_buffer(const char* mpi_name, const void* called_from, const void* b
ta_print_loc(called_from);
return -1;
}
int typeId;
size_t count = 0;
typeart_status typeart_status_v = typeart_get_type(buf, &typeId, &count);
// int typeId;
// size_t count = 0;
typeart_type_info info;
typeart_status typeart_status_v = typeart_get_type(buf, &info);
if (typeart_status_v != TYPEART_OK) {
++mcounter.error;
const char* msg = ta_get_error_message(typeart_status_v);
Expand Down
2 changes: 1 addition & 1 deletion lib/passes/TypeARTPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class TypeArtPass : public llvm::PassInfoMixin<TypeArtPass> {
bool runOnFunc(llvm::Function& f) {
using namespace typeart;

if (f.isDeclaration() || util::starts_with_any_of(f.getName(), "__typeart")) {
if (f.isDeclaration() || util::starts_with_any_of(f.getName(), "__typeart", "typeart")) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/passes/typegen/dimeta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ set_target_properties(
typeart_target_coverage_options(${TYPEART_PREFIX}_TypeGenDimetaStatic)

target_link_libraries(${TYPEART_PREFIX}_TypeGenDimetaStatic PUBLIC typeart::TypesStatic)
target_link_libraries(${TYPEART_PREFIX}_TypeGenDimetaStatic PUBLIC dimeta::Types)
target_link_libraries(${TYPEART_PREFIX}_TypeGenDimetaStatic PRIVATE dimeta::Types)

target_include_directories(
${TYPEART_PREFIX}_TypeGenDimetaStatic ${warning_guard}
Expand Down
67 changes: 26 additions & 41 deletions lib/runtime/RuntimeInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,24 @@ typedef struct typeart_struct_layout_t { // NOLINT
const size_t* count;
} typeart_struct_layout;

typedef struct typeart_base_type_info_t {
const void* address;
int type_id;
size_t count;
} typeart_base_type_info;

typedef struct typeart_type_info_t {
const void* address;
int type_id;
size_t count;
typeart_base_type_info base_type_info; // API dependent
} typeart_type_info;

/**
* Determines the type and array element count at the given address.
* For nested types with classes/structs, the containing type is resolved recursively, until an exact with the address
* is found.
* See typeart_get_type_length and typeart_get_type_id for resolving only one such parameter
*
* Note that this function will always return the outermost type lining up with the address.
* Given a pointer to the start of a struct, the returned type will therefore be that of the struct, not of the first
* member.
* base_type_info is the outermost type and array element count at the given address.
*
* Code example:
* {
Expand All @@ -68,20 +77,15 @@ typedef struct typeart_struct_layout_t { // NOLINT
* }
*
* \param[in] addr The address.
* \param[out] type_id Type ID
* \param[out] count Allocation size
* \param[out] base_type allocation info at the address addr. The address equals [in] param addr.
*
* \return A status code:
* - TYPEART_OK: The query was successful and the contents of type and count are valid.
* - TYPEART_UNKNOWN_ADDRESS: The given address is either not allocated, or was not correctly recorded by the runtime.
* - TYPEART_BAD_ALIGNMENT: The given address does not line up with the start of the atomic type at that location.
* - TYPEART_INVALID_ID: Encountered unregistered ID during lookup.
*/
typeart_status typeart_get_type(const void* addr, int* type_id, size_t* count);

typeart_status typeart_get_type_length(const void* addr, size_t* count);

typeart_status typeart_get_type_id(const void* addr, int* type_id);
typeart_status typeart_get_type(const void* addr, typeart_type_info* type_info);

/**
* Determines the outermost type and array element count at the given address.
Expand Down Expand Up @@ -117,17 +121,18 @@ typeart_status typeart_get_type_id(const void* addr, int* type_id);
* to &data[0])
* }
*
* \param[in] addr The address.
* \param[out] type_id Type ID of the containing type
* \param[out] count Number of elements in the containing buffer, not counting elements before the given address.
* \param[out] base_address Address of the containing buffer.
* \param[in] type The result of a `typeart_get_type` call on some address.
* \param[out] containing_type Type information of the containing type.
* \param[out] byte_offset The byte offset within that buffer element.
*
* \return A status code.
* - TYPEART_OK: The query was successful.
* - TYPEART_UNKNOWN_ADDRESS: The given address is either not allocated, or was not correctly recorded by the runtime.
*/
typeart_status typeart_get_containing_type(const void* addr, int* type_id, size_t* count, const void** base_address,
// typeart_status typeart_get_containing_type(const void* addr, int* type_id, size_t* count, const void** base_address,
// size_t* byte_offset);

typeart_status typeart_get_containing_type(typeart_type_info type_info, typeart_base_type_info* containing_type,
size_t* byte_offset);

/**
Expand Down Expand Up @@ -156,24 +161,20 @@ typeart_status typeart_get_containing_type(const void* addr, int* type_id, size_
* -> subtype_count: 1 (length of member float[2] at offset 20)
* }
*
* \param[in] container_layout typeart_struct_layout corresponding to the containing type
* \param[in] baseAddr Pointer to the start of the containing type.
* \param[in] offset Byte offset within the containing type.
* \param[in] container_layout typeart_struct_layout corresponding to the containing type
* \param[out] subtype_id The type ID corresponding to the subtype.
* \param[out] subtype_base_addr Pointer to the start of the subtype.
* \param[out] subtype_info The type container to the subtype.
* \param[out] subtype_byte_offset Byte offset within the subtype.
* \param[out] subtype_count Number of elements in subarray.
*
* \return One of the following status codes:
* - TYPEART_OK: Success.
* - TYPEART_BAD_ALIGNMENT: Address corresponds to location inside an atomic type or padding.
* - TYPEART_BAD_OFFSET: The provided offset is invalid.
* - TYPEART_ERROR: The typeart_struct_layout is invalid.
*/
typeart_status typeart_get_subtype(const void* base_addr, size_t offset, const typeart_struct_layout* container_layout,
int* subtype_id, const void** subtype_base_addr, size_t* subtype_byte_offset,
size_t* subtype_count);

typeart_status typeart_get_subtype(const typeart_struct_layout* container_layout, const void* base_addr, size_t offset,
typeart_base_type_info* subtype_info, size_t* subtype_byte_offset);
/**
* Returns the stored debug address generated by __builtin_return_address(0).
*
Expand Down Expand Up @@ -204,22 +205,6 @@ typeart_status typeart_get_return_address(const void* addr, const void** return_
*/
typeart_status typeart_get_source_location(const void* addr, char** file, char** function, char** line);

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

/**
* Given a type ID, this function provides information about the corresponding struct type.
*
Expand Down
77 changes: 35 additions & 42 deletions lib/runtime/TypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,23 @@ inline typeart_status query_type(const void* addr, int* type, size_t* count) {
return TYPEART_UNKNOWN_ADDRESS;
}

inline typeart_status query_type(const void* addr, typeart_type_info& info) {
auto alloc = typeart::RuntimeSystem::get().allocTracker.findBaseAlloc(addr);
typeart::RuntimeSystem::get().recorder.incUsedInRequest(addr);
if (alloc) {
typeart_base_type_info base;
base.address = alloc->first;
base.type_id = alloc->second.typeId;
base.count = alloc->second.count;
info.base_type_info = base;
info.address = addr;
const auto result = typeart::RuntimeSystem::get().typeResolution.getTypeInfo(addr, alloc->first, alloc->second,
&info.type_id, &info.count);
return result;
}
return TYPEART_UNKNOWN_ADDRESS;
}

inline typeart_status query_struct_layout(int type_id, typeart_struct_layout* struct_layout) {
const typeart::StructTypeInfo* struct_info;
typeart_status status = typeart::RuntimeSystem::get().typeResolution.getStructInfo(type_id, &struct_info);
Expand All @@ -295,9 +312,9 @@ inline typeart_status query_struct_layout(int type_id, typeart_struct_layout* st
struct_layout->name = struct_info->name.c_str();
struct_layout->num_members = struct_info->num_members;
struct_layout->extent = struct_info->extent;
struct_layout->offsets = &struct_info->offsets[0];
struct_layout->member_types = &struct_info->member_types[0];
struct_layout->count = &struct_info->array_sizes[0];
struct_layout->offsets = (struct_info->offsets).data();
struct_layout->member_types = (struct_info->member_types).data();
struct_layout->count = (struct_info->array_sizes).data();
} else {
struct_layout->type_id = std::numeric_limits<decltype(typeart_struct_layout::type_id)>::min();
struct_layout->name = "";
Expand Down Expand Up @@ -334,57 +351,33 @@ char* string2char(std::string_view src) {
*
*/

typeart_status typeart_get_type(const void* addr, int* type_id, size_t* count) {
typeart::RTGuard guard;
return typeart::detail::query_type(addr, type_id, count);
}

typeart_status typeart_get_type_length(const void* addr, size_t* count) {
typeart::RTGuard guard;
int type{0};
return typeart::detail::query_type(addr, &type, count);
}

typeart_status typeart_get_type_id(const void* addr, int* type_id) {
typeart_status typeart_get_type(const void* addr, typeart_type_info* base_type) {
typeart::RTGuard guard;
size_t count{0};
return typeart::detail::query_type(addr, type_id, &count);
return typeart::detail::query_type(addr, *base_type);
}

typeart_status typeart_get_containing_type(const void* addr, int* type_id, size_t* count, const void** base_address,
typeart_status typeart_get_containing_type(typeart_type_info type, typeart_base_type_info* containing_type,
size_t* byte_offset) {
typeart::RTGuard guard;
auto alloc = typeart::RuntimeSystem::get().allocTracker.findBaseAlloc(addr);
if (alloc) {
// auto& allocVal = alloc.value();
*type_id = alloc->second.typeId;
*base_address = alloc->first;
return typeart::RuntimeSystem::get().typeResolution.getContainingTypeInfo(addr, alloc->first, alloc->second, count,
byte_offset);
}
return TYPEART_UNKNOWN_ADDRESS;
containing_type->type_id = type.base_type_info.type_id;
containing_type->count = type.base_type_info.count;
containing_type->address = type.base_type_info.address;
const typeart::PointerInfo info{type.base_type_info.type_id, type.base_type_info.count};
const auto result = typeart::RuntimeSystem::get().typeResolution.getContainingTypeInfo(
type.address, containing_type->address, info, &containing_type->count, byte_offset);

return result;
}

typeart_status typeart_get_subtype(const void* base_addr, size_t offset, const typeart_struct_layout* container_layout,
int* subtype_id, const void** subtype_base_addr, size_t* subtype_byte_offset,
size_t* subtype_count) {
typeart_status typeart_get_subtype(const typeart_struct_layout* container_layout, const void* base_addr, size_t offset,
typeart_base_type_info* subtype_info, size_t* subtype_byte_offset) {
typeart::RTGuard guard;
auto status = typeart::RuntimeSystem::get().typeResolution.getSubTypeInfo(
base_addr, offset, *container_layout, subtype_id, subtype_base_addr, subtype_byte_offset, subtype_count);
base_addr, offset, *container_layout, &subtype_info->type_id, &subtype_info->address, subtype_byte_offset,
&subtype_info->count);
return status;
}

typeart_status typeart_resolve_type_addr(const void* addr, typeart_struct_layout* struct_layout) {
typeart::RTGuard guard;
int type_id{0};
size_t size{0};
auto status = typeart::detail::query_type(addr, &type_id, &size);
if (status != TYPEART_OK) {
return status;
}
return typeart::detail::query_struct_layout(type_id, struct_layout);
}

typeart_status typeart_resolve_type_id(int type_id, typeart_struct_layout* struct_layout) {
typeart::RTGuard guard;
return typeart::detail::query_struct_layout(type_id, struct_layout);
Expand Down
8 changes: 4 additions & 4 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ function(typeart_configure_script input output)
set(TYPEART_PASS_DIR ${LIBRARY_OUTPUT_PATH})
set(TYPEART_ANALYSIS_PASS_DIR ${LIBRARY_OUTPUT_PATH})
else()
set(TYPEART_MPI_INTERCEPT_DIR ${CMAKE_BINARY_DIR}/lib/mpi_interceptor)
set(TYPEART_RT_DIR ${CMAKE_BINARY_DIR}/lib/runtime)
set(TYPEART_PASS_DIR ${CMAKE_BINARY_DIR}/lib/passes)
set(TYPEART_MPI_INTERCEPT_DIR ${CMAKE_CURRENT_BINARY_DIR}/../lib/mpi_interceptor)
set(TYPEART_RT_DIR ${CMAKE_CURRENT_BINARY_DIR}/../lib/runtime)
set(TYPEART_PASS_DIR ${CMAKE_CURRENT_BINARY_DIR}/../lib/passes)
set(TYPEART_ANALYSIS_PASS_DIR ${TYPEART_PASS_DIR}/analysis)
endif()

if(EXECUTABLE_OUTPUT_PATH)
set(TYPEART_BINARY_DIR ${EXECUTABLE_OUTPUT_PATH})
else()
set(TYPEART_BINARY_DIR ${CMAKE_BINARY_DIR})
set(TYPEART_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/..)
endif()

set(TYPEART_RELOCATABLE 0)
Expand Down
4 changes: 3 additions & 1 deletion scripts/typeart-tmpl.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ function toolchain_init() {
}

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

Expand Down
6 changes: 3 additions & 3 deletions test/runtime/10_vector_fill_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ void free_vector(vector v) {
}

int fill_vector(void* values, int count, vector* v) {
int type;
typeart_status result = typeart_get_type_id(values, &type);
if (result == TYPEART_OK && type == TYPEART_FLOAT_64) {
typeart_type_info info;
typeart_status result = typeart_get_type(values, &info);
if (result == TYPEART_OK && info.type_id == TYPEART_FLOAT_64) {
memcpy(v->vals, values, count);
v->size = count;
fprintf(stderr, "Success\n");
Expand Down
8 changes: 5 additions & 3 deletions test/runtime/29_threads_concurrent_rwx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// clang-format on

#include "../../lib/runtime/CallbackInterface.h"
#include "RuntimeInterface.h"
#include "TypeInterface.h"
#include "util.h"

Expand Down Expand Up @@ -38,10 +39,11 @@ template <typename S, typename E>
void repeat_type_check(S s, E e) {
do {
std::for_each(s, e, [&](auto addr) {
int id_result{-1};
size_t count_check{0};
typeart_status status = typeart_get_type(reinterpret_cast<const void*>(addr), &id_result, &count_check);
typeart_type_info info;
typeart_status status = typeart_get_type(reinterpret_cast<const void*>(addr), &info);
if (status == TYPEART_OK) {
int id_result{info.type_id};
size_t count_check{info.count};
if (count_check != extent) {
fprintf(stderr, "[Error]: Length mismatch of %i (%#02x) is: type=%i count=%zu\n", addr, addr, id_result,
count_check);
Expand Down
Loading