Simplify LowerTo pragma handling

This commit is contained in:
lchelini 2021-07-12 14:15:20 +02:00 committed by lorenzo chelini
parent 3db50fd2b8
commit 1146340bd8
4 changed files with 17 additions and 24 deletions

View File

@ -1398,7 +1398,7 @@ ValueWithOffsets MLIRScanner::CommonArrayLookup(ValueWithOffsets array,
EmittingFunctionDecl->dump(); EmittingFunctionDecl->dump();
builder.getInsertionBlock()->dump(); builder.getInsertionBlock()->dump();
function.dump(); function.dump();
llvm::errs() << val << "\n"; llvm::errs() << "value: " << val << "\n";
} }
ValueWithOffsets dref; ValueWithOffsets dref;
@ -2841,7 +2841,7 @@ ValueWithOffsets MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) {
if (!cond.getType().isa<mlir::IntegerType>()) { if (!cond.getType().isa<mlir::IntegerType>()) {
BO->dump(); BO->dump();
BO->getType()->dump(); BO->getType()->dump();
llvm::errs() << cond << "\n"; llvm::errs() << "cond: " << cond << "\n";
} }
auto prevTy = cond.getType().cast<mlir::IntegerType>(); auto prevTy = cond.getType().cast<mlir::IntegerType>();
if (!prevTy.isInteger(1)) { if (!prevTy.isInteger(1)) {
@ -3406,7 +3406,7 @@ ValueWithOffsets MLIRScanner::CommonFieldLookup(clang::QualType CT,
loc, iTy, builder.getIntegerAttr(iTy, fnum))}; loc, iTy, builder.getIntegerAttr(iTy, fnum))};
if (!PT.getElementType() if (!PT.getElementType()
.isa<mlir::LLVM::LLVMStructType, mlir::LLVM::LLVMArrayType>()) { .isa<mlir::LLVM::LLVMStructType, mlir::LLVM::LLVMArrayType>()) {
llvm::errs() << function << "\n"; llvm::errs() << "function: " << function << "\n";
// rd->dump(); // rd->dump();
FD->dump(); FD->dump();
FD->getType()->dump(); FD->getType()->dump();
@ -3580,7 +3580,7 @@ ValueWithOffsets MLIRScanner::VisitMemberExpr(MemberExpr *ME) {
EmittingFunctionDecl->dump(); EmittingFunctionDecl->dump();
function.dump(); function.dump();
ME->dump(); ME->dump();
llvm::errs() << base.val << "\n"; llvm::errs() << "base value: " << base.val << "\n";
} }
assert(base.isReference); assert(base.isReference);
const FieldDecl *field = cast<FieldDecl>(ME->getMemberDecl()); const FieldDecl *field = cast<FieldDecl>(ME->getMemberDecl());
@ -3707,7 +3707,7 @@ ValueWithOffsets MLIRScanner::VisitCastExpr(CastExpr *E) {
if (!scalar.getType().isa<mlir::MemRefType>()) { if (!scalar.getType().isa<mlir::MemRefType>()) {
E->dump(); E->dump();
E->getType()->dump(); E->getType()->dump();
llvm::errs() << scalar << "\n"; llvm::errs() << "scalar: " << scalar << "\n";
} }
auto ut = scalar.getType().cast<mlir::MemRefType>(); auto ut = scalar.getType().cast<mlir::MemRefType>();
auto mlirty = getMLIRType(E->getType()); auto mlirty = getMLIRType(E->getType());
@ -3857,7 +3857,7 @@ ValueWithOffsets MLIRScanner::VisitCastExpr(CastExpr *E) {
auto scalar = Visit(E->getSubExpr()).getValue(builder); auto scalar = Visit(E->getSubExpr()).getValue(builder);
if (!scalar.getType().isa<mlir::FloatType>()) { if (!scalar.getType().isa<mlir::FloatType>()) {
E->dump(); E->dump();
llvm::errs() << scalar << "\n"; llvm::errs() << "scalar: " << scalar << "\n";
} }
auto prevTy = scalar.getType().cast<mlir::FloatType>(); auto prevTy = scalar.getType().cast<mlir::FloatType>();
auto postTy = getMLIRType(E->getType()).cast<mlir::FloatType>(); auto postTy = getMLIRType(E->getType()).cast<mlir::FloatType>();
@ -3931,7 +3931,7 @@ ValueWithOffsets MLIRScanner::VisitCastExpr(CastExpr *E) {
return ValueWithOffsets(val, /*isReference*/ false); return ValueWithOffsets(val, /*isReference*/ false);
} }
function.dump(); function.dump();
llvm::errs() << scalar << "\n"; llvm::errs() << "scalar: " << scalar << "\n";
E->dump(); E->dump();
assert(0 && "unhandled ptrtobool cast"); assert(0 && "unhandled ptrtobool cast");
} }
@ -3947,7 +3947,7 @@ ValueWithOffsets MLIRScanner::VisitCastExpr(CastExpr *E) {
return ValueWithOffsets(val, /*isReference*/ false); return ValueWithOffsets(val, /*isReference*/ false);
} }
function.dump(); function.dump();
llvm::errs() << scalar << "\n"; llvm::errs() << "scalar: " << scalar << "\n";
E->dump(); E->dump();
assert(0 && "unhandled ptrtoint cast"); assert(0 && "unhandled ptrtoint cast");
} }

