[coroutines] Respect alloca alignment requirements when building coroutine frame
authorGor Nishanov <GorNishanov@gmail.com>
Tue, 3 Apr 2018 20:54:20 +0000 (20:54 +0000)
committerGor Nishanov <GorNishanov@gmail.com>
Tue, 3 Apr 2018 20:54:20 +0000 (20:54 +0000)
commitd4712715dd3dfc7c387e7e97a5eee92a3ecfcee3
tree71a6fc8a3f687a60f4af0593fd64764c40d7222c
parent9467ccf447fd6611cdb1c77c1353a16f27682c5a
[coroutines] Respect alloca alignment requirements when building coroutine frame

Summary:
If an alloca need to be stored in the coroutine frame and it has an alignment specified and the alignment does not match the natural alignment of the alloca type. Insert appropriate padding into the coroutine frame to make sure that it gets requested alignment.

For example for a packet type (which natural alignment is 1), but alloca alignment is 8, we may need to insert a padding field with required number of bytes to make sure it is properly aligned.

```
%PackedStruct = type <{ i64 }>
...
  %data = alloca %PackedStruct, align 8
```

If the previous field in the coroutine frame had alignment 2, we would have [6 x i8] inserted before %PackedStruct in the coroutine frame:

```
%f.Frame = type { ..., i16, [6 x i8], %PackedStruct }
```

Reviewers: rnk, lewissbaker, modocache

Reviewed By: modocache

Subscribers: EricWF, llvm-commits

Differential Revision: https://reviews.llvm.org/D45221

llvm-svn: 329112
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/lib/Transforms/Coroutines/CoroInternal.h
llvm/test/Transforms/Coroutines/coro-padding.ll [new file with mode: 0644]