Skip to content

Commit

Permalink
Trying to get access to MLIRABC in Python Frontend. WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Miro-H committed Dec 8, 2021
1 parent 7eb48a6 commit eccc343
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,4 @@ if(PYTHON_FRONTEND_BUILD)
endif()
add_subdirectory(python)
endif()

15 changes: 8 additions & 7 deletions include/ast_opt/visitor/MLIRTransformVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SpecialMLIRTransformVisitor : public PlainVisitor {
mlir::OpBuilder builder;
// TODO: change to mlir::OwningModuleRef
mlir::FloatAttr module;
mlir::Attribute attr;

public:
explicit SpecialMLIRTransformVisitor(mlir::FloatAttr module, mlir::MLIRContext &context);
Expand Down Expand Up @@ -54,10 +55,10 @@ class SpecialMLIRTransformVisitor : public PlainVisitor {
// void visit(LiteralChar &elem);
//
// void visit(LiteralInt &elem);

void visit(LiteralFloat &elem);

// void visit(LiteralDouble &elem);
//
// void visit(LiteralFloat &elem);
//
void visit(LiteralDouble &elem);
//
// void visit(LiteralString &elem);
//
Expand All @@ -70,9 +71,9 @@ class SpecialMLIRTransformVisitor : public PlainVisitor {
// void visit(UnaryExpression &elem);
//
// void visit(Assignment &elem);
//
// void visit(VariableDeclaration &elem);
//

void visit(VariableDeclaration &elem);

// void visit(Variable &elem);

};
Expand Down
13 changes: 6 additions & 7 deletions python/pyabc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@ set_target_properties(
# XXX: Add libraries used in python wrapper here
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)

set(LIBS
ast_opt
${dialect_libs}
${conversion_libs}
# MLIRArithmetic
# MLIROptLib
# MLIRAnalysis
MLIRIR
# MLIRParser
# MLIRSideEffectInterfaces
# MLIRTransforms
MLIRABC
)

llvm_update_compile_flags(pyabc)
target_link_libraries(pyabc
PRIVATE
${LIBS}
Expand All @@ -51,3 +47,6 @@ target_link_options(pyabc
$<$<PLATFORM_ID:Linux>:LINKER:--exclude-libs,ALL>
)

mlir_check_all_link_libraries(pyabc)


1 change: 0 additions & 1 deletion python/pyabc/abc_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class ABCProgramWrapper {

MLIRTransformVisitor v(module, context);
programAst->accept(v);
module.dump();

// TODO: where can we mark arguments as secret? The args argument has a boolen for those that should be secret, but do
// we have to already mark them while/before parsing the AST or only when executing?
Expand Down
17 changes: 15 additions & 2 deletions src/visitor/MLIRTransformVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
#include "ast_opt/ast/Literal.h"
#include "ast_opt/visitor/MLIRTransformVisitor.h"

#include "ABCDialect.h"

using namespace mlir;
using namespace abc;

SpecialMLIRTransformVisitor::SpecialMLIRTransformVisitor(mlir::FloatAttr module,
mlir::MLIRContext &context) : builder(&context) {}

void SpecialMLIRTransformVisitor::visit(LiteralFloat &elem) {
module = builder.getF32FloatAttr(elem.getValue());
void SpecialMLIRTransformVisitor::visit(LiteralDouble &elem) {
attr = builder.getF32FloatAttr(elem.getValue());
}

void SpecialMLIRTransformVisitor::visit(VariableDeclaration &elem) {
if (elem.hasTarget()) {
auto id = elem.getTarget().getIdentifier();
auto val = 5; //SpecialMLIRTransformVisitor::visit(elem.getValue());
ABC_VariableDeclarationOp(id, val);
}
}
5 changes: 3 additions & 2 deletions test/python_frontend/test_mlir_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def test_mlir_constant_float():

with ABCContext(p, logging.DEBUG):
def main():
return 1.0
r = 10.0
return r

r = p.execute()
assert r == 1.0
assert r == 2.0

0 comments on commit eccc343

Please sign in to comment.