Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
HexagonAlignment.h
Go to the documentation of this file.
1#ifndef HALIDE_HEXAGON_ALIGNMENT_H
2#define HALIDE_HEXAGON_ALIGNMENT_H
3
4/** \file
5 * Class for analyzing Alignment of loads and stores for Hexagon.
6 */
7
8#include "IR.h"
9
10namespace Halide {
11namespace Internal {
12
13// TODO: This class is barely stateful, and could probably be replaced with free functions.
15 const int required_alignment;
16
17public:
18 HexagonAlignmentAnalyzer(int required_alignment)
19 : required_alignment(required_alignment) {
20 internal_assert(required_alignment != 0);
21 }
22
23 /** Analyze the index of a load/store instruction for alignment
24 * Returns true if it can determing that the address of the store or load is aligned, false otherwise.
25 */
26 template<typename T>
27 bool is_aligned_impl(const T *op, int native_lanes, int64_t *aligned_offset) {
28 debug(3) << "HexagonAlignmentAnalyzer: Check if " << op->index << " is aligned to a "
29 << required_alignment << " byte boundary\n"
30 << "native_lanes: " << native_lanes << "\n";
31 Expr index = op->index;
32 const Ramp *ramp = index.as<Ramp>();
33 if (ramp) {
34 index = ramp->base;
35 } else if (index.type().is_vector()) {
36 debug(3) << "Is Unaligned\n";
37 return false;
38 }
39
40 internal_assert(native_lanes != 0) << "Type is larger than required alignment of " << required_alignment << " bytes\n";
41
42 // If this is a parameter, the base_alignment should be
43 // host_alignment. Otherwise, this is an internal buffer,
44 // which we assume has been aligned to the required alignment.
45 if (op->param.defined() && ((op->param.host_alignment() % required_alignment) != 0)) {
46 return false;
47 }
48
49 bool known_alignment = (op->alignment.modulus % native_lanes) == 0;
50 if (known_alignment) {
51 *aligned_offset = op->alignment.remainder % native_lanes;
52 }
53 return known_alignment && (*aligned_offset == 0);
54 }
55
56 bool is_aligned(const Load *op, int64_t *aligned_offset) {
57 int native_lanes = required_alignment / op->type.bytes();
58 return is_aligned_impl<Load>(op, native_lanes, aligned_offset);
59 }
60
61 bool is_aligned(const Store *op, int64_t *aligned_offset) {
62 int native_lanes = required_alignment / op->value.type().bytes();
63 return is_aligned_impl<Store>(op, native_lanes, aligned_offset);
64 }
65};
66
67} // namespace Internal
68} // namespace Halide
69#endif
#define internal_assert(c)
Definition Errors.h:19
Subtypes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
bool is_aligned(const Load *op, int64_t *aligned_offset)
bool is_aligned_impl(const T *op, int native_lanes, int64_t *aligned_offset)
Analyze the index of a load/store instruction for alignment Returns true if it can determing that the...
bool is_aligned(const Store *op, int64_t *aligned_offset)
For optional debugging during codegen, use the debug class as follows:
Definition Debug.h:49
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
signed __INT64_TYPE__ int64_t
A fragment of Halide syntax.
Definition Expr.h:258
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
Definition Expr.h:327
const T * as() const
Downcast this ir node to its actual type (e.g.
Definition Expr.h:205
Load a value from a named symbol if predicate is true.
Definition IR.h:217
A linear ramp vector node.
Definition IR.h:247
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
Definition IR.h:333
HALIDE_ALWAYS_INLINE bool is_vector() const
Is this type a vector type? (lanes() != 1).
Definition Type.h:410
int bytes() const
The number of bytes required to store a single scalar value of this type.
Definition Type.h:299