Files
clang-p2996/mlir/lib/Dialect/AMDGPU/Utils/Chipset.cpp
Jakub Kuderski 763bc9249c [mlir][amdgpu] Align Chipset with TargetParser (#107720)
Update the Chipset struct to follow the `IsaVersion` definition from
llvm's `TargetParser`. This is a follow up to
https://github.com/llvm/llvm-project/pull/106169#discussion_r1733955012.

* Add the stepping version. Note: This may break downstream code that
compares against the minor version directly.
* Use comparisons with full Chipset version where possible.

Note that we can't use the code in `TargetParser` directly because the
chipset utility is outside of `mlir/Target` that re-exports llvm's
target library.
2024-09-09 11:12:26 -04:00

37 lines
1.1 KiB
C++

//===- Chipset.cpp - AMDGPU Chipset version struct parsing ----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/AMDGPU/Utils/Chipset.h"
#include "llvm/ADT/StringRef.h"
namespace mlir::amdgpu {
FailureOr<Chipset> Chipset::parse(StringRef name) {
if (!name.consume_front("gfx"))
return failure();
if (name.size() < 3)
return failure();
unsigned major = 0;
unsigned minor = 0;
unsigned stepping = 0;
StringRef majorRef = name.drop_back(2);
StringRef minorRef = name.take_back(2).drop_back(1);
StringRef steppingRef = name.take_back(1);
if (majorRef.getAsInteger(10, major))
return failure();
if (minorRef.getAsInteger(16, minor))
return failure();
if (steppingRef.getAsInteger(16, stepping))
return failure();
return Chipset(major, minor, stepping);
}
} // namespace mlir::amdgpu