@@ -46,15 +46,12 @@ ExpressionOp createExpression(Operation *op, OpBuilder &builder) {
4646ClassOp createClass (FuncOp funcOp, OpBuilder &builder) {
4747 builder.setInsertionPoint (funcOp);
4848
49- // 2. Create the class
5049 auto classOp = builder.create <emitc::ClassOp>(
5150 funcOp.getLoc (), builder.getStringAttr (" MyModelClass" ));
5251
53- // Create a block inside the class body and set insertion point
5452 builder.createBlock (&classOp.getBody ());
5553 builder.setInsertionPointToStart (&classOp.getBody ().front ());
5654
57- // 3. Extract input/output names from function arguments
5855 SmallVector<std::pair<StringRef, Type>> fields;
5956 llvm::SmallDenseMap<Value, Value> argToFieldMap;
6057
@@ -69,25 +66,26 @@ ClassOp createClass(FuncOp funcOp, OpBuilder &builder) {
6966 .getElementType ()));
7067 fields.push_back ({fieldName.str (), fieldType});
7168
72- // 4.Create the class fields
7369 auto typeAttr = TypeAttr::get (val.getType ());
7470 mlir::Attribute emptyAttr = builder.getAttr <mlir::UnitAttr>();
7571 auto dictAttr = DictionaryAttr::get (
7672 builder.getContext (),
7773 {builder.getNamedAttr (fieldName.str (), emptyAttr)});
7874 builder.create <emitc::FieldOp>(funcOp.getLoc (), fieldName, typeAttr,
7975 /* attributes*/ dictAttr);
80- // 5. Get the pointers to the class fields
81- auto pointer = emitc::PointerType::get (
82- dyn_cast_or_null<emitc::ArrayType>(val.getType ()).getElementType ());
83- auto ptr = builder.create <emitc::GetFieldOp>(
84- funcOp.getLoc (), pointer, val, " MyModelClass" , fieldName);
85- argToFieldMap[val] = ptr;
76+
77+ // TODO: From my current understanding, we need to instantiate a class
78+ // so we can get the pointers from .field but we can't do that in here
79+ // so I'm unsure how I can rewrite the following line to ensure
80+ // GetFieldOp works correctly. auto pointer =
81+ // emitc::PointerType::get(dyn_cast_or_null<emitc::ArrayType>(val.getType()).getElementType());
82+ // auto ptr = builder.create<emitc::GetFieldOp>(funcOp.getLoc(),
83+ // pointer, val, "MyModelClass", fieldName);
84+ argToFieldMap[val] = nullptr ;
8685 }
8786 }
8887 }
8988
90- // Create the new function inside the class
9189 auto funcContext = funcOp.getContext ();
9290 auto inputTypes = funcOp.getFunctionType ().getInputs ();
9391 auto results = funcOp.getFunctionType ().getResults ();
@@ -99,10 +97,8 @@ ClassOp createClass(FuncOp funcOp, OpBuilder &builder) {
9997 builder.createBlock (&newFuncOp.getBody ());
10098 builder.setInsertionPointToStart (&newFuncOp.getBody ().front ());
10199
102- // 7. Remap original arguments to field pointers
103100 IRMapping mapper;
104101
105- // 8. move or clone operations from original function
106102 auto body = llvm::make_early_inc_range (funcOp.getBody ().front ());
107103 for (Operation &opToClone : body) {
108104 if (isa<emitc::ConstantOp>(opToClone) ||
@@ -115,7 +111,8 @@ ClassOp createClass(FuncOp funcOp, OpBuilder &builder) {
115111 }
116112 }
117113
118- // if (funcOp->use_empty()) funcOp->erase();
114+ // TODO: Need to erase the funcOp after all this. Using funcOp->erase raises
115+ // errors:
119116
120117 return classOp;
121118}
0 commit comments