This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 876f52805d [LLVM] Stringref API deprecation fixes (#16968)
876f52805d is described below
commit 876f52805d3184d6d8b05439e9c9578687b6ae77
Author: Anirudh Sundar Subramaniam <[email protected]>
AuthorDate: Mon May 6 17:36:15 2024 +0530
[LLVM] Stringref API deprecation fixes (#16968)
The `startswith`/`endswith` functions in `StringRef` API were
[changed](https://reviews.llvm.org/D136030) to
`starts_with` and `ends_with` to be compatible with `std::string` and
the older APIs were deprecated and removed.
---
src/target/llvm/codegen_hexagon.cc | 11 +++++++++++
src/target/llvm/codegen_llvm.cc | 4 ++++
src/target/llvm/llvm_instance.cc | 4 ++++
3 files changed, 19 insertions(+)
diff --git a/src/target/llvm/codegen_hexagon.cc
b/src/target/llvm/codegen_hexagon.cc
index 6ef5e064c0..5113957aa1 100644
--- a/src/target/llvm/codegen_hexagon.cc
+++ b/src/target/llvm/codegen_hexagon.cc
@@ -126,9 +126,16 @@ void CodeGenHexagon::InitTarget() {
const auto hvx_length_feature = "+hvx-length"; // +hvx-length{64|128}b
for (const std::string& f : llvm_target_->GetTargetFeatures()) {
llvm::StringRef fs(f);
+#if TVM_LLVM_VERSION >= 180
+ if (!fs.starts_with(hvx_length_feature)) continue;
+
+ ICHECK(fs.ends_with("b")) << "malformed target feature: " << f;
+#else
if (!fs.startswith(hvx_length_feature)) continue;
ICHECK(fs.endswith("b")) << "malformed target feature: " << f;
+#endif
+
int hvx_bytes = 0;
size_t len_begin = std::strlen(hvx_length_feature);
ICHECK(!fs.substr(len_begin, fs.size() - len_begin - 1).getAsInteger(10,
hvx_bytes))
@@ -639,7 +646,11 @@ runtime::Module BuildHexagon(IRModule mod, Target target) {
Map<String, String> extra_args;
if (target->attrs.count("mcpu")) {
std::string mcpu = Downcast<String>(target->attrs.at("mcpu"));
+#if TVM_LLVM_VERSION >= 180
+ ICHECK(llvm::StringRef(mcpu).starts_with("hexagon"))
+#else
ICHECK(llvm::StringRef(mcpu).startswith("hexagon"))
+#endif
<< "unexpected -mcpu value in target:" << mcpu;
extra_args.Set("hex_arch",
llvm::StringRef(mcpu).drop_front(strlen("hexagon")).str());
}
diff --git a/src/target/llvm/codegen_llvm.cc b/src/target/llvm/codegen_llvm.cc
index 6566bb4291..6fc083d17c 100644
--- a/src/target/llvm/codegen_llvm.cc
+++ b/src/target/llvm/codegen_llvm.cc
@@ -372,7 +372,11 @@ std::unique_ptr<llvm::Module> CodeGenLLVM::Finish() {
void CodeGenLLVM::HandleImport(const std::string& code) {
llvm::StringRef code_str(code);
std::unique_ptr<llvm::Module> mlib;
+#if TVM_LLVM_VERSION >= 180
+ if (code_str.ends_with(".ll") || code_str.ends_with(".bc")) {
+#else
if (code_str.endswith(".ll") || code_str.endswith(".bc")) {
+#endif
mlib = llvm_target_->GetInstance().LoadIR(code);
} else {
mlib = llvm_target_->GetInstance().ParseIR(code);
diff --git a/src/target/llvm/llvm_instance.cc b/src/target/llvm/llvm_instance.cc
index bd2eee85b0..dd5a3fb681 100644
--- a/src/target/llvm/llvm_instance.cc
+++ b/src/target/llvm/llvm_instance.cc
@@ -916,7 +916,11 @@ std::string LLVMTarget::GetTargetMetadata(const
llvm::Module& module) {
if (llvm::Metadata* tvm_target = module.getModuleFlag("tvm_target")) {
auto* mdstr = llvm::cast<llvm::MDString>(tvm_target);
llvm::StringRef meta = mdstr->getString();
+#if TVM_LLVM_VERSION >= 180
+ if (meta.starts_with("llvm")) {
+#else
if (meta.startswith("llvm")) {
+#endif
return meta.str();
}
}