Page MenuHomePhabricator

Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline

[Attributor] New attribute to identify what byte ranges are alive for an allocation
Needs ReviewPublic

Authored by vidsinghal on Aug 3 2023, 9:31 PM.



Changes the size of allocations automatically.
Only implements the case when a single range from start of the allocation is alive.

Diff Detail

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

Fix typo in assert.
Add a positive test case for malloc with a TODO.

This comment was removed by vidsinghal.
jdoerfert added inline comments.Aug 20 2023, 3:11 PM

Don't cast it to an "Impl". There is no need anymore anyway.


State could be anything. At least call it PIState.


This is basically BinSize != 1, return, no?


Why does this not trigger for the ptr/i64 case? Is one of them in bytes the other in bits?


This is fine for OffsetEnd = 2,4,8, but then it becomes a little iffy. Check for non default sizes and go with a char array instead.


Same as above.

82 ↗(On Diff #551856)

This doesn't actually make it smaller, we should avoid such changes.

135 ↗(On Diff #551856)

Same here.

vidsinghal marked 13 inline comments as done.

Revision based on comments


umm, I think BinSize == 0


if its a ptr

public: std::optional<TypeSize> getAllocationSize(const DataLayout &DL)

returns a size of 0 which is why that if condition is not triggered.
At the LLVM IR level, I think the size of pointer is just 0.

jdoerfert added inline comments.Aug 21 2023, 6:04 PM

Why do you give up on struct type like {i32, i32}?
I don't understand why we need this conditional at all.

vidsinghal marked an inline comment as done.

Remove un-necessary if condition for struct with only one element.

vidsinghal added inline comments.Aug 21 2023, 6:50 PM

I was trying to indicate a fix point for structs like
type S = {ptr}
where the struct has only one element in it.
But I think that OffsetEnd == AllocationSize check should work for this now (after fixing the size of pointer issue) I'll remove this check.
Previously this was not working which is why I had to had this check and i think
getNumContainedTypes should have been getStructNumElements instead.

check for zero alloca and indicate fixpoint.

tianshilei1992 added inline comments.Aug 23 2023, 2:17 PM

Better to use [[maybe_unused]] now.

jdoerfert added inline comments.Aug 23 2023, 2:59 PM

As I said before, no casting to implementations of the interface. put the method you need into AAPointerInfo.

384 ↗(On Diff #552461)

unrelated, just keep the old version of this file.

vidsinghal marked an inline comment as done.

1.) Insert a new instruction instead of modiying the old one (Char array)
2.) Restore value-simplify-local-remote.ll
3.) Add a new positive test to reduce size of array alloca

vidsinghal marked 2 inline comments as done.

1.) Put method to get offsetBins in AAPointerInfo
2.) work on other comments.

vidsinghal marked an inline comment as done.

add maybe_unused pragma

jdoerfert added inline comments.Aug 27 2023, 11:05 AM

This is not a good idea. What happend to the old API you had?
We do not want to leak out the underlying map if we don't have to.
All you want is a size and begin/end, no?

vidsinghal added inline comments.Aug 27 2023, 11:33 AM

Yeah I see.
The underlying map is protected in the state I think.
Yeah for now, size begin and end should be good.
I think I will try making those virtual pure in AAPointerInfo and then override them in the state?

Add API for begin, end size in AAPointerInfo

vidsinghal marked an inline comment as done.Aug 27 2023, 11:59 AM

Add a positive test with TODO

vidsinghal updated this revision to Diff 555543.Sep 1 2023, 6:50 PM

Make switch to indentify alloca vs malloc instruction

tianshilei1992 added inline comments.Sep 1 2023, 6:51 PM

Then there is no need (void)Success;.

vidsinghal updated this revision to Diff 555544.Sep 1 2023, 7:03 PM

remove (void)success

vidsinghal marked an inline comment as done.Sep 1 2023, 7:04 PM
vidsinghal updated this revision to Diff 555601.Sep 2 2023, 2:19 PM

Support for modifying malloc instructions
TODO: The original malloc call is not being removed by changeAfterManifest even though it is dead.

vidsinghal updated this revision to Diff 555605.Sep 2 2023, 4:23 PM

fix name variable

vidsinghal updated this revision to Diff 555607.Sep 2 2023, 5:59 PM

Delete malloc call after attributor update

vidsinghal updated this revision to Diff 555608.Sep 2 2023, 6:14 PM

fix example IR

vidsinghal updated this revision to Diff 555610.Sep 2 2023, 8:51 PM

Don't call AAPointerInfoGetOrCreate other than Alloca and Malloc Instruction. Results in infinite loop for instance when calling a ptr

vidsinghal updated this revision to Diff 555633.Sep 3 2023, 9:03 AM

Clean up code

Add new test where argument to malloc isn't a constant.
Use AAPotentialConstantValues to get the constant value.

Add null check for IntOperand

vidsinghal updated this revision to Diff 555765.Sep 4 2023, 9:42 AM

New example and question about what the optimization should do for an example like @baz in allocator.ll

Remove run commands in depgraph.ll that were not being parsed