mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-17 21:35:07 +00:00
dc84650679
of offset and the alignment of ptr if these are both powers of 2. While the ptr alignment is guaranteed to be a power of 2, there is no reason to think that offset is. For example, if offset is 12 (the size of a long double on x86-32 linux) and the alignment of ptr is 8, then the alignment of ptr+offset will in general be 4, not 8. Introduce a function MinAlign, lifted from gcc, for computing the minimum guaranteed alignment. I've tried to fix up everywhere under lib/CodeGen/SelectionDAG/. I also changed some places that weren't wrong (because both values were a power of 2), as a defensive change against people copying and pasting the code. Hopefully someone who cares about alignment will review the rest of LLVM and fix up the remaining places. Since I'm on x86 I'm not very motivated to do this myself... git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43421 91177308-0d34-0410-b5e6-96231b3b80d8
29 lines
924 B
C++
29 lines
924 B
C++
//===----------- Alignment.h - Alignment computation ------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file was developed by Duncan Sands and is distributed under
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines utilities for computing alignments.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_SUPPORT_ALIGNMENT_H
|
|
#define LLVM_SUPPORT_ALIGNMENT_H
|
|
|
|
namespace llvm {
|
|
|
|
/// MinAlign - A and B are either alignments or offsets. Return the minimum
|
|
/// alignment that may be assumed after adding the two together.
|
|
|
|
static inline unsigned MinAlign(unsigned A, unsigned B) {
|
|
// The largest power of 2 that divides both A and B.
|
|
return (A | B) & -(A | B);
|
|
}
|
|
|
|
} // end namespace llvm
|
|
#endif
|