[PATCH] D71435: [WIP] [Attributor] Function level undefined behavior attribute
Stefanos Baziotis via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 15 06:46:09 PST 2019
baziotis updated this revision to Diff 233964.
baziotis added a comment.
This is a high level overview of the algorithm. noUBLoads is monotonically increasing and upper bounded thus this procedure will end (note that for the time being though,
we can't derive pessimistic fixpoint).
A note on the DS: I assume LLVM has its own version of unordered_set but I don't know its internals and this seemed to be the most applicable in this case.
Feel free to propose LLVM alternatives.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71435/new/
https://reviews.llvm.org/D71435
Files:
llvm/lib/Transforms/IPO/Attributor.cpp
Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -38,6 +38,8 @@
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
+#include <unordered_set>
+
#include <cassert>
using namespace llvm;
@@ -1968,21 +1970,36 @@
struct AAUndefinedBehaviorImpl : public AAUndefinedBehavior {
AAUndefinedBehaviorImpl(const IRPosition &IRP) : AAUndefinedBehavior(IRP) {}
+ std::unordered_set<Instruction*> noUBLoads;
+
/// See AbstractAttribute::initialize(...).
void initialize(Attributor &A) override {
AAUndefinedBehavior::initialize(A);
-
- auto HandleLoadInstruction = [&](Instruction &I) {
- // TODO: Do something for every load instruction...
- return true;
- };
- A.checkForAllInstructions(HandleLoadInstruction, *this,
- {Instruction::Load});
}
/// See AbstractAttribute::updateImpl(...).
ChangeStatus updateImpl(Attributor &A) override {
- return indicatePessimisticFixpoint();
+ size_t prevSize = noUBLoads.size();
+
+ auto CantCauseUB = [&](Instruction &Iref) {
+ Instruction *I = &Iref;
+ // If this load instruction is not one of the instructions
+ // that are already assumed to cause UB.
+ if (noUBLoads.find(I) == noUBLoads.end()) {
+ // Find whether it can cause UB by checking if the pointer
+ // is null or undef.
+ bool canCauseUB;
+ if (!canCauseUB) {
+ noUBLoads.insert(I);
+ }
+ }
+ return true;
+ };
+ A.checkForAllInstructions(CantCauseUB, *this, {Instruction::Load});
+ if (prevSize != noUBLoads.size()) {
+ return ChangeStatus::CHANGED;
+ }
+ return ChangeStatus::UNCHANGED;
}
/// See AbstractAttribute::getAsStr()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71435.233964.patch
Type: text/x-patch
Size: 1910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191215/da69e195/attachment.bin>
More information about the llvm-commits
mailing list