From cdc2caaa42fc46e01c8c42b71cb778521037a57e Mon Sep 17 00:00:00 2001 From: Philipp Grulich Date: Fri, 14 Jun 2024 23:57:07 -0400 Subject: [PATCH] update readme --- .github/workflows/sanitizer.yml | 42 +++++ nautilus/include/nautilus/val.hpp | 146 ++++++------------ .../backends/bc/BCLoweringProvider.cpp | 2 +- .../backends/mlir/MLIRLoweringProvider.cpp | 10 +- 4 files changed, 97 insertions(+), 103 deletions(-) create mode 100644 .github/workflows/sanitizer.yml diff --git a/.github/workflows/sanitizer.yml b/.github/workflows/sanitizer.yml new file mode 100644 index 00000000..123f9a15 --- /dev/null +++ b/.github/workflows/sanitizer.yml @@ -0,0 +1,42 @@ +name: Sanitizer Nautilus +run-name: ${{ github.actor }} builds Nautilus +on: [ push ] +jobs: + build-test: + runs-on: ${{matrix.os}} + name: Build on ${{ matrix.os }} with ${{ matrix.cc }} ${{ matrix.flags }} + strategy: + fail-fast: false + matrix: + include: + - os: 'ubuntu-24.04' + cc: 'clang-18' + cxx: 'clang++-18' + flags: '-DENABLE_ADDRESS_SANITIZER=ON' + env: + CC: ${{ matrix.cc }} + CXX: ${{ matrix.cxx }} + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - name: get cmake + uses: lukka/get-cmake@latest + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2.13 + with: + key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.cc }} + - name: cmake + shell: bash + run: | + cmake -DCMAKE_BUILD_TYPE=Release -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache ${{ matrix.flags }} -G Ninja -S . -B . + - name: build + shell: bash + run: | + cmake --build . --target all + - name: test + shell: bash + run: | + cd nautilus && ctest --test-dir=nautilus --output-on-failure + + diff --git a/nautilus/include/nautilus/val.hpp b/nautilus/include/nautilus/val.hpp index 9a4db48b..b735a520 100644 --- a/nautilus/include/nautilus/val.hpp +++ b/nautilus/include/nautilus/val.hpp @@ -86,49 +86,43 @@ tracing::value_ref getState(T&& value) { } // namespace details +template +class base_val { +public: +#ifdef ENABLE_TRACING + const tracing::value_ref state; + base_val() : state(tracing::traceConstant(0)) {}; + base_val(ValueType value) : state(tracing::traceConstant(value)), value(value) {}; + base_val(tracing::value_ref& tc) : state(tc), value() {}; + base_val(const base_val& other) : state(tracing::traceCopy(other.state)), value(other.value) {}; + base_val(const base_val&& other) noexcept : state(other.state), value(other.value) {}; +#else + base_val() {}; + base_val(ValueType value) : value(value) {}; +#endif +protected: + template + friend T details::getRawValue(val& val); + ValueType value; +}; + // val substitution for all arithmetic value type, integer, float, bool template -class val { +class val : public base_val { public: using raw_type = ValueType; using basic_type = ValueType; + using base_val::base_val; -#ifdef ENABLE_TRACING - const tracing::value_ref state; - inline val() : state(tracing::traceConstant(0)) {}; - inline val(ValueType value) : state(tracing::traceConstant(value)), value(value) {}; // copy constructor - inline val(const val& other) : state(tracing::traceCopy(other.state)), value(other.value) {}; + inline val(const val& other) : base_val(other) {}; // move constructor - inline val(const val&& other) noexcept : state(other.state), value(other.value) {}; - inline val(tracing::value_ref& tc) : state(tc), value() {}; -#else - val() {}; - val(ValueType value) : value(value) {}; - // copy constructor - val(const val& other) : value(other.value) {}; - // move constructor - val(const val&& other) : value(other.value) {}; -#endif - - ~val() { - -#ifdef ENABLE_TRACING - if (tracing::inTracer()) { - - // tracing::getVarRefMap()[state.ref]--; - // if (tracing::getVarRefMap()[state.ref] == 0) { - // tracing::traceValueDestruction(state); - // std::cout << "destructor " << state << " - " << tag << std::endl; - // } - } -#endif - } + inline val(const val&& other) noexcept : base_val(std::move(other)) {}; val& operator=(const val& other) { #ifdef ENABLE_TRACING if (tracing::inTracer()) { - tracing::traceAssignment(state, other.state, tracing::to_type()); + tracing::traceAssignment(this->state, other.state, tracing::to_type()); } #endif this->value = other.value; @@ -141,11 +135,11 @@ class val { // cast if SHOULD_TRACE () { #ifdef ENABLE_TRACING - auto resultRef = tracing::traceCast(state, tracing::to_type()); + auto resultRef = tracing::traceCast(this->state, tracing::to_type()); return val(resultRef); #endif } - return val(value); + return val(this->value); } const val& operator++() { @@ -186,9 +180,6 @@ class val { } private: - friend ValueType details::getRawValue(val& left); - ValueType value; - template friend COMMON_RETURN_TYPE mul(val& left, val& right); @@ -245,65 +236,41 @@ class val { }; template <> -class val { +class val : public base_val { public: using raw_type = bool; using basic_type = bool; - -#ifdef ENABLE_TRACING - - tracing::value_ref state; - val() : state(tracing::traceConstant(0)), value(false) {}; - val(bool value) : state(tracing::traceConstant(value)), value(value) {}; - // copy constructor - val(const val& other) : state(tracing::traceCopy(other.state)), value(other.value) {}; - // move constructor - val(const val&& other) noexcept : state(other.state), value(other.value) {}; - val(tracing::value_ref& tc) : state(tc) {}; - -#else - val() {}; - val(bool value) : value(value) {}; + using base_val::base_val; // copy constructor - val(const val& other) : value(other.value) {}; + inline val(const val& other) : base_val(other) {}; // move constructor - val(const val&& other) : value(other.value) {}; -#endif - - ~val() { - if SHOULD_TRACE () { - - // tracing::getVarRefMap()[state.ref]--; - // if (tracing::getVarRefMap()[state.ref] == 0) { - // tracing::traceValueDestruction(state); - // std::cout << "destructor " << state << " - " << tag << std::endl; - // } - } - } + inline val(const val&& other) noexcept : base_val(std::move(other)) {}; val& operator=(const val& other) { - - if SHOULD_TRACE () { #ifdef ENABLE_TRACING - tracing::traceAssignment(state, other.state, tracing::to_type()); -#endif + if (tracing::inTracer()) { + tracing::traceAssignment( this->state, other.state, tracing::to_type()); } +#endif this->value = other.value; return *this; }; - operator bool() const { - if SHOULD_TRACE () { #ifdef ENABLE_TRACING - auto ref = state; + operator bool() const { + if (tracing::inTracer()) { + auto ref = this->state; return tracing::traceBool(ref); -#endif } - return value; + return this->value; + } +#else + operator bool() const { + return this->value; } +#endif - bool value; }; template @@ -356,22 +323,6 @@ auto&& cast_value(LeftType&& value) { namespace details { -#ifdef ENABLE_TRACING -#define TRAC_BINARY_OP(OP) \ - if (tracing::inTracer()) { \ - auto tc = tracing::traceBinaryOp(lValue.state, rValue.state); \ - return val(tc); \ - } - -#define TRAC_BINARY_OP_DIRECT(OP) \ - if (tracing::inTracer()) { \ - auto tc = tracing::traceBinaryOp(left.state, right.state); \ - return val(tc); \ - } -#else -#define TRAC_OP(OP) -#endif - #ifdef ENABLE_TRACING #define TRAC_LOGICAL_BINARY_OP(OP) \ if (tracing::inTracer()) { \ @@ -389,7 +340,8 @@ namespace details { auto&& lValue = cast_value(std::forward(left)); \ auto&& rValue = cast_value(std::forward(right)); \ if SHOULD_TRACE () { \ - auto tc = tracing::traceBinaryOp(details::getState(lValue), details::getState(rValue)); \ + auto tc = tracing::traceBinaryOp(details::getState(lValue), \ + details::getState(rValue)); \ return RES_TYPE(tc); \ } \ return RES_TYPE(getRawValue(lValue) OP getRawValue(rValue)); \ @@ -437,7 +389,7 @@ val inline neg(val& val) { } template -LHS inline getRawValue(val& val) { +LHS getRawValue(val& val) { return val.value; } @@ -567,7 +519,7 @@ val inline lOr(val& left, val& right) { return val {tc}; } #endif - return left.value || right.value; + return getRawValue(left) || getRawValue(right); } val inline lAnd(val& left, val& right) { @@ -577,7 +529,7 @@ val inline lAnd(val& left, val& right) { return val {tc}; } #endif - return left.value && right.value; + return getRawValue(left) && getRawValue(right); } val inline lNot(val& arg) { @@ -587,7 +539,7 @@ val inline lNot(val& arg) { return val {tc}; } #endif - return !arg.value; + return !getRawValue(arg); } } // namespace details diff --git a/nautilus/src/nautilus/compiler/backends/bc/BCLoweringProvider.cpp b/nautilus/src/nautilus/compiler/backends/bc/BCLoweringProvider.cpp index 2eb59098..d7f145c9 100644 --- a/nautilus/src/nautilus/compiler/backends/bc/BCLoweringProvider.cpp +++ b/nautilus/src/nautilus/compiler/backends/bc/BCLoweringProvider.cpp @@ -773,7 +773,7 @@ void BCLoweringProvider::LoweringContext::process(const std::unique_ptr(opt); auto defaultRegister = registerProvider.allocRegister(); - defaultRegisterFile[defaultRegister] = (int64_t)constPtr->getValue(); + defaultRegisterFile[defaultRegister] = (int64_t) constPtr->getValue(); auto targetRegister = registerProvider.allocRegister(); frame.setValue(constPtr->getIdentifier(), targetRegister); diff --git a/nautilus/src/nautilus/compiler/backends/mlir/MLIRLoweringProvider.cpp b/nautilus/src/nautilus/compiler/backends/mlir/MLIRLoweringProvider.cpp index e339260a..c0aff3d0 100644 --- a/nautilus/src/nautilus/compiler/backends/mlir/MLIRLoweringProvider.cpp +++ b/nautilus/src/nautilus/compiler/backends/mlir/MLIRLoweringProvider.cpp @@ -405,12 +405,12 @@ void MLIRLoweringProvider::generateMLIR(ir::ConstIntOperation* constIntOp, Value } } -void MLIRLoweringProvider::generateMLIR(ir::ConstPtrOperation* , ValueFrame& ) { - //builder->create(getNameLoc("location"), mlir::LLVM::LLVMPointerType, constPtrOperation->getValue()); - - //frame.setValue(constPtrOperation->getIdentifier(), - // getConstInt("ConstantOp", constIntOp->getStamp(), constIntOp->getValue())); +void MLIRLoweringProvider::generateMLIR(ir::ConstPtrOperation*, ValueFrame&) { + // builder->create(getNameLoc("location"), mlir::LLVM::LLVMPointerType, + // constPtrOperation->getValue()); + // frame.setValue(constPtrOperation->getIdentifier(), + // getConstInt("ConstantOp", constIntOp->getStamp(), constIntOp->getValue())); } void MLIRLoweringProvider::generateMLIR(ir::ConstFloatOperation* constFloatOp, ValueFrame& frame) {