@@ -34,6 +34,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
34
35
35
#include " common/LLVMWarningsPush.hpp"
36
36
#include " llvm/IR/DataLayout.h"
37
+ #include " llvm/IR/DebugInfoMetadata.h"
37
38
#include " llvm/IR/Dominators.h"
38
39
#include " common/LLVMWarningsPop.hpp"
39
40
@@ -77,7 +78,7 @@ namespace IGC {
77
78
78
79
// / @brief Resolve collected alloca instructions.
79
80
// / @return true if there were resolved alloca, false otherwise.
80
- bool resolveAllocaInstuctions (bool stackCall);
81
+ bool resolveAllocaInstructions (bool stackCall);
81
82
82
83
// / Initialize setup like UseScratchSpacePrivateMemory.
83
84
bool safeToUseScratchSpace (llvm::Module& M) const ;
@@ -493,7 +494,7 @@ bool PrivateMemoryResolution::runOnModule(llvm::Module& M)
493
494
}
494
495
bool hasStackCall = (FGA && FGA->getGroup (m_currFunction)->hasStackCall ());
495
496
// Resolve collected alloca instructions for current function
496
- changed |= resolveAllocaInstuctions (hasStackCall);
497
+ changed |= resolveAllocaInstructions (hasStackCall);
497
498
}
498
499
499
500
if (changed)
@@ -540,7 +541,7 @@ bool PrivateMemoryResolution::runOnModule(llvm::Module& M)
540
541
static void sinkAllocas (SmallVectorImpl<AllocaInst*>& Allocas) {
541
542
assert (!Allocas.empty ());
542
543
DominatorTree DT;
543
- bool Calcluated = false ;
544
+ bool Calcuated = false ;
544
545
545
546
// For each alloca, sink it if it has a use that dominates all other uses.
546
547
// This use is called the dominating use.
@@ -567,10 +568,10 @@ static void sinkAllocas(SmallVectorImpl<AllocaInst*>& Allocas) {
567
568
continue ;
568
569
569
570
// Compute dominator tree lazily.
570
- if (!Calcluated ) {
571
+ if (!Calcuated ) {
571
572
Function* F = AI->getParent ()->getParent ();
572
573
DT.recalculate (*F);
573
- Calcluated = true ;
574
+ Calcuated = true ;
574
575
}
575
576
576
577
// Find the Nearest Common Denominator for all the uses
@@ -683,7 +684,7 @@ class TransposeHelperPrivateMem : public TransposeHelper
683
684
};
684
685
685
686
686
- bool PrivateMemoryResolution::resolveAllocaInstuctions (bool stackCall)
687
+ bool PrivateMemoryResolution::resolveAllocaInstructions (bool stackCall)
687
688
{
688
689
// It is possible that there is no alloca instruction in the caller but there
689
690
// is alloca in the callee. Save the total private memory to the metadata.
@@ -745,9 +746,11 @@ bool PrivateMemoryResolution::resolveAllocaInstuctions(bool stackCall)
745
746
llvm::IRBuilder<> entryBuilder (&*m_currFunction->getEntryBlock ().getFirstInsertionPt ());
746
747
ImplicitArgs implicitArgs (*m_currFunction, m_pMdUtils);
747
748
748
- // This declaration will invoke constructor of DebugLoc class and result in an empty DebugLoc
749
- // instance, ie with line and scope set to 0.
750
- IF_DEBUG_INFO (DebugLoc emptyDebugLoc);
749
+ // Construct an empty DebugLoc.
750
+ IF_DEBUG_INFO (DebugLoc entryDebugLoc);
751
+ // Assign with the function location if available.
752
+ IF_DEBUG_INFO_IF (DISubprogram *subprogram = m_currFunction->getSubprogram (), entryDebugLoc = DebugLoc::get (subprogram->getLine (), 0 , subprogram););
753
+ IF_DEBUG_INFO (entryBuilder.SetCurrentDebugLocation (entryDebugLoc));
751
754
752
755
if (stackCall)
753
756
{
@@ -760,7 +763,7 @@ bool PrivateMemoryResolution::resolveAllocaInstuctions(bool stackCall)
760
763
{
761
764
bool isUniform = pAI->getMetadata (" uniform" ) != nullptr ;
762
765
llvm::IRBuilder<> builder (pAI);
763
- IF_DEBUG_INFO (builder.SetCurrentDebugLocation (emptyDebugLoc ));
766
+ IF_DEBUG_INFO (builder.SetCurrentDebugLocation (entryDebugLoc ));
764
767
765
768
// SP will be adjusted to include all the alloca space, therefore offset need to be adjusted back
766
769
int scalarBufferOffset = m_ModAllocaInfo->getBufferOffset (pAI) - totalPrivateMemPerWI;
@@ -808,14 +811,13 @@ bool PrivateMemoryResolution::resolveAllocaInstuctions(bool stackCall)
808
811
llvm::IRBuilder<> builder (pAI);
809
812
// Post upgrade to LLVM 3.5.1, it was found that inliner propagates debug info of callee
810
813
// in to the alloca. Further, those allocas are somehow hoisted to the top of program.
811
- // When those allocas are lowered to below sequence, they result in prolog instructions
814
+ // When those allocas are lowered to below sequence, they result in prologue instructions
812
815
// pointing to a much later line of code. This causes a single src line to now have
813
816
// multiple VISA offset mappings and prevents debugger from setting breakpoints
814
- // correctly. So instead, we clear DebugLoc for the instructions generated by lowering
815
- // alloca and so the incorrect mapping will not be emitted .
817
+ // correctly. So instead, we set DebugLoc for the instructions generated by lowering
818
+ // alloca to mark that they are part of the prologue .
816
819
// Note: As per Amjad, later LLVM version has a fix for this in llvm/lib/Transforms/Utils/InlineFunction.cpp.
817
-
818
- IF_DEBUG_INFO (builder.SetCurrentDebugLocation (emptyDebugLoc));
820
+ IF_DEBUG_INFO (builder.SetCurrentDebugLocation (entryDebugLoc));
819
821
820
822
// Get buffer information from the analysis
821
823
unsigned int scalarBufferOffset = m_ModAllocaInfo->getBufferOffset (pAI);
@@ -949,7 +951,7 @@ bool PrivateMemoryResolution::resolveAllocaInstuctions(bool stackCall)
949
951
// %privateBuffer = bitcast i8* %offsettmp1 to <buffer type>
950
952
951
953
llvm::IRBuilder<> builder (pAI);
952
- IF_DEBUG_INFO (builder.SetCurrentDebugLocation (emptyDebugLoc ));
954
+ IF_DEBUG_INFO (builder.SetCurrentDebugLocation (entryDebugLoc ));
953
955
bool isUniform = pAI->getMetadata (" uniform" ) != nullptr ;
954
956
// Get buffer information from the analysis
955
957
unsigned int scalarBufferOffset = m_ModAllocaInfo->getBufferOffset (pAI);
0 commit comments