Skip to content

Commit

Permalink
Frontend Type Fixes (#140)
Browse files Browse the repository at this point in the history
* Handle delegating init

* Handle recursive types

* Correct lnot and builtin strlen/frexp

* Cleanup
  • Loading branch information
wsmoses authored Jan 5, 2022
1 parent 92b7f11 commit 4325b34
Show file tree
Hide file tree
Showing 5 changed files with 346 additions and 200 deletions.
12 changes: 11 additions & 1 deletion tools/mlir-clang/Lib/CGStmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ ValueCategory MLIRScanner::VisitDeclStmt(clang::DeclStmt *decl) {
if (auto vd = dyn_cast<VarDecl>(sub)) {
VisitVarDecl(vd);
} else if (isa<TypeAliasDecl, RecordDecl, StaticAssertDecl, TypedefDecl,
UsingDecl>(sub)) {
UsingDecl, UsingDirectiveDecl>(sub)) {
} else {
emitError(getMLIRLocation(decl->getBeginLoc()))
<< " + visiting unknonwn sub decl stmt\n";
Expand Down Expand Up @@ -1034,6 +1034,16 @@ ValueCategory MLIRScanner::VisitReturnStmt(clang::ReturnStmt *stmt) {
else if (val.getType().isa<LLVM::LLVMPointerType>() &&
postTy.isa<MemRefType>())
val = builder.create<polygeist::Pointer2MemrefOp>(loc, postTy, val);
if (postTy != val.getType()) {
stmt->dump();
llvm::errs() << " val: " << val << " postTy: " << postTy
<< " rv.val: " << rv.val << " rv.isRef"
<< (int)rv.isReference << " mm: "
<< (int)(stmt->getRetValue()->isLValue() ||
stmt->getRetValue()->isXValue())
<< "\n";
}
assert(postTy == val.getType());
builder.create<mlir::memref::StoreOp>(loc, val, returnVal);
}
}
Expand Down
24 changes: 19 additions & 5 deletions tools/mlir-clang/Lib/ValueCategory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ ValueCategory::ValueCategory(mlir::Value val, bool isReference)
val.getType().isa<LLVM::LLVMPointerType>())) {
llvm::errs() << "val: " << val << "\n";
}
assert(val.getType().isa<MemRefType>() ||
val.getType().isa<LLVM::LLVMPointerType>() &&
"Reference value must have pointer/memref type");
assert((val.getType().isa<MemRefType>() ||
val.getType().isa<LLVM::LLVMPointerType>()) &&
"Reference value must have pointer/memref type");
}
}

Expand All @@ -54,12 +54,26 @@ void ValueCategory::store(mlir::OpBuilder &builder, mlir::Value toStore) const {
assert(val && "expect not-null");
auto loc = builder.getUnknownLoc();
if (auto pt = val.getType().dyn_cast<mlir::LLVM::LLVMPointerType>()) {
if (auto p2m = toStore.getDefiningOp<polygeist::Pointer2MemrefOp>()) {
if (pt.getElementType() == p2m.source().getType())
toStore = p2m.source();
else if (auto nt = p2m.source().getDefiningOp<LLVM::NullOp>()) {
if (pt.getElementType().isa<LLVM::LLVMPointerType>())
toStore =
builder.create<LLVM::NullOp>(nt.getLoc(), pt.getElementType());
}
}
if (toStore.getType() != pt.getElementType()) {
if (auto mt = toStore.getType().dyn_cast<MemRefType>()) {
if (auto spt =
pt.getElementType().dyn_cast<mlir::LLVM::LLVMPointerType>()) {
assert(mt.getElementType() == spt.getElementType() &&
"expect same type");
if (mt.getElementType() != spt.getElementType()) {
// llvm::errs() << " func: " <<
// val.getDefiningOp()->getParentOfType<FuncOp>() << "\n";
llvm::errs() << "warning potential store type mismatch:\n";
llvm::errs() << "val: " << val << " tosval: " << toStore << "\n";
llvm::errs() << "mt: " << mt << "spt: " << spt << "\n";
}
toStore =
builder.create<polygeist::Memref2PointerOp>(loc, spt, toStore);
}
Expand Down
Loading

0 comments on commit 4325b34

Please sign in to comment.