Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrulich committed Mar 23, 2024
1 parent da41db6 commit 96fa858
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 18 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ set(CATCH_ENABLE_REPRODUCIBLE_BUILD OFF CACHE INTERNAL "Turn off tests")


set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Werror -Wunused -Werror=vla -Wnarrowing -pedantic")
set(CMAKE_CXX_FLAGS "-fpermissive -fPIC -g")
set(CMAKE_CXX_FLAGS "-fpermissive -fPIC -g -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -fstandalone-debug -fdebug-default-version=4 -fno-omit-frame-pointer")


include(cmake/macros.cmake)
Expand Down
19 changes: 10 additions & 9 deletions nautilus-api/include/Interface/DataTypes/Val.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ namespace nautilus {
// tracing::traceAssignment(other.state, other.state);
};

/*
val<ValueType>(val<ValueType> &&other) noexcept // move constructor
: value(other.value), loc(other.loc), state(other.state) {
// auto tag = tracing::getTag();
tracing::getVarRefMap()[state]++;
//std::cout << "move constructor " << other.state << " - " << tag << std::endl;
}
}*/

#else

Expand All @@ -173,15 +174,15 @@ namespace nautilus {

#ifdef ENABLE_TRACING

explicit inline val<ValueType>(tracing::value_ref &tc) : state(tc) {
inline val<ValueType>(ValueType, tracing::value_ref &tc) : state(tc) {
// auto tag = tracing::getTag();
tracing::getVarRefMap()[state]++;
// std::cout << "trace constructor " << state << " - " << tag << std::endl;
};
#endif


~val<ValueType>() {
~val() {
// auto tag = tracing::getTag();
tracing::getVarRefMap()[state]--;
if (tracing::getVarRefMap()[state] == 0) {
Expand Down Expand Up @@ -352,7 +353,7 @@ namespace nautilus {
#define TRAC_BINARY_OP(OP) \
if (tracing::inTracer()) {\
auto tc = tracing::traceBinaryOp<tracing::OP, commonType>(lValue.state, rValue.state);\
return val<commonType>((tracing::value_ref)tc);\
return val<commonType>((commonType)0, tc);\
}
#else
#define TRAC_OP(OP)
Expand All @@ -362,7 +363,7 @@ namespace nautilus {
#define TRAC_LOGICAL_BINARY_OP(OP) \
if (tracing::inTracer()) {\
auto tc = tracing::traceBinaryOp<tracing::OP, commonType>(lValue.state, rValue.state);\
return val<bool>(tc);\
return val<bool>(lValue.value, tc);\
}
#else
#define TRAC_LOGICAL_BINARY_OP(OP)
Expand Down Expand Up @@ -461,23 +462,23 @@ namespace nautilus {
val<bool> inline lOr(val<bool> &left, val<bool> &right) {
if (tracing::inTracer()) {
auto tc = tracing::traceBinaryOp<tracing::OR, bool>(left.state, right.state);
return val<bool>{tc};
return val<bool>{true, tc};
}
return left.value || right.value;
}

val<bool> inline lAnd(val<bool> &left, val<bool> &right) {
if (tracing::inTracer()) {
auto tc = tracing::traceBinaryOp<tracing::AND, bool>(left.state, right.state);
return val<bool>{tc};
return val<bool>{true,tc};
}
return left.value && right.value;
}

val<bool> inline lNot(val<bool> &val) {
if (tracing::inTracer()) {
auto tc = tracing::traceUnaryOp<tracing::NOT, bool>(val.state);
return ::nautilus::val<bool>{tc};
return ::nautilus::val<bool>{true,tc};
}
return !val.value;
}
Expand Down Expand Up @@ -881,7 +882,7 @@ template<typename T> requires std::is_integral_v<T>
class sval {
public:

sval<T>(T value) : value(value) {};
sval(T v) : value(v) {};

const auto &operator++() {
nautilus::tracing::getVarRefMap()[54]++;
Expand Down
4 changes: 2 additions & 2 deletions nautilus-api/include/Interface/DataTypes/ValPtr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ namespace nautilus {
auto value = make_value<baseType>(other);
// store value
*ptr = details::getRawValue(value);
};
}

template<class T>
requires std::is_convertible_v<T, baseType>
void operator=(val<T> other) noexcept {
// store value
*ptr = details::getRawValue(other);
};
}

operator val<baseType>() const {
// load
Expand Down
3 changes: 2 additions & 1 deletion nautilus-api/include/engine/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ namespace nautilus::engine {

template<typename Arg>
auto createTraceArgument() {
auto defaultVal = (typename Arg::basic_type) 0;
auto type = tracing::to_type<typename Arg::basic_type>();
auto valueRef = tracing::registerFunctionArgument(type);
return Arg(valueRef);
return Arg(defaultVal,valueRef);
}

template<typename Arg>
Expand Down
5 changes: 3 additions & 2 deletions nautilus-jit/include/Tracing/trace_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ namespace nautilus::tracing {
os << *inputRef << "\t";
} else if (auto blockRef = std::get_if<BlockRef>(&opInput)) {
os << *blockRef << "\t";
} else if (auto anyRef = std::get_if<std::any>(&opInput)) {
//os << anyRef << "\t";
}
//else if (auto anyRef = std::get_if<std::any>(&opInput)) {
//os << anyRef << "\t";
//}
//else if (auto ref = std::get_if<FunctionCallTarget>(&input)) {
// os << ref->mangledName << "\t";
//}
Expand Down
7 changes: 6 additions & 1 deletion nautilus-jit/src/Tracing/tag/tag_recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace nautilus::tracing {
// throw NotImplementedException("No plugin registered that can handle this operation between");
[[maybe_unused]] void* root = __builtin_thread_pointer();
std::vector<TagAddress> addresses;
for (int i = 0; i < MAX_TAG_SIZE; i++) {
for (size_t i = 0; i < MAX_TAG_SIZE; i++) {
auto address = getReturnAddress(i);
[[maybe_unused]] void *addr = __builtin_extract_return_addr (address);
addresses.emplace_back((TagAddress) address);
Expand Down Expand Up @@ -69,6 +69,11 @@ namespace nautilus::tracing {

Tag *TagRecorder::createReferenceTag() {
auto *currentTagNode = &rootTagThreeNode;
#pragma GCC diagnostic ignored "-Wframe-address"
[[maybe_unused]] auto tag1 = __builtin_return_address(0);
[[maybe_unused]] auto tag2 = __builtin_return_address(1);
[[maybe_unused]] auto tag3 = __builtin_return_address(1);

for (size_t i = 0; i <= MAX_TAG_SIZE; i++) {
auto tagAddress = (TagAddress) getReturnAddress(i);
if (tagAddress == startAddress) {
Expand Down
24 changes: 22 additions & 2 deletions nautilus-jit/src/Tracing/tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace nautilus::tracing {

std::array<uint8_t, 256>& getVarRefMap(){
return TraceContext::get()->getVarRefMap();
std::array<uint8_t, 256> &getVarRefMap() {
return TraceContext::get()->getVarRefMap();
}

void traceAssignment(value_ref target, value_ref source) {
Expand Down Expand Up @@ -63,6 +63,8 @@ namespace nautilus::tracing {
return TraceContext::get()->traceUnaryOperation(op, leftState);
}


#if __APPLE__
#define INSTANTIATE_TRACE_FUNC(OP) \
template value_ref traceBinaryOp<OP, int8_t>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, int16_t>(value_ref leftState, value_ref rightState); \
Expand All @@ -76,6 +78,21 @@ template value_ref traceBinaryOp<OP, float>(value_ref leftState, value_ref right
template value_ref traceBinaryOp<OP, double>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, size_t>(value_ref leftState, value_ref rightState); \

#else
#define INSTANTIATE_TRACE_FUNC(OP) \
template value_ref traceBinaryOp<OP, int8_t>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, int16_t>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, int32_t>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, int64_t>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, uint8_t>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, uint16_t>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, uint32_t>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, uint64_t>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, float>(value_ref leftState, value_ref rightState); \
template value_ref traceBinaryOp<OP, double>(value_ref leftState, value_ref rightState);
#endif


#define INSTANTIATE_TRACE_UN_FUNC(OP) \
template value_ref traceUnaryOp<OP, int8_t>(value_ref leftState); \
template value_ref traceUnaryOp<OP, int16_t>(value_ref leftState); \
Expand Down Expand Up @@ -181,10 +198,13 @@ template value_ref traceUnaryOp<OP, double>(value_ref leftState); \
template value_ref traceConstant<uint16_t>(uint16_t value);

template value_ref traceConstant<uint32_t>(uint32_t value);

template value_ref traceConstant<uint64_t>(uint64_t value);

#if __APPLE__
template value_ref traceConstant<size_t>(size_t value);
#endif

template value_ref traceConstant<float>(float value);

template value_ref traceConstant<double>(double value);
Expand Down

0 comments on commit 96fa858

Please sign in to comment.