Lower serene.symbol to llvm struct type
This commit is contained in:
parent
bbebc449dd
commit
d64910e9cc
|
@ -103,12 +103,6 @@ static ll::GlobalOp getOrCreateString(mlir::Location loc,
|
|||
mlir::OpBuilder::InsertionGuard insertGuard(builder);
|
||||
builder.setInsertionPointToStart(module.getBody());
|
||||
|
||||
auto createIndex = [&](int32_t value) -> mlir::Value {
|
||||
return builder.create<ll::ConstantOp>(
|
||||
loc, mlir::IntegerType::get(ctx, I32_SIZE),
|
||||
builder.getI32IntegerAttr(value));
|
||||
};
|
||||
|
||||
mlir::Attribute initValue{};
|
||||
auto type = slir::getStringTypeinLLVM(*ctx);
|
||||
|
||||
|
@ -125,14 +119,21 @@ static ll::GlobalOp getOrCreateString(mlir::Location loc,
|
|||
auto strOp = getOrCreateInternalString(loc, builder, name, value, module);
|
||||
auto ptrToStr = getPtrToInternalString(builder, strOp);
|
||||
|
||||
auto length = builder.create<ll::ConstantOp>(
|
||||
loc, mlir::IntegerType::get(ctx, I32_SIZE),
|
||||
builder.getI32IntegerAttr(len));
|
||||
|
||||
// Setting the string pointer field
|
||||
structInstant = builder.create<ll::InsertElementOp>(
|
||||
loc, structInstant.getType(), structInstant, ptrToStr, createIndex(0));
|
||||
structInstant = builder.create<ll::InsertValueOp>(
|
||||
loc, structInstant.getType(), structInstant, ptrToStr,
|
||||
builder.getI64ArrayAttr(0));
|
||||
|
||||
// Setting the len field
|
||||
structInstant = builder.create<ll::InsertElementOp>(
|
||||
loc, structInstant.getType(), structInstant, createIndex(len),
|
||||
createIndex(1));
|
||||
structInstant = builder.create<ll::InsertValueOp>(
|
||||
loc, structInstant.getType(), structInstant, length,
|
||||
builder.getI64ArrayAttr(1));
|
||||
|
||||
builder.create<ll::ReturnOp>(loc, structInstant);
|
||||
}
|
||||
|
||||
return global;
|
||||
|
@ -154,12 +155,6 @@ static ll::GlobalOp getOrCreateSymbol(mlir::Location loc,
|
|||
mlir::OpBuilder::InsertionGuard insertGuard(builder);
|
||||
builder.setInsertionPointToStart(module.getBody());
|
||||
|
||||
auto createIndex = [&](int32_t value) -> mlir::Value {
|
||||
return builder.create<ll::ConstantOp>(
|
||||
loc, mlir::IntegerType::get(ctx, I32_SIZE),
|
||||
builder.getI32IntegerAttr(value));
|
||||
};
|
||||
|
||||
mlir::Attribute initValue{};
|
||||
auto type = slir::getSymbolTypeinLLVM(*ctx);
|
||||
|
||||
|
@ -194,12 +189,16 @@ static ll::GlobalOp getOrCreateSymbol(mlir::Location loc,
|
|||
auto ptrToName = builder.create<ll::AddressOfOp>(loc, nameField);
|
||||
|
||||
// Setting the string pointer field
|
||||
structInstant = builder.create<ll::InsertElementOp>(
|
||||
loc, structInstant.getType(), structInstant, ptrToNs, createIndex(0));
|
||||
structInstant = builder.create<ll::InsertValueOp>(
|
||||
loc, structInstant.getType(), structInstant, ptrToNs,
|
||||
builder.getI64ArrayAttr(0));
|
||||
|
||||
// Setting the len field
|
||||
structInstant = builder.create<ll::InsertElementOp>(
|
||||
loc, structInstant.getType(), structInstant, ptrToName, createIndex(1));
|
||||
structInstant = builder.create<ll::InsertValueOp>(
|
||||
loc, structInstant.getType(), structInstant, ptrToName,
|
||||
builder.getI64ArrayAttr(0));
|
||||
|
||||
builder.create<ll::ReturnOp>(loc, structInstant);
|
||||
}
|
||||
|
||||
return global;
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include "serene/slir/type_converter.h"
|
||||
|
||||
#include <mlir/Dialect/LLVMIR/LLVMTypes.h>
|
||||
|
||||
namespace ll = mlir::LLVM;
|
||||
|
||||
namespace serene {
|
||||
|
@ -27,7 +29,7 @@ mlir::Type getStringTypeinLLVM(mlir::MLIRContext &ctx) {
|
|||
auto stringStruct =
|
||||
ll::LLVMStructType::getIdentified(&ctx, "serene.core.string");
|
||||
|
||||
mlir::SmallVector<mlir::Type, 4> subtypes;
|
||||
mlir::SmallVector<mlir::Type, 2> subtypes;
|
||||
|
||||
subtypes.push_back(
|
||||
ll::LLVMPointerType::get(mlir::IntegerType::get(&ctx, I8_SIZE)));
|
||||
|
@ -37,7 +39,7 @@ mlir::Type getStringTypeinLLVM(mlir::MLIRContext &ctx) {
|
|||
|
||||
(void)stringStruct.setBody(subtypes, false);
|
||||
|
||||
return ll::LLVMPointerType::get(stringStruct);
|
||||
return stringStruct;
|
||||
};
|
||||
|
||||
mlir::Type getSymbolTypeinLLVM(mlir::MLIRContext &ctx) {
|
||||
|
@ -45,12 +47,14 @@ mlir::Type getSymbolTypeinLLVM(mlir::MLIRContext &ctx) {
|
|||
ll::LLVMStructType::getIdentified(&ctx, "serene.core.symbol");
|
||||
|
||||
auto strType = getStringTypeinLLVM(ctx);
|
||||
llvm::SmallVector<mlir::Type, 2> strings{strType, strType};
|
||||
auto strPtr = ll::LLVMPointerType::get(strType);
|
||||
|
||||
llvm::SmallVector<mlir::Type, 2> strings{strPtr, strPtr};
|
||||
|
||||
// We discard the result becasue if the body was already set it means
|
||||
// that we're ok and the struct already exists
|
||||
(void)symbolStruct.setBody(strings, false);
|
||||
return ll::LLVMPointerType::get(symbolStruct);
|
||||
return symbolStruct;
|
||||
};
|
||||
|
||||
TypeConverter::ConverterFn TypeConverter::convertSereneTypes() {
|
||||
|
|
Loading…
Reference in New Issue