From 3cda93c34dda65e44044db8e1cd268a035d539d7 Mon Sep 17 00:00:00 2001 From: doe300 Date: Sat, 7 Dec 2019 09:45:49 +0100 Subject: [PATCH] Small improvements and fixes - Fixes bug in ValueRange, fixes https://github.com/doe300/VC4CL/issues/88 - Some small performance improvements - Fixes a few clang-tidy warnings --- .clang-tidy | 4 +++- include/Optional.h | 2 +- include/VC4C.h | 5 ++--- src/CMakeLists.txt | 8 ++++---- src/CompilationError.cpp | 2 +- src/Compiler.cpp | 4 ++-- src/Disassembler.cpp | 2 +- src/Graph.h | 3 +++ src/HalfType.cpp | 14 +++++++------- src/HalfType.h | 17 ++++++++--------- src/Locals.h | 3 +-- src/ProcessUtil.cpp | 6 +++--- src/Profiler.cpp | 9 +++++---- src/ThreadPool.h | 2 +- src/Values.cpp | 10 +++++----- src/analysis/ValueRange.cpp | 2 +- src/intermediate/Helper.cpp | 2 +- src/intermediate/TypeConversions.cpp | 5 +++-- src/intermediate/VectorHelper.cpp | 2 +- src/intermediate/operators.h | 14 +++++++------- src/intrinsics/Operators.cpp | 6 +++--- src/llvm/BitcodeReader.cpp | 6 +++--- src/normalization/LiteralValues.cpp | 2 +- src/optimization/ControlFlow.cpp | 4 ++-- src/optimization/Eliminator.cpp | 14 +++++--------- 25 files changed, 74 insertions(+), 74 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index c5b4b825..f77e7b67 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: '*,-abseil*,-android*,-boost*,-fuchsia*,-google*,-llvm*,-*objc*,-openmp*,-hicpp-braces-around-statements,-readability-braces-around-statements,-misc-unused-parameters,-clang-diagnostic-shadow-field-in-constructor,-modernize-use-auto,-clang-diagnostic-c++98-*,-clang-diagnostic-padded,-cppcoreguidelines-pro-type-reinterpret-cast,-cert-err58-cpp,-hicpp-special-member-functions,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-modernize-use-using,-readability-else-after-return,-clang-analyzer-osx*,-clang-diagnostic-shadow,-clang-diagnostic-missing-braces,-clang-diagnostic-missing-prototypes,-misc-non-private-member-variables-in-classes,-cppcoreguidelines-non-private-member-variables-in-classes,-hicpp-uppercase-literal-suffix,-readability-uppercase-literal-suffix,-modernize-use-transparent-functors,-readability-implicit-bool-conversion,-cppcoreguidelines-pro-bounds-constant-array-index,-readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers,-readability-redundant-member-init,-cppcoreguidelines-pro-type-union-access,-hicpp-no-array-decay,-readability-named-parameter,-misc-unconventional-assign-operator,-modernize-use-default-member-init' +Checks: '*,-abseil*,-android*,-boost*,-fuchsia*,-google*,-llvm*,-*objc*,-openmp*,-hicpp-braces-around-statements,-readability-braces-around-statements,-misc-unused-parameters,-clang-diagnostic-shadow-field-in-constructor,-modernize-use-auto,-clang-diagnostic-c++98-*,-clang-diagnostic-padded,-cppcoreguidelines-pro-type-reinterpret-cast,-cert-err58-cpp,-hicpp-special-member-functions,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-modernize-use-using,-readability-else-after-return,-clang-analyzer-osx*,-clang-diagnostic-shadow,-clang-diagnostic-missing-braces,-clang-diagnostic-missing-prototypes,-misc-non-private-member-variables-in-classes,-cppcoreguidelines-non-private-member-variables-in-classes,-hicpp-uppercase-literal-suffix,-readability-uppercase-literal-suffix,-modernize-use-transparent-functors,-readability-implicit-bool-conversion,-cppcoreguidelines-pro-bounds-constant-array-index,-readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers,-readability-redundant-member-init,-cppcoreguidelines-pro-type-union-access,-hicpp-no-array-decay,-readability-named-parameter,-misc-unconventional-assign-operator,-cppcoreguidelines-c-copy-assignment-signature,-modernize-use-default-member-init,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-modernize-return-braced-init-list,-hicpp-use-auto,-bugprone-forward-declaration-namespace,-cppcoreguidelines-owning-memory' WarningsAsErrors: '' HeaderFilterRegex: '.*' AnalyzeTemporaryDtors: true @@ -137,6 +137,8 @@ CheckOptions: value: '' - key: modernize-use-noexcept.UseNoexceptFalse value: '1' + - key: modernize-use-override.AllowOverrideAndFinal + value: '1' - key: modernize-use-nullptr.NullMacros value: 'NULL' - key: modernize-use-transparent-functors.SafeMode diff --git a/include/Optional.h b/include/Optional.h index 4a447aba..b1148e53 100644 --- a/include/Optional.h +++ b/include/Optional.h @@ -225,7 +225,7 @@ namespace vc4c constexpr Optional(const T& value) : Base(value) {} constexpr Optional(T&& value) : Base(std::forward(value)) {} constexpr Optional(const Optional& other) : Base(other) {} - constexpr Optional(Optional&& other) : Base(std::forward(other)) {} + constexpr Optional(Optional&& other) noexcept : Base(std::forward(other)) {} ~Optional() noexcept = default; Optional& operator=(const Optional&) = default; diff --git a/include/VC4C.h b/include/VC4C.h index 674b8bcd..0bfe012c 100644 --- a/include/VC4C.h +++ b/include/VC4C.h @@ -21,13 +21,12 @@ namespace vc4c /* * Disassembles the given machine-code module and writes the converted code into output */ - std::size_t disassembleModule( - std::istream& binary, std::ostream& output, const OutputMode outputMode = OutputMode::HEX); + std::size_t disassembleModule(std::istream& binary, std::ostream& output, OutputMode outputMode = OutputMode::HEX); /* * Disassembles the given machine code (containing only instructions) and writes the converted code into output */ std::size_t disassembleCodeOnly(std::istream& binary, std::ostream& output, std::size_t numInstructions, - const OutputMode outputMode = OutputMode::HEX); + OutputMode outputMode = OutputMode::HEX); } /* namespace vc4c */ #endif /* VC4C_H */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f32dcb8..6c3e1ef4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -90,8 +90,8 @@ endif(MULTI_THREADED) if(VC4C_ENABLE_SPIRV_FRONTEND) add_dependencies(${VC4C_LIBRARY_NAME} SPIRV-Dependencies) target_link_libraries(${VC4C_LIBRARY_NAME} ${SPIRV_Tools_LIBS}) - target_include_directories(${VC4C_LIBRARY_NAME} PRIVATE ${SPIRV_Headers_HEADERS}) - target_include_directories(${VC4C_LIBRARY_NAME} PRIVATE ${SPIRV_Tools_HEADERS}) + target_include_directories(${VC4C_LIBRARY_NAME} SYSTEM PRIVATE ${SPIRV_Headers_HEADERS}) + target_include_directories(${VC4C_LIBRARY_NAME} SYSTEM PRIVATE ${SPIRV_Tools_HEADERS}) target_compile_definitions(${VC4C_LIBRARY_NAME} PRIVATE SPIRV_LLVM_SPIRV_PATH="${SPIRV_LLVM_SPIR_FOUND}" SPIRV_FRONTEND=1) target_compile_definitions(${VC4C_PROGRAM_NAME} PRIVATE SPIRV_LLVM_SPIRV_PATH="${SPIRV_LLVM_SPIR_FOUND}" SPIRV_FRONTEND=1) @@ -130,8 +130,8 @@ endif() # Download mpark/variant library as dependency add_dependencies(${VC4C_LIBRARY_NAME} variant-dependencies) -target_include_directories(${VC4C_LIBRARY_NAME} PRIVATE ${variant_HEADERS}) -target_include_directories(${VC4C_PROGRAM_NAME} PRIVATE ${variant_HEADERS}) +target_include_directories(${VC4C_LIBRARY_NAME} SYSTEM PRIVATE ${variant_HEADERS}) +target_include_directories(${VC4C_PROGRAM_NAME} SYSTEM PRIVATE ${variant_HEADERS}) if(VC4CL_STDLIB_DIR) # Pre-compile VC4CL standard library files if development headers available and output files do not yet exist diff --git a/src/CompilationError.cpp b/src/CompilationError.cpp index f4a559a1..3f1f4c99 100644 --- a/src/CompilationError.cpp +++ b/src/CompilationError.cpp @@ -124,7 +124,7 @@ static void demangleAndPrint(char* line, int i) void CompilationError::logBacktrace() { #if defined(DEBUG_MODE) and defined(__GNUC__) - std::array funcPointers; + std::array funcPointers{}; int numFuncs = backtrace(funcPointers.data(), funcPointers.size()); char** strings = backtrace_symbols(funcPointers.data(), numFuncs); diff --git a/src/Compiler.cpp b/src/Compiler.cpp index a56a84be..33fce094 100644 --- a/src/Compiler.cpp +++ b/src/Compiler.cpp @@ -178,7 +178,7 @@ std::unique_ptr logging::LOGGER(new logging::ColoredLogger(std: void vc4c::setLogger(std::wostream& outputStream, const bool coloredOutput, const LogLevel level) { if(coloredOutput) - logging::LOGGER.reset(new logging::ColoredLogger(outputStream, static_cast(level))); + logging::LOGGER = std::make_unique(outputStream, static_cast(level)); else - logging::LOGGER.reset(new logging::StreamLogger(outputStream, static_cast(level))); + logging::LOGGER = std::make_unique(outputStream, static_cast(level)); } diff --git a/src/Disassembler.cpp b/src/Disassembler.cpp index 427ca3aa..8cdb0820 100644 --- a/src/Disassembler.cpp +++ b/src/Disassembler.cpp @@ -217,7 +217,7 @@ LCOV_EXCL_STOP static std::string readString(std::istream& binary, uint64_t stringLength) { - std::array buffer; + std::array buffer = {0}; binary.read(buffer.data(), static_cast(stringLength)); const std::string name(buffer.data(), stringLength); diff --git a/src/Graph.h b/src/Graph.h index 8926f8e3..b09f3367 100644 --- a/src/Graph.h +++ b/src/Graph.h @@ -64,6 +64,7 @@ namespace vc4c Node(const Node&) = delete; Node(Node&&) noexcept = delete; + ~Node() noexcept = default; Node& operator=(const Node&) = delete; Node& operator=(Node&&) noexcept = delete; @@ -467,6 +468,7 @@ namespace vc4c Edge(const Edge&) = delete; Edge(Edge&&) noexcept = delete; + ~Edge() noexcept = default; Edge& operator=(const Edge&) = delete; Edge& operator=(Edge&&) noexcept = delete; @@ -596,6 +598,7 @@ namespace vc4c } Graph(const Graph&) = delete; Graph(Graph&&) noexcept = delete; + ~Graph() noexcept = default; Graph& operator=(const Graph&) = delete; Graph& operator=(Graph&&) noexcept = delete; diff --git a/src/HalfType.cpp b/src/HalfType.cpp index 43cbfa37..3e888a4c 100644 --- a/src/HalfType.cpp +++ b/src/HalfType.cpp @@ -9,7 +9,7 @@ static uint16_t extractHalfExponent(float f) { if(f == 0.0f || f == -0.0f) return 0; - auto exp = (bit_cast(f) & 0x7F800000) >> 23; + auto exp = (bit_cast(f) & 0x7F800000u) >> 23u; if(exp == 0) // subnormal value -> flush to zero return 0; @@ -18,21 +18,21 @@ static uint16_t extractHalfExponent(float f) return 0x1F; return std::min(static_cast(exp - 127 /* floating-point exponent bias*/ + 15 /* half exponent bias */), - static_cast(0x1F)); + uint16_t{0x1F}); } static uint16_t extractHalfMantissa(float f) { - auto exp = ((bit_cast(f) & 0x7F800000) >> 23) - 127 + 15; + auto exp = ((bit_cast(f) & 0x7F800000u) >> 23u) - 127 + 15; if(exp >= 0x1F) // will be converted to +-Inf -> mantissa of zero return 0; // TODO wrong for subnormals, will convert x * 2^-127 to x*2^-15 - return static_cast((bit_cast(f) & 0x007FFFFF) >> 13); + return static_cast((bit_cast(f) & 0x007FFFFFu) >> 13u); } Binary16::Binary16(float val) : - sign(static_cast(bit_cast(val) >> 31)), exponent(extractHalfExponent(val)), + sign(static_cast(bit_cast(val) >> 31u)), exponent(extractHalfExponent(val)), fraction(extractHalfMantissa(val)) { } @@ -45,8 +45,8 @@ Binary16::operator float() const return sign ? -std::numeric_limits::infinity() : std::numeric_limits::infinity(); if(isNaN()) return std::numeric_limits::quiet_NaN(); - uint32_t tmp = (static_cast(sign) << 31) | ((static_cast(exponent) + (127 - 15)) << 23) | - (static_cast(fraction) << 13); + uint32_t tmp = (static_cast(sign) << 31u) | ((static_cast(exponent) + (127 - 15)) << 23u) | + (static_cast(fraction) << 13u); // TODO rewrite (value-mapping instead of bit-wise?) and make constexpr, // also constructor return bit_cast(tmp); diff --git a/src/HalfType.h b/src/HalfType.h index 4fc2e31b..c209caef 100644 --- a/src/HalfType.h +++ b/src/HalfType.h @@ -25,8 +25,8 @@ namespace vc4c uint16_t fraction : 10; constexpr explicit Binary16(uint16_t val = 0) : - sign(static_cast(val >> 15)), exponent(static_cast((val & 0x7C00) >> 10)), - fraction(static_cast(val & 0x3FF)) + sign(static_cast(val >> 15u)), exponent(static_cast((val & 0x7C00u) >> 10u)), + fraction(static_cast(val & 0x3FFu)) { } @@ -41,7 +41,7 @@ namespace vc4c inline constexpr operator uint16_t() const { - return static_cast((sign << 15) | (exponent << 10) | (fraction)); + return static_cast((sign << 15u) | (exponent << 10u) | (fraction)); } inline constexpr bool isZero() const @@ -70,12 +70,11 @@ namespace vc4c constexpr Binary16 HALF_INF(0, 0x1F, 0); static_assert(sizeof(Binary16) == 2, "Binary16 type has wrong size!"); - static_assert(static_cast(Binary16(static_cast(0x1234))) == static_cast(0x1234), - "Bit conversion failed!"); - static_assert((Binary16(static_cast(0))).isZero(), "Bitwise check failed!"); - static_assert((Binary16(static_cast(0x123))).isSubnormal(), "Bitwise check failed!"); - static_assert((Binary16(static_cast(0x7C00))).isInf(), "Bitwise check failed!"); - static_assert((Binary16(static_cast(0xFFFF))).isNaN(), "Bitwise check failed!"); + static_assert(static_cast(Binary16(uint16_t{0x1234})) == uint16_t{0x1234}, "Bit conversion failed!"); + static_assert((Binary16(uint16_t{0})).isZero(), "Bitwise check failed!"); + static_assert((Binary16(uint16_t{0x123})).isSubnormal(), "Bitwise check failed!"); + static_assert((Binary16(uint16_t{0x7C00})).isInf(), "Bitwise check failed!"); + static_assert((Binary16(uint16_t{0xFFFF})).isNaN(), "Bitwise check failed!"); inline Binary16 operator""_h(long double val) { diff --git a/src/Locals.h b/src/Locals.h index a273fb4f..93256c47 100644 --- a/src/Locals.h +++ b/src/Locals.h @@ -189,8 +189,7 @@ namespace vc4c struct RAIILock { using UnlockFunc = std::function; - explicit RAIILock() : func(nullptr) {} - RAIILock(UnlockFunc&& f) : func(std::move(f)) {} + explicit RAIILock(UnlockFunc&& f = nullptr) : func(std::move(f)) {} RAIILock(const RAIILock&) = delete; RAIILock(RAIILock&& other) noexcept : func(std::move(other.func)) { diff --git a/src/ProcessUtil.cpp b/src/ProcessUtil.cpp index ece72478..f3384006 100644 --- a/src/ProcessUtil.cpp +++ b/src/ProcessUtil.cpp @@ -139,7 +139,7 @@ static int runReadOnlySubprocess(const std::string& command, std::ostream* outpu std::size_t numRead = 0; while((numRead = fread(buffer.data(), sizeof(char), buffer.size(), fd)) > 0) { - output->write(buffer.data(), numRead); + output->write(buffer.data(), static_cast(numRead)); } if(ferror(fd)) { @@ -161,7 +161,7 @@ static int runWriteOnlySubprocess(const std::string& command, std::istream* inpu std::array buffer; while(input->read(buffer.data(), buffer.size())) { - fwrite(buffer.data(), sizeof(char), input->gcount(), fd); + fwrite(buffer.data(), sizeof(char), static_cast(input->gcount()), fd); } if(ferror(fd)) { @@ -247,7 +247,7 @@ int vc4c::runProcess(const std::string& command, std::istream* stdin, std::ostre { in.read(buffer.data(), buffer.size()); numBytes = in.gcount(); - write(pipes[STD_IN][WRITE], buffer.data(), in.gcount()); + write(pipes[STD_IN][WRITE], buffer.data(), static_cast(in.gcount())); if(numBytes != buffer.size()) break; } diff --git a/src/Profiler.cpp b/src/Profiler.cpp index 32f59041..418857b9 100644 --- a/src/Profiler.cpp +++ b/src/Profiler.cpp @@ -106,7 +106,8 @@ void profiler::dumpProfileResults(bool writeAsWarning) logFunc() << std::setw(40) << entry.name << std::setw(7) << std::chrono::duration_cast(entry.duration).count() << " ms" << std::setw(12) << entry.duration.count() << " us" << std::setw(10) << entry.invocations - << " calls" << std::setw(12) << entry.duration.count() / entry.invocations << " us/call" + << " calls" << std::setw(12) + << static_cast(entry.duration.count()) / entry.invocations << " us/call" << std::setw(64) << entry.fileName << "#" << entry.lineNumber << logging::endl; } @@ -115,9 +116,9 @@ void profiler::dumpProfileResults(bool writeAsWarning) for(const Counter& counter : counts) { logFunc() << std::setw(40) << counter.name << std::setw(7) << counter.count << " counts" << std::setw(5) - << counter.invocations << " calls" << std::setw(6) << counter.count / counter.invocations - << " avg./call" << std::setw(8) << (counter.prevCounter == SIZE_MAX ? "" : "diff") << std::setw(7) - << std::showpos + << counter.invocations << " calls" << std::setw(6) + << static_cast(counter.count) / counter.invocations << " avg./call" << std::setw(8) + << (counter.prevCounter == SIZE_MAX ? "" : "diff") << std::setw(7) << std::showpos << (counter.prevCounter == SIZE_MAX ? 0 : counter.count - counters[counter.prevCounter].count) << " (" << std::setw(5) << std::showpos << (counter.prevCounter == SIZE_MAX ? diff --git a/src/ThreadPool.h b/src/ThreadPool.h index e40fb493..ddf44bd3 100644 --- a/src/ThreadPool.h +++ b/src/ThreadPool.h @@ -19,7 +19,7 @@ namespace vc4c class ThreadPool { public: - ThreadPool(const std::string& poolName, unsigned numThreads = std::thread::hardware_concurrency()); + explicit ThreadPool(const std::string& poolName, unsigned numThreads = std::thread::hardware_concurrency()); ThreadPool(const ThreadPool&) = delete; ThreadPool(ThreadPool&&) noexcept = delete; ~ThreadPool(); diff --git a/src/Values.cpp b/src/Values.cpp index 8fc618c1..a4d3fcb4 100644 --- a/src/Values.cpp +++ b/src/Values.cpp @@ -386,11 +386,11 @@ std::string SmallImmediate::to_string() const return (std::to_string(static_cast(value) - 32) + " (") + std::to_string(static_cast(value)) + ")"; if(value <= 39) // 1.0, ..., 128.0 - return (std::to_string(static_cast(1 << (static_cast(value) - 32))) + " (") + + return (std::to_string(static_cast(1u << (static_cast(value) - 32))) + " (") + std::to_string(static_cast(value)) + ")"; if(value <= 47) // 1/256, ..., 1/2 - return (std::to_string(1.0f / static_cast(1 << (48 - static_cast(value)))) + " (") + + return (std::to_string(1.0f / static_cast(1u << (48 - static_cast(value)))) + " (") + std::to_string(static_cast(value)) + ")"; if(value == 48) return "<< r5"; @@ -416,10 +416,10 @@ Optional SmallImmediate::getFloatingValue() const noexcept { if(value >= 32 && value <= 39) // 1.0, ..., 128.0 - return static_cast(1 << (static_cast(value) - 32)); + return static_cast(1u << (static_cast(value) - 32)); if(value >= 40 && value <= 47) // 1/256, ..., 1/2 - return 1.0f / static_cast(1 << (48 - static_cast(value))); + return 1.0f / static_cast(1u << (48 - static_cast(value))); return {}; } @@ -540,7 +540,7 @@ bool SIMDVector::isUndefined() const SIMDVector SIMDVector::transform(const std::function& transformOp) const & { SIMDVector copy; - for(unsigned i = 0; i < elements.size(); ++i) + for(std::size_t i = 0; i < elements.size(); ++i) { copy.elements[i] = transformOp(elements[i]); } diff --git a/src/analysis/ValueRange.cpp b/src/analysis/ValueRange.cpp index d80fad16..16b7b267 100644 --- a/src/analysis/ValueRange.cpp +++ b/src/analysis/ValueRange.cpp @@ -293,7 +293,7 @@ void ValueRange::update(const Optional& constant, const FastMapfindLiteralArgument()) - extendBoundaries(0, static_cast(litArg->literal().unsignedInt())); + extendBoundaries(0, static_cast(litArg->getLiteralValue()->unsignedInt())); else throw CompilationError(CompilationStep::GENERAL, "Failed to get literal argument for operation which reads a literal value", op->to_string()); diff --git a/src/intermediate/Helper.cpp b/src/intermediate/Helper.cpp index a963b057..358659b8 100644 --- a/src/intermediate/Helper.cpp +++ b/src/intermediate/Helper.cpp @@ -96,7 +96,7 @@ InstructionWalker intermediate::insertRestoreSign( { if(src.getLiteralValue() && sign.getLiteralValue()) { - dest = sign.isZeroInitializer() ? src : Value(Literal(-src.literal().signedInt()), src.type); + dest = sign.isZeroInitializer() ? src : Value(Literal(-src.getLiteralValue()->signedInt()), src.type); } else { diff --git a/src/intermediate/TypeConversions.cpp b/src/intermediate/TypeConversions.cpp index f690d7ef..0f9ce7e7 100644 --- a/src/intermediate/TypeConversions.cpp +++ b/src/intermediate/TypeConversions.cpp @@ -298,12 +298,13 @@ InstructionWalker intermediate::insertSignExtension(InstructionWalker it, Method { // out = asr(shl(in, bit_diff) bit_diff) // where bit_diff is the difference to full 32-bit - Value widthDiff(Literal(static_cast(32 - src.type.getScalarBitCount())), TYPE_INT8); + Literal diffLit(static_cast(32 - src.type.getScalarBitCount())); + Value widthDiff(diffLit, TYPE_INT8); if(!allowLiteral) { Value tmp = method.addNewLocal(TYPE_INT8, "%sext"); - it.emplace(new LoadImmediate(tmp, widthDiff.literal())); + it.emplace(new LoadImmediate(tmp, diffLit)); it.nextInBlock(); widthDiff = tmp; } diff --git a/src/intermediate/VectorHelper.cpp b/src/intermediate/VectorHelper.cpp index d25dcb12..468bf4dd 100644 --- a/src/intermediate/VectorHelper.cpp +++ b/src/intermediate/VectorHelper.cpp @@ -105,7 +105,7 @@ InstructionWalker intermediate::insertVectorRotation(InstructionWalker it, const } // 2. create rotation instruction - if(appliedOffset.hasLiteral(INT_ZERO.literal())) + if(appliedOffset.hasLiteral(0_lit)) // a rotation by 0 is a simple move assign(it, dest) = src; else diff --git a/src/intermediate/operators.h b/src/intermediate/operators.h index e16aeb43..c6198dad 100644 --- a/src/intermediate/operators.h +++ b/src/intermediate/operators.h @@ -64,9 +64,9 @@ namespace vc4c struct OperationWrapper : private NonCopyable { - const OpCode op; - const Value arg0; - const Optional arg1 = NO_VALUE; + OpCode op; + Value arg0; + Optional arg1 = NO_VALUE; OperationWrapper(OpCode code, const Value& arg0) : op(code), arg0(arg0) {} OperationWrapper(OpCode code, const Value& arg0, const Value& arg1) : op(code), arg0(arg0), arg1(arg1) {} @@ -134,11 +134,11 @@ namespace vc4c struct ComparisonWrapper : private NonCopyable { - const ConditionCode code; - const Value arg0; - const Value arg1; + ConditionCode code; + Value arg0; + Value arg1; using FuncType = std::function; - const FuncType func; + FuncType func; ComparisonWrapper(ConditionCode code, const Value& arg0, const Value& arg1, FuncType&& func) : code(code), arg0(arg0), arg1(arg1), func(std::forward(func)) diff --git a/src/intrinsics/Operators.cpp b/src/intrinsics/Operators.cpp index 6e12267f..f5f402a1 100644 --- a/src/intrinsics/Operators.cpp +++ b/src/intrinsics/Operators.cpp @@ -51,7 +51,7 @@ InstructionWalker intermediate::intrinsifySignedIntegerMultiplication( // skip the original instruction it.nextInBlock(); - if(op1Sign.hasLiteral(INT_ZERO.literal()) && op2Sign.hasLiteral(INT_ZERO.literal())) + if(op1Sign.hasLiteral(0_lit) && op2Sign.hasLiteral(0_lit)) { // if both operands are marked with (unsigned), we don't need to invert the result it.emplace(new MoveOperation(opDest, tmpDest)); @@ -233,7 +233,7 @@ InstructionWalker intermediate::intrinsifySignedIntegerDivision( it = intrinsifyUnsignedIntegerDivision(method, it, op, useRemainder); it.nextInBlock(); - if(op1Sign.hasLiteral(INT_ZERO.literal()) && op2Sign.hasLiteral(INT_ZERO.literal())) + if(op1Sign.hasLiteral(0_lit) && op2Sign.hasLiteral(0_lit)) { // if both operands are marked with (unsigned), we don't need to invert the result it.emplace(new MoveOperation(opDest, tmpDest)); @@ -375,7 +375,7 @@ InstructionWalker intermediate::intrinsifySignedIntegerDivisionByConstant( it = intrinsifyUnsignedIntegerDivisionByConstant(method, it, op, useRemainder); it.nextInBlock(); - if(op1Sign.hasLiteral(INT_ZERO.literal()) && op2Sign.hasLiteral(INT_ZERO.literal())) + if(op1Sign.hasLiteral(0_lit) && op2Sign.hasLiteral(0_lit)) { // if both operands are marked with (unsigned), we don't need to invert the result assign(it, opDest) = tmpDest; diff --git a/src/llvm/BitcodeReader.cpp b/src/llvm/BitcodeReader.cpp index 7b93f3e3..6a27ad98 100644 --- a/src/llvm/BitcodeReader.cpp +++ b/src/llvm/BitcodeReader.cpp @@ -1273,7 +1273,7 @@ Value BitcodeReader::toConstant(Module& module, const llvm::Value* val) } else if(llvm::dyn_cast(val) != nullptr) { - return Value(INT_ZERO.literal(), type); + return Value(Literal(0u), type); } else if(auto constant = llvm::dyn_cast(val)) { @@ -1410,7 +1410,7 @@ Value BitcodeReader::precalculateConstantExpression(Module& module, const llvm:: switch(predicate) { case llvm::CmpInst::FCMP_FALSE: - return Value(BOOL_FALSE.literal(), boolType); + return Value(Literal(false), boolType); case llvm::CmpInst::FCMP_OEQ: return Value(Literal(src0.getLiteralValue()->real() == src1.getLiteralValue()->real()), boolType); case llvm::CmpInst::FCMP_OGT: @@ -1433,7 +1433,7 @@ Value BitcodeReader::precalculateConstantExpression(Module& module, const llvm:: case llvm::CmpInst::FCMP_UNE: break; case llvm::CmpInst::FCMP_TRUE: - return Value(BOOL_TRUE.literal(), destType); + return Value(Literal(true), destType); case llvm::CmpInst::ICMP_EQ: return Value( Literal(src0.getLiteralValue()->unsignedInt() == src1.getLiteralValue()->unsignedInt()), boolType); diff --git a/src/normalization/LiteralValues.cpp b/src/normalization/LiteralValues.cpp index 0f1ad447..f57ee6a4 100644 --- a/src/normalization/LiteralValues.cpp +++ b/src/normalization/LiteralValues.cpp @@ -231,7 +231,7 @@ InstructionWalker normalization::handleContainer( const Value& container = op->assertArgument(i); op->setArgument(i, Value((*con)[0], container.type)); } - else if(op->assertArgument(i).vector().isElementNumber()) + else if(con->isElementNumber()) { op->setArgument(i, Value(REG_ELEMENT_NUMBER, op->assertArgument(i).type)); } diff --git a/src/optimization/ControlFlow.cpp b/src/optimization/ControlFlow.cpp index a91dc7cb..21ac5a0e 100644 --- a/src/optimization/ControlFlow.cpp +++ b/src/optimization/ControlFlow.cpp @@ -525,7 +525,7 @@ static void fixInitialValueAndStep( Optional initialValueWalker; bool isStepPlusOne = stepOp->op == OP_ADD && stepValue.unsignedInt() == 1u; Optional precalculatedInitialValue; - if(move != nullptr && move->getSource().hasLiteral(INT_ZERO.literal()) && isStepPlusOne) + if(move != nullptr && move->getSource().hasLiteral(0_lit) && isStepPlusOne) { // special/default case: initial value is zero and step is +1 move->setSource(Value(ELEMENT_NUMBER_REGISTER)); @@ -811,7 +811,7 @@ void optimizations::extendBranches(const Module& module, Method& method, const C if(auto branch = it.get()) { CPPLOG_LAZY(logging::Level::DEBUG, log << "Extending branch: " << branch->to_string() << logging::endl); - if(branch->hasConditionalExecution() || !branch->getCondition().hasLiteral(BOOL_TRUE.literal())) + if(branch->hasConditionalExecution() || !branch->getCondition().hasLiteral(Literal(true))) { /* * branch can only depend on scalar value diff --git a/src/optimization/Eliminator.cpp b/src/optimization/Eliminator.cpp index a3bdb54b..e38a6ee3 100644 --- a/src/optimization/Eliminator.cpp +++ b/src/optimization/Eliminator.cpp @@ -589,7 +589,7 @@ bool optimizations::propagateMoves(const Module& module, Method& method, const C if(replacedThisInstruction) foldConstants(module, method, it2, config); - if(it2->getOutput().has_value() && it2->getOutput().value() == oldValue) + if(it2->getOutput() && it2->getOutput() == oldValue) break; it2.nextInBlock(); @@ -770,7 +770,7 @@ bool optimizations::eliminateRedundantBitOp(const Module& module, Method& method // // and v1, v2, v3 => and v1, v2, v3 // or v4, v1, v2 mov v4, v2 - auto foundAnd = [&](Local* out, Local* in, InstructionWalker walker) { + auto foundAnd = [&](const Local* out, const Local* in, InstructionWalker walker) { auto it = walker.copy().nextInBlock(); while(!it.isEndOfBlock()) { @@ -795,10 +795,8 @@ bool optimizations::eliminateRedundantBitOp(const Module& module, Method& method const auto& arg0 = op->assertArgument(0); const auto& arg1 = op->assertArgument(1); - if(op->getOutput() && op->getOutput()->checkLocal()) + if(auto out = op->checkOutputLocal()) { - auto out = op->getOutput().value().local(); - if(arg0.checkLocal()) foundAnd(out, arg0.local(), it); if(arg1.checkLocal()) @@ -813,7 +811,7 @@ bool optimizations::eliminateRedundantBitOp(const Module& module, Method& method // // or v1, v2, v3 => or v1, v2, v3 // or v4, v1, v2 mov v4, v1 - auto foundOr = [&](Local* out, Local* in, InstructionWalker walker) { + auto foundOr = [&](const Local* out, const Local* in, InstructionWalker walker) { auto it = walker.copy().nextInBlock(); while(!it.isEndOfBlock()) { @@ -840,10 +838,8 @@ bool optimizations::eliminateRedundantBitOp(const Module& module, Method& method const auto& arg0 = op->assertArgument(0); const auto& arg1 = op->assertArgument(1); - if(op->getOutput() && op->getOutput()->checkLocal()) + if(auto out = op->checkOutputLocal()) { - auto out = op->getOutput()->local(); - if(arg0.checkLocal()) foundOr(out, arg0.local(), it); if(arg1.checkLocal())