Skip to content

Commit a84e99b

Browse files
committed
Make LLVM integer support optional
1 parent 54c7f07 commit a84e99b

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ option(LIBSCRATCHCPP_BUILD_UNIT_TESTS "Build unit tests" ON)
1010
option(LIBSCRATCHCPP_NETWORK_SUPPORT "Support for downloading projects" ON)
1111
option(LIBSCRATCHCPP_PRINT_LLVM_IR "Print LLVM IR of compiled Scratch scripts (for debugging)" OFF)
1212
option(LIBSCRATCHCPP_ENABLE_CODE_ANALYZER "Analyze Scratch scripts to enable various optimizations" ON)
13+
option(LIBSCRATCHCPP_LLVM_INTEGER_SUPPORT "Use integers when possible to enable various optimizations" ON)
1314
option(LIBSCRATCHCPP_ENABLE_SANITIZER "Enable sanitizer to detect memory issues" OFF)
1415

1516
if (LIBSCRATCHCPP_ENABLE_SANITIZER)
@@ -126,6 +127,10 @@ if(LIBSCRATCHCPP_ENABLE_CODE_ANALYZER)
126127
target_compile_definitions(scratchcpp PRIVATE ENABLE_CODE_ANALYZER)
127128
endif()
128129

130+
if(LIBSCRATCHCPP_LLVM_INTEGER_SUPPORT)
131+
target_compile_definitions(scratchcpp PRIVATE LLVM_INTEGER_SUPPORT)
132+
endif()
133+
129134
# Macros
130135
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_LIBRARY)
131136
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_VERSION="${PROJECT_VERSION}")

src/engine/internal/llvm/instructions/instructionbuilder.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
#include "variables.h"
1111
#include "lists.h"
1212
#include "procedures.h"
13+
#include "../llvminstruction.h"
14+
#include "../llvmbuildutils.h"
1315

1416
using namespace libscratchcpp;
1517
using namespace libscratchcpp::llvmins;
1618

17-
InstructionBuilder::InstructionBuilder(LLVMBuildUtils &utils)
19+
InstructionBuilder::InstructionBuilder(LLVMBuildUtils &utils) :
20+
m_utils(utils)
1821
{
1922
// Create groups
2023
m_groups.push_back(std::make_shared<Functions>(utils));
@@ -34,8 +37,14 @@ LLVMInstruction *InstructionBuilder::process(LLVMInstruction *ins)
3437
for (const auto &group : m_groups) {
3538
ProcessResult result = group->process(ins);
3639

37-
if (result.match)
40+
if (result.match) {
41+
#ifndef LLVM_INTEGER_SUPPORT
42+
if (ins->functionReturnReg)
43+
ins->functionReturnReg->isInt = m_utils.builder().getInt1(false);
44+
#endif
45+
3846
return result.next;
47+
}
3948
}
4049

4150
assert(false); // instruction not found

src/engine/internal/llvm/instructions/instructionbuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class InstructionBuilder
1515
LLVMInstruction *process(LLVMInstruction *ins);
1616

1717
private:
18+
LLVMBuildUtils &m_utils;
1819
std::vector<std::shared_ptr<InstructionGroup>> m_groups;
1920
};
2021

src/engine/internal/llvm/llvmbuildutils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ void LLVMBuildUtils::init(llvm::Function *function, BlockPrototype *procedurePro
6565

6666
// Init registers
6767
for (auto reg : regs) {
68+
#ifdef LLVM_INTEGER_SUPPORT
6869
bool isIntConst = (reg->isConst() && optimizeRegisterType(reg.get()) == Compiler::StaticType::Number && reg->constValue().toDouble() == std::floor(reg->constValue().toDouble()));
6970
reg->isInt = m_builder.getInt1(isIntConst);
71+
#else
72+
reg->isInt = m_builder.getInt1(false);
73+
#endif
7074
reg->intValue = llvm::ConstantInt::get(m_builder.getInt64Ty(), reg->constValue().toDouble(), true);
7175
}
7276

0 commit comments

Comments
 (0)