This is an automated email from the ASF dual-hosted git repository.
kparzysz 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 910624a86b [LLVM/String] Remove conversion operator of String to
llvm::StringRef (#11807)
910624a86b is described below
commit 910624a86bb7618f0039235128b82ac2a4ed549a
Author: Krzysztof Parzyszek <[email protected]>
AuthorDate: Wed Jun 22 18:31:54 2022 -0500
[LLVM/String] Remove conversion operator of String to llvm::StringRef
(#11807)
* [LLVM/String] Remove conversion operator of String to llvm::StringRef
We should not be declaring LLVM data structures in headers unrelated
to LLVM. There are only a handful of places where such a conversion
was used, it was replaced with a more local solution.
* Rebase to restart CI
* Restart CI
---
include/tvm/runtime/container/string.h | 13 -------------
src/target/llvm/codegen_cpu.cc | 9 ++++-----
src/target/llvm/codegen_hexagon.cc | 7 ++++---
src/target/llvm/codegen_llvm.cc | 10 +++++-----
src/target/llvm/codegen_llvm.h | 6 ++++++
src/target/llvm/llvm_common.h | 5 -----
6 files changed, 19 insertions(+), 31 deletions(-)
diff --git a/include/tvm/runtime/container/string.h
b/include/tvm/runtime/container/string.h
index bb9e7ff65a..28b0358014 100644
--- a/include/tvm/runtime/container/string.h
+++ b/include/tvm/runtime/container/string.h
@@ -69,11 +69,6 @@
#include <utility>
#include <vector>
-namespace llvm {
-// String to llvm object compatibility.
-class StringRef;
-} // namespace llvm
-
namespace tvm {
namespace runtime {
@@ -266,14 +261,6 @@ class String : public ObjectRef {
*/
operator std::string() const { return std::string{get()->data, size()}; }
- // LLVM compatibility function, implemented in src/target/llvm/llvm_common.h
- /*!
- * \brief Convert String to an llvm::StringRef object
- *
- * \return llvm::StringRef
- */
- inline operator llvm::StringRef() const;
-
/*!
* \brief Check if a TVMArgValue can be converted to String, i.e. it can be
std::string or String
* \param val The value to be checked
diff --git a/src/target/llvm/codegen_cpu.cc b/src/target/llvm/codegen_cpu.cc
index 2a66ff37c9..ba40c35e04 100644
--- a/src/target/llvm/codegen_cpu.cc
+++ b/src/target/llvm/codegen_cpu.cc
@@ -403,10 +403,10 @@ llvm::Value* CodeGenCPU::CreateCallExtern(Type ret_type,
String global_symbol,
#endif
return builder_->CreateCall(ext_callee, arg_values);
} else {
- llvm::Function* f = module_->getFunction(global_symbol);
+ llvm::Function* f = module_->getFunction(MakeStringRef(global_symbol));
if (f == nullptr) {
f = llvm::Function::Create(ftype, llvm::Function::ExternalLinkage,
- global_symbol.operator llvm::StringRef(),
module_.get());
+ MakeStringRef(global_symbol), module_.get());
}
#if TVM_LLVM_VERSION >= 90
auto ext_callee = llvm::FunctionCallee(f);
@@ -535,9 +535,8 @@ void CodeGenCPU::CreateComputeScope(const AttrStmtNode* op)
{
// Linkage ld Error: CALL16 reloc at 0x290 not against global symbol
const StringImmNode* value = op->value.as<StringImmNode>();
ICHECK(value != nullptr);
- llvm::Function* fcompute =
- llvm::Function::Create(ftype, llvm::Function::InternalLinkage,
- value->value.operator llvm::StringRef(),
module_.get());
+ llvm::Function* fcompute = llvm::Function::Create(ftype,
llvm::Function::InternalLinkage,
+
MakeStringRef(value->value), module_.get());
SetTargetAttributes(fcompute);
BasicBlock* compute_call_end =
CheckCallSuccess(builder_->CreateCall(fcompute, arg_values));
diff --git a/src/target/llvm/codegen_hexagon.cc
b/src/target/llvm/codegen_hexagon.cc
index c007eacfce..0e8b975f9c 100644
--- a/src/target/llvm/codegen_hexagon.cc
+++ b/src/target/llvm/codegen_hexagon.cc
@@ -419,9 +419,10 @@ runtime::Module BuildHexagon(IRModule mod, Target target) {
Array<PrimExpr> o_names = {StringImm(o_name)};
Map<String, String> extra_args;
if (target->attrs.count("mcpu")) {
- llvm::StringRef mcpu = Downcast<String>(target->attrs.at("mcpu"));
- ICHECK(mcpu.startswith("hexagon")) << "unexpected -mcpu value in target:"
<< mcpu.str();
- extra_args.Set("hex_arch", mcpu.drop_front(strlen("hexagon")).str());
+ std::string mcpu = Downcast<String>(target->attrs.at("mcpu"));
+ ICHECK(llvm::StringRef(mcpu).startswith("hexagon"))
+ << "unexpected -mcpu value in target:" << mcpu;
+ extra_args.Set("hex_arch",
llvm::StringRef(mcpu).drop_front(strlen("hexagon")).str());
}
int rc = (*f)(so_name, o_names, extra_args);
ICHECK(rc == 0) << "Failed to link " << so_name;
diff --git a/src/target/llvm/codegen_llvm.cc b/src/target/llvm/codegen_llvm.cc
index 981aef2f6c..9eaab15d11 100644
--- a/src/target/llvm/codegen_llvm.cc
+++ b/src/target/llvm/codegen_llvm.cc
@@ -135,10 +135,10 @@ void CodeGenLLVM::AddFunctionInternal(const PrimFunc& f,
bool ret_void) {
auto global_symbol = f->GetAttr<String>(tvm::attr::kGlobalSymbol);
ICHECK(global_symbol.defined())
<< "CodeGenLLVM: Expect PrimFunc to have the global_symbol attribute";
- function_ =
module_->getFunction(static_cast<std::string>(global_symbol.value()));
+ function_ = module_->getFunction(MakeStringRef(global_symbol.value()));
if (function_ == nullptr) {
function_ = llvm::Function::Create(ftype, llvm::Function::ExternalLinkage,
- global_symbol.value().operator
std::string(), module_.get());
+ MakeStringRef(global_symbol.value()),
module_.get());
}
function_->setCallingConv(llvm::CallingConv::C);
function_->setDLLStorageClass(llvm::GlobalValue::DLLStorageClassTypes::DLLExportStorageClass);
@@ -808,10 +808,10 @@ llvm::Value* CodeGenLLVM::CreateCallExtern(Type ret_type,
String global_symbol,
arg_type.push_back(arg_value.back()->getType());
}
llvm::FunctionType* ftype = llvm::FunctionType::get(GetLLVMType(ret_type),
arg_type, false);
- llvm::Function* f = module_->getFunction(global_symbol);
+ llvm::Function* f = module_->getFunction(MakeStringRef(global_symbol));
if (f == nullptr) {
- f = llvm::Function::Create(ftype, llvm::Function::ExternalLinkage,
- global_symbol.operator llvm::StringRef(),
module_.get());
+ f = llvm::Function::Create(ftype, llvm::Function::ExternalLinkage,
MakeStringRef(global_symbol),
+ module_.get());
}
llvm::CallInst* call = builder_->CreateCall(f, arg_value);
return call;
diff --git a/src/target/llvm/codegen_llvm.h b/src/target/llvm/codegen_llvm.h
index 0f259d6a6c..e458b59aef 100644
--- a/src/target/llvm/codegen_llvm.h
+++ b/src/target/llvm/codegen_llvm.h
@@ -201,6 +201,12 @@ class CodeGenLLVM : public ExprFunctor<llvm::Value*(const
PrimExpr&)>,
/*! \brief The alignment of allocation */
int alignment{0};
};
+ /*!
+ * \brief Convert tvm::runtime::String into llvm::StringRef
+ */
+ static llvm::StringRef MakeStringRef(const String& string) {
+ return llvm::StringRef(string.c_str(), string.size());
+ }
/*!
* \brief Execute falloca at the beginning of the
* currrent function and obtain its return value.
diff --git a/src/target/llvm/llvm_common.h b/src/target/llvm/llvm_common.h
index e2e3384c1a..d59f3977cd 100644
--- a/src/target/llvm/llvm_common.h
+++ b/src/target/llvm/llvm_common.h
@@ -131,10 +131,5 @@ void PrintModule(const llvm::Module* mod);
} // namespace codegen
} // namespace tvm
-namespace tvm {
-namespace runtime {
-inline String::operator llvm::StringRef() const { return
llvm::StringRef(get()->data, size()); }
-} // namespace runtime
-} // namespace tvm
#endif // TVM_LLVM_VERSION
#endif // TVM_TARGET_LLVM_LLVM_COMMON_H_