Loading...
Searching...
No Matches
HexagonAlignment.h
Go to the documentation of this file.
#ifndef HALIDE_HEXAGON_ALIGNMENT_H
#define HALIDE_HEXAGON_ALIGNMENT_H
/** \file
* Class for analyzing Alignment of loads and stores for Hexagon.
*/
#include "IR.h"
namespace Halide {
namespace Internal {
// TODO: This class is barely stateful, and could probably be replaced with free functions.
class HexagonAlignmentAnalyzer {
const int required_alignment;
public:
HexagonAlignmentAnalyzer(int required_alignment)
: required_alignment(required_alignment) {
internal_assert(required_alignment != 0);
}
/** Analyze the index of a load/store instruction for alignment
* Returns true if it can determing that the address of the store or load is aligned, false otherwise.
*/
template<typename T>
bool is_aligned_impl(const T *op, int native_lanes, int64_t *aligned_offset) {
debug(3) << "HexagonAlignmentAnalyzer: Check if " << op->index << " is aligned to a "
<< required_alignment << " byte boundary\n"
<< "native_lanes: " << native_lanes << "\n";
Expr index = op->index;
const Ramp *ramp = index.as<Ramp>();
if (ramp) {
index = ramp->base;
} else if (index.type().is_vector()) {
debug(3) << "Is Unaligned\n";
return false;
}
internal_assert(native_lanes != 0) << "Type is larger than required alignment of " << required_alignment << " bytes\n";
// If this is a parameter, the base_alignment should be
// host_alignment. Otherwise, this is an internal buffer,
// which we assume has been aligned to the required alignment.
if (op->param.defined() && ((op->param.host_alignment() % required_alignment) != 0)) {
return false;
}
bool known_alignment = (op->alignment.modulus % native_lanes) == 0;
if (known_alignment) {
*aligned_offset = op->alignment.remainder % native_lanes;
}
return known_alignment && (*aligned_offset == 0);
}
bool is_aligned(const Load *op, int64_t *aligned_offset) {
int native_lanes = required_alignment / op->type.bytes();
return is_aligned_impl<Load>(op, native_lanes, aligned_offset);
}
bool is_aligned(const Store *op, int64_t *aligned_offset) {
int native_lanes = required_alignment / op->value.type().bytes();
return is_aligned_impl<Store>(op, native_lanes, aligned_offset);
}
};
} // namespace Internal
} // namespace Halide
#endif
debug
#define debug(n)
For optional debugging during codegen, use the debug macro as follows:
Definition Debug.h:52
internal_assert
#define internal_assert(c)
Definition Error.h:218
IR.h
Subtypes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt).
Halide::Internal::HexagonAlignmentAnalyzer::HexagonAlignmentAnalyzer
HexagonAlignmentAnalyzer(int required_alignment)
Definition HexagonAlignment.h:18
Halide::Internal::HexagonAlignmentAnalyzer::is_aligned
bool is_aligned(const Load *op, int64_t *aligned_offset)
Definition HexagonAlignment.h:56
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::HexagonAlignmentAnalyzer::is_aligned
bool is_aligned(const Store *op, int64_t *aligned_offset)
Definition HexagonAlignment.h:61
Halide::Internal
Definition AbstractGenerator.h:24
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
int64_t
signed __INT64_TYPE__ int64_t
Definition runtime_internal.h:22
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258
Halide::Expr::type
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
Definition Expr.h:327
Halide::Internal::BaseExprNode::type
Type type
Definition Expr.h:148
Halide::Internal::IRHandle::as
const T * as() const
Downcast this ir node to its actual type (e.g.
Definition Expr.h:205
Halide::Internal::Load
Load a value from a named symbol if predicate is true.
Definition IR.h:217
Halide::Internal::Ramp
A linear ramp vector node.
Definition IR.h:247
Halide::Internal::Store
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
Definition IR.h:333
Halide::Internal::Store::value
Expr value
Definition IR.h:335
Halide::Type::is_vector
HALIDE_ALWAYS_INLINE bool is_vector() const
Is this type a vector type?
Definition Type.h:410
Halide::Type::bytes
int bytes() const
The number of bytes required to store a single scalar value of this type.
Definition Type.h:299