MLIR  20.0.0git
Chipset.cpp
Go to the documentation of this file.
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 
10 #include "llvm/ADT/StringRef.h"
11 
12 namespace mlir::amdgpu {
13 
14 FailureOr<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::amdgpu
static FailureOr< Chipset > parse(StringRef name)
Parses the chipset version string and returns the chipset on success, and failure otherwise.
Definition: Chipset.cpp:14
constexpr Chipset()=default