Halide
CodeGen_ARM.h
Go to the documentation of this file.
1 #ifndef HALIDE_CODEGEN_ARM_H
2 #define HALIDE_CODEGEN_ARM_H
3 
4 /** \file
5  * Defines the code-generator for producing ARM machine code
6  */
7 
8 #include <utility>
9 
10 #include "CodeGen_Posix.h"
11 
12 namespace Halide {
13 namespace Internal {
14 
15 /** A code generator that emits ARM code from a given Halide stmt. */
16 class CodeGen_ARM : public CodeGen_Posix {
17 public:
18  /** Create an ARM code generator for the given arm target. */
20 
21 protected:
23 
24  /** Nodes for which we want to emit specific neon intrinsics */
25  // @{
26  void visit(const Cast *) override;
27  void visit(const Sub *) override;
28  void visit(const Div *) override;
29  void visit(const Mul *) override;
30  void visit(const Min *) override;
31  void visit(const Max *) override;
32  void visit(const Store *) override;
33  void visit(const Load *) override;
34  void visit(const Call *) override;
35  void visit(const LT *) override;
36  void visit(const LE *) override;
37  void codegen_vector_reduce(const VectorReduce *, const Expr &) override;
38  // @}
39 
40  /** Various patterns to peephole match against */
41  struct Pattern {
42  std::string intrin32; ///< Name of the intrinsic for 32-bit arm
43  std::string intrin64; ///< Name of the intrinsic for 64-bit arm
44  int intrin_lanes; ///< The native vector width of the intrinsic
45  Expr pattern; ///< The pattern to match against
46  enum PatternType { Simple = 0, ///< Just match the pattern
47  LeftShift, ///< Match the pattern if the RHS is a const power of two
48  RightShift, ///< Match the pattern if the RHS is a const power of two
49  NarrowArgs ///< Match the pattern if the args can be losslessly narrowed
50  };
52  Pattern() = default;
53  Pattern(const std::string &i32, const std::string &i64, int l, Expr p, PatternType t = Simple)
54  : intrin32("llvm.arm.neon." + i32),
55  intrin64("llvm.aarch64.neon." + i64),
56  intrin_lanes(l), pattern(std::move(p)), type(t) {
57  }
58  };
59  std::vector<Pattern> casts, averagings, negations, multiplies;
60 
61  // Call an intrinsic as defined by a pattern. Dispatches to the
62  // 32- or 64-bit name depending on the target's bit width.
63  // @{
64  llvm::Value *call_pattern(const Pattern &p, Type t, const std::vector<Expr> &args);
65  llvm::Value *call_pattern(const Pattern &p, llvm::Type *t, const std::vector<llvm::Value *> &args);
66  // @}
67 
68  std::string mcpu() const override;
69  std::string mattrs() const override;
70  bool use_soft_float_abi() const override;
71  int native_vector_bits() const override;
72 
73  // NEON can be disabled for older processors.
76  }
77 };
78 
79 } // namespace Internal
80 } // namespace Halide
81 
82 #endif
Halide::Internal::CodeGen_ARM::negations
std::vector< Pattern > negations
Definition: CodeGen_ARM.h:59
Halide::Internal::CodeGen_ARM::mcpu
std::string mcpu() const override
What should be passed as -mcpu, -mattrs, and related for compilation.
Halide::Internal::CodeGen_ARM::Pattern::type
PatternType type
Definition: CodeGen_ARM.h:51
Halide::Target::has_feature
bool has_feature(Feature f) const
Halide::Internal::CodeGen_ARM::use_soft_float_abi
bool use_soft_float_abi() const override
Halide::Internal::CodeGen_ARM::Pattern::Simple
@ Simple
Just match the pattern.
Definition: CodeGen_ARM.h:46
Halide::Target::NoNEON
@ NoNEON
Definition: Target.h:69
Halide::Internal::CodeGen_ARM::Pattern::intrin32
std::string intrin32
Name of the intrinsic for 32-bit arm.
Definition: CodeGen_ARM.h:42
Halide::Internal::VectorReduce
Horizontally reduce a vector to a scalar or narrower vector using the given commutative and associati...
Definition: IR.h:827
Halide::Internal::CodeGen_Posix
A code generator that emits posix code from a given Halide stmt.
Definition: CodeGen_Posix.h:14
Halide::Internal::CodeGen_Posix::visit
void visit(const Allocate *) override
Posix implementation of Allocate.
Halide::Internal::Div
The ratio of two expressions.
Definition: IR.h:65
Halide::Internal::CodeGen_ARM
A code generator that emits ARM code from a given Halide stmt.
Definition: CodeGen_ARM.h:16
Halide::Internal::CodeGen_ARM::Pattern::pattern
Expr pattern
The pattern to match against.
Definition: CodeGen_ARM.h:45
Halide::Internal::Cast
The actual IR nodes begin here.
Definition: IR.h:29
Halide::Internal::LE
Is the first expression less than or equal to the second.
Definition: IR.h:130
Halide::Internal::CodeGen_ARM::Pattern::intrin64
std::string intrin64
Name of the intrinsic for 64-bit arm.
Definition: CodeGen_ARM.h:43
Halide::Internal::CodeGen_ARM::Pattern::NarrowArgs
@ NarrowArgs
Match the pattern if the args can be losslessly narrowed.
Definition: CodeGen_ARM.h:49
Halide::Internal::CodeGen_ARM::Pattern::intrin_lanes
int intrin_lanes
The native vector width of the intrinsic.
Definition: CodeGen_ARM.h:44
Halide::Type
Types in the halide type system.
Definition: Type.h:269
Halide::Internal::CodeGen_ARM::codegen_vector_reduce
void codegen_vector_reduce(const VectorReduce *, const Expr &) override
Compile a horizontal reduction that starts with an explicit initial value.
Halide::Internal::CodeGen_ARM::native_vector_bits
int native_vector_bits() const override
What's the natural vector bit-width to use for loads, stores, etc.
Halide::Internal::Load
Load a value from a named symbol if predicate is true.
Definition: IR.h:199
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::Internal::CodeGen_ARM::call_pattern
llvm::Value * call_pattern(const Pattern &p, Type t, const std::vector< Expr > &args)
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Internal::Max
The greater of two values.
Definition: IR.h:94
Halide::Internal::CodeGen_ARM::neon_intrinsics_disabled
bool neon_intrinsics_disabled()
Definition: CodeGen_ARM.h:74
Halide::Internal::CodeGen_ARM::Pattern::Pattern
Pattern(const std::string &i32, const std::string &i64, int l, Expr p, PatternType t=Simple)
Definition: CodeGen_ARM.h:53
Halide::Internal::CodeGen_LLVM::target
Halide::Target target
The target we're generating code for.
Definition: CodeGen_LLVM.h:169
Halide::Internal::CodeGen_ARM::Pattern
Various patterns to peephole match against.
Definition: CodeGen_ARM.h:41
Halide::Internal::CodeGen_ARM::casts
std::vector< Pattern > casts
Definition: CodeGen_ARM.h:59
Halide::Internal::Store
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
Definition: IR.h:315
Halide::Internal::CodeGen_ARM::Pattern::RightShift
@ RightShift
Match the pattern if the RHS is a const power of two.
Definition: CodeGen_ARM.h:48
Halide::Internal::CodeGen_ARM::Pattern::LeftShift
@ LeftShift
Match the pattern if the RHS is a const power of two.
Definition: CodeGen_ARM.h:47
Halide::Internal::Min
The lesser of two values.
Definition: IR.h:85
Halide::Internal::CodeGen_ARM::multiplies
std::vector< Pattern > multiplies
Definition: CodeGen_ARM.h:59
Halide::Internal::Call
A function call.
Definition: IR.h:464
Halide::Internal::CodeGen_ARM::averagings
std::vector< Pattern > averagings
Definition: CodeGen_ARM.h:59
Halide::ConciseCasts::i64
Expr i64(Expr e)
Definition: ConciseCasts.h:28
Halide::ConciseCasts::i32
Expr i32(Expr e)
Definition: ConciseCasts.h:33
Halide::Internal::CodeGen_ARM::Pattern::Pattern
Pattern()=default
Halide::Internal::CodeGen_ARM::Pattern::PatternType
PatternType
Definition: CodeGen_ARM.h:46
Halide::Internal::CodeGen_ARM::CodeGen_ARM
CodeGen_ARM(Target)
Create an ARM code generator for the given arm target.
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:256
Halide::Internal::CodeGen_ARM::mattrs
std::string mattrs() const override
Halide::Internal::Sub
The difference of two expressions.
Definition: IR.h:47
Halide::Target
A struct representing a target machine and os to generate code for.
Definition: Target.h:19
CodeGen_Posix.h
Halide::Internal::LT
Is the first expression less than the second.
Definition: IR.h:121
Halide::Internal::Mul
The product of two expressions.
Definition: IR.h:56
Halide::Internal::CodeGen_ARM::visit
void visit(const Cast *) override
Nodes for which we want to emit specific neon intrinsics.