32#define DEBUG_TYPE "hexagon-global-array-alignment"
35 "hexagon-disable-global-array-align",
36 cl::desc(
"Disable aligning global integer arrays to an 8-byte boundary"),
40 "hexagon-disable-align-opt-byte-half",
41 cl::desc(
"Disable keeping byte and half-word arrays at their natural "
42 "alignment when reducing .rodata size"),
47class HexagonAlignGlobalArrays :
public ModulePass {
48 bool ReduceRodataSize;
53 explicit HexagonAlignGlobalArrays(
bool ReduceRodataSize =
false)
54 :
ModulePass(ID), ReduceRodataSize(ReduceRodataSize) {}
56 StringRef getPassName()
const override {
57 return "Hexagon Global Array Alignment";
60 bool runOnModule(
Module &M)
override;
65char HexagonAlignGlobalArrays::ID = 0;
68 "Align Global Arrays to 8-byte",
false,
false)
71 return new HexagonAlignGlobalArrays(ReduceRodataSize);
84bool HexagonAlignGlobalArrays::runOnModule(
Module &M) {
89 const DataLayout &
DL =
M.getDataLayout();
91 for (GlobalVariable &GV :
M.globals()) {
92 Type *VT = GV.getValueType();
102 if (!GV.canIncreaseAlignment())
106 MaybeAlign GVAlign = GV.getAlign();
108 GVAlign =
DL.getABITypeAlign(VT);
113 if (!ReduceRodataSize || !GVAlign || *GVAlign >
Align(2) ||
116 if (NewAlign != GVAlign) {
117 GV.setAlignment(NewAlign);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< bool > DisableGlobalArrayAlignment("hexagon-disable-global-array-align", cl::desc("Disable aligning global integer arrays to an 8-byte boundary"), cl::init(false), cl::Hidden)
static cl::opt< bool > DisableHexAlignOptByteHalf("hexagon-disable-align-opt-byte-half", cl::desc("Disable keeping byte and half-word arrays at their natural " "alignment when reducing .rodata size"), cl::Hidden)
static Type * getUnderlyingArrayElmTy(Type *Ty)
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isArrayTy() const
True if this is an instance of ArrayType.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
ModulePass * createHexagonAlignGlobalArrays(bool ReduceRodataSize)
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.