tensorflow/compiler/mlir/quantization/tensorflow/utils/lift_as_function_call_utils.cc
// Finds the name of each attribute in `attributes` and set the attr_map
// attribute which maps an attribute identifier to its attribute name. The
// identifier is the order of that attribute in `attributes`. This map
// is then used to set attributes in the quantized functions in the
// QuantizeCompositeFunctionsPass.
// This function returns success if all attributes could be found.
Finds the name of each attribute in `attributes` and set the attr_map
attribute which maps an attribute identifier to its attribute name. The
identifier is the order of that attribute in `attributes`. This map
is then used to set attributes in the quantized functions in the
QuantizeCompositeFunctionsPass.
This function returns success if all attributes could be found.
Finds the name of each attribute in ` attributes ` and set the attr_map attribute which maps an attribute identifier to its attribute name . The identifier is the order of that attribute in ` attributes ` . This map is then used to set attributes in the quantized functions in the QuantizeCompositeFunctionsPass . This function returns success if all attributes could be found .
LogicalResult SetAttributeMap(MLIRContext *context,
                              const llvm::SmallVector<Attribute> &attributes,
                              const llvm::SmallVector<Operation *> &ops) {
  llvm::SmallDenseMap<Attribute, Operation *> attr_to_op_map;
  llvm::SmallDenseMap<Attribute, llvm::StringRef> attr_to_name_map;
  for (Operation *op : ops) {
    for (const auto &named_attr : op->getAttrs()) {
      attr_to_op_map.insert({named_attr.getValue(), op});
      attr_to_name_map.insert(
          {named_attr.getValue(), named_attr.getName().getValue()});
    }
  }
  for (int idx : llvm::seq<int>(0, attributes.size())) {
    const Attribute &attribute = attributes[idx];
    auto string_attr = attribute.dyn_cast_or_null<StringAttr>();
    if (string_attr != nullptr &&
        string_attr.getValue().equals(kNullAttributeValue)) {
      continue;
    }
    if (attr_to_op_map.count(attribute) == 0) {
      return failure();
    }
    llvm::StringRef attribute_name = attr_to_name_map[attribute];
    std::string identifier = std::to_string(idx);
    Operation *owner_op = attr_to_op_map[attribute];
    std::string new_attr_map_str;
    if (owner_op->hasAttr(kAttrMapAttribute)) {
      new_attr_map_str =
          owner_op->getAttrOfType<StringAttr>(kAttrMapAttribute).str();
      absl::StrAppend(&new_attr_map_str, ",");
    }
    absl::StrAppend(&new_attr_map_str, identifier, ":", attribute_name.str());
    owner_op->setAttr(kAttrMapAttribute,
                      StringAttr::get(context, new_attr_map_str));
  }
  return success();
}
LogicalResult SetAttributeMap ( MLIRContext * context , const llvm :: SmallVector < Attribute > & attributes , const llvm :: SmallVector < Operation * > & ops ) { llvm :: SmallDenseMap < Attribute , Operation * > attr_to_op_map ; llvm :: SmallDenseMap < Attribute , llvm :: StringRef > attr_to_name_map ; for ( Operation * op : ops ) { for ( const auto & named_attr : op -> getAttrs ( ) ) { attr_to_op_map . insert ( { named_attr . getValue ( ) , op } ) ; attr_to_name_map . insert ( { named_attr . getValue ( ) , named_attr . getName ( ) . getValue ( ) } ) ; } } for ( int idx : llvm :: seq < int > ( 0 , attributes . size ( ) ) ) { const Attribute & attribute = attributes [ idx ] ; auto string_attr = attribute . dyn_cast_or_null < StringAttr > ( ) ; if ( string_attr != nullptr && string_attr . getValue ( ) . equals ( kNullAttributeValue ) ) { continue ; } if ( attr_to_op_map . count ( attribute ) == 0 ) { return failure ( ) ; } llvm :: StringRef attribute_name = attr_to_name_map [ attribute ] ; std :: string identifier = std :: to_string ( idx ) ; Operation * owner_op = attr_to_op_map [ attribute ] ; std :: string new_attr_map_str ; if ( owner_op -> hasAttr ( kAttrMapAttribute ) ) { new_attr_map_str = owner_op -> getAttrOfType < StringAttr > ( kAttrMapAttribute ) . str ( ) ; absl :: StrAppend ( & new_attr_map_str , " " ) ; } absl :: StrAppend ( & new_attr_map_str , identifier , " " , attribute_name . str ( ) ) ; owner_op -> setAttr ( kAttrMapAttribute , StringAttr :: get ( context , new_attr_map_str ) ) ; } return success ( ) ; }
Finds the name of each attribute in `attributes` and set the attr_map
attribute which maps an attribute identifier to its attribute name.
Finds the name of each attribute in ` attributes ` and set the attr_map attribute which maps an attribute identifier to its attribute name .
// A map to find which operation an attribute belongs to. // A map from the attribute to its name. // Skip following steps if this attribute is a `NullAttribute`.