Skip to content

Commit 0dd6c2d

Browse files
committed
MLIR: fix and clean up register allocation
1 parent dfd0498 commit 0dd6c2d

153 files changed

Lines changed: 2021 additions & 511 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

integration/program.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ template<typename T> void assert_interpreter_object_value(std::string name, T ex
8888
auto key_ = p->operator[](0);
8989
auto value_ = p->operator[](1);
9090
// only support string keys for now
91-
ASSERT(key_.unwrap())
91+
ASSERT(key_.unwrap());
9292
auto key_string = as<PyString>(key_.unwrap())->value();
9393
check_value(value_.unwrap(), expected_value[key_string]);
9494
}

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ elseif(ENABLE_LLVM_BACKEND AND LLVM_FOUND)
348348
target_link_libraries(unittests_ PRIVATE python-cpp-llvm)
349349
endif()
350350

351-
target_link_libraries(unittests_ PRIVATE python-cpp gtest gtest_main cxxopts project_options project_warnings tsl::ordered_map)
351+
target_link_libraries(unittests_ PRIVATE python-cpp gtest gtest_main cxxopts project_options project_warnings tsl::ordered_map TargetPythonBytecode)
352+
target_include_directories(unittests_ SYSTEM PRIVATE ${MLIR_INCLUDE_DIRS})
353+
target_include_directories(unittests_ PRIVATE ${CMAKE_SOURCE_DIR}/src/executable/mlir/ ${CMAKE_BINARY_DIR}/src/executable/mlir/Dialect)
352354
set_target_properties(unittests_ PROPERTIES OUTPUT_NAME "unittests")
353355
add_custom_target(run-unittests COMMAND $<TARGET_FILE:unittests_> DEPENDS unittests_)
354356

src/ast/AST.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ class Subscript : public ASTNode
11871187
const std::shared_ptr<ASTNode> &value() const { return m_value; }
11881188
const SliceType &slice() const
11891189
{
1190-
ASSERT(m_slice)
1190+
ASSERT(m_slice);
11911191
return *m_slice;
11921192
}
11931193
ContextType context() const { return m_ctx; }
@@ -1304,7 +1304,7 @@ class Assert : public ASTNode
13041304
: ASTNode(ASTNodeType::Assert, source_location), m_test(std::move(test)),
13051305
m_msg(std::move(msg))
13061306
{
1307-
ASSERT(m_test)
1307+
ASSERT(m_test);
13081308
}
13091309

13101310
const std::shared_ptr<ASTNode> &test() const { return m_test; }

