Browse Source

Small fixes in LLVM debug info (#7527)

Vadim Averin 7 months ago
parent
commit
9ec6f05266

+ 3 - 0
ydb/library/yql/minikql/codegen/codegen.cpp

@@ -390,6 +390,9 @@ public:
 
         bool dumpTimers = compileOpts.Contains("time-passes");
         bool disableOpt = compileOpts.Contains("disable-opt");
+#ifndef NDEBUG
+        disableOpt = true;
+#endif
 
 #if defined(_msan_enabled_)
         ReverseGlobalMapping_[(const void*)&__emutls_get_address] = "__emutls_get_address";

+ 4 - 4
ydb/library/yql/minikql/comp_nodes/mkql_wide_top_sort.cpp

@@ -404,7 +404,7 @@ public:
 #ifndef MKQL_DISABLE_CODEGEN
     ICodegeneratorInlineWideNode::TGenerateResult DoGenGetValues(const TCodegenContext& ctx, Value* statePtr, BasicBlock*& block) const {
         auto& context = ctx.Codegen.GetContext();
-        DIScopeAnnotator annotate(*ctx.Annotator);
+        DIScopeAnnotator annotate(ctx.Annotator);
 
         const auto valueType = Type::getInt128Ty(context);
         const auto ptrValueType = PointerType::getUnqual(valueType);
@@ -424,7 +424,7 @@ public:
 
         for (auto i = 0U; i < getters.size(); ++i) {
             getters[Indexes[i]] = [i, outs, indexType, valueType, outputPtrType, outputType](const TCodegenContext& ctx, BasicBlock*& block) {
-                DIScopeAnnotator annotate(*ctx.Annotator);
+                DIScopeAnnotator annotate(ctx.Annotator);
                 const auto values = annotate(new LoadInst(outputPtrType, outs, "values", block));
                 const auto pointer = annotate(GetElementPtrInst::CreateInBounds(outputType, values, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, i)}, (TString("ptr_") += ToString(i)).c_str(), block));
                 return annotate(new LoadInst(valueType, pointer, (TString("load_") += ToString(i)).c_str(), block));
@@ -927,7 +927,7 @@ public:
 #ifndef MKQL_DISABLE_CODEGEN
     ICodegeneratorInlineWideNode::TGenerateResult DoGenGetValues(const TCodegenContext& ctx, Value* statePtr, BasicBlock*& block) const {
         auto& context = ctx.Codegen.GetContext();
-        DIScopeAnnotator annotate(*ctx.Annotator);
+        DIScopeAnnotator annotate(ctx.Annotator);
 
         const auto valueType = Type::getInt128Ty(context);
         const auto ptrValueType = PointerType::getUnqual(valueType);
@@ -947,7 +947,7 @@ public:
 
         for (auto i = 0U; i < getters.size(); ++i) {
             getters[Indexes[i]] = [i, outs, indexType, valueType, outputPtrType, outputType](const TCodegenContext& ctx, BasicBlock*& block) {
-                DIScopeAnnotator annotate(*ctx.Annotator);
+                DIScopeAnnotator annotate(ctx.Annotator);
                 const auto values = annotate(new LoadInst(outputPtrType, outs, "values", block));
                 const auto pointer = annotate(GetElementPtrInst::CreateInBounds(outputType, values, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, i)}, (TString("ptr_") += ToString(i)).c_str(), block));
                 return annotate(new LoadInst(valueType, pointer, (TString("load_") += ToString(i)).c_str(), block));

+ 10 - 6
ydb/library/yql/minikql/computation/mkql_computation_node_codegen.cpp

@@ -2618,7 +2618,7 @@ DISubprogramAnnotator::DISubprogramAnnotator(TCodegenContext& ctx, Function* sub
 DISubprogramAnnotator::~DISubprogramAnnotator() {
     Ctx.Annotator = nullptr;
     { // necessary stub annotation of "CallInst"s
-        DIScopeAnnotator stubAnnotate(*this);
+        DIScopeAnnotator stubAnnotate(this);
         for (BasicBlock& block : *Func) {
             for (Instruction& inst : block) {
                 if (CallInst* callInst = dyn_cast_or_null<CallInst>(&inst)) {
@@ -2651,13 +2651,17 @@ DISubprogram* DISubprogramAnnotator::MakeDISubprogram(const StringRef& name, con
     );
 }
 
-DIScopeAnnotator::DIScopeAnnotator(DISubprogramAnnotator& subprogramAnnotator, const TSrcLocation& location)
-    : SubprogramAnnotator(subprogramAnnotator)
-    , Scope(SubprogramAnnotator.DebugBuilder->createLexicalBlock(SubprogramAnnotator.Subprogram, SubprogramAnnotator.MakeDIFile(location), location.line(), location.column()))
-{}
+DIScopeAnnotator::DIScopeAnnotator(DISubprogramAnnotator* subprogramAnnotator, const TSrcLocation& location)
+    : SubprogramAnnotator(nullptr)
+    , Scope(nullptr)
+{
+    Y_ENSURE(subprogramAnnotator != nullptr);
+    SubprogramAnnotator = subprogramAnnotator;
+    Scope = SubprogramAnnotator->DebugBuilder->createLexicalBlock(SubprogramAnnotator->Subprogram, SubprogramAnnotator->MakeDIFile(location), location.line(), location.column());
+}
 
 Instruction* DIScopeAnnotator::operator()(Instruction* inst, const TSrcLocation& location) const {
-    inst->setDebugLoc(DILocation::get(SubprogramAnnotator.Ctx.Codegen.GetContext(), location.line(), location.column(), Scope));
+    inst->setDebugLoc(DILocation::get(SubprogramAnnotator->Ctx.Codegen.GetContext(), location.line(), location.column(), Scope));
     return inst;
 }
 

+ 2 - 2
ydb/library/yql/minikql/computation/mkql_computation_node_codegen.h.txt

@@ -1247,12 +1247,12 @@ private:
 
 class DIScopeAnnotator final {
 public:
-    explicit DIScopeAnnotator(DISubprogramAnnotator& subprogramAnnotator, const TSrcLocation& location = TSrcLocation::current());
+    explicit DIScopeAnnotator(DISubprogramAnnotator* subprogramAnnotator, const TSrcLocation& location = TSrcLocation::current());
 
     Instruction* operator()(Instruction* inst, const TSrcLocation& location = TSrcLocation::current()) const;
 
 private:
-    DISubprogramAnnotator& SubprogramAnnotator;
+    DISubprogramAnnotator* SubprogramAnnotator;
     DIScope* Scope;
 };