@@ -34,6 +34,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3434
3535#include " common/LLVMWarningsPush.hpp"
3636#include " llvm/IR/DataLayout.h"
37+ #include " llvm/IR/DebugInfoMetadata.h"
3738#include " llvm/IR/Dominators.h"
3839#include " common/LLVMWarningsPop.hpp"
3940
@@ -77,7 +78,7 @@ namespace IGC {
7778
7879 // / @brief Resolve collected alloca instructions.
7980 // / @return true if there were resolved alloca, false otherwise.
80- bool resolveAllocaInstuctions (bool stackCall);
81+ bool resolveAllocaInstructions (bool stackCall);
8182
8283 // / Initialize setup like UseScratchSpacePrivateMemory.
8384 bool safeToUseScratchSpace (llvm::Module& M) const ;
@@ -493,7 +494,7 @@ bool PrivateMemoryResolution::runOnModule(llvm::Module& M)
493494 }
494495 bool hasStackCall = (FGA && FGA->getGroup (m_currFunction)->hasStackCall ());
495496 // Resolve collected alloca instructions for current function
496- changed |= resolveAllocaInstuctions (hasStackCall);
497+ changed |= resolveAllocaInstructions (hasStackCall);
497498 }
498499
499500 if (changed)
@@ -540,7 +541,7 @@ bool PrivateMemoryResolution::runOnModule(llvm::Module& M)
540541static void sinkAllocas (SmallVectorImpl<AllocaInst*>& Allocas) {
541542 assert (!Allocas.empty ());
542543 DominatorTree DT;
543- bool Calcluated = false ;
544+ bool Calcuated = false ;
544545
545546 // For each alloca, sink it if it has a use that dominates all other uses.
546547 // This use is called the dominating use.
@@ -567,10 +568,10 @@ static void sinkAllocas(SmallVectorImpl<AllocaInst*>& Allocas) {
567568 continue ;
568569
569570 // Compute dominator tree lazily.
570- if (!Calcluated ) {
571+ if (!Calcuated ) {
571572 Function* F = AI->getParent ()->getParent ();
572573 DT.recalculate (*F);
573- Calcluated = true ;
574+ Calcuated = true ;
574575 }
575576
576577 // Find the Nearest Common Denominator for all the uses
@@ -683,7 +684,7 @@ class TransposeHelperPrivateMem : public TransposeHelper
683684};
684685
685686
686- bool PrivateMemoryResolution::resolveAllocaInstuctions (bool stackCall)
687+ bool PrivateMemoryResolution::resolveAllocaInstructions (bool stackCall)
687688{
688689 // It is possible that there is no alloca instruction in the caller but there
689690 // is alloca in the callee. Save the total private memory to the metadata.
@@ -745,9 +746,11 @@ bool PrivateMemoryResolution::resolveAllocaInstuctions(bool stackCall)
745746 llvm::IRBuilder<> entryBuilder (&*m_currFunction->getEntryBlock ().getFirstInsertionPt ());
746747 ImplicitArgs implicitArgs (*m_currFunction, m_pMdUtils);
747748
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));
751754
752755 if (stackCall)
753756 {
@@ -760,7 +763,7 @@ bool PrivateMemoryResolution::resolveAllocaInstuctions(bool stackCall)
760763 {
761764 bool isUniform = pAI->getMetadata (" uniform" ) != nullptr ;
762765 llvm::IRBuilder<> builder (pAI);
763- IF_DEBUG_INFO (builder.SetCurrentDebugLocation (emptyDebugLoc ));
766+ IF_DEBUG_INFO (builder.SetCurrentDebugLocation (entryDebugLoc ));
764767
765768 // SP will be adjusted to include all the alloca space, therefore offset need to be adjusted back
766769 int scalarBufferOffset = m_ModAllocaInfo->getBufferOffset (pAI) - totalPrivateMemPerWI;
@@ -808,14 +811,13 @@ bool PrivateMemoryResolution::resolveAllocaInstuctions(bool stackCall)
808811 llvm::IRBuilder<> builder (pAI);
809812 // Post upgrade to LLVM 3.5.1, it was found that inliner propagates debug info of callee
810813 // 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
812815 // pointing to a much later line of code. This causes a single src line to now have
813816 // 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 .
816819 // 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));
819821
820822 // Get buffer information from the analysis
821823 unsigned int scalarBufferOffset = m_ModAllocaInfo->getBufferOffset (pAI);
@@ -949,7 +951,7 @@ bool PrivateMemoryResolution::resolveAllocaInstuctions(bool stackCall)
949951 // %privateBuffer = bitcast i8* %offsettmp1 to <buffer type>
950952
951953 llvm::IRBuilder<> builder (pAI);
952- IF_DEBUG_INFO (builder.SetCurrentDebugLocation (emptyDebugLoc ));
954+ IF_DEBUG_INFO (builder.SetCurrentDebugLocation (entryDebugLoc ));
953955 bool isUniform = pAI->getMetadata (" uniform" ) != nullptr ;
954956 // Get buffer information from the analysis
955957 unsigned int scalarBufferOffset = m_ModAllocaInfo->getBufferOffset (pAI);
0 commit comments