[Mlir-commits] [mlir] Unify handling of operations which are emitted in a deferred way (PR #97804)
Gil Rapaport
llvmlistbot at llvm.org
Fri Jul 5 13:09:01 PDT 2024
================
@@ -1134,20 +1127,41 @@ std::string CppEmitter::getSubscriptName(emitc::SubscriptOp op) {
return out;
}
+LogicalResult CppEmitter::cacheDeferredOpResult(Operation *op) {
+ if (op->getNumResults() != 1)
+ return op->emitError("Adding deferred ops into value cache only works for "
+ "single result operations, got ")
+ << op->getNumResults() << " results";
+
+ Value result = op->getResult(0);
+ if (valueMapper.count(result))
+ return success();
+
+ if (auto getGlobal = dyn_cast<emitc::GetGlobalOp>(op)) {
+ valueMapper.insert(result, getGlobal.getName().str());
+ return success();
+ }
+
+ if (auto literal = dyn_cast<emitc::LiteralOp>(op)) {
+ valueMapper.insert(result, literal.getValue().str());
+ return success();
+ }
+
+ if (auto subscript = dyn_cast<emitc::SubscriptOp>(op)) {
+ valueMapper.insert(result, getSubscriptName(subscript));
+ return success();
+ }
+
+ return op->emitError("cacheDeferredOpResult not implemented");
+}
+
----------------
aniragil wrote:
```suggestion
LogicalResult CppEmitter::cacheDeferredOpResult(Value result, std::string str) {
if (!valueMapper.count(result))
valueMapper.insert(result, str);
return success();
}
```
https://github.com/llvm/llvm-project/pull/97804
More information about the Mlir-commits
mailing list