| 148 | } // anonymous namespace |
| 149 | |
| 150 | std::string OpOrArgLocNameMapper::GetName(OpOrVal op_or_val) { |
| 151 | if (auto* op = op_or_val.dyn_cast<mlir::Operation*>()) { |
| 152 | auto name_from_loc = GetNameFromLoc(op->getLoc()); |
| 153 | if (!name_from_loc.empty()) return name_from_loc; |
| 154 | // If the location is none of the expected types, then simply use name |
| 155 | // generated using the op type. |
| 156 | return std::string(op->getName().getStringRef()); |
| 157 | } |
| 158 | auto val = op_or_val.dyn_cast<mlir::Value>(); |
| 159 | auto name_from_loc = GetNameFromLoc(val.getLoc()); |
| 160 | if (!name_from_loc.empty()) return name_from_loc; |
| 161 | // If the location is none of the expected types, then simply use name |
| 162 | // generated using the op type. Follow TF convention and append the result |
| 163 | // index unless 0. |
| 164 | if (auto result = val.dyn_cast<mlir::OpResult>()) { |
| 165 | if (result.getResultNumber() > 0) |
| 166 | return llvm::formatv("{0}:{1}", |
| 167 | result.getOwner()->getName().getStringRef(), |
| 168 | result.getResultNumber()); |
| 169 | return std::string(result.getOwner()->getName().getStringRef()); |
| 170 | } |
| 171 | // Use the ASM syntax for BloackArgument |
| 172 | if (auto arg = val.dyn_cast<mlir::BlockArgument>()) { |
| 173 | return "arg" + std::to_string(arg.getArgNumber()); |
| 174 | } |
| 175 | return ""; |
| 176 | } |
| 177 | |
| 178 | std::string OpOrArgStripNameMapper::GetName(OpOrVal op_or_val) { |
| 179 | return llvm::APInt(32, count_++).toString(/*Radix=*/36, /*Signed=*/false); |
no test coverage detected