From 9f53737bf3fd5d10ab2dd3cb1abaf04dd880ef95 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 4 Nov 2021 00:35:06 +0100 Subject: [PATCH] Set IL offsets for calls created during devirtualization Since inlined statements use the IL location of the inliner's statement all statements created while inlining devirtualized calls would get no debug info before, while normally these will have IL location pointing to the call statement in the root. --- src/coreclr/jit/compiler.h | 6 +++--- src/coreclr/jit/fgstmt.cpp | 14 ++++++++------ src/coreclr/jit/indirectcalltransformer.cpp | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 03a71eae71077..befb4a6f60b7b 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -6144,10 +6144,10 @@ class Compiler #endif public: - Statement* fgNewStmtAtBeg(BasicBlock* block, GenTree* tree); + Statement* fgNewStmtAtBeg(BasicBlock* block, GenTree* tree, IL_OFFSETX offs = BAD_IL_OFFSET); void fgInsertStmtAtEnd(BasicBlock* block, Statement* stmt); - Statement* fgNewStmtAtEnd(BasicBlock* block, GenTree* tree); - Statement* fgNewStmtNearEnd(BasicBlock* block, GenTree* tree); + Statement* fgNewStmtAtEnd(BasicBlock* block, GenTree* tree, IL_OFFSETX offs = BAD_IL_OFFSET); + Statement* fgNewStmtNearEnd(BasicBlock* block, GenTree* tree, IL_OFFSETX offs = BAD_IL_OFFSET); private: void fgInsertStmtNearEnd(BasicBlock* block, Statement* stmt); diff --git a/src/coreclr/jit/fgstmt.cpp b/src/coreclr/jit/fgstmt.cpp index 256e8ede73420..67da44726f994 100644 --- a/src/coreclr/jit/fgstmt.cpp +++ b/src/coreclr/jit/fgstmt.cpp @@ -101,13 +101,14 @@ void Compiler::fgInsertStmtAtBeg(BasicBlock* block, Statement* stmt) // Arguments: // block - the block into which 'tree' will be inserted; // tree - the tree to be inserted. +// offs - the offset to use for the statement // // Return Value: // The new created statement with `tree` inserted into `block`. // -Statement* Compiler::fgNewStmtAtBeg(BasicBlock* block, GenTree* tree) +Statement* Compiler::fgNewStmtAtBeg(BasicBlock* block, GenTree* tree, IL_OFFSETX offs) { - Statement* stmt = gtNewStmt(tree); + Statement* stmt = gtNewStmt(tree, offs); fgInsertStmtAtBeg(block, stmt); return stmt; } @@ -153,6 +154,7 @@ void Compiler::fgInsertStmtAtEnd(BasicBlock* block, Statement* stmt) // Arguments: // block - the block into which 'stmt' will be inserted; // tree - the tree to be inserted. +// offs - the offset to use for the statement // // Return Value: // The new created statement with `tree` inserted into `block`. @@ -160,9 +162,9 @@ void Compiler::fgInsertStmtAtEnd(BasicBlock* block, Statement* stmt) // Note: // If the block can be a conditional block, use fgNewStmtNearEnd. // -Statement* Compiler::fgNewStmtAtEnd(BasicBlock* block, GenTree* tree) +Statement* Compiler::fgNewStmtAtEnd(BasicBlock* block, GenTree* tree, IL_OFFSETX offs) { - Statement* stmt = gtNewStmt(tree); + Statement* stmt = gtNewStmt(tree, offs); fgInsertStmtAtEnd(block, stmt); return stmt; } @@ -245,9 +247,9 @@ void Compiler::fgInsertStmtNearEnd(BasicBlock* block, Statement* stmt) // Return Value: // The new created statement with `tree` inserted into `block`. // -Statement* Compiler::fgNewStmtNearEnd(BasicBlock* block, GenTree* tree) +Statement* Compiler::fgNewStmtNearEnd(BasicBlock* block, GenTree* tree, IL_OFFSETX offs) { - Statement* stmt = gtNewStmt(tree); + Statement* stmt = gtNewStmt(tree, offs); fgInsertStmtNearEnd(block, stmt); return stmt; } diff --git a/src/coreclr/jit/indirectcalltransformer.cpp b/src/coreclr/jit/indirectcalltransformer.cpp index 6be64a86b6ebb..feb7418fbb869 100644 --- a/src/coreclr/jit/indirectcalltransformer.cpp +++ b/src/coreclr/jit/indirectcalltransformer.cpp @@ -781,14 +781,14 @@ class IndirectCallTransformer } else { - compiler->fgNewStmtAtEnd(thenBlock, call); + compiler->fgNewStmtAtEnd(thenBlock, call, stmt->GetILOffsetX()); } } else { // Add the call. // - compiler->fgNewStmtAtEnd(thenBlock, call); + compiler->fgNewStmtAtEnd(thenBlock, call, stmt->GetILOffsetX()); // Re-establish this call as an inline candidate. // @@ -831,7 +831,7 @@ class IndirectCallTransformer elseBlock = CreateAndInsertBasicBlock(BBJ_NONE, thenBlock); elseBlock->bbFlags |= currBlock->bbFlags & BBF_SPLIT_GAINED; GenTreeCall* call = origCall; - Statement* newStmt = compiler->gtNewStmt(call); + Statement* newStmt = compiler->gtNewStmt(call, stmt->GetILOffsetX()); call->gtFlags &= ~GTF_CALL_INLINE_CANDIDATE; call->SetIsGuarded();