37 lines · cpp
1//===- Chipset.cpp - AMDGPU Chipset version struct parsing ----------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/Dialect/AMDGPU/Utils/Chipset.h"10#include "llvm/ADT/StringRef.h"11 12namespace mlir::amdgpu {13 14FailureOr<Chipset> Chipset::parse(StringRef name) {15 if (!name.consume_front("gfx"))16 return failure();17 if (name.size() < 3)18 return failure();19 20 unsigned major = 0;21 unsigned minor = 0;22 unsigned stepping = 0;23 24 StringRef majorRef = name.drop_back(2);25 StringRef minorRef = name.take_back(2).drop_back(1);26 StringRef steppingRef = name.take_back(1);27 if (majorRef.getAsInteger(10, major))28 return failure();29 if (minorRef.getAsInteger(16, minor))30 return failure();31 if (steppingRef.getAsInteger(16, stepping))32 return failure();33 return Chipset(major, minor, stepping);34}35 36} // namespace mlir::amdgpu37