Skip to content

Bound external memory field expansion - #1883

Merged
yuleisui merged 1 commit into
SVF-tools:masterfrom
bjjwwang:fix/extapi-field-expansion-limit
Aug 31, 2026
Merged

Bound external memory field expansion #1883
yuleisui merged 1 commit into
SVF-tools:masterfrom
bjjwwang:fix/extapi-field-expansion-limit

Conversation

@bjjwwang

Copy link
Copy Markdown
Contributor

Sub- PR from #1878

Aggregate memcpy and memset models create one SVF statement per flattened field, so a single external call can dominate SVFIR construction on large recovered types.

Add the opt-in -ext-mem-field-limit option. Once the limit is exceeded, summarize the operation through field-insensitive variant-GEP pointers instead of continuing field-wise expansion. Statically resolved objects are marked immediately, while variant GEPs conservatively collapse objects discovered during points-to analysis, including objects reached through formal parameters.

The option defaults to zero (unlimited), preserving existing behavior.

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.89%. Comparing base (dc7da7e) to head (c763274).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1883   +/-   ##
=======================================
  Coverage   67.89%   67.89%           
=======================================
  Files         261      261           
  Lines       26677    26682    +5     
  Branches     5110     5109    -1     
=======================================
+ Hits        18112    18117    +5     
  Misses       8565     8565           
Files with missing lines Coverage Δ
svf-llvm/lib/SVFIRExtAPI.cpp 88.69% <100.00%> (+0.25%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread svf/include/Util/Options.h Outdated
/// Maximum number of flattened fields expanded for one external memory
/// operation (e.g. memcpy/memset) before it is summarized. 0 (the default)
/// keeps the unlimited field-by-field expansion.
static const Option<u32_t> ExtMemFieldLimit;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need another option but not reusing Options::MaxFieldLimit()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need another option but not reusing Options::MaxFieldLimit()?

Reuse it

@bjjwwang
bjjwwang force-pushed the fix/extapi-field-expansion-limit branch from c018f8f to 953ba92 Compare August 25, 2026 23:53
Comment thread svf-llvm/lib/SVFIRExtAPI.cpp Outdated
return objType;
}

void SVFIRBuilder::addExtMemCopySummary(Value* D, Value* S)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this method?

@bjjwwang
bjjwwang force-pushed the fix/extapi-field-expansion-limit branch from 953ba92 to 55cb4a4 Compare August 26, 2026 12:08
@yuleisui

Copy link
Copy Markdown
Collaborator

Have you tested the large bcs? I will merge it once the testing is done.

@bjjwwang

Copy link
Copy Markdown
Contributor Author

--- base.log
+++ delta.log
@@ -9,39 +9,39 @@
ConstStructObj 63
ConstantObj 0
CopysNum 14437
-FIObjNum 6561
-FSObjNum 24011
+FIObjNum 6562
+FSObjNum 24010
FunctionObjs 5103
-GepsNum 75113
+GepsNum 69802
GlobalObjs 1682
HeapObjs 207
IndCallSites 1450
-LoadsNum 122603
+LoadsNum 119955
MaxStructSize 3115
NonPtrObj 17828
ReturnsNum 13415
StackObjs 23580
-StoresNum 70292
+StoresNum 67629
TotalCallSite 31388
-TotalFieldObjects 4391
-TotalObjects 34964
-TotalPTASVFStmts 246217
-TotalPointers 452077
-TotalSVFStmts 448503
+TotalFieldObjects 4384
+TotalObjects 34957
+TotalPTASVFStmts 235610
+TotalPointers 442118
+TotalSVFStmts 437881
VarArrayObj 480
VarStructObj 1674
----------------Time and memory stats--------------------
-LLVMIRTime 0.638246
-SVFIRTime 2.22761
-SymbolTableTime 0.220104
+LLVMIRTime 0.61508
+SVFIRTime 2.09037
+SymbolTableTime 0.233666
#######################################################

