@@ -45,15 +45,12 @@ ExpressionOp createExpression(Operation *op, OpBuilder &builder) {
45
45
ClassOp createClass (FuncOp funcOp, OpBuilder &builder) {
46
46
builder.setInsertionPoint (funcOp);
47
47
48
- // 2. Create the class
49
48
auto classOp = builder.create <emitc::ClassOp>(
50
49
funcOp.getLoc (), builder.getStringAttr (" MyModelClass" ));
51
50
52
- // Create a block inside the class body and set insertion point
53
51
builder.createBlock (&classOp.getBody ());
54
52
builder.setInsertionPointToStart (&classOp.getBody ().front ());
55
53
56
- // 3. Extract input/output names from function arguments
57
54
SmallVector<std::pair<StringRef, Type>> fields;
58
55
llvm::SmallDenseMap<Value, Value> argToFieldMap;
59
56
@@ -68,25 +65,26 @@ ClassOp createClass(FuncOp funcOp, OpBuilder &builder) {
68
65
.getElementType ()));
69
66
fields.push_back ({fieldName.str (), fieldType});
70
67
71
- // 4.Create the class fields
72
68
auto typeAttr = TypeAttr::get (val.getType ());
73
69
mlir::Attribute emptyAttr = builder.getAttr <mlir::UnitAttr>();
74
70
auto dictAttr = DictionaryAttr::get (
75
71
builder.getContext (),
76
72
{builder.getNamedAttr (fieldName.str (), emptyAttr)});
77
73
builder.create <emitc::FieldOp>(funcOp.getLoc (), fieldName, typeAttr,
78
74
/* attributes*/ dictAttr);
79
- // 5. Get the pointers to the class fields
80
- auto pointer = emitc::PointerType::get (
81
- dyn_cast_or_null<emitc::ArrayType>(val.getType ()).getElementType ());
82
- auto ptr = builder.create <emitc::GetFieldOp>(
83
- funcOp.getLoc (), pointer, val, " MyModelClass" , fieldName);
84
- argToFieldMap[val] = ptr;
75
+
76
+ // TODO: From my current understanding, we need to instantiate a class
77
+ // so we can get the pointers from .field but we can't do that in here
78
+ // so I'm unsure how I can rewrite the following line to ensure
79
+ // GetFieldOp works correctly. auto pointer =
80
+ // emitc::PointerType::get(dyn_cast_or_null<emitc::ArrayType>(val.getType()).getElementType());
81
+ // auto ptr = builder.create<emitc::GetFieldOp>(funcOp.getLoc(),
82
+ // pointer, val, "MyModelClass", fieldName);
83
+ argToFieldMap[val] = nullptr ;
85
84
}
86
85
}
87
86
}
88
87
89
- // Create the new function inside the class
90
88
auto funcContext = funcOp.getContext ();
91
89
auto inputTypes = funcOp.getFunctionType ().getInputs ();
92
90
auto results = funcOp.getFunctionType ().getResults ();
@@ -98,10 +96,8 @@ ClassOp createClass(FuncOp funcOp, OpBuilder &builder) {
98
96
builder.createBlock (&newFuncOp.getBody ());
99
97
builder.setInsertionPointToStart (&newFuncOp.getBody ().front ());
100
98
101
- // 7. Remap original arguments to field pointers
102
99
IRMapping mapper;
103
100
104
- // 8. move or clone operations from original function
105
101
auto body = llvm::make_early_inc_range (funcOp.getBody ().front ());
106
102
for (Operation &opToClone : body) {
107
103
if (isa<emitc::ConstantOp>(opToClone) ||
@@ -114,7 +110,8 @@ ClassOp createClass(FuncOp funcOp, OpBuilder &builder) {
114
110
}
115
111
}
116
112
117
- // if (funcOp->use_empty()) funcOp->erase();
113
+ // TODO: Need to erase the funcOp after all this. Using funcOp->erase raises
114
+ // errors:
118
115
119
116
return classOp;
120
117
}
0 commit comments