@@ -186,11 +186,16 @@ void CodeGenCPU::Init(const std::string& module_name, LLVMTarget* llvm_target, b
186186llvm::DISubprogram* CodeGenCPU::CreateDebugFunction (const PrimFunc& f) {
187187#if TVM_LLVM_VERSION >= 50
188188 llvm::SmallVector<llvm::Metadata*, 4 > paramTys;
189+
190+ paramTys.push_back (GetDebugType (f->ret_type ));
191+ for (const auto & param : f->params ) {
192+ paramTys.push_back (GetDebugType (GetType (param)));
193+ }
194+
189195 auto * DIFunctionTy = dbg_info_->di_builder_ ->createSubroutineType (
190196 dbg_info_->di_builder_ ->getOrCreateTypeArray (paramTys));
191197
192- // TODO(driazati): add the right argument info to the function
193- bool local_to_unit = false ;
198+ bool local_to_unit = llvm::GlobalVariable::isLocalLinkage (llvm::GlobalValue::InternalLinkage);
194199
195200#if TVM_LLVM_VERSION >= 80
196201 auto SPFlags = llvm::DISubprogram::toSPFlags (local_to_unit, /* IsDefinition=*/ true ,
@@ -207,14 +212,15 @@ llvm::DISubprogram* CodeGenCPU::CreateDebugFunction(const PrimFunc& f) {
207212 /* Flags=*/ llvm::DINode::FlagPrototyped, /* isOptimized=*/ true );
208213#endif
209214 return DIFunction;
215+ #else
216+ return nullptr ;
210217#endif
211218}
212219
213220void CodeGenCPU::AddFunction (const PrimFunc& f) {
214221#if TVM_LLVM_VERSION >= 50
215222 di_subprogram_ = CreateDebugFunction (f);
216223#endif
217-
218224 EmitDebugLocation (f->span );
219225 CodeGenLLVM::AddFunction (f);
220226 if (f_tvm_register_system_symbol_ != nullptr ) {
@@ -231,6 +237,17 @@ void CodeGenCPU::AddFunction(const PrimFunc& f) {
231237void CodeGenCPU::AddDebugInformation (PrimFunc f_tir, llvm::Function* f_llvm) {
232238#if TVM_LLVM_VERSION >= 50
233239 ICHECK (di_subprogram_);
240+ // llvm::SmallVector<llvm::Metadata*, 4> paramTys;
241+ // auto* DIFunctionTy = dbg_info_->di_builder_->createSubroutineType(
242+ // dbg_info_->di_builder_->getOrCreateTypeArray(paramTys));
243+ // auto SPFlags = llvm::DISubprogram::toSPFlags(false, /*IsDefinition=*/true,
244+ // /*IsOptimized=*/true);
245+ // auto* DIFunction = dbg_info_->di_builder_->createFunction(
246+ // /*Scope=*/dbg_info_->file_, /*Name=*/"main.tir", /*LinkageName=*/"",
247+ // /*File=*/dbg_info_->file_, /*LineNo=*/0, /*Ty=*/DIFunctionTy,
248+ // /*ScopeLine=*/0, /*Flags=*/llvm::DINode::FlagZero, /*SPFlags=*/SPFlags);
249+ // di_subprogram_ = DIFunction;
250+ // di_subprogram_->
234251 f_llvm->setSubprogram (di_subprogram_);
235252 ICHECK_EQ (f_llvm->getSubprogram (), di_subprogram_);
236253
@@ -272,6 +289,9 @@ void CodeGenCPU::AddDebugInformation(PrimFunc f_tir, llvm::Function* f_llvm) {
272289#endif
273290}
274291
292+ llvm::DIType* CodeGenCPU::GetDebugType (const Type& ty_tir) {
293+ return GetDebugType (ty_tir, GetLLVMType (ty_tir));
294+ }
275295llvm::DIType* CodeGenCPU::GetDebugType (const Type& ty_tir, llvm::Type* ty_llvm) {
276296 if (ty_llvm == t_void_) {
277297 return nullptr ;
@@ -952,7 +972,6 @@ llvm::Value* CodeGenCPU::CreateCallPacked(const CallNode* op, bool use_string_lo
952972}
953973
954974llvm::Value* CodeGenCPU::CreateCallTracePacked (const CallNode* op) {
955- EmitDebugLocation (op);
956975 ICHECK_EQ (op->args .size (), 6U );
957976 PackedCall pc = MakeCallPackedLowered (op->args , op->dtype , op->args [3 ].as <IntImmNode>()->value ,
958977 op->args [4 ].as <IntImmNode>()->value , true );
@@ -1388,7 +1407,6 @@ void CodeGenCPU::AddStartupFunction() {
13881407}
13891408
13901409llvm::Value* CodeGenCPU::CreateIntrinsic (const CallNode* op) {
1391- EmitDebugLocation (op);
13921410 if (op->op .same_as (builtin::tvm_call_packed_lowered ())) {
13931411 return CreateCallPacked (op, true /* use_string_lookup */ );
13941412 } else if (op->op .same_as (builtin::tvm_call_trace_packed_lowered ())) {
0 commit comments