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 | ||
---|---|---|
345 | 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. | |
418–421 | 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 | ||
---|---|---|
418–421 | 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 | ||
---|---|---|
418–421 | I changed the name of getTypeSize to make more explicit what it does. |
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
899 | 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 | ||
---|---|---|
259 | There is no output parameter in this. This is just non-const because getSCEV does not take const. |
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
122 | 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. | |
974 | No, that doesn't work because it's too new for LLVM code.
|
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
261 | Can you replace typeSizeToSCEV with two overloads? bool isSafeAccess(... Value *AccessSize) bool isSafeAccess(...TypeSize AccessSize) | |
320–326 | why don't we do this in case if isSafeAccess? | |
345 | auto *IntTy = IntegerType::getIntNTy(SE.getContext(), PointerSize); return SE.getConstant(IntTy, TS.getFixedSize()); | |
354 | UI -> U | |
355 | I is not needed, it can be retrived from U | |
368–370 | In all 3 cases can you please replace | |
415 | maybe add for this case a dedicated function US.addUnsaveAccess(I); | |
489 | 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 | ||
---|---|---|
261 | 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. | |
320–326 | Added this and a test that fails without this. Thanks! | |
354 | Ok. Although this is called UI in analyzeAllUses. | |
415 | Let's hold off of this for now, as that needs some changes (UnknownRange is in StackSafetyLocalAnalysis). |
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
261 | please do this to remove SCEV stuff from that long loop | |
368–370 | maybe: can you make toCharPtr same local lambda? or you plan to use it outside? | |
463 | it's going to make instruction safe even if user is not alloca For consistency isSafeMemIntrinsicAccess will help |
llvm/lib/Analysis/StackSafetyAnalysis.cpp | ||
---|---|---|
463 | 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 | ||
---|---|---|
122 | Just noticed: Then you pass that reference to the set as new arg of analyzeAllUses | |
463 |
*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 | ||
---|---|---|
122 | Can we do this in a separate change? This doesn't really belong here. | |
463 | 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 | ||
---|---|---|
122 | sure | |
463 | 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?