PTACallGraph Stats (Andersen analysis)******
################ (program : redis.bc)###############
----------------Numbers stats----------------------------
-CalRetPairInCycle 46958
-MaxNodeInCycle 2667
-NodeInCycle 2690
+CalRetPairInCycle 46497
+MaxNodeInCycle 2663
+NodeInCycle 2686
TotalCycle 19
TotalEdge 80006
TotalNode 5103
@@ -50,13 +50,13 @@
Andersen Pointer Analysis Stats******
################ (program : redis.bc)###############
----------------Time and memory stats--------------------
-AvgIn/OutAddrEdge 0.169167
-AvgIn/OutCopyEdge 1.01081
-AvgIn/OutEdge 1.67608
-AvgIn/OutLoadEdge 0.334779
-AvgIn/OutStoreEdge 0.161329
-AvgPtsSetSize 477.991
-AvgTopLvlPtsSize 1000.59
+AvgIn/OutAddrEdge 0.175494
+AvgIn/OutCopyEdge 0.950185
+AvgIn/OutEdge 1.6152
+AvgIn/OutLoadEdge 0.334693
+AvgIn/OutStoreEdge 0.154824
+AvgPtsSetSize 485.872
+AvgTopLvlPtsSize 1024.75
CollapseTime 0
CopyGepTime 0
LoadStoreTime 0
@@ -64,155 +64,155 @@
MemoryUsageVmsize 0
SCCDetectTime 0
SCCMergeTime 0
-TotalTime 138.523
+TotalTime 123.924
UpdateCGTime 0
----------------Numbers stats----------------------------
AddrProcessed 42715
-CopyProcessed 484643
+CopyProcessed 469052
DummyFieldPtrs 1721
-FieldObjs 4391
-GepProcessed 219175
+FieldObjs 4384
+GepProcessed 213616
IndCallSites 1450
IndEdgeSolved 50000
-LoadProcessed 112714835
+LoadProcessed 112562180
LocalVarInRecur 1720
MaxInAddrEdge 1
-MaxInCopyEdge 7853
-MaxInLoadEdge 8392
+MaxInCopyEdge 5215
+MaxInLoadEdge 8308
MaxInStoreEdge 260
MaxNodesInSCC 91
MaxOutAddrEdge 12170
-MaxOutCopyEdge 27176
+MaxOutCopyEdge 27193
MaxOutLoadEdge 385
-MaxOutStoreEdge 7103
-MaxPtsSetSize 2265
-MemObjects 34964
+MaxOutStoreEdge 7048
+MaxPtsSetSize 2260
+MemObjects 34957
NodesInCycles 1563
NullPointer 2802
-NumOfAddrs 37250
-NumOfCGEdge 331817
-NumOfCGNode 223987
-NumOfCopys 148178
+NumOfAddrs 37265
+NumOfCGEdge 305712
+NumOfCGNode 216130
+NumOfCopys 132679
NumOfFieldExpand 0
-NumOfGeps 74398
-NumOfLoads 73717
+NumOfGeps 69087
+NumOfLoads 71070
NumOfSCCDetect 14
NumOfSFRs 0
-NumOfStores 35524
-NumOfValidNode 220196
-NumOfValidObjNode 27478
-Pointers 452077
+NumOfStores 32876
+NumOfValidNode 212344
+NumOfValidObjNode 27491
+Pointers 442118
PointsToBlkPtr 0
-PointsToConstPtr 26882
+PointsToConstPtr 26852
SolveIterations 14
-StoreProcessed 8205000
+StoreProcessed 8193604
TotalCycleNum 220
-TotalObjects 34964
+TotalObjects 34957
TotalPWCCycleNum 61
-TotalPointers 452077
+TotalPointers 442118
#######################################################

Persistent Points-To Cache Statistics: Andersen's analysis bitvector
################ (program : redis.bc)###############
-UniquePointsToSets 64867
-TotalUnions 887078
-PropertyUnions 312491
-UniqueUnions 16091
-LookupUnions 528325
-PreemptiveUnions 30171
-TotalComplements 3345340
-PropertyComplements 2865351
-UniqueComplements 19179
-LookupComplements 441632
-PreemptiveComplements 19178
-TotalIntersections 12716631
-PropertyIntersections 12673733
-UniqueIntersections 84
-LookupIntersections 4374
-PreemptiveIntersections 38440
+UniquePointsToSets 64862
+TotalUnions 865725
+PropertyUnions 304102
+UniqueUnions 16068
+LookupUnions 515417
+PreemptiveUnions 30138
+TotalComplements 3234683
+PropertyComplements 2754815
+UniqueComplements 19184
+LookupComplements 441501
+PreemptiveComplements 19183
+TotalIntersections 12600276
+PropertyIntersections 12557418
+UniqueIntersections 78
+LookupIntersections 4335
+PreemptiveIntersections 38445
#######################################################

