File tree Expand file tree Collapse file tree 3 files changed +15
-0
lines changed
Expand file tree Collapse file tree 3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
99option (LIBSCRATCHCPP_BUILD_UNIT_TESTS "Build unit tests" ON )
1010option (LIBSCRATCHCPP_NETWORK_SUPPORT "Support for downloading projects" ON )
1111option (LIBSCRATCHCPP_PRINT_LLVM_IR "Print LLVM IR of compiled Scratch scripts (for debugging)" OFF )
12+ option (LIBSCRATCHCPP_ENABLE_CODE_ANALYZER "Analyze Scratch scripts to enable various optimizations" ON )
1213option (LIBSCRATCHCPP_ENABLE_SANITIZER "Enable sanitizer to detect memory issues" OFF )
1314
1415if (LIBSCRATCHCPP_ENABLE_SANITIZER)
@@ -121,6 +122,10 @@ if(LIBSCRATCHCPP_PRINT_LLVM_IR)
121122 target_compile_definitions (scratchcpp PRIVATE PRINT_LLVM_IR)
122123endif ()
123124
125+ if (LIBSCRATCHCPP_ENABLE_CODE_ANALYZER)
126+ target_compile_definitions (scratchcpp PRIVATE ENABLE_CODE_ANALYZER)
127+ endif ()
128+
124129# Macros
125130target_compile_definitions (scratchcpp PRIVATE LIBSCRATCHCPP_LIBRARY)
126131target_compile_definitions (scratchcpp PRIVATE LIBSCRATCHCPP_VERSION="${PROJECT_VERSION} " )
Original file line number Diff line number Diff line change @@ -52,6 +52,14 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::build()
5252 m_warp = true ;
5353 }
5454
55+ if (m_warp) {
56+ #ifdef ENABLE_CODE_ANALYZER
57+ // Analyze the script (type analysis, optimizations, etc.)
58+ // NOTE: Do this only for non-warp scripts
59+ m_codeAnalyzer.analyzeScript (m_instructions);
60+ #endif
61+ }
62+
5563 // Set fast math flags
5664 llvm::FastMathFlags fmf;
5765 fmf.setFast (true );
Original file line number Diff line number Diff line change 1111
1212#include " ../icodebuilder.h"
1313#include " llvmbuildutils.h"
14+ #include " llvmcodeanalyzer.h"
1415#include " llvminstruction.h"
1516#include " llvminstructionlist.h"
1617#include " llvmcoroutine.h"
@@ -137,6 +138,7 @@ class LLVMCodeBuilder : public ICodeBuilder
137138 llvm::IRBuilder<> m_builder;
138139 llvm::Function *m_function = nullptr ;
139140 LLVMBuildUtils m_utils;
141+ LLVMCodeAnalyzer m_codeAnalyzer;
140142
141143 llvm::StructType *m_valueDataType = nullptr ;
142144 llvm::StructType *m_stringPtrType = nullptr ;
You can’t perform that action at this time.
0 commit comments