@@ -239,6 +239,8 @@ enum ForceVeneers {
239239pub struct MachBuffer < I : VCodeInst > {
240240 /// The buffer contents, as raw bytes.
241241 data : SmallVec < [ u8 ; 1024 ] > ,
242+ /// The required alignment of this buffer.
243+ min_alignment : u32 ,
242244 /// Any relocations referring to this code. Note that only *external*
243245 /// relocations are tracked here; references to labels within the buffer are
244246 /// resolved before emission.
@@ -433,6 +435,7 @@ impl<I: VCodeInst> MachBuffer<I> {
433435 pub fn new ( ) -> MachBuffer < I > {
434436 MachBuffer {
435437 data : SmallVec :: new ( ) ,
438+ min_alignment : I :: function_alignment ( ) . minimum ,
436439 relocs : SmallVec :: new ( ) ,
437440 traps : SmallVec :: new ( ) ,
438441 call_sites : SmallVec :: new ( ) ,
@@ -607,7 +610,7 @@ impl<I: VCodeInst> MachBuffer<I> {
607610 /// at the ISA's minimum function alignment and can be increased due to
608611 /// constant requirements.
609612 fn finish_constants ( & mut self , constants : & VCodeConstants ) -> u32 {
610- let mut alignment = I :: function_alignment ( ) . minimum ;
613+ let mut alignment = self . min_alignment ;
611614 for ( constant, offset) in mem:: take ( & mut self . used_constants ) {
612615 let constant = constants. get ( constant) ;
613616 let data = constant. as_slice ( ) ;
@@ -1665,6 +1668,15 @@ impl<I: VCodeInst> MachBuffer<I> {
16651668 stack_map. finalize ( emit_state. frame_layout ( ) . sp_to_sized_stack_slots ( ) ) ;
16661669 self . user_stack_maps . push ( ( return_addr, span, stack_map) ) ;
16671670 }
1671+
1672+ /// Increase the alignment of the buffer to the given alignment if bigger
1673+ /// than the current alignment.
1674+ pub fn set_log2_min_function_alignment ( & mut self , align_to : u8 ) {
1675+ self . min_alignment = self . min_alignment . max (
1676+ 1u32 . checked_shl ( u32:: from ( align_to) )
1677+ . expect ( "log2_min_function_alignment too large" ) ,
1678+ ) ;
1679+ }
16681680}
16691681
16701682impl < I : VCodeInst > Extend < u8 > for MachBuffer < I > {
0 commit comments