Memory SSA Statistics******
################ (program : redis.bc)###############
----------------Time and memory stats--------------------
-AverageRegSize 29.8393
-GenMUCHITime 1.19266
-GenRegionTime 226.553
-InsertPHITime 0.267744
-SSARenameTime 0.044949
-TotalMSSATime 228.066
+AverageRegSize 29.9425
+GenMUCHITime 1.13361
+GenRegionTime 293.312
+InsertPHITime 0.256734
+SSARenameTime 0.041727
+TotalMSSATime 294.751
----------------Numbers stats----------------------------
-BBHasMSSAPhi 8961
-CSChiNode 71504
-CSHasChi 16916
-CSHasMu 19767
-CSMuNode 107036
-FunEntryChi 32537
+BBHasMSSAPhi 8945
+CSChiNode 71292
+CSHasChi 16869
+CSHasMu 19765
+CSMuNode 106859
+FunEntryChi 32529
FunHasEntryChi 4595
FunHasRetMu 4799
-FunRetMu 32505
-LoadHasMu 78393
-LoadMuNode 114804
-MSSAPhi 48403
-MaxRegSize 2148
+FunRetMu 32497
+LoadHasMu 75745
+LoadMuNode 109461
+MSSAPhi 48300
+MaxRegSize 2143
MemRegions 16414
-StoreChiNode 28364
-StoreHasChi 25133
+StoreChiNode 25716
+StoreHasChi 22485
#######################################################

SVFG Statistics******
################ (program : redis.bc)###############
----------------Time and memory stats--------------------
-ATNodeTime 0.294275
-AvgWeight 232.12
+ATNodeTime 0.269885
+AvgWeight 235.101
ConnDirEdgeTime 0
-ConnIndEdgeTime 3.58679
+ConnIndEdgeTime 3.40785
OptTime 0
TLNodeTime 0
-TotalTime 3.88107
+TotalTime 3.67774
----------------Numbers stats----------------------------
-ActualIn 107036
-ActualOut 71504
+ActualIn 106859
+ActualOut 71292
ActualParam 43388
ActualRet 6778
Addr 42715
AvgInDegree 1
AvgIndInDeg 1
-AvgIndOutDeg 2
+AvgIndOutDeg 1
AvgOutDegree 1
Copy 560
DirectCallEdge 35233
-DirectEdge 315337
+DirectEdge 302082
DirectRetEdge 5990
-FormalIn 32537
-FormalOut 32505
+FormalIn 32529
+FormalOut 32497
FormalParam 6847
FormalRet 870
-Gep 75113
-IndCallEdge 121412
-IndRetEdge 76682
-IndirectEdge 600198
-IndirectEdgeLabels 139317670
-Load 78393
-MSSAPhi 48403
+Gep 69802
+IndCallEdge 121234
+IndRetEdge 76468
+IndirectEdge 591378
+IndirectEdgeLabels 139033601
+Load 75745
+MSSAPhi 48300
MaxInDegree 8563
MaxIndInDeg 8563
-MaxIndOutDeg 3100
+MaxIndOutDeg 1633
MaxOutDegree 8130
PHI 1205
-Store 37241
-TotalEdge 915535
-TotalNode 585096
+Store 34593
+TotalEdge 893460
+TotalNode 573981
#######################################################

