Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This looks nice. Any idea how much does it improve analysis success rate in practice?
Would be great to have a test with some loop, if it works.
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
344 | It's a little strange to compute type size in a pointer, but SCEV does not care as long as the number of bits is the same, so I guess it is fine. | |
402–405 | move getTypeStoreSize into getTypeSize |
It doesn't support loops yet, I've been experimenting with isKnownAtEveryIteration without success so far. Will keep trying.
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
402–405 | The way it is now makes it more obvious that this TypeSize is the same that we use in the getAccessRange call, so I'd prefer to leave it like this. WDYT? |
improve naming
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
402–405 | I changed the name of getTypeSize to make more explicit what it does. |
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
876 | If converted to set this loop could be: Info->AccessIsUnsafe[A.first].insert(KV.second.AccessIsUnsafe.first, KV.second.AccessIsUnsafe.end); There is also set::merge in C++ 17, but it will move the elements from the second set I think. |
address comments
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
258 | There is no output parameter in this. This is just non-const because getSCEV does not take const. |
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
121 | That doesn't work though. What we want is any(instr is unsafe for alloca for all allocas reachable) for that we need to keep track of the unsafe instructions for each alloca. | |
951 | No, that doesn't work because it's too new for LLVM code.
|
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
260 | Can you replace typeSizeToSCEV with two overloads? bool isSafeAccess(... Value *AccessSize) bool isSafeAccess(...TypeSize AccessSize) | |
319–325 | why don't we do this in case if isSafeAccess? | |
344 | auto *IntTy = IntegerType::getIntNTy(SE.getContext(), PointerSize); return SE.getConstant(IntTy, TS.getFixedSize()); | |
353 | UI -> U | |
354 | I is not needed, it can be retrived from U | |
367–369 | In all 3 cases can you please replace | |
399 | maybe add for this case a dedicated function US.addUnsaveAccess(I); | |
466 | for consistency US.addRange(I, getAccessRange(UI, Ptr, TypeSize);, isSafeAccess(UI, AI, I, typeSizeToSCEV(TypeSize))); or: auto AccessRange = getAccessRange(UI, Ptr, TypeSize); bool Safe = isSafeAccess(UI, AI, I, typeSizeToSCEV(TypeSize)); US.addRange(I, AccessRange, Safe); |
address comments
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
260 | I think that just adds more complexity, as this way we will need bool isSafeAccess(... Value *AccessSize) which only do the conversion and call some isSafeAccess(... SCEV *AccessSize). Doing the conversion explicitly in the caller seems more readable to me. | |
319–325 | Added this and a test that fails without this. Thanks! | |
353 | Ok. Although this is called UI in analyzeAllUses. | |
399 | Let's hold off of this for now, as that needs some changes (UnknownRange is in StackSafetyLocalAnalysis). |
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
260 | please do this to remove SCEV stuff from that long loop | |
367–369 | maybe: can you make toCharPtr same local lambda? or you plan to use it outside? | |
447 | it's going to make instruction safe even if user is not alloca For consistency isSafeMemIntrinsicAccess will help |
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
447 | This is consistent with the API this is used in // Returns true if the instruction can be proven to do only two types of // memory accesses: // (1) live stack locations in-bounds or // (2) non-stack locations. If the user is not alloca, that is (2). |
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
121 | Just noticed: Then you pass that reference to the set as new arg of analyzeAllUses | |
447 |
*user* -> location isSafeAccess() line 355 I don't like to have undefined behavior for (2) even if you don't use it now. It's trivial to make it defined either true or false. However if instruction access function argument, we don't know if it a stack of another function. So unsafe (false) seems reasonable choose here. BTW why this is not important for current callers? |
address comments
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
121 | Can we do this in a separate change? This doesn't really belong here. | |
447 | Good point, if !AI in isSafeAccess we should also return true, for consistency. Then the semantics remain well-defined and the same: "all *stack* accesses done by this instruction are safe. The callers check findAllocaForValue to make sure this is definitely a stack access before calling stackAccessIsSafe. |
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
121 | sure | |
447 | i don't like this assumption on what user will do However It should be easier to do after "UnsafeAccesses" followup patch. |
Isn't that just a set?