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/Conversion/AMDGPUToROCDL/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.startswith("gfx")) 18 return failure(); 19 unsigned major = 0; 20 unsigned minor = 0; 21 StringRef majorRef = name.drop_front(3).drop_back(2); 22 StringRef minorRef = name.take_back(2); 23 if (majorRef.getAsInteger(10, major)) 24 return failure(); 25 if (minorRef.getAsInteger(16, minor)) 26 return failure(); 27 return Chipset(major, minor); 28 } 29