PTACallGraph Stats (Flow-sensitive analysis)******
################ (program : redis.bc)###############
----------------Numbers stats----------------------------
-CalRetPairInCycle 45356
-FIObjNum 6562
-FSObjNum 24011
-MaxNodeInCycle 2289
-NodeInCycle 2317
+CalRetPairInCycle 45414
+FIObjNum 6563
+FSObjNum 24010
+MaxNodeInCycle 2284
+NodeInCycle 2312
TotalCycle 24
TotalEdge 80006
TotalNode 5103
@@ -223,9 +223,9 @@
----------------Time and memory stats--------------------
AddrTime 0
AverageSCCSize 0
-AvgPtsSize 124.24
-AvgTopLvlPtsSize 889.425
-AvgVersionPtsSize 143.919
+AvgPtsSize 100.944
+AvgTopLvlPtsSize 909.692
+AvgVersionPtsSize 132.435
CopyTime 0
DirectPropaTime 0
GepTime 0
@@ -234,61 +234,61 @@
MemoryUsageVmrss 0
MemoryUsageVmsize 0
PhiTime 0
-PrelabelingTime 0.058502
+PrelabelingTime 0.06032
ProcessTime 0
PropagationTime 0
SCCTime 0
-SolveTime 269.724
+SolveTime 273.684
StoreTime 0
Strong/WeakUpdTime 0
-TotalTime 412.341
+TotalTime 405.231
UpdateCGTime 0
VersionPropTime 0
-meldLabelingTime 140.662
+meldLabelingTime 129.575
----------------Numbers stats----------------------------
CopysNum 560
DummyFieldPtrs 1721
-FieldObjs 4393
+FieldObjs 4386
IndEdgeSolved 50000
-LocalVarInRecur 16201
-MaxPtsSize 2217
+LocalVarInRecur 16205
+MaxPtsSize 2210
MaxSCCSize 1
-MaxTopLvlPtsSize 2217
-MaxVersionPtsSize 2192
+MaxTopLvlPtsSize 2210
+MaxVersionPtsSize 2185
MaxVersionsForObj 0
-MemObjects 34964
+MemObjects 34957
NumOfNodesInSCC 0
NumOfSCC 0
-Pointers 452077
+Pointers 442118
ProcessedAParam 0
ProcessedAddr 85430
-ProcessedCopy 3283
+ProcessedCopy 3299
ProcessedFRet 0
-ProcessedGep 518383
-ProcessedLoad 1512461
-ProcessedMSSANode 583970
-ProcessedPhi 11937
-ProcessedStore 502245
+ProcessedGep 501428
+ProcessedLoad 1524456
+ProcessedMSSANode 582954
+ProcessedPhi 11904
+ProcessedStore 450595
SolveIterations 2
-StoresNum 37241
-StrongUpdates 8898
+StoresNum 34593
+StrongUpdates 8895
TotalEmptyVPts 0
-TotalExistingVPts 25313210
-TotalNonEmptyVPts 25313210
-TotalObjects 34964
-TotalPointers 452077
+TotalExistingVPts 25235280
+TotalNonEmptyVPts 25235280
+TotalObjects 34957
+TotalPointers 442118
TotalSingleVObjs 0
-TotalVersions 27418826
+TotalVersions 27381544
#######################################################

Persistent Points-To Cache Statistics: flow-sensitive analysis bitvector
################ (program : redis.bc)###############
-UniquePointsToSets 52139
-TotalUnions 1377530786
-PropertyUnions 1194590373
-UniqueUnions 58537
-LookupUnions 182803232
-PreemptiveUnions 78644
+UniquePointsToSets 52099
+TotalUnions 1396693309
+PropertyUnions 1213112606
+UniqueUnions 58460
+LookupUnions 183443712
+PreemptiveUnions 78531
TotalComplements 0
PropertyComplements 0
UniqueComplements 0

Comment thread svf-llvm/lib/SVFIRExtAPI.cpp Outdated
const DataLayout& dl,
IRGraph* pag,
std::vector<MemcpyField>& fields,
u32_t fieldLimit,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this argument? If not, pls remove.

@bjjwwang
bjjwwang force-pushed the fix/extapi-field-expansion-limit branch from 55cb4a4 to 4f95e0f Compare August 31, 2026 00:46
Comment thread svf-llvm/lib/SVFIRExtAPI.cpp Outdated
{
if (llvmType == nullptr || svfType == nullptr)
return;
if (fields.size() >= std::max(Options::MaxFieldLimit(), 1u))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sound

@bjjwwang
bjjwwang force-pushed the fix/extapi-field-expansion-limit branch 3 times, most recently from 634affc to 31ec4fc Compare August 31, 2026 03:14
Aggregate memcpy and memset models create GEP, load, and store statements for each flattened field. A single external call can therefore dominate SVFIR construction even though the existing field limit already bounds object field sensitivity.

Apply -field-limit while collecting AccessPaths and byte-layout pointer fields for external memory operations, then reuse the existing field-wise modeling. This bounds generated statements by a constant factor of the field limit without adding another option or a separate summary path.

A zero field limit retains one representative field, consistent with field-insensitive object modeling.
@bjjwwang
bjjwwang force-pushed the fix/extapi-field-expansion-limit branch from 31ec4fc to c763274 Compare August 31, 2026 03:32
@yuleisui
yuleisui merged commit 15224fc into SVF-tools:master Aug 31, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants