Skip to content

Commit b62c262

Browse files
aparshin-inteligcbot
authored andcommitted
deleted some deprecated code, changed source layout for DWARF utility functions
deleted some deprecated code, changed source layout for DWARF utility functions
1 parent 04075d7 commit b62c262

18 files changed

+194
-200
lines changed

IGC/AdaptorOCL/UnifyIROCL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ SPDX-License-Identifier: MIT
111111
#include "Compiler/CISACodeGen/DebugInfo.hpp"
112112
#include "Compiler/CISACodeGen/TimeStatsCounter.h"
113113
#include "Compiler/DebugInfo/ScalarVISAModule.h"
114+
#include "Compiler/DebugInfo/Utils.h"
114115
#include "DebugInfo/VISADebugEmitter.hpp"
115-
#include "DebugInfo/DebugInfoUtils.hpp"
116116

117117
#include <string>
118118
#include <algorithm>

IGC/Compiler/DebugInfo/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88

99
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
1010

11-
set(IGC_BUILD__SRC__DebugInfo "${CMAKE_CURRENT_SOURCE_DIR}/ScalarVISAModule.cpp")
11+
set(IGC_BUILD__SRC__DebugInfo
12+
"${CMAKE_CURRENT_SOURCE_DIR}/Utils.cpp"
13+
"${CMAKE_CURRENT_SOURCE_DIR}/ScalarVISAModule.cpp")
1214
set(IGC_BUILD__SRC__Compiler_DebugInfo ${IGC_BUILD__SRC__DebugInfo} PARENT_SCOPE)
1315

14-
set(IGC_BUILD__HDR__DebugInfo "${CMAKE_CURRENT_SOURCE_DIR}/ScalarVISAModule.h")
16+
set(IGC_BUILD__HDR__DebugInfo
17+
"${CMAKE_CURRENT_SOURCE_DIR}/Utils.h"
18+
"${CMAKE_CURRENT_SOURCE_DIR}/ScalarVISAModule.h")
1519
set(IGC_BUILD__HDR__Compiler_DebugInfo ${IGC_BUILD__HDR__DebugInfo} PARENT_SCOPE)
1620

