141 std::tuple<OperationPropertyTs...> opProps,
142 std::tuple<OperatorTypePropertyTs...> oprProps,
143 std::tuple<DependencePropertyTs...> depProps,
144 std::tuple<InstancePropertyTs...> instProps) {
145 ProblemT prob(instOp);
148 prob, instOp.getSspPropertiesAttr());
149 if (
auto instName = instOp.getSymNameAttr())
150 prob.setInstanceName(instName);
160 auto libraryOp = instOp.getOperatorLibrary();
161 libraryOp.walk([&](OperatorTypeOp oprOp) {
162 operatorTypes[oprOp] =
166 if (
auto libName = libraryOp.getSymNameAttr())
167 prob.setLibraryName(libName);
170 auto graphOp = instOp.getDependenceGraph();
171 graphOp.walk([&](OperationOp opOp) {
172 prob.insertOperation(opOp);
174 prob, opOp, opOp.getSspPropertiesAttr());
175 if (
auto opName = opOp.getSymNameAttr())
176 prob.setOperationName(opOp, opName);
181 if (!prob.getLinkedOperatorType(opOp).has_value())
186 SymbolRefAttr oprRef = opOp.getLinkedOperatorTypeAttr().getValue();
190 oprOp = SymbolTable::lookupSymbolIn(libraryOp, oprRef);
193 oprOp = SymbolTable::lookupSymbolIn(instOp, oprRef);
197 SymbolTable::lookupNearestSymbolFrom(instOp->getParentOp(), oprRef);
199 assert(oprOp && isa<OperatorTypeOp>(oprOp));
202 auto &opr = operatorTypes[oprOp];
205 prob, cast<OperatorTypeOp>(oprOp), operatorTypeIds);
208 prob.setLinkedOperatorType(opOp, opr);
213 graphOp.walk([&](OperationOp opOp) {
214 ArrayAttr depsAttr = opOp.getDependencesAttr();
218 for (
auto depAttr : depsAttr.getAsRange<DependenceAttr>()) {
220 if (FlatSymbolRefAttr sourceRef = depAttr.getSourceRef()) {
221 Operation *sourceOp = SymbolTable::lookupSymbolIn(graphOp, sourceRef);
224 LogicalResult res = prob.insertDependence(dep);
228 dep =
Dependence(&opOp->getOpOperand(depAttr.getOperandIdx()));
231 prob, dep, depAttr.getProperties());
320saveProblem(ProblemT &prob, std::tuple<OperationPropertyTs...> opProps,
321 std::tuple<OperatorTypePropertyTs...> oprProps,
322 std::tuple<DependencePropertyTs...> depProps,
323 std::tuple<InstancePropertyTs...> instProps, OpBuilder &builder) {
324 ImplicitLocOpBuilder b(builder.getUnknownLoc(), builder);
327 auto instOp = b.create<InstanceOp>(
328 builder.getStringAttr(ProblemT::name),
330 if (
auto instName = prob.getInstanceName())
331 instOp.setSymNameAttr(instName);
334 b.setInsertionPointToEnd(instOp.getBodyBlock());
335 auto libraryOp = b.create<OperatorLibraryOp>();
336 if (
auto libName = prob.getLibraryName())
337 libraryOp.setSymNameAttr(libName);
338 b.setInsertionPointToStart(libraryOp.getBodyBlock());
340 for (
auto opr : prob.getOperatorTypes())
341 b.create<OperatorTypeOp>(
342 opr, saveOperatorTypeProperties<ProblemT, OperatorTypePropertyTs...>(
347 DenseMap<Operation *, StringAttr> opNames;
348 for (
auto *op : prob.getOperations()) {
349 if (
auto opName = prob.getOperationName(op))
350 opNames[op] = opName;
352 for (
auto &dep : prob.getDependences(op)) {
353 Operation *src = dep.getSource();
354 if (!dep.isAuxiliary() || opNames.count(src))
356 if (
auto srcOpName = prob.getOperationName(src)) {
357 opNames[src] = srcOpName;
360 opNames[src] = b.getStringAttr(Twine(
"Op") + Twine(opNames.size()));
365 b.setInsertionPointToEnd(instOp.getBodyBlock());
366 auto graphOp = b.create<DependenceGraphOp>();
367 b.setInsertionPointToStart(graphOp.getBodyBlock());
371 for (
auto *op : prob.getOperations()) {
374 ArrayAttr dependences;
375 SmallVector<Attribute> depAttrs;
376 unsigned auxOperandIdx = op->getNumOperands();
377 for (
auto &dep : prob.getDependences(op)) {
381 if (dep.isDefUse() && depProps) {
382 auto depAttr = b.getAttr<DependenceAttr>(*dep.getDestinationIndex(),
383 FlatSymbolRefAttr(), depProps);
384 depAttrs.push_back(depAttr);
388 if (!dep.isAuxiliary())
391 auto sourceOpName = opNames.lookup(dep.getSource());
393 auto sourceRef = b.getAttr<FlatSymbolRefAttr>(sourceOpName);
395 b.getAttr<DependenceAttr>(auxOperandIdx, sourceRef, depProps);
396 depAttrs.push_back(depAttr);
399 if (!depAttrs.empty())
400 dependences = b.getArrayAttr(depAttrs);
403 ArrayAttr properties =
410 b.create<OperationOp>(op->getNumResults(), v.
get(op->getOperands()),
411 opNames.lookup(op), dependences, properties);
412 v.
set(op->getResults(), opOp->getResults());
ProblemT loadProblem(InstanceOp instOp, std::tuple< OperationPropertyTs... > opProps, std::tuple< OperatorTypePropertyTs... > oprProps, std::tuple< DependencePropertyTs... > depProps, std::tuple< InstancePropertyTs... > instProps)
Construct an instance of ProblemT from instOp, and attempt to set properties from the given attribute...
InstanceOp saveProblem(ProblemT &prob, std::tuple< OperationPropertyTs... > opProps, std::tuple< OperatorTypePropertyTs... > oprProps, std::tuple< DependencePropertyTs... > depProps, std::tuple< InstancePropertyTs... > instProps, OpBuilder &builder)
Construct an InstanceOp from a given ProblemT instance, and create/attach attributes of the given cla...