Skip to content

Commit 5311057

Browse files
[MemProf] Always add hints to allocations with memprof attributes (#157222)
Apply hints even if the attribute is the default "notcold" or "ambiguous", to enable better tracking through the allocator. Add an option to control the ambiguous allocation hint value.
1 parent 88a5429 commit 5311057

File tree

2 files changed

+145
-64
lines changed

2 files changed

+145
-64
lines changed

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ static cl::opt<unsigned, false, HotColdHintParser>
9797
static cl::opt<unsigned, false, HotColdHintParser> HotNewHintValue(
9898
"hot-new-hint-value", cl::Hidden, cl::init(254),
9999
cl::desc("Value to pass to hot/cold operator new for hot allocation"));
100+
static cl::opt<unsigned, false, HotColdHintParser> AmbiguousNewHintValue(
101+
"ambiguous-new-hint-value", cl::Hidden, cl::init(222),
102+
cl::desc(
103+
"Value to pass to hot/cold operator new for ambiguous allocation"));
100104

101105
//===----------------------------------------------------------------------===//
102106
// Helper Functions
@@ -1767,6 +1771,9 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
17671771
HotCold = NotColdNewHintValue;
17681772
else if (CI->getAttributes().getFnAttr("memprof").getValueAsString() == "hot")
17691773
HotCold = HotNewHintValue;
1774+
else if (CI->getAttributes().getFnAttr("memprof").getValueAsString() ==
1775+
"ambiguous")
1776+
HotCold = AmbiguousNewHintValue;
17701777
else
17711778
return nullptr;
17721779

@@ -1784,19 +1791,17 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
17841791
LibFunc_Znwm12__hot_cold_t, HotCold);
17851792
break;
17861793
case LibFunc_Znwm:
1787-
if (HotCold != NotColdNewHintValue)
1788-
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
1789-
LibFunc_Znwm12__hot_cold_t, HotCold);
1794+
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
1795+
LibFunc_Znwm12__hot_cold_t, HotCold);
17901796
break;
17911797
case LibFunc_Znam12__hot_cold_t:
17921798
if (OptimizeExistingHotColdNew)
17931799
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
17941800
LibFunc_Znam12__hot_cold_t, HotCold);
17951801
break;
17961802
case LibFunc_Znam:
1797-
if (HotCold != NotColdNewHintValue)
1798-
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
1799-
LibFunc_Znam12__hot_cold_t, HotCold);
1803+
return emitHotColdNew(CI->getArgOperand(0), B, TLI,
1804+
LibFunc_Znam12__hot_cold_t, HotCold);
18001805
break;
18011806
case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
18021807
if (OptimizeExistingHotColdNew)
@@ -1805,10 +1810,9 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
18051810
LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t, HotCold);
18061811
break;
18071812
case LibFunc_ZnwmRKSt9nothrow_t:
1808-
if (HotCold != NotColdNewHintValue)
1809-
return emitHotColdNewNoThrow(
1810-
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1811-
LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t, HotCold);
1813+
return emitHotColdNewNoThrow(CI->getArgOperand(0), CI->getArgOperand(1), B,
1814+
TLI, LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t,
1815+
HotCold);
18121816
break;
18131817
case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
18141818
if (OptimizeExistingHotColdNew)
@@ -1817,10 +1821,9 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
18171821
LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t, HotCold);
18181822
break;
18191823
case LibFunc_ZnamRKSt9nothrow_t:
1820-
if (HotCold != NotColdNewHintValue)
1821-
return emitHotColdNewNoThrow(
1822-
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1823-
LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t, HotCold);
1824+
return emitHotColdNewNoThrow(CI->getArgOperand(0), CI->getArgOperand(1), B,
1825+
TLI, LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t,
1826+
HotCold);
18241827
break;
18251828
case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
18261829
if (OptimizeExistingHotColdNew)
@@ -1829,10 +1832,9 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
18291832
LibFunc_ZnwmSt11align_val_t12__hot_cold_t, HotCold);
18301833
break;
18311834
case LibFunc_ZnwmSt11align_val_t:
1832-
if (HotCold != NotColdNewHintValue)
1833-
return emitHotColdNewAligned(
1834-
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1835-
LibFunc_ZnwmSt11align_val_t12__hot_cold_t, HotCold);
1835+
return emitHotColdNewAligned(CI->getArgOperand(0), CI->getArgOperand(1), B,
1836+
TLI, LibFunc_ZnwmSt11align_val_t12__hot_cold_t,
1837+
HotCold);
18361838
break;
18371839
case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
18381840
if (OptimizeExistingHotColdNew)
@@ -1841,10 +1843,9 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
18411843
LibFunc_ZnamSt11align_val_t12__hot_cold_t, HotCold);
18421844
break;
18431845
case LibFunc_ZnamSt11align_val_t:
1844-
if (HotCold != NotColdNewHintValue)
1845-
return emitHotColdNewAligned(
1846-
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1847-
LibFunc_ZnamSt11align_val_t12__hot_cold_t, HotCold);
1846+
return emitHotColdNewAligned(CI->getArgOperand(0), CI->getArgOperand(1), B,
1847+
TLI, LibFunc_ZnamSt11align_val_t12__hot_cold_t,
1848+
HotCold);
18481849
break;
18491850
case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
18501851
if (OptimizeExistingHotColdNew)
@@ -1854,11 +1855,9 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
18541855
HotCold);
18551856
break;
18561857
case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1857-
if (HotCold != NotColdNewHintValue)
1858-
return emitHotColdNewAlignedNoThrow(
1859-
CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), B,
1860-
TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1861-
HotCold);
1858+
return emitHotColdNewAlignedNoThrow(
1859+
CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), B,
1860+
TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t, HotCold);
18621861
break;
18631862
case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
18641863
if (OptimizeExistingHotColdNew)
@@ -1868,17 +1867,14 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
18681867
HotCold);
18691868
break;
18701869
case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1871-
if (HotCold != NotColdNewHintValue)
1872-
return emitHotColdNewAlignedNoThrow(
1873-
CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), B,
1874-
TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1875-
HotCold);
1870+
return emitHotColdNewAlignedNoThrow(
1871+
CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), B,
1872+
TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t, HotCold);
18761873
break;
18771874
case LibFunc_size_returning_new:
1878-
if (HotCold != NotColdNewHintValue)
1879-
return emitHotColdSizeReturningNew(CI->getArgOperand(0), B, TLI,
1880-
LibFunc_size_returning_new_hot_cold,
1881-
HotCold);
1875+
return emitHotColdSizeReturningNew(CI->getArgOperand(0), B, TLI,
1876+
LibFunc_size_returning_new_hot_cold,
1877+
HotCold);
18821878
break;
18831879
case LibFunc_size_returning_new_hot_cold:
18841880
if (OptimizeExistingHotColdNew)
@@ -1887,10 +1883,9 @@ Value *LibCallSimplifier::optimizeNew(CallInst *CI, IRBuilderBase &B,
18871883
HotCold);
18881884
break;
18891885
case LibFunc_size_returning_new_aligned:
1890-
if (HotCold != NotColdNewHintValue)
1891-
return emitHotColdSizeReturningNewAligned(
1892-
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1893-
LibFunc_size_returning_new_aligned_hot_cold, HotCold);
1886+
return emitHotColdSizeReturningNewAligned(
1887+
CI->getArgOperand(0), CI->getArgOperand(1), B, TLI,
1888+
LibFunc_size_returning_new_aligned_hot_cold, HotCold);
18941889
break;
18951890
case LibFunc_size_returning_new_aligned_hot_cold:
18961891
if (OptimizeExistingHotColdNew)

0 commit comments

Comments
 (0)