Halide
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 
10 namespace Halide {
11 namespace Internal {
12 
13 // TODO: This class is barely stateful, and could probably be replaced with free functions.
15  const int required_alignment;
16 
17 public:
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
Halide::Internal::IRMatcher::ramp
HALIDE_ALWAYS_INLINE auto ramp(A &&a, B &&b, C &&c) noexcept -> RampOp< decltype(pattern_arg(a)), decltype(pattern_arg(b)), decltype(pattern_arg(c))>
Definition: IRMatch.h:1868
internal_assert
#define internal_assert(c)
Definition: Errors.h:19
Halide::Internal::BaseExprNode::type
Type type
Definition: Expr.h:147
Halide::Type::bytes
int bytes() const
The number of bytes required to store a single scalar value of this type.
Definition: Type.h:292
IR.h
Halide::Type::is_vector
HALIDE_ALWAYS_INLINE bool is_vector() const
Is this type a vector type? (lanes() != 1).
Definition: Type.h:399
Halide::Internal::Load
Load a value from a named symbol if predicate is true.
Definition: IR.h:209
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::Runtime::Internal::aligned_offset
ALWAYS_INLINE size_t aligned_offset(size_t offset, size_t alignment)
Definition: memory_resources.h:128
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Internal::HexagonAlignmentAnalyzer::is_aligned_impl
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...
Definition: HexagonAlignment.h:27
Halide::Internal::Ramp
A linear ramp vector node.
Definition: IR.h:239
Halide::Expr::type
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
Definition: Expr.h:321
Halide::Internal::debug
For optional debugging during codegen, use the debug class as follows:
Definition: Debug.h:49
int64_t
signed __INT64_TYPE__ int64_t
Definition: runtime_internal.h:22
Halide::Internal::Store
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
Definition: IR.h:325
Halide::Internal::HexagonAlignmentAnalyzer::is_aligned
bool is_aligned(const Load *op, int64_t *aligned_offset)
Definition: HexagonAlignment.h:56
Halide::Internal::HexagonAlignmentAnalyzer
Definition: HexagonAlignment.h:14
Halide::Internal::HexagonAlignmentAnalyzer::HexagonAlignmentAnalyzer
HexagonAlignmentAnalyzer(int required_alignment)
Definition: HexagonAlignment.h:18
Halide::Internal::HexagonAlignmentAnalyzer::is_aligned
bool is_aligned(const Store *op, int64_t *aligned_offset)
Definition: HexagonAlignment.h:61
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:257
Halide::Internal::Store::value
Expr value
Definition: IR.h:327
Halide::Internal::IRHandle::as
const T * as() const
Downcast this ir node to its actual type (e.g.
Definition: Expr.h:204