src/ast/optimizers/ConstantFolding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace optimizer {
1111
&& node->rhs()->node_type() == ASTNodeType::Constant) {
1212
const auto &lhs = as<Constant>(node->lhs())->value();
1313
const auto &rhs = as<Constant>(node->rhs())->value();
14-
ASSERT(lhs)
15-
ASSERT(rhs)
14+
ASSERT(lhs);
15+
ASSERT(rhs);
1616
switch (node->op_type()) {
1717
case BinaryOpType::PLUS: {
1818
auto result = std::visit(

src/executable/Label.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Label
2424
protected:
2525
void set_position(int64_t position) const
2626
{
27-
ASSERT(!m_position.has_value())
27+
ASSERT(!m_position.has_value());
2828
m_position = position;
2929
}
3030

src/executable/Mangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class DefaultMangler : public Mangler
6262

6363
std::string_view mangled_class{ mangled_name.c_str() + start, end - start };
6464

65-
ASSERT(mangled_class.starts_with("__class__"))
66-
ASSERT(mangled_class.ends_with("__"))
65+
ASSERT(mangled_class.starts_with("__class__"));
66+
ASSERT(mangled_class.ends_with("__"));
6767

6868
// extract name from __class__{}__
6969
return std::string{ mangled_class.begin() + 9, mangled_class.end() - 2 };

src/executable/bytecode/Bytecode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ py::PyResult<py::Value> Bytecode::eval_loop(VirtualMachine &vm, Interpreter &int
125125
const auto end_instruction_it = end();
126126
for (; vm.instruction_pointer() != end_instruction_it;
127127
vm.set_instruction_pointer(std::next(vm.instruction_pointer()))) {
128-
ASSERT((*vm.instruction_pointer()).get())
128+
ASSERT((*vm.instruction_pointer()).get());
129129
const auto &current_ip = vm.instruction_pointer();
130130
const auto &instruction = *current_ip;
131131
spdlog::debug("{} {}", (void *)instruction.get(), instruction->to_string());
132132
auto result = instruction->execute(vm, vm.interpreter());
133133
// we left the current stack frame in the previous instruction
134134
if (vm.stack().size() != stack_depth) {
135-
ASSERT(result.is_ok())
135+
ASSERT(result.is_ok());
136136
return result;
137137
}
138138
// vm.dump();
@@ -143,7 +143,7 @@ py::PyResult<py::Value> Bytecode::eval_loop(VirtualMachine &vm, Interpreter &int
143143
PyTraceback *tb_next = exception->traceback();
144144
auto traceback =
145145
PyTraceback::create(interpreter.execution_frame(), tb_lasti, tb_lineno, tb_next);
146-
ASSERT(traceback.is_ok())
146+
ASSERT(traceback.is_ok());
147147
exception->set_traceback(traceback.unwrap());
148148

149149
interpreter.raise_exception(exception);
@@ -165,6 +165,6 @@ py::PyResult<py::Value> Bytecode::eval_loop(VirtualMachine &vm, Interpreter &int
165165
}
166166
}
167167

168-
ASSERT(value.has_value())
168+
ASSERT(value.has_value());
169169
return Ok(*value);
170170
}

src/executable/bytecode/BytecodeProgram.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ size_t BytecodeProgram::main_stack_size() const { return m_main_function->regist
104104
InstructionVector::const_iterator BytecodeProgram::begin() const
105105
{
106106
// FIXME: assumes all functions are bytecode
107-
ASSERT(m_main_function->function()->backend() == FunctionExecutionBackend::BYTECODE)
107+
ASSERT(m_main_function->function()->backend() == FunctionExecutionBackend::BYTECODE);
108108
return static_cast<Bytecode *>(m_main_function->function().get())->begin();
109109
}
110110

111111
InstructionVector::const_iterator BytecodeProgram::end() const
112112
{
113113
// FIXME: assumes all functions are bytecode
114-
ASSERT(m_main_function->function()->backend() == FunctionExecutionBackend::BYTECODE)
114+
ASSERT(m_main_function->function()->backend() == FunctionExecutionBackend::BYTECODE);
115115
return static_cast<Bytecode *>(m_main_function->function().get())->end();
116116
}
117117

@@ -136,7 +136,7 @@ int BytecodeProgram::execute(VirtualMachine *vm)
136136

137137
if (result.is_err()) {
138138
auto *exception = interpreter.execution_frame()->pop_exception();
139-
ASSERT(exception == result.unwrap_err())
139+
ASSERT(exception == result.unwrap_err());
140140
std::cout << exception->format_traceback() << std::endl;
141141

142142
// if (interpreter.execution_frame()->exception_info().has_value()) {
@@ -214,7 +214,7 @@ std::vector<uint8_t> BytecodeProgram::serialize() const
214214
}
215215

216216
// TODO: Add support to serialize functions from different backends
217-
ASSERT(m_backends.empty())
217+
ASSERT(m_backends.empty());
218218

219219
return result;
220220
}
@@ -226,14 +226,14 @@ std::shared_ptr<BytecodeProgram> BytecodeProgram::deserialize(const std::vector<
226226

227227
auto span = std::span{ buffer };
228228
auto deserialized_result = PyCode::deserialize(span, program);
229-
ASSERT(deserialized_result.first.is_ok())
229+
ASSERT(deserialized_result.first.is_ok());
230230
program->m_main_function = deserialized_result.first.unwrap();
231231
spdlog::debug(
232232
"Deserialized main function:\n{}\n\n", program->m_main_function->function()->to_string());
233233

234234
while (!span.empty()) {
235235
deserialized_result = PyCode::deserialize(span, program);
236-
ASSERT(deserialized_result.first.is_ok())
236+
ASSERT(deserialized_result.first.is_ok());
237237
program->m_functions.push_back(deserialized_result.first.unwrap());
238238
spdlog::debug("Deserialized function {}:\n{}\n\n",
239239
program->m_functions.back()->function()->function_name(),

src/executable/bytecode/BytecodeProgram_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ std::shared_ptr<BytecodeProgram> generate_bytecode(std::string_view program)
1515
p.parse();
1616

1717
auto module = as<ast::Module>(p.module());
18-
ASSERT(module)
18+
ASSERT(module);
1919

2020
return std::static_pointer_cast<BytecodeProgram>(compiler::compile(
2121
module, {}, compiler::Backend::BYTECODE_GENERATOR, compiler::OptimizationLevel::None));

src/executable/bytecode/Bytecode_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// p.parse();
1818

1919
// auto module = as<ast::Module>(p.module());
20-
// ASSERT(module)
20+
// ASSERT(module);
2121

2222
// auto bytecode =
2323
// codegen::BytecodeGenerator::compile(module, {}, compiler::OptimizationLevel::None);

0 commit comments

Comments
 (0)