|
53 | 53 | #include <llvm/Support/raw_ostream.h> |
54 | 54 | #include <llvm/Target/TargetMachine.h> |
55 | 55 | #include <llvm/Target/TargetOptions.h> |
56 | | -#if TVM_LLVM_VERSION >= 190 |
57 | | -#include <llvm/TargetParser/RISCVISAInfo.h> |
58 | | -#else |
59 | | -#if TVM_LLVM_VERSION >= 140 |
60 | | -#include <llvm/Support/RISCVISAInfo.h> |
61 | | -#endif |
62 | | -#endif |
63 | | -#if TVM_LLVM_VERSION >= 160 |
64 | | -#include <llvm/TargetParser/RISCVTargetParser.h> |
65 | | -#else |
66 | | -#include <llvm/Support/TargetParser.h> |
67 | | -#endif |
68 | 56 | #include <tvm/runtime/container/array.h> |
69 | 57 | #include <tvm/runtime/container/map.h> |
70 | 58 | #include <tvm/runtime/container/optional.h> |
@@ -299,34 +287,25 @@ LLVMTargetInfo::LLVMTargetInfo(LLVMInstance& instance, const TargetJSON& target) |
299 | 287 | // code model |
300 | 288 | code_model_ = llvm::CodeModel::Medium; |
301 | 289 | #if TVM_LLVM_VERSION >= 140 |
302 | | - // VLEN inference |
303 | | - const auto cpu_name = GetOrCreateTargetMachine(false)->getMCSubtargetInfo()->getCPU(); |
304 | | - const auto canon_arch = llvm::RISCV::getMArchFromMcpu(cpu_name); |
305 | | - auto ISAInfo = |
306 | | - llvm::RISCVISAInfo::parseArchString(canon_arch, /*EnableExperimentalExtensions=*/true); |
307 | | - // infer VLEN from LLVM RISCVInfo parser |
308 | | - if (!llvm::errorToBool(ISAInfo.takeError()) && (vector_width_ == 0)) { |
309 | | - vector_width_ = (*ISAInfo)->getMinVLen(); |
310 | | - } |
311 | | - // infer VLEN from LLVM options (zvlXXXb override) |
312 | | - for (const auto& attr : attrs_) { |
313 | | - if (attr.find("zvl") != std::string::npos) { |
314 | | - std::string vec; |
315 | | - for (char c : attr) { |
316 | | - if (std::isdigit(c)) vec += c; |
| 290 | + // get VLEN from the LLVM backend (zvlXXXb) |
| 291 | + Map<String, String> features = GetAllLLVMCpuFeatures(); |
| 292 | + // check vector ISA |
| 293 | + if (features.count("v") > 0) { |
| 294 | + vector_width_ = 0; |
| 295 | + int zvlbits = 0; |
| 296 | + for (const auto& [attr, val] : features) { |
| 297 | + if (std::string(attr).find("zvl") != std::string::npos) { |
| 298 | + std::string vec; |
| 299 | + for (char c : std::string(attr)) { |
| 300 | + if (std::isdigit(c)) vec += c; |
| 301 | + } |
| 302 | + zvlbits = std::stoi(vec); |
| 303 | + // max of the multiple zvlXXXb |
| 304 | + if (vector_width_ < zvlbits) vector_width_ = zvlbits; |
317 | 305 | } |
318 | | - vector_width_ = std::stoi(vec); |
319 | 306 | } |
320 | 307 | } |
321 | 308 | #endif |
322 | | - if (vector_width_ > 0) { |
323 | | - // push cl-opt to LLVM |
324 | | - llvm_options_.push_back( |
325 | | - ParseOptionString("-riscv-v-vector-bits-min:int=" + std::to_string(vector_width_))); |
326 | | - } else { |
327 | | - // fallback default (codegen will warn) |
328 | | - llvm_options_.push_back(ParseOptionString("-riscv-v-vector-bits-min:int=256")); |
329 | | - } |
330 | 309 | } |
331 | 310 |
|
332 | 311 | // Target options |
@@ -943,9 +922,7 @@ const int LLVMTargetInfo::GetVectorWidth() { |
943 | 922 | } else if (arch == llvm::Triple::arm || arch == llvm::Triple::aarch64) { |
944 | 923 | vector_width_ = 128; |
945 | 924 | } else if (arch == llvm::Triple::riscv32 || arch == llvm::Triple::riscv64) { |
946 | | - vector_width_ = 256; |
947 | | - LOG(WARNING) << "LLVM RVV VLEN inference failed, " |
948 | | - << "using 256 bits, set -vector-width=XXX to override"; |
| 925 | + vector_width_ = 128; |
949 | 926 | } else { |
950 | 927 | // fallback default |
951 | 928 | vector_width_ = 128; |
|
0 commit comments