From 13eb17378872ea63b8b58dd720c11ea719e36d14 Mon Sep 17 00:00:00 2001 From: Victor Perez Date: Tue, 29 Nov 2022 09:58:40 +0000 Subject: [PATCH 1/3] [SYCL-MLIR] Improve warning and debug messages Use mlirclang::warning or llvm::dbgs when suitable. Signed-off-by: Victor Perez --- polygeist/tools/cgeist/Lib/CGCall.cc | 3 +- polygeist/tools/cgeist/Lib/CGExpr.cc | 49 +++++++++++----------- polygeist/tools/cgeist/Lib/CGStmt.cc | 4 +- polygeist/tools/cgeist/Lib/CodeGenTypes.cc | 4 +- polygeist/tools/cgeist/Lib/clang-mlir.cc | 4 +- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/polygeist/tools/cgeist/Lib/CGCall.cc b/polygeist/tools/cgeist/Lib/CGCall.cc index b01afc7db4e7a..c264f7594cdab 100644 --- a/polygeist/tools/cgeist/Lib/CGCall.cc +++ b/polygeist/tools/cgeist/Lib/CGCall.cc @@ -1167,7 +1167,8 @@ MLIRScanner::emitGPUCallExpr(clang::CallExpr *Expr) { } if (Sr->getDecl()->getIdentifier() && Sr->getDecl()->getName() == "cudaFuncSetCacheConfig") { - llvm::errs() << " Not emitting GPU option: cudaFuncSetCacheConfig\n"; + mlirclang::warning() + << " Not emitting GPU option: cudaFuncSetCacheConfig\n"; return std::make_pair(ValueCategory(), true); } // TODO move free out. diff --git a/polygeist/tools/cgeist/Lib/CGExpr.cc b/polygeist/tools/cgeist/Lib/CGExpr.cc index 06ae3e7585e6e..ee82cf6332b0f 100644 --- a/polygeist/tools/cgeist/Lib/CGExpr.cc +++ b/polygeist/tools/cgeist/Lib/CGExpr.cc @@ -673,7 +673,7 @@ ValueCategory MLIRScanner::VisitMaterializeTemporaryExpr( if (IsArray) return V; - mlirclang::warning() << "cleanup of materialized not handled"; + mlirclang::warning() << "cleanup of materialized not handled\n"; auto Op = createAllocOp(Glob.getTypes().getMLIRType(Expr->getSubExpr()->getType()), nullptr, 0, /*isArray*/ IsArray, /*LLVMABI*/ LLVMABI); @@ -801,7 +801,7 @@ MLIRScanner::VisitCXXScalarValueInitExpr(clang::CXXScalarValueInitExpr *Expr) { ValueCategory MLIRScanner::VisitCXXPseudoDestructorExpr( clang::CXXPseudoDestructorExpr *Expr) { Visit(Expr->getBase()); - llvm::errs() << "not running pseudo destructor\n"; + mlirclang::warning() << "not running pseudo destructor\n"; return nullptr; } @@ -1383,18 +1383,20 @@ ValueCategory MLIRScanner::VisitCXXNoexceptExpr(CXXNoexceptExpr *Expr) { } ValueCategory MLIRScanner::VisitMemberExpr(MemberExpr *ME) { - if (auto *Sr2 = dyn_cast(ME->getBase())) { - if (auto *SR = dyn_cast(Sr2->getSourceExpr())) { - if (SR->getDecl()->getName() == "blockIdx") - llvm::errs() << "known block index"; - if (SR->getDecl()->getName() == "blockDim") - llvm::errs() << "known block dim"; - if (SR->getDecl()->getName() == "threadIdx") - llvm::errs() << "known thread index"; - if (SR->getDecl()->getName() == "gridDim") - llvm::errs() << "known grid index"; + LLVM_DEBUG({ + if (auto *Sr2 = dyn_cast(ME->getBase())) { + if (auto *SR = dyn_cast(Sr2->getSourceExpr())) { + if (SR->getDecl()->getName() == "blockIdx") + llvm::dbgs() << "known block index"; + else if (SR->getDecl()->getName() == "blockDim") + llvm::dbgs() << "known block dim"; + else if (SR->getDecl()->getName() == "threadIdx") + llvm::dbgs() << "known thread index"; + else if (SR->getDecl()->getName() == "gridDim") + llvm::dbgs() << "known grid index"; + } } - } + }); auto Base = Visit(ME->getBase()); clang::QualType OT = ME->getBase()->getType(); if (ME->isArrow()) { @@ -1651,13 +1653,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { return ValueCategory(Nval, /*isReference*/ false); } -#ifdef DEBUG if (!Scalar.getType().isa()) { E->dump(); E->getType()->dump(); llvm::errs() << "Scalar: " << Scalar << "\n"; } -#endif assert(Scalar.getType().isa() && "Expecting 'Scalar' to have MemRefType"); @@ -1700,11 +1700,10 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { /*isReference*/ false); } -#ifdef DEBUG E->dump(); E->getType()->dump(); llvm::errs() << " Scalar: " << Scalar << " MLIRTy: " << MLIRTy << "\n"; -#endif + llvm_unreachable("illegal type for cast"); } break; case clang::CastKind::CK_LValueToRValue: { @@ -1800,12 +1799,12 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { PostTy.isa()) return ValueCategory( Builder.create(Loc, PostTy, Scalar), false); -#ifdef DEBUG + if (!Scalar.getType().isa()) { E->dump(); llvm::errs() << " Scalar: " << Scalar << "\n"; } -#endif + auto PrevTy = Scalar.getType().cast(); bool SignedType = true; if (const auto *Bit = @@ -1860,12 +1859,12 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } case clang::CastKind::CK_FloatingCast: { auto Scalar = Visit(E->getSubExpr()).getValue(Builder); -#ifdef DEBUG + if (!Scalar.getType().isa()) { E->dump(); llvm::errs() << "Scalar: " << Scalar << "\n"; } -#endif + auto PrevTy = Scalar.getType().cast(); auto PostTy = Glob.getTypes().getMLIRType(E->getType()).cast(); @@ -1958,11 +1957,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { auto Val = Builder.create(Loc, MLIRTy, Scalar); return ValueCategory(Val, /*isReference*/ false); } -#ifdef DEBUG - function.dump(); + + Function.dump(); llvm::errs() << "Scalar: " << Scalar << "\n"; E->dump(); -#endif + llvm_unreachable("unhandled ptrtoint cast"); } break; case clang::CastKind::CK_IntegralToBoolean: { @@ -2642,7 +2641,7 @@ BinOpInfo MLIRScanner::EmitBinOps(BinaryOperator *E, QualType PromotionType) { static void informNoOverflowCheck(LangOptions::SignedOverflowBehaviorTy SOB, llvm::StringRef OpName) { if (SOB != clang::LangOptions::SOB_Defined) - llvm::errs() << "Not emitting overflow-checked " << OpName << "\n"; + mlirclang::warning() << "Not emitting overflow-checked " << OpName << "\n"; } ValueCategory MLIRScanner::EmitBinMul(const BinOpInfo &Info) { diff --git a/polygeist/tools/cgeist/Lib/CGStmt.cc b/polygeist/tools/cgeist/Lib/CGStmt.cc index 14ece1395f183..f5ed2564dff9d 100644 --- a/polygeist/tools/cgeist/Lib/CGStmt.cc +++ b/polygeist/tools/cgeist/Lib/CGStmt.cc @@ -572,8 +572,8 @@ MLIRScanner::VisitOMPParallelDirective(clang::OMPParallelDirective *Par) { } break; default: - llvm::errs() << "may not handle omp clause " << (int)F->getClauseKind() - << "\n"; + mlirclang::warning() << "may not handle omp clause " + << (int)F->getClauseKind() << "\n"; } } diff --git a/polygeist/tools/cgeist/Lib/CodeGenTypes.cc b/polygeist/tools/cgeist/Lib/CodeGenTypes.cc index 2e52a2e67255f..50489a9e049ad 100644 --- a/polygeist/tools/cgeist/Lib/CodeGenTypes.cc +++ b/polygeist/tools/cgeist/Lib/CodeGenTypes.cc @@ -341,7 +341,7 @@ void ClangToLLVMArgMapping::construct(const clang::ASTContext &Context, if (AI.isDirect() && AI.getCanBeFlattened() && STy) mlirclang::warning() << "struct should be flattened but MLIR codegen " - "cannot yet handle it. Needs to be fixed."; + "cannot yet handle it. Needs to be fixed.\n"; if (AllowStructFlattening && AI.isDirect() && AI.getCanBeFlattened() && STy) { @@ -592,7 +592,7 @@ CodeGenTypes::getFunctionType(const clang::CodeGen::CGFunctionInfo &FI, if (ST && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened()) mlirclang::warning() << "struct should be flattened but MLIR codegen " - "cannot yet handle it. Needs to be fixed."; + "cannot yet handle it. Needs to be fixed.\n"; if (AllowStructFlattening && ST && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened()) { diff --git a/polygeist/tools/cgeist/Lib/clang-mlir.cc b/polygeist/tools/cgeist/Lib/clang-mlir.cc index 5d5bf7ec02833..88638024b3db2 100644 --- a/polygeist/tools/cgeist/Lib/clang-mlir.cc +++ b/polygeist/tools/cgeist/Lib/clang-mlir.cc @@ -238,7 +238,7 @@ void MLIRScanner::init(FunctionOpInterface func, const FunctionToEmit &FTE) { clang::Expr *init = expr->getInit(); if (auto clean = dyn_cast(init)) { - llvm::errs() << "TODO: cleanup\n"; + mlirclang::warning() << "TODO: cleanup\n"; init = clean->getSubExpr(); } @@ -250,7 +250,7 @@ void MLIRScanner::init(FunctionOpInterface func, const FunctionToEmit &FTE) { if (expr->isDelegatingInitializer()) { clang::Expr *init = expr->getInit(); if (auto clean = dyn_cast(init)) { - llvm::errs() << "TODO: cleanup\n"; + mlirclang::warning() << "TODO: cleanup\n"; init = clean->getSubExpr(); } From ced1671734bbf2b284ca4ca7944c0c580015fede Mon Sep 17 00:00:00 2001 From: Victor Perez Date: Tue, 29 Nov 2022 15:06:14 +0000 Subject: [PATCH 2/3] Remove more #ifdef DEBUG --- polygeist/tools/cgeist/Lib/CGExpr.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/polygeist/tools/cgeist/Lib/CGExpr.cc b/polygeist/tools/cgeist/Lib/CGExpr.cc index ee82cf6332b0f..c4648cdf289f0 100644 --- a/polygeist/tools/cgeist/Lib/CGExpr.cc +++ b/polygeist/tools/cgeist/Lib/CGExpr.cc @@ -1634,10 +1634,8 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } } auto SE = Visit(E->getSubExpr()); -#ifdef DEBUG if (!SE.val) E->dump(); -#endif auto Scalar = SE.getValue(Builder); if (auto SPT = Scalar.getType().dyn_cast()) { mlir::Type NT = Glob.getTypes().getMLIRType(E->getType()); @@ -1741,12 +1739,14 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { return Prev; auto Lres = Prev.getValue(Builder); -#ifdef DEBUG - if (!prev.isReference) { - E->dump(); - lres.dump(); - } -#endif + LLVM_DEBUG({ + if (!Prev.isReference) { + llvm::dbgs() << "LValueToRValue cast performed on an RValue: "; + E->dump(llvm::dbgs(), Glob.getCGM().getContext()); + Lres.print(llvm::dbgs()); + llvm::dbgs() << "\n"; + } + }); return ValueCategory(Lres, /*isReference*/ false); } case clang::CastKind::CK_IntegralToFloating: { @@ -2018,10 +2018,8 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } case clang::CastKind::CK_IntegralToPointer: { auto Vc = Visit(E->getSubExpr()); -#ifdef DEBUG - if (!vc.val) + if (!Vc.val) E->dump(); -#endif assert(Vc.val); auto Res = Vc.getValue(Builder); mlir::Type PostTy = Glob.getTypes().getMLIRType(E->getType()); From 91af93830b32769d8c51bb786234a1b70c691787 Mon Sep 17 00:00:00 2001 From: Victor Perez Date: Tue, 29 Nov 2022 18:00:15 +0000 Subject: [PATCH 3/3] Use LLVM_DEBUG --- polygeist/tools/cgeist/Lib/CGExpr.cc | 68 +++++++++++++++------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/polygeist/tools/cgeist/Lib/CGExpr.cc b/polygeist/tools/cgeist/Lib/CGExpr.cc index c4648cdf289f0..aa54f3811a077 100644 --- a/polygeist/tools/cgeist/Lib/CGExpr.cc +++ b/polygeist/tools/cgeist/Lib/CGExpr.cc @@ -1634,8 +1634,10 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } } auto SE = Visit(E->getSubExpr()); - if (!SE.val) - E->dump(); + LLVM_DEBUG({ + if (!SE.val) + E->dump(); + }); auto Scalar = SE.getValue(Builder); if (auto SPT = Scalar.getType().dyn_cast()) { mlir::Type NT = Glob.getTypes().getMLIRType(E->getType()); @@ -1651,11 +1653,13 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { return ValueCategory(Nval, /*isReference*/ false); } - if (!Scalar.getType().isa()) { - E->dump(); - E->getType()->dump(); - llvm::errs() << "Scalar: " << Scalar << "\n"; - } + LLVM_DEBUG({ + if (!Scalar.getType().isa()) { + E->dump(); + E->getType()->dump(); + llvm::errs() << "Scalar: " << Scalar << "\n"; + } + }); assert(Scalar.getType().isa() && "Expecting 'Scalar' to have MemRefType"); @@ -1697,11 +1701,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { return ValueCategory(Builder.create(Loc, Ty, Scalar), /*isReference*/ false); } - - E->dump(); - E->getType()->dump(); - llvm::errs() << " Scalar: " << Scalar << " MLIRTy: " << MLIRTy << "\n"; - + LLVM_DEBUG({ + E->dump(); + E->getType()->dump(); + llvm::errs() << " Scalar: " << Scalar << " MLIRTy: " << MLIRTy << "\n"; + }); llvm_unreachable("illegal type for cast"); } break; case clang::CastKind::CK_LValueToRValue: { @@ -1799,12 +1803,12 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { PostTy.isa()) return ValueCategory( Builder.create(Loc, PostTy, Scalar), false); - - if (!Scalar.getType().isa()) { - E->dump(); - llvm::errs() << " Scalar: " << Scalar << "\n"; - } - + LLVM_DEBUG({ + if (!Scalar.getType().isa()) { + E->dump(); + llvm::errs() << " Scalar: " << Scalar << "\n"; + } + }); auto PrevTy = Scalar.getType().cast(); bool SignedType = true; if (const auto *Bit = @@ -1859,12 +1863,12 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } case clang::CastKind::CK_FloatingCast: { auto Scalar = Visit(E->getSubExpr()).getValue(Builder); - - if (!Scalar.getType().isa()) { - E->dump(); - llvm::errs() << "Scalar: " << Scalar << "\n"; - } - + LLVM_DEBUG({ + if (!Scalar.getType().isa()) { + E->dump(); + llvm::errs() << "Scalar: " << Scalar << "\n"; + } + }); auto PrevTy = Scalar.getType().cast(); auto PostTy = Glob.getTypes().getMLIRType(E->getType()).cast(); @@ -1957,11 +1961,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { auto Val = Builder.create(Loc, MLIRTy, Scalar); return ValueCategory(Val, /*isReference*/ false); } - - Function.dump(); - llvm::errs() << "Scalar: " << Scalar << "\n"; - E->dump(); - + LLVM_DEBUG({ + Function.dump(); + llvm::errs() << "Scalar: " << Scalar << "\n"; + E->dump(); + }); llvm_unreachable("unhandled ptrtoint cast"); } break; case clang::CastKind::CK_IntegralToBoolean: { @@ -2018,8 +2022,10 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } case clang::CastKind::CK_IntegralToPointer: { auto Vc = Visit(E->getSubExpr()); - if (!Vc.val) - E->dump(); + LLVM_DEBUG({ + if (!Vc.val) + E->dump(); + }); assert(Vc.val); auto Res = Vc.getValue(Builder); mlir::Type PostTy = Glob.getTypes().getMLIRType(E->getType());