lhutton1 commented on code in PR #16425:
URL: https://github.com/apache/tvm/pull/16425#discussion_r1469390515
##########
src/target/llvm/llvm_instance.cc:
##########
@@ -199,32 +199,37 @@ std::ostream& operator<<(std::ostream& os, const
LLVMTargetInfo::Option& opt) {
return os;
}
-LLVMTargetInfo::LLVMTargetInfo(LLVMInstance& instance, const Target& target) {
- triple_ = target->GetAttr<String>("mtriple").value_or("default");
+LLVMTargetInfo::LLVMTargetInfo(LLVMInstance& instance, const Target& target)
+ : LLVMTargetInfo(instance, target->Export()) {}
+LLVMTargetInfo::LLVMTargetInfo(LLVMInstance& instance, const TargetJSON&
target) {
+ triple_ =
Downcast<String>(target.Get("mtriple").value_or(String("default")));
if (triple_.empty() || triple_ == "default") {
triple_ = llvm::sys::getDefaultTargetTriple();
}
- cpu_ = target->GetAttr<String>("mcpu").value_or(defaults::cpu);
+ cpu_ = Downcast<String>(target.Get("mcpu").value_or(String(defaults::cpu)));
- if (const Optional<Array<String>>& v =
target->GetAttr<Array<String>>("mattr")) {
+ if (const auto& v = Downcast<Optional<Array<String>>>(target.Get("mattr"))) {
for (const String& s : v.value()) {
attrs_.push_back(s);
}
}
// llvm module target
- if (target->kind->name == "llvm") {
+ if (Downcast<String>(target.Get("kind")) == "llvm") {
// legalize -mcpu with the target -mtriple
auto arches = GetAllLLVMTargetArches();
bool has_arch =
std::any_of(arches.begin(), arches.end(), [&](const auto& var) {
return var == cpu_; });
if (!has_arch) {
- LOG(FATAL) << "LLVM cpu architecture `-mcpu=" << cpu_
- << "` is not valid in `-mtriple=" << triple_ << "`";
+ // Flag an error, but don't abort. This mimicks the behaviour of 'llc' to
+ // give the code a chance to run with a less-specific target.
+ LOG(ERROR) << "LLVM cpu architecture `-mcpu=" << cpu_
+ << "` is not valid in `-mtriple=" << triple_ << "`"
+ << ", cpu architecture ignored";
Review Comment:
The result of `GetLLVMSubtargetInfo(triple_, "", "")->getCPU().data()`
always seems to be "generic", so I stuck to hardcoding that for now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]