@@ -4838,6 +4838,35 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
4838
4838
return NewAI;
4839
4839
}
4840
4840
4841
+ static void insertNewDbgInst (DIBuilder &DIB, DbgDeclareInst *Orig,
4842
+ AllocaInst *NewAddr, DIExpression *NewFragmentExpr,
4843
+ Instruction *BeforeInst) {
4844
+ DIB.insertDeclare (NewAddr, Orig->getVariable (), NewFragmentExpr,
4845
+ Orig->getDebugLoc (), BeforeInst);
4846
+ }
4847
+ static void insertNewDbgInst (DIBuilder &DIB, DbgAssignIntrinsic *Orig,
4848
+ AllocaInst *NewAddr, DIExpression *NewFragmentExpr,
4849
+ Instruction *BeforeInst) {
4850
+ (void )BeforeInst;
4851
+ if (!NewAddr->hasMetadata (LLVMContext::MD_DIAssignID)) {
4852
+ NewAddr->setMetadata (LLVMContext::MD_DIAssignID,
4853
+ DIAssignID::getDistinct (NewAddr->getContext ()));
4854
+ }
4855
+ auto *NewAssign = DIB.insertDbgAssign (
4856
+ NewAddr, Orig->getValue (), Orig->getVariable (), NewFragmentExpr, NewAddr,
4857
+ Orig->getAddressExpression (), Orig->getDebugLoc ());
4858
+ LLVM_DEBUG (dbgs () << " Created new assign intrinsic: " << *NewAssign << " \n " );
4859
+ }
4860
+ static void insertNewDbgInst (DIBuilder &DIB, DPValue *Orig, AllocaInst *NewAddr,
4861
+ DIExpression *NewFragmentExpr,
4862
+ Instruction *BeforeInst) {
4863
+ (void )DIB;
4864
+ DPValue *New = new DPValue (ValueAsMetadata::get (NewAddr), Orig->getVariable (),
4865
+ NewFragmentExpr, Orig->getDebugLoc (),
4866
+ DPValue::LocationType::Declare);
4867
+ BeforeInst->getParent ()->insertDPValueBefore (New, BeforeInst->getIterator ());
4868
+ }
4869
+
4841
4870
// / Walks the slices of an alloca and form partitions based on them,
4842
4871
// / rewriting each of their uses.
4843
4872
bool SROA::splitAlloca (AllocaInst &AI, AllocaSlices &AS) {
@@ -4939,15 +4968,7 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
4939
4968
4940
4969
// Migrate debug information from the old alloca to the new alloca(s)
4941
4970
// and the individual partitions.
4942
- TinyPtrVector<DbgVariableIntrinsic *> DbgVariables;
4943
- SmallVector<DbgDeclareInst *, 1 > DbgDeclares;
4944
- findDbgDeclares (DbgDeclares, &AI);
4945
- for (auto *DbgDeclare : DbgDeclares)
4946
- DbgVariables.push_back (DbgDeclare);
4947
- for (auto *DbgAssign : at::getAssignmentMarkers (&AI))
4948
- DbgVariables.push_back (DbgAssign);
4949
-
4950
- for (DbgVariableIntrinsic *DbgVariable : DbgVariables) {
4971
+ auto MigrateOne = [&](auto *DbgVariable) {
4951
4972
auto *Expr = DbgVariable->getExpression ();
4952
4973
DIBuilder DIB (*AI.getModule (), /* AllowUnresolved*/ false );
4953
4974
uint64_t AllocaSize =
@@ -5001,37 +5022,33 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
5001
5022
// Remove any existing intrinsics on the new alloca describing
5002
5023
// the variable fragment.
5003
5024
SmallVector<DbgDeclareInst *, 1 > FragDbgDeclares;
5004
- findDbgDeclares (FragDbgDeclares, Fragment. Alloca ) ;
5005
- for (DbgDeclareInst *OldDII : FragDbgDeclares) {
5006
- auto SameVariableFragment = []( const DbgVariableIntrinsic *LHS,
5007
- const DbgVariableIntrinsic *RHS) {
5025
+ SmallVector<DPValue *, 1 > FragDPVs ;
5026
+ findDbgDeclares (FragDbgDeclares, Fragment. Alloca , &FragDPVs);
5027
+ auto RemoveOne = [DbgVariable]( auto *OldDII) {
5028
+ auto SameVariableFragment = []( const auto *LHS, const auto *RHS) {
5008
5029
return LHS->getVariable () == RHS->getVariable () &&
5009
5030
LHS->getDebugLoc ()->getInlinedAt () ==
5010
5031
RHS->getDebugLoc ()->getInlinedAt ();
5011
5032
};
5012
5033
if (SameVariableFragment (OldDII, DbgVariable))
5013
5034
OldDII->eraseFromParent ();
5014
- }
5035
+ };
5036
+ for_each (FragDbgDeclares, RemoveOne);
5037
+ for_each (FragDPVs, RemoveOne);
5015
5038
5016
- if (auto *DbgAssign = dyn_cast<DbgAssignIntrinsic>(DbgVariable)) {
5017
- if (!Fragment.Alloca ->hasMetadata (LLVMContext::MD_DIAssignID)) {
5018
- Fragment.Alloca ->setMetadata (
5019
- LLVMContext::MD_DIAssignID,
5020
- DIAssignID::getDistinct (AI.getContext ()));
5021
- }
5022
- auto *NewAssign = DIB.insertDbgAssign (
5023
- Fragment.Alloca , DbgAssign->getValue (), DbgAssign->getVariable (),
5024
- FragmentExpr, Fragment.Alloca , DbgAssign->getAddressExpression (),
5025
- DbgAssign->getDebugLoc ());
5026
- NewAssign->setDebugLoc (DbgAssign->getDebugLoc ());
5027
- LLVM_DEBUG (dbgs () << " Created new assign intrinsic: " << *NewAssign
5028
- << " \n " );
5029
- } else {
5030
- DIB.insertDeclare (Fragment.Alloca , DbgVariable->getVariable (),
5031
- FragmentExpr, DbgVariable->getDebugLoc (), &AI);
5032
- }
5039
+ insertNewDbgInst (DIB, DbgVariable, Fragment.Alloca , FragmentExpr, &AI);
5033
5040
}
5034
- }
5041
+ };
5042
+
5043
+ // Migrate debug information from the old alloca to the new alloca(s)
5044
+ // and the individual partitions.
5045
+ SmallVector<DbgDeclareInst *, 1 > DbgDeclares;
5046
+ SmallVector<DPValue *, 1 > DPValues;
5047
+ findDbgDeclares (DbgDeclares, &AI, &DPValues);
5048
+ for_each (DbgDeclares, MigrateOne);
5049
+ for_each (DPValues, MigrateOne);
5050
+ for_each (at::getAssignmentMarkers (&AI), MigrateOne);
5051
+
5035
5052
return Changed;
5036
5053
}
5037
5054
@@ -5153,9 +5170,12 @@ bool SROA::deleteDeadInstructions(
5153
5170
if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
5154
5171
DeletedAllocas.insert (AI);
5155
5172
SmallVector<DbgDeclareInst *, 1 > DbgDeclares;
5156
- findDbgDeclares (DbgDeclares, AI);
5173
+ SmallVector<DPValue *, 1 > DPValues;
5174
+ findDbgDeclares (DbgDeclares, AI, &DPValues);
5157
5175
for (DbgDeclareInst *OldDII : DbgDeclares)
5158
5176
OldDII->eraseFromParent ();
5177
+ for (DPValue *OldDII : DPValues)
5178
+ OldDII->eraseFromParent ();
5159
5179
}
5160
5180
5161
5181
at::deleteAssignmentMarkers (I);
0 commit comments