[llvm] [Hexagon] Add GlobalArrayAlignment pass (PR #217850)
Abinaya Saravanan via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 24 04:27:25 PDT 2026
================
@@ -0,0 +1,125 @@
+//===- HexagonAlignGlobalArrays.cpp - Align Global Arrays -----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass increases the alignment of global integer arrays (char, short,
+// int), including multi-dimensional arrays, to an 8-byte boundary. This gives
+// their base address a wider alignment, which is beneficial for the wide
+// (double-word) loads and stores available on Hexagon.
+//
+// When optimizing to reduce .rodata size, byte and half-word arrays already at
+// an alignment of two bytes or less are left at their natural alignment; only
+// word arrays are promoted. This size behavior can be turned off with
+// -hexagon-disable-align-opt-byte-half.
+//
+// The pass is enabled by default and can be disabled with
+// -hexagon-disable-global-array-align.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Hexagon.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "hexagon-global-array-alignment"
+
+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",
----------------
quic-asaravan wrote:
Should we have a test case to cover this flag?
https://github.com/llvm/llvm-project/pull/217850
More information about the llvm-commits
mailing list