[PATCH] D66551: [Attributor] Manifest constant return values
Johannes Doerfert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 23 10:41:23 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369785: [Attributor] Manifest constant return values (authored by jdoerfert, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D66551?vs=216462&id=216899#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66551/new/
https://reviews.llvm.org/D66551
Files:
llvm/trunk/lib/Transforms/IPO/Attributor.cpp
llvm/trunk/test/Transforms/FunctionAttrs/nounwind.ll
Index: llvm/trunk/test/Transforms/FunctionAttrs/nounwind.ll
===================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/nounwind.ll
+++ llvm/trunk/test/Transforms/FunctionAttrs/nounwind.ll
@@ -92,6 +92,15 @@
ret i32 -1
}
+define i32 @catch_thing_user() {
+; ATTRIBUTOR: define i32 @catch_thing_user
+; ATTRIBUTOR-NEXT: %catch_thing_call = call
+; ATTRIBUTOR-NEXT: ret i32 -1
+ %catch_thing_call = call i32 @catch_thing()
+ ret i32 %catch_thing_call
+}
+
+
declare i32 @__gxx_personality_v0(...)
declare i8* @__cxa_begin_catch(i8*)
Index: llvm/trunk/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/trunk/lib/Transforms/IPO/Attributor.cpp
+++ llvm/trunk/lib/Transforms/IPO/Attributor.cpp
@@ -807,10 +807,34 @@
STATS_DECLTRACK(UniqueReturnValue, FunctionReturn,
"Number of function with unique return");
+ // Callback to replace the uses of CB with the constant C.
+ auto ReplaceCallSiteUsersWith = [](CallBase &CB, Constant &C) {
+ if (CB.getNumUses() == 0)
+ return ChangeStatus::UNCHANGED;
+ CB.replaceAllUsesWith(&C);
+ return ChangeStatus::CHANGED;
+ };
+
// If the assumed unique return value is an argument, annotate it.
if (auto *UniqueRVArg = dyn_cast<Argument>(UniqueRV.getValue())) {
getIRPosition() = IRPosition::argument(*UniqueRVArg);
- Changed = IRAttribute::manifest(A) | Changed;
+ Changed = IRAttribute::manifest(A);
+ } else if (auto *RVC = dyn_cast<Constant>(UniqueRV.getValue())) {
+ // We can replace the returned value with the unique returned constant.
+ Value &AnchorValue = getAnchorValue();
+ if (Function *F = dyn_cast<Function>(&AnchorValue)) {
+ for (const Use &U : F->uses())
+ if (CallBase *CB = dyn_cast<CallBase>(U.getUser()))
+ if (CB->isCallee(&U))
+ Changed = ReplaceCallSiteUsersWith(*CB, *RVC) | Changed;
+ } else {
+ assert(isa<CallBase>(AnchorValue) &&
+ "Expcected a function or call base anchor!");
+ Changed = ReplaceCallSiteUsersWith(cast<CallBase>(AnchorValue), *RVC);
+ }
+ if (Changed == ChangeStatus::CHANGED)
+ STATS_DECLTRACK(UniqueConstantReturnValue, FunctionReturn,
+ "Number of function returns replaced by constant return");
}
return Changed;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66551.216899.patch
Type: text/x-patch
Size: 2393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190823/2da80d0e/attachment.bin>
More information about the llvm-commits
mailing list