Skip to content

Commit 4325b34

Browse files
authored
Frontend Type Fixes (#140)
* Handle delegating init * Handle recursive types * Correct lnot and builtin strlen/frexp * Cleanup
1 parent 92b7f11 commit 4325b34

File tree

5 files changed

+346
-200
lines changed

5 files changed

+346
-200
lines changed

tools/mlir-clang/Lib/CGStmt.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ ValueCategory MLIRScanner::VisitDeclStmt(clang::DeclStmt *decl) {
902902
if (auto vd = dyn_cast<VarDecl>(sub)) {
903903
VisitVarDecl(vd);
904904
} else if (isa<TypeAliasDecl, RecordDecl, StaticAssertDecl, TypedefDecl,
905-
UsingDecl>(sub)) {
905+
UsingDecl, UsingDirectiveDecl>(sub)) {
906906
} else {
907907
emitError(getMLIRLocation(decl->getBeginLoc()))
908908
<< " + visiting unknonwn sub decl stmt\n";
@@ -1034,6 +1034,16 @@ ValueCategory MLIRScanner::VisitReturnStmt(clang::ReturnStmt *stmt) {
10341034
else if (val.getType().isa<LLVM::LLVMPointerType>() &&
10351035
postTy.isa<MemRefType>())
10361036
val = builder.create<polygeist::Pointer2MemrefOp>(loc, postTy, val);
1037+
if (postTy != val.getType()) {
1038+
stmt->dump();
1039+
llvm::errs() << " val: " << val << " postTy: " << postTy
1040+
<< " rv.val: " << rv.val << " rv.isRef"
1041+
<< (int)rv.isReference << " mm: "
1042+
<< (int)(stmt->getRetValue()->isLValue() ||
1043+
stmt->getRetValue()->isXValue())
1044+
<< "\n";
1045+
}
1046+
assert(postTy == val.getType());
10371047
builder.create<mlir::memref::StoreOp>(loc, val, returnVal);
10381048
}
10391049
}

tools/mlir-clang/Lib/ValueCategory.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ ValueCategory::ValueCategory(mlir::Value val, bool isReference)
2626
val.getType().isa<LLVM::LLVMPointerType>())) {
2727
llvm::errs() << "val: " << val << "\n";
2828
}
29-
assert(val.getType().isa<MemRefType>() ||
30-
val.getType().isa<LLVM::LLVMPointerType>() &&
31-
"Reference value must have pointer/memref type");
29+
assert((val.getType().isa<MemRefType>() ||
30+
val.getType().isa<LLVM::LLVMPointerType>()) &&
31+
"Reference value must have pointer/memref type");
3232
}
3333
}
3434

@@ -54,12 +54,26 @@ void ValueCategory::store(mlir::OpBuilder &builder, mlir::Value toStore) const {
5454
assert(val && "expect not-null");
5555
auto loc = builder.getUnknownLoc();
5656
if (auto pt = val.getType().dyn_cast<mlir::LLVM::LLVMPointerType>()) {
57+
if (auto p2m = toStore.getDefiningOp<polygeist::Pointer2MemrefOp>()) {
58+
if (pt.getElementType() == p2m.source().getType())
59+
toStore = p2m.source();
60+
else if (auto nt = p2m.source().getDefiningOp<LLVM::NullOp>()) {
61+
if (pt.getElementType().isa<LLVM::LLVMPointerType>())
62+
toStore =
63+
builder.create<LLVM::NullOp>(nt.getLoc(), pt.getElementType());
64+
}
65+
}
5766
if (toStore.getType() != pt.getElementType()) {
5867
if (auto mt = toStore.getType().dyn_cast<MemRefType>()) {
5968
if (auto spt =
6069
pt.getElementType().dyn_cast<mlir::LLVM::LLVMPointerType>()) {
61-
assert(mt.getElementType() == spt.getElementType() &&
62-
"expect same type");
70+
if (mt.getElementType() != spt.getElementType()) {
71+
// llvm::errs() << " func: " <<
72+
// val.getDefiningOp()->getParentOfType<FuncOp>() << "\n";
73+
llvm::errs() << "warning potential store type mismatch:\n";
74+
llvm::errs() << "val: " << val << " tosval: " << toStore << "\n";
75+
llvm::errs() << "mt: " << mt << "spt: " << spt << "\n";
76+
}
6377
toStore =
6478
builder.create<polygeist::Memref2PointerOp>(loc, spt, toStore);
6579
}

0 commit comments

Comments
 (0)