1721
igc_sg_register(

IGC/Compiler/DebugInfo/ScalarVISAModule.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ SPDX-License-Identifier: MIT
77
============================= end_copyright_notice ===========================*/
88

99
#include "Compiler/DebugInfo/ScalarVISAModule.h"
10+
#include "Compiler/DebugInfo/Utils.h"
1011
#include "Compiler/Optimizer/OpenCLPasses/KernelArgs.hpp"
1112
#include "Compiler/CISACodeGen/ShaderCodeGen.hpp"
1213
#include "GenISAIntrinsics/GenIntrinsicInst.h"
1314
#include "common/debug/Debug.hpp"
1415

15-
#include "DebugInfo/DebugInfoUtils.hpp"
16-
1716
#include "common/LLVMWarningsPush.hpp"
1817
#include "llvm/IR/Function.h"
1918
#include "llvm/IR/Module.h"
@@ -37,7 +36,7 @@ namespace IGC {
3736
fullDebugInfo = false;
3837
lineNumbersOnly = false;
3938

40-
if (DebugInfoUtils::HasDebugInfo(*ctx->getModule()))
39+
if (Utils::HasDebugInfo(*ctx->getModule()))
4140
{
4241
bool hasDbgIntrinsic = false;
4342
bool hasDbgLoc = false;
@@ -673,7 +672,7 @@ void insertOCLMissingDebugConstMetadata(CodeGenContext* ctx)
673672

674673
if (!GlobalValue::isLocalLinkage(g->getLinkage()) || isConstForThisFunc)
675674
{
676-
DebugInfoUtils::UpdateGlobalVarDebugInfo(g, init, &func.getEntryBlock().getInstList().front(), false);
675+
Utils::UpdateGlobalVarDebugInfo(g, init, &func.getEntryBlock().getInstList().front(), false);
677676
}
678677
}
679678
}

IGC/Compiler/DebugInfo/Utils.cpp

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2017-2021 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#include "llvm/Config/llvm-config.h"
10+
#include "common/LLVMWarningsPush.hpp"
11+
#include "llvm/IR/Instruction.h"
12+
#include "llvm/IR/Function.h"
13+
#include "llvm/IR/Module.h"
14+
#include "llvmWrapper/IR/DIBuilder.h"
15+
#include "llvm/IR/DebugInfo.h"
16+
#include "llvm/IR/DebugLoc.h"
17+
#include "llvm/IR/DebugInfoMetadata.h"
18+
#include "common/LLVMWarningsPop.hpp"
19+
20+
#include "Utils.h"
21+
22+
namespace IGC {
23+
namespace Utils {
24+
25+
/// @brief return true if given module contain debug info
26+
/// @param M The LLVM module.
27+
/// @return true if given module contain debug info
28+
bool HasDebugInfo(llvm::Module& M)
29+
{
30+
llvm::NamedMDNode* CU_Nodes = M.getNamedMetadata("llvm.dbg.cu");
31+
return (CU_Nodes != nullptr);
32+
}
33+
34+
/// @brief creates a new call instruction to llvm.dbg.value intrinsic with
35+
/// same information as in debug info of given global variable and
36+
/// with value set to new given value.
37+
/// @param pGlobalVar global variable to handle its debug info
38+
/// @param pNewVal new value to map to the source variable (in the debug info)
39+
/// @param pEntryPoint entry point instruction to add new instructions before.
40+
/// @isIndirect true iff pNewValue type is a pointer to source variable type.
41+
/// @return new call instruction to llvm.dbg.value intrinsic
42+
llvm::Instruction* UpdateGlobalVarDebugInfo(
43+
llvm::GlobalVariable* pGlobalVar, llvm::Value* pNewVal,
44+
llvm::Instruction* pEntryPoint, bool isIndirect)
45+
{
46+
llvm::Function* userFunc = pEntryPoint->getParent()->getParent();
47+
llvm::Module& M = *userFunc->getParent();
48+
llvm::NamedMDNode* CU_Nodes = M.getNamedMetadata("llvm.dbg.cu");
49+
if (!CU_Nodes)
50+
{
51+
return nullptr;
52+
}
53+
54+
llvm::DINode::DIFlags flags = llvm::DINode::FlagZero;
55+
llvm::DIScope* spScope = nullptr;
56+
llvm::DILocation* loc = nullptr;
57+
bool done = false;
58+
for (auto bbIt = userFunc->begin();
59+
bbIt != userFunc->end() && !done;
60+
bbIt++)
61+
{
62+
for (auto instIt = bbIt->begin();
63+
instIt != bbIt->end();
64+
instIt++)
65+
{
66+
// Discover first valid Loc in function
67+
// and use it in dbg.declare nodes inserted
68+
// later. Make sure the location belongs to
69+
// the function and not to an inlined
70+
// callee.
71+
if (instIt->getDebugLoc() &&
72+
!instIt->getDebugLoc().getInlinedAt())
73+
{
74+
loc = instIt->getDebugLoc().get();
75+
spScope = loc->getScope()->getSubprogram();
76+
done = true;
77+
break;
78+
}
79+
}
80+
}
81+
82+
llvm::SmallVector<llvm::DIGlobalVariableExpression*, 1> GVs;
83+
pGlobalVar->getDebugInfo(GVs);
84+
for (unsigned int j = 0; j < GVs.size(); j++)
85+
{
86+
IGCLLVM::DIBuilder Builder(M);
87+
llvm::DIGlobalVariable* GV = GVs[j]->getVariable();
88+
llvm::DIScope* scopeToUse = GV->getScope();
89+
llvm::DILocation* locToUse = llvm::DebugLoc::get(GV->getLine(), 0, scopeToUse, loc);
90+
if (llvm::isa<llvm::DICompileUnit>(GV->getScope()))
91+
{
92+
// Function has no DebugLoc so it is either internal
93+
// or optimized. So there is no point inserting
94+
// global var metadata as "local" to function.
95+
if (!done)
96+
continue;
97+
98+
// Use scope of current sub-program
99+
scopeToUse = spScope;
100+
locToUse = loc;
101+
}
102+
llvm::DIVariable* Var = Builder.createAutoVariable(scopeToUse,
103+
GV->getDisplayName(),
104+
Builder.createFile(GV->getFilename(), GV->getDirectory()),
105+
GV->getLine(),
106+
GV->getType(),
107+
false,
108+
flags
109+
);
110+
111+
if (isIndirect)
112+
return Builder.insertDeclare(pNewVal, llvm::cast<llvm::DILocalVariable>(Var), Builder.createExpression(), locToUse, pEntryPoint);
113+
114+
return Builder.insertDbgValueIntrinsic(pNewVal, 0, llvm::cast<llvm::DILocalVariable>(Var), Builder.createExpression(), locToUse, pEntryPoint);
115+
}
116+
return nullptr;
117+
}
118+
119+
bool IsSpecialDebugVariable(const std::string& name)
120+
{
121+
// Check for OCL special debug variable such as:
122+
// "__ocl_dbg_gid0"
123+
// "__ocl_dbg_gid1"
124+
// "__ocl_dbg_gid2"
125+
// Assuming all OCL debug special variables starts with "__ocl_dbg" prefix.
126+
return (name.find("__ocl_dbg", 0) == 0);
127+
}
128+
129+
} // namespace Utils
130+
} // namespace IGC

IGC/Compiler/DebugInfo/Utils.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2017-2021 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#pragma once
10+
11+
#include "llvm/Config/llvm-config.h"
12+
#include "common/LLVMWarningsPush.hpp"
13+
#include "llvm/IR/Instruction.h"
14+
#include "llvm/IR/Module.h"
15+
#include "llvmWrapper/IR/DIBuilder.h"
16+
#include "llvm/IR/DebugInfoMetadata.h"
17+
#include "common/LLVMWarningsPop.hpp"
18+
19+
namespace IGC {
20+
namespace Utils {
21+
22+
/// @brief return true if given module contain debug info
23+
/// @param M The LLVM module.
24+
/// @return true if given module contain debug info
25+
bool HasDebugInfo(llvm::Module& M);
26+
27+
/// @brief creates a new call instruction to llvm.dbg.value intrinsic with
28+
/// same information as in debug info of given global variable and
29+
/// with value set to new given value.
30+
/// @param pGlobalVar global variable to handle its debug info
31+
/// @param pNewVal new value to map to the source variable (in the debug info)
32+
/// @param pEntryPoint entry point instruction to add new instructions before.
33+
/// @isIndirect true iff pNewValue type is a pointer to source variable type.
34+
/// @return new call instruction to llvm.dbg.value intrinsic
35+
llvm::Instruction* UpdateGlobalVarDebugInfo(
36+
llvm::GlobalVariable* pGlobalVar, llvm::Value* pNewVal,
37+
llvm::Instruction* pEntryPoint, bool isIndirect);
38+
39+
bool IsSpecialDebugVariable(const std::string& name);
40+
41+
} // namespace Utils
42+
} // namespace IGC

IGC/Compiler/Optimizer/OCLBIUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SPDX-License-Identifier: MIT
99
#include "Compiler/Optimizer/OCLBIUtils.h"
1010
#include "Compiler/CISACodeGen/helper.h"
1111
#include "Compiler/MetaDataApi/MetaDataApi.h"
12-
#include "DebugInfo/DebugInfoUtils.hpp"
12+
#include "Compiler/DebugInfo/Utils.h"
1313
#include "common/LLVMWarningsPush.hpp"
1414
#include "llvmWrapper/IR/DerivedTypes.h"
1515
#include "llvmWrapper/IR/IRBuilder.h"

IGC/Compiler/Optimizer/OpenCLPasses/DebuggerSupport/ImplicitGIDPass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SPDX-License-Identifier: MIT
1313
#include "common/LLVMWarningsPop.hpp"
1414
#include "Compiler/Optimizer/OpenCLPasses/DebuggerSupport/ImplicitGIDPass.hpp"
1515
#include "Compiler/Optimizer/OpenCLPasses/WIFuncs/WIFuncsAnalysis.hpp"
16-
#include "DebugInfo/DebugInfoUtils.hpp"
16+
#include "Compiler/DebugInfo/Utils.h"
1717
#include "Compiler/IGCPassSupport.h"
1818
#include "Probe/Assertion.h"
1919
#include "common/igc_regkeys.hpp"
@@ -47,7 +47,7 @@ ImplicitGlobalId::ImplicitGlobalId() : ModulePass(ID)
4747

4848
bool ImplicitGlobalId::runOnModule(Module& M)
4949
{
50-
if (!DebugInfoUtils::HasDebugInfo(M))
50+
if (!Utils::HasDebugInfo(M))
5151
{
5252
// If there is no debug info, then it must be GenISA debugger.
5353
// Thus, no need to add OpenCL global id variable. Just return.
@@ -336,7 +336,7 @@ bool CleanImplicitIds::processFunc(Function& F)
336336
if (auto DbgVal = dyn_cast_or_null<DbgValueInst>(&I))
337337
{
338338
auto Name = DbgVal->getVariable()->getName().str();
339-
if (DebugInfoUtils::IsSpecialDebugVariable(Name))
339+
if (Utils::IsSpecialDebugVariable(Name))
340340
{
341341
auto PredefVar = FindPredefinedInst(PredefinedInsts, Name);
342342
if (PredefVar == nullptr)

IGC/Compiler/Optimizer/OpenCLPasses/LocalBuffers/InlineLocalsResolution.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SPDX-License-Identifier: MIT
1111
#include "Compiler/CodeGenPublic.h"
1212
#include "Compiler/IGCPassSupport.h"
1313
#include "Compiler/CISACodeGen/helper.h"
14-
#include "DebugInfo/DebugInfoUtils.hpp"
14+
#include "Compiler/DebugInfo/Utils.h"
1515
#include "common/LLVMWarningsPush.hpp"
1616
#include <llvm/IR/Module.h>
1717
#include <llvm/IR/Instructions.h>
@@ -456,7 +456,7 @@ void InlineLocalsResolution::collectInfoOnSharedLocalMem(Module& M)
456456
{
457457
IF_DEBUG_INFO(Instruction * pInsertBefore = &(*userFunc->begin()->getFirstInsertionPt());)
458458
TODO("Should inline local buffer points to origin offset 'globalVar' or to fixed offset 'pMovedPtr'?");
459-
IF_DEBUG_INFO(DebugInfoUtils::UpdateGlobalVarDebugInfo(G, G, pInsertBefore, true););
459+
IF_DEBUG_INFO(Utils::UpdateGlobalVarDebugInfo(G, G, pInsertBefore, true););
460460
}
461461
}
462462
}

IGC/Compiler/Optimizer/ValueTracker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SPDX-License-Identifier: MIT
99
#include "Compiler/Optimizer/OCLBIUtils.h"
1010
#include "Compiler/Optimizer/ValueTracker.h"
1111
#include "Compiler/MetaDataApi/MetaDataApi.h"
12-
#include "DebugInfo/DebugInfoUtils.hpp"
12+
#include "Compiler/DebugInfo/Utils.h"
1313
#include "common/LLVMWarningsPush.hpp"
1414
#include "llvmWrapper/IR/DerivedTypes.h"
1515
#include "common/LLVMWarningsPop.hpp"
@@ -182,7 +182,7 @@ Value* ValueTracker::handleGlobalVariable(GlobalVariable* G)
182182
Constant* pSamplerVal = G->getInitializer();
183183
// Add debug info intrinsic for this variable inside the function using this sampler.
184184
Instruction* pEntryPoint = &(*m_Function->getEntryBlock().getFirstInsertionPt());
185-
IF_DEBUG_INFO(DebugInfoUtils::UpdateGlobalVarDebugInfo(G, pSamplerVal, pEntryPoint, false);)
185+
IF_DEBUG_INFO(Utils::UpdateGlobalVarDebugInfo(G, pSamplerVal, pEntryPoint, false);)
186186
// Found a global sampler, return it.
187187
return isa<ConstantStruct>(pSamplerVal) ?
188188
pSamplerVal->getAggregateElement(0U) : pSamplerVal;
@@ -479,4 +479,4 @@ Value* ValueTracker::track(
479479
{
480480
ValueTracker VT(pCallInst->getParent()->getParent(), pMdUtils, pModMD);
481481
return VT.trackValue(pCallInst, index);
482-
}
482+
}

0 commit comments

Comments
 (0)