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 "llvm/ADT/StringRef.h" |
11 | |
12 | namespace mlir::amdgpu { |
13 | |
14 | FailureOr<Chipset> Chipset::parse(StringRef name) { |
15 | if (!name.consume_front(Prefix: "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(N: 2); |
25 | StringRef minorRef = name.take_back(N: 2).drop_back(N: 1); |
26 | StringRef steppingRef = name.take_back(N: 1); |
27 | if (majorRef.getAsInteger(Radix: 10, Result&: major)) |
28 | return failure(); |
29 | if (minorRef.getAsInteger(Radix: 16, Result&: minor)) |
30 | return failure(); |
31 | if (steppingRef.getAsInteger(Radix: 16, Result&: stepping)) |
32 | return failure(); |
33 | return Chipset(major, minor, stepping); |
34 | } |
35 | |
36 | } // namespace mlir::amdgpu |
37 |