@@ -99,9 +99,10 @@ static constexpr tosa_level_t TOSA_LEVEL_NONE = {0, 0, 0, 0};
9999struct TosaValidation : public tosa ::impl::TosaValidationBase<TosaValidation> {
100100public:
101101 explicit TosaValidation () { populateConstantOperandChecks (); }
102- explicit TosaValidation (const ValidationOptions &options) : TosaValidation() {
102+ explicit TosaValidation (const TosaValidationOptions &options)
103+ : TosaValidation() {
103104 this ->profile = options.profile ;
104- this ->StrictOperationSpecAlignment = options.strictOperationSpecAlignment ;
105+ this ->StrictOperationSpecAlignment = options.StrictOperationSpecAlignment ;
105106 this ->level = options.level ;
106107 }
107108 void runOnOperation () final ;
@@ -409,7 +410,7 @@ struct TosaValidation : public tosa::impl::TosaValidationBase<TosaValidation> {
409410
410411 SmallVector<std::function<LogicalResult(Operation *)>> const_checkers;
411412 tosa_level_t tosa_level;
412- std::unordered_map<std::string , mlir::Type> variables_map;
413+ DenseMap< const mlir::StringAttr * , mlir::Type> variables_map;
413414};
414415
415416LogicalResult TosaValidation::applyLevelCheck (Operation *op) {
@@ -445,26 +446,17 @@ inline bool CompatibleTypes(const mlir::Type &type,
445446
446447bool TosaValidation::CheckVariable (Operation *op) {
447448 if (isa<mlir::tosa::VariableOp>(op)) {
448- auto name_attr = dyn_cast<mlir::StringAttr>(op->getAttr (" name" ));
449- if (!name_attr) {
450- op->emitOpError () << " Name attribute is not StringAttr" ;
451- return false ;
452- }
453- std::string name = name_attr.getValue ().str ();
449+ auto name_attr = cast<mlir::StringAttr>(op->getAttr (" name" ));
454450
455- if (variables_map.count (name )) {
451+ if (variables_map.count (&name_attr )) {
456452 op->emitOpError () << " name has already been declared" ;
457453 return false ;
458454 }
459455
460- auto type_attr = dyn_cast<mlir::TypeAttr>(op->getAttr (" type" ));
461- if (!type_attr) {
462- op->emitOpError () << " type attribute is not TypeAttr" ;
463- return false ;
464- }
456+ auto type_attr = cast<mlir::TypeAttr>(op->getAttr (" type" ));
465457 mlir::Type type = type_attr.getValue ();
466458
467- variables_map[name ] = type;
459+ variables_map[&name_attr ] = type;
468460 }
469461
470462 return true ;
@@ -473,19 +465,14 @@ bool TosaValidation::CheckVariable(Operation *op) {
473465bool TosaValidation::CheckVariableReadOrWrite (Operation *op) {
474466 if (isa<mlir::tosa::VariableReadOp>(op) ||
475467 isa<mlir::tosa::VariableWriteOp>(op)) {
476- auto name_attr = dyn_cast<mlir::FlatSymbolRefAttr>(op->getAttr (" name" ));
477- if (!name_attr) {
478- op->emitOpError () << " name attribute is not FlatSymbolRefAttr" ;
479- return false ;
480- }
481- std::string name = name_attr.getValue ().str ();
468+ auto name_attr = cast<mlir::StringAttr>(op->getAttr (" name" ));
482469
483- if (!variables_map.count (name )) {
470+ if (!variables_map.count (&name_attr )) {
484471 op->emitOpError () << " name has not been declared" ;
485472 return false ;
486473 }
487474
488- auto var_type = variables_map[name ];
475+ auto var_type = variables_map[&name_attr ];
489476
490477 for (auto v : op->getOperands ()) {
491478 auto type = v.getType ();
@@ -542,8 +529,3 @@ void TosaValidation::runOnOperation() {
542529 });
543530}
544531} // namespace
545-
546- std::unique_ptr<OperationPass<ModuleOp>>
547- mlir::tosa::createTosaValidationPass (ValidationOptions const &options) {
548- return std::make_unique<TosaValidation>(options);
549- }
0 commit comments