Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions compiler/lib/codegen/optree_to_llvmir/llvmir_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using namespace optree;
using namespace optree::llvmir_generator;

// NOLINTBEGIN(readability-avoid-return-with-void-value)
namespace {

namespace external {
Expand Down Expand Up @@ -342,20 +343,33 @@ void LLVMIRGenerator::visit(const LogicUnaryOp &op) {
}

void LLVMIRGenerator::visit(const AllocateOp &op) {
const auto &pointee = op.result()->type->as<PointerType>().pointee;
auto *llvmType = convertType(pointee);
auto *inst = builder.CreateAlloca(llvmType);
const auto &type = op.result()->type->as<PointerType>();
auto *llvmType = convertType(type.pointee);
llvm::Value *size = nullptr;
if (type.numElements > 1U)
size = llvm::ConstantInt::get(llvm::Type::getIntNTy(context, 64U), type.numElements);
auto *inst = builder.CreateAlloca(llvmType, size);
saveValue(op.result(), inst);
typedValues[inst] = llvmType;
}

void LLVMIRGenerator::visit(const LoadOp &op) {
auto *ptr = findValue(op.src());
saveValue(op.result(), builder.CreateLoad(typedValues[ptr], ptr));
auto *type = typedValues[ptr];
if (auto offset = op.offset()) {
auto *index = findValue(offset);
ptr = builder.CreateGEP(type, ptr, index);
}
saveValue(op.result(), builder.CreateLoad(type, ptr));
}

void LLVMIRGenerator::visit(const StoreOp &op) {
builder.CreateStore(findValue(op.valueToStore()), findValue(op.dst()));
auto *ptr = findValue(op.dst());
if (auto offset = op.offset()) {
auto *index = findValue(offset);
ptr = builder.CreateGEP(typedValues[ptr], ptr, index);
}
builder.CreateStore(findValue(op.valueToStore()), ptr);
}

void LLVMIRGenerator::visit(const IfOp &op) {
Expand Down Expand Up @@ -468,3 +482,5 @@ void LLVMIRGenerator::dumpToFile(const std::string &filename) const {
dump(os);
os.close();
}

// NOLINTEND(readability-avoid-return-with-void-value)