View File

@ -437,8 +437,7 @@ struct MLIRASTConsumer : public ASTConsumer {
reverseTypeTranslator(lcontext) { reverseTypeTranslator(lcontext) {
PP.AddPragmaHandler(new PragmaScopHandler(scopLocList)); PP.AddPragmaHandler(new PragmaScopHandler(scopLocList));
PP.AddPragmaHandler(new PragmaEndScopHandler(scopLocList)); PP.AddPragmaHandler(new PragmaEndScopHandler(scopLocList));
Sema Actions(PP, astContext, *this); addPragmaLowerToHandlers(PP, LTInfo);
addPragmaLowerToHandlers(PP, Actions, LTInfo);
} }
~MLIRASTConsumer() {} ~MLIRASTConsumer() {}

View File

@ -1,10 +1,10 @@
#include "pragmaLowerToHandler.h" #include "pragmaLowerToHandler.h"
#include "clang/AST/AST.h" #include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTConsumer.h"
#include "clang/AST/Attr.h" #include "clang/AST/Attr.h"
#include "clang/Frontend/FrontendPluginRegistry.h" #include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/LexDiagnostic.h"
#include "clang/Lex/LiteralSupport.h"
#include "clang/Lex/Preprocessor.h" #include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Sema.h" #include "clang/Sema/Sema.h"
@ -20,13 +20,11 @@ namespace {
/// Handles the #pragma lower_to(<identifier>, "<mlir function target>") /// Handles the #pragma lower_to(<identifier>, "<mlir function target>")
/// directive. /// directive.
class PragmaLowerToHandler : public PragmaHandler { class PragmaLowerToHandler : public PragmaHandler {
Sema &Actions;
LowerToInfo &Info; LowerToInfo &Info;
public: public:
PragmaLowerToHandler(Sema &Actions, LowerToInfo &Info) PragmaLowerToHandler(LowerToInfo &Info)
: PragmaHandler("lower_to"), Actions(Actions), Info(Info) {} : PragmaHandler("lower_to"), Info(Info) {}
/// The pragma handler will extract the single argument to the lower_to(...) /// The pragma handler will extract the single argument to the lower_to(...)
/// pragma definition, which is the target MLIR function symbol, and relate /// pragma definition, which is the target MLIR function symbol, and relate
@ -58,14 +56,12 @@ public:
assert(SymbolTok.is(tok::string_literal) && assert(SymbolTok.is(tok::string_literal) &&
"The second argument of lower_to should be a string literal."); "The second argument of lower_to should be a string literal.");
SymbolToks.push_back(SymbolTok); SymbolToks.push_back(SymbolTok);
clang::StringLiteral *SymbolName = cast<clang::StringLiteral>( StringRef SymbolName = StringLiteralParser(SymbolToks, PP).GetString();
Actions.ActOnStringLiteral(SymbolToks).get());
PP.Lex(Tok); // rparen PP.Lex(Tok); // rparen
assert(Tok.is(tok::r_paren) && "lower_to should end with '('."); assert(Tok.is(tok::r_paren) && "lower_to should end with '('.");
// Link SymbolName with the function. // Link SymbolName with the function.
auto result = Info.SymbolTable.try_emplace(FuncId, SymbolName->getString()); auto result = Info.SymbolTable.try_emplace(FuncId, SymbolName);
assert(result.second && assert(result.second &&
"Shouldn't define lower_to over the same func id more than once."); "Shouldn't define lower_to over the same func id more than once.");
} }
@ -75,7 +71,6 @@ private:
} // namespace } // namespace
void addPragmaLowerToHandlers(Preprocessor &PP, Sema &Actions, void addPragmaLowerToHandlers(Preprocessor &PP, LowerToInfo &LTInfo) {
LowerToInfo &LTInfo) { PP.AddPragmaHandler(new PragmaLowerToHandler(LTInfo));
PP.AddPragmaHandler(new PragmaLowerToHandler(Actions, LTInfo));
} }

View File

@ -11,7 +11,6 @@ struct LowerToInfo {
llvm::StringMap<std::string> SymbolTable; llvm::StringMap<std::string> SymbolTable;
}; };
void addPragmaLowerToHandlers(clang::Preprocessor &PP, clang::Sema &Actions, void addPragmaLowerToHandlers(clang::Preprocessor &PP, LowerToInfo &LTInfo);
LowerToInfo &LTInfo);
#endif #endif