Skip to content

Commit 9366610

Browse files
committed
[Attributor][NFC] Add querying AA to shouldSpecializeCallSiteForCallee
The callback might require an AA, e.g., to ask other AAs for information in a way that will enfore dependences.
1 parent b11ef3a commit 9366610

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,8 @@ struct AttributorConfig {
14191419

14201420
/// Callback function to determine if an indirect call targets should be made
14211421
/// direct call targets (with an if-cascade).
1422-
std::function<bool(Attributor &A, CallBase &CB, Function &AssummedCallee)>
1422+
std::function<bool(Attributor &A, const AbstractAttribute &AA, CallBase &CB,
1423+
Function &AssummedCallee)>
14231424
IndirectCalleeSpecializationCallback = nullptr;
14241425

14251426
/// Helper to update an underlying call graph and to delete functions.
@@ -1695,10 +1696,11 @@ struct Attributor {
16951696

16961697
/// Return true if we should specialize the call site \b CB for the potential
16971698
/// callee \p Fn.
1698-
bool shouldSpecializeCallSiteForCallee(CallBase &CB, Function &Callee) {
1699+
bool shouldSpecializeCallSiteForCallee(const AbstractAttribute &AA,
1700+
CallBase &CB, Function &Callee) {
16991701
return Configuration.IndirectCalleeSpecializationCallback
1700-
? Configuration.IndirectCalleeSpecializationCallback(*this, CB,
1701-
Callee)
1702+
? Configuration.IndirectCalleeSpecializationCallback(*this, AA,
1703+
CB, Callee)
17021704
: true;
17031705
}
17041706

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,18 +3752,19 @@ static bool runAttributorOnFunctions(InformationCache &InfoCache,
37523752
DenseMap<CallBase *, std::unique_ptr<SmallPtrSet<Function *, 8>>>
37533753
IndirectCalleeTrackingMap;
37543754
if (MaxSpecializationPerCB.getNumOccurrences()) {
3755-
AC.IndirectCalleeSpecializationCallback = [&](Attributor &, CallBase &CB,
3756-
Function &Callee) {
3757-
if (MaxSpecializationPerCB == 0)
3758-
return false;
3759-
auto &Set = IndirectCalleeTrackingMap[&CB];
3760-
if (!Set)
3761-
Set = std::make_unique<SmallPtrSet<Function *, 8>>();
3762-
if (Set->size() >= MaxSpecializationPerCB)
3763-
return Set->contains(&Callee);
3764-
Set->insert(&Callee);
3765-
return true;
3766-
};
3755+
AC.IndirectCalleeSpecializationCallback =
3756+
[&](Attributor &, const AbstractAttribute &AA, CallBase &CB,
3757+
Function &Callee) {
3758+
if (MaxSpecializationPerCB == 0)
3759+
return false;
3760+
auto &Set = IndirectCalleeTrackingMap[&CB];
3761+
if (!Set)
3762+
Set = std::make_unique<SmallPtrSet<Function *, 8>>();
3763+
if (Set->size() >= MaxSpecializationPerCB)
3764+
return Set->contains(&Callee);
3765+
Set->insert(&Callee);
3766+
return true;
3767+
};
37673768
}
37683769

37693770
Attributor A(Functions, InfoCache, AC);

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12204,7 +12204,7 @@ struct AAIndirectCallInfoCallSite : public AAIndirectCallInfo {
1220412204
SmallVector<Function *, 8> SkippedAssumedCallees;
1220512205
SmallVector<std::pair<CallInst *, Instruction *>> NewCalls;
1220612206
for (Function *NewCallee : AssumedCallees) {
12207-
if (!A.shouldSpecializeCallSiteForCallee(*CB, *NewCallee)) {
12207+
if (!A.shouldSpecializeCallSiteForCallee(*this, *CB, *NewCallee)) {
1220812208
SkippedAssumedCallees.push_back(NewCallee);
1220912209
SpecializedForAllCallees = false;
1221012210
continue;

0 commit comments

Comments
 (0)