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-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "mlir/Dialect/AMDGPU/Utils/Chipset.h" |
10 | #include "mlir/Support/LLVM.h" |
11 | #include "llvm/ADT/StringRef.h" |
12 | |
13 | using namespace mlir; |
14 | using namespace mlir::amdgpu; |
15 | |
16 | FailureOr<Chipset> Chipset::parse(StringRef name) { |
17 | if (!name.starts_with(Prefix: "gfx")) |
18 | return failure(); |
19 | unsigned major = 0; |
20 | unsigned minor = 0; |
21 | StringRef majorRef = name.drop_front(N: 3).drop_back(N: 2); |
22 | StringRef minorRef = name.take_back(N: 2); |
23 | if (majorRef.getAsInteger(Radix: 10, Result&: major)) |
24 | return failure(); |
25 | if (minorRef.getAsInteger(Radix: 16, Result&: minor)) |
26 | return failure(); |
27 | return Chipset(major, minor); |
28 | } |
29 |