<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I am working on a custom LLVM backend for a 16 bit architecture.<div class=""><br class=""></div><div class="">For my architecture, I need smaller array alignments for arrays created on the stack.<br class=""><div class=""><br class=""></div><div class="">For example, consider the following code at the start of a C function:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">char</span> localBuff[<span style="color: #272ad8" class="">20</span>];</div><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">char</span> localBuff2[<span style="color: #272ad8" class="">6</span>];</div></div></div><div class=""><br class=""></div><div class="">this gets converted by Clang into this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""> %localBuff = alloca [20 x i8], align 16</div><div style="margin: 0px; line-height: normal;" class=""> %localBuff2 = alloca [6 x i8], align 1</div></div></div></div><div class=""><br class=""></div><div class="">Note that char arrays smaller than 16 bytes are specified to be aligned to 1 byte, but bigger ones are aligned to 16 bytes.</div><div class=""><br class=""></div><div class="">On the LLVM backend, this creates bigger than necessary frame index offsets, which are undesirable for my architecture.</div><div class=""><br class=""></div><div class="">As a side note, my target machine is 16 bits, so I have already modified ‘TargetInfo.ccp' with 16 bit ints and pointers, which works like a charm</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);" class=""> PointerWidth<span style="color: #000000" class=""> = </span>PointerAlign<span style="color: #000000" class=""> = </span><span style="color: #272ad8" class="">16</span><span style="color: #000000" class="">;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""> </span>IntWidth<span style="color: #000000" class=""> = </span>IntAlign<span style="color: #000000" class=""> = </span><span style="color: #272ad8" class="">16</span><span style="color: #000000" class="">;</span></div></div><div class=""><br class=""></div><div class="">The Question is:</div><div class=""><br class=""></div><div class="">- How do I make CLang to emit code with smaller array alignment, say 2 or 4 byte aligned arrays?</div><div class="">- Otherwise, is there a way to override that alignment on the LLVM backend implementation, particularly to get it create frame index offsets aligned by a smaller size, thus ignoring the clang specified alignment? </div><div class=""><br class="webkit-block-placeholder"></div><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Joan Lluch<br class=""><br class=""></div></div></div>
</div>
<br class=""></div></body></html>