yunho-c commented on issue #18585:
URL: https://github.com/apache/tvm/issues/18585#issuecomment-3649857591

   I experimented with the following fixes and verified that they work (at 
least for the repro script):
   
   ### Option 1. Skipping float/vector values
   
   ```diff
   void CodeGenLLVM::AddDebugInformation(llvm::Value* llvm_value, const Var& 
tir_var,
                                         llvm::Instruction* insert_before) {
     llvm_value->setName(tir_var->name_hint.c_str());
   
   #if TVM_LLVM_VERSION >= 50
     if (!di_subprogram_) return;
   
   + #if TVM_LLVM_VERSION >= 150
   +   // LLVM 15+ requires dbg_declare to reference pointer or integer types 
only.
   +   // Skip debug info for float/vector types to avoid verification failure.
   +   if (!llvm_value->getType()->isPointerTy() && 
!llvm_value->getType()->isIntegerTy()) {
   +       return;  // No debug info for float temporaries
   +   }
   + #endif
   
   ...
   ```
   
   ### Option 2. Using `dbg_value` for float/vector values
   
   ```diff
   void CodeGenLLVM::AddDebugInformation(llvm::Value* llvm_value, const Var& 
tir_var,
                                         llvm::Instruction* insert_before) {
     llvm_value->setName(tir_var->name_hint.c_str());
   
   #if TVM_LLVM_VERSION >= 50
     if (!di_subprogram_) return;
   
     auto dbg_dtype = GetDebugType(GetType(tir_var));
     // no invalid dtypes
     if (!dbg_dtype) return;
     auto local_var = dbg_info_->di_builder_->createAutoVariable(
         di_subprogram_, std::string(tir_var->name_hint), dbg_info_->file_, 0, 
dbg_dtype);
   
     auto* di_loc = llvm::DILocation::get(*llvm_target_->GetContext(), 0, 0, 
di_subprogram_);
   
   + #if TVM_LLVM_VERSION >= 150
   +   // LLVM 15+ requires dbg_declare to reference pointer or integer types 
only.
   +   // For non-pointer types (floats, vectors), use dbg_value instead to 
track
   +   // the SSA value directly rather than a memory location.
   +   if (!llvm_value->getType()->isPointerTy()) {
   +     if (insert_before) {
   +       // LLVM 20+ changed insertDbgValueIntrinsic to take 
BasicBlock::iterator
   +       // instead of Instruction* for the insertion point.
   + #if TVM_LLVM_VERSION >= 200
   +       dbg_info_->di_builder_->insertDbgValueIntrinsic(
   +           llvm_value, local_var, 
dbg_info_->di_builder_->createExpression(), llvm::DebugLoc(di_loc),
   +           llvm::BasicBlock::iterator(insert_before));
   + #else
   +       dbg_info_->di_builder_->insertDbgValueIntrinsic(llvm_value, 
local_var,
   +                                                       
dbg_info_->di_builder_->createExpression(),
   +                                                       
llvm::DebugLoc(di_loc), insert_before);
   + #endif
   +     } else {
   +       dbg_info_->di_builder_->insertDbgValueIntrinsic(
   +           llvm_value, local_var, 
dbg_info_->di_builder_->createExpression(), llvm::DebugLoc(di_loc),
   +           builder_->GetInsertBlock());
   +     }
   +     return;
   +   }
   + #endif
   
   ...
   ```
   
   I would be happy to commit either of these and create a PR—yet still would 
prefer someone with LLVM expertise to have a look over this (and help decide 
which fix is more appropriate)! Thanks


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to