Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,6 @@ void AttributeInferer::run(const SCCNodeSet &SCCNodes,

struct SCCNodesResult {
SCCNodeSet SCCNodes;
bool HasUnknownCall;
};

} // end anonymous namespace
Expand Down Expand Up @@ -2227,29 +2226,13 @@ static void addWillReturn(const SCCNodeSet &SCCNodes,

static SCCNodesResult createSCCNodeSet(ArrayRef<Function *> Functions) {
SCCNodesResult Res;
Res.HasUnknownCall = false;
for (Function *F : Functions) {
if (!F || F->hasOptNone() || F->hasFnAttribute(Attribute::Naked) ||
F->isPresplitCoroutine()) {
// Treat any function we're trying not to optimize as if it were an
// indirect call and omit it from the node set used below.
Res.HasUnknownCall = true;
// Omit any functions we're trying not to optimize from the set.
continue;
}
// Track whether any functions in this SCC have an unknown call edge.
// Note: if this is ever a performance hit, we can common it with
// subsequent routines which also do scans over the instructions of the
// function.
if (!Res.HasUnknownCall) {
for (Instruction &I : instructions(*F)) {
if (auto *CB = dyn_cast<CallBase>(&I)) {
if (!CB->getCalledFunction()) {
Res.HasUnknownCall = true;
break;
}
}
}
}

Res.SCCNodes.insert(F);
}
return Res;
Expand Down Expand Up @@ -2282,15 +2265,10 @@ deriveAttrsInPostOrder(ArrayRef<Function *> Functions, AARGetterT &&AARGetter,
addColdAttrs(Nodes.SCCNodes, Changed);
addWillReturn(Nodes.SCCNodes, Changed);
addNoUndefAttrs(Nodes.SCCNodes, Changed);

// If we have no external nodes participating in the SCC, we can deduce some
// more precise attributes as well.
if (!Nodes.HasUnknownCall) {
addNoAliasAttrs(Nodes.SCCNodes, Changed);
addNonNullAttrs(Nodes.SCCNodes, Changed);
inferAttrsFromFunctionBodies(Nodes.SCCNodes, Changed);
addNoRecurseAttrs(Nodes.SCCNodes, Changed);
}
addNoAliasAttrs(Nodes.SCCNodes, Changed);
addNonNullAttrs(Nodes.SCCNodes, Changed);
inferAttrsFromFunctionBodies(Nodes.SCCNodes, Changed);
addNoRecurseAttrs(Nodes.SCCNodes, Changed);

// Finally, infer the maximal set of attributes from the ones we've inferred
// above. This is handling the cases where one attribute on a signature
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/FunctionAttrs/noalias.ll
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ define ptr @return_unknown_call(ptr %fn) {
}

define ptr @return_unknown_noalias_call(ptr %fn) {
; CHECK-LABEL: define ptr @return_unknown_noalias_call(
; CHECK-LABEL: define noalias ptr @return_unknown_noalias_call(
; CHECK-SAME: ptr readonly captures(none) [[FN:%.*]]) {
; CHECK-NEXT: [[A:%.*]] = call noalias ptr [[FN]]()
; CHECK-NEXT: ret ptr [[A]]
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/FunctionAttrs/nonnull.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ define ptr @unknown_func(ptr %fn) {
}

define ptr @unknown_nonnull_func(ptr %fn) {
; FNATTRS-LABEL: define ptr @unknown_nonnull_func(
; FNATTRS-LABEL: define nonnull ptr @unknown_nonnull_func(
; FNATTRS-SAME: ptr readonly captures(none) [[FN:%.*]]) {
; FNATTRS-NEXT: [[RES:%.*]] = call nonnull ptr [[FN]]()
; FNATTRS-NEXT: ret ptr [[RES]]
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/Transforms/FunctionAttrs/nounwind.ll
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,10 @@ define void @unknown_call(ptr %fn) {
}

define void @unknown_nounwind_call(ptr %fn) {
; FNATTRS: Function Attrs: nounwind
; FNATTRS-LABEL: define {{[^@]+}}@unknown_nounwind_call
; FNATTRS-SAME: (ptr readonly captures(none) [[FN:%.*]]) {
; FNATTRS-NEXT: call void [[FN]]() #[[ATTR2:[0-9]+]]
; FNATTRS-SAME: (ptr readonly captures(none) [[FN:%.*]]) #[[ATTR2:[0-9]+]] {
; FNATTRS-NEXT: call void [[FN]]() #[[ATTR2]]
; FNATTRS-NEXT: ret void
;
; ATTRIBUTOR: Function Attrs: nounwind
Expand Down