clang-tools 19.0.0git
Go to the documentation of this file.
1//===--- UnrollLoopsCheck.h - clang-tidy ------------------------*- C++ -*-===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12#include "../ClangTidyCheck.h"
14namespace clang::tidy::altera {
16/// Finds inner loops that have not been unrolled, as well as fully unrolled
17/// loops with unknown loop bounds or a large number of iterations.
19/// Unrolling inner loops could improve the performance of OpenCL kernels.
20/// However, if they have unknown loop bounds or a large number of iterations,
21/// they cannot be fully unrolled, and should be partially unrolled.
23/// For the user-facing documentation see:
27 UnrollLoopsCheck(StringRef Name, ClangTidyContext *Context);
28 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32 /// Recommend partial unrolling if number of loop iterations is greater than
33 /// MaxLoopIterations.
34 const unsigned MaxLoopIterations;
35 /// The kind of unrolling, if any, applied to a given loop.
36 enum UnrollType {
37 // This loop has no #pragma unroll directive associated with it.
38 NotUnrolled,
39 // This loop has a #pragma unroll directive associated with it.
40 FullyUnrolled,
41 // This loop has a #pragma unroll <num> directive associated with it.
42 PartiallyUnrolled
43 };
44 /// Attempts to extract an integer value from either side of the
45 /// BinaryOperator. Returns true and saves the result to &value if successful,
46 /// returns false otherwise.
47 bool extractValue(int &Value, const BinaryOperator *Op,
48 const ASTContext *Context);
49 /// Returns true if the given loop statement has a large number of iterations,
50 /// as determined by the integer value in the loop's condition expression,
51 /// if one exists.
52 bool hasLargeNumIterations(const Stmt *Statement,
53 const IntegerLiteral *CXXLoopBound,
54 const ASTContext *Context);
55 /// Checks one hand side of the binary operator to ascertain if the upper
56 /// bound on the number of loops is greater than max_loop_iterations or not.
57 /// If the expression is not evaluatable or not an integer, returns false.
58 bool exprHasLargeNumIterations(const Expr *Expression,
59 const ASTContext *Context) const;
60 /// Returns the type of unrolling, if any, associated with the given
61 /// statement.
62 enum UnrollType unrollType(const Stmt *Statement, ASTContext *Context);
63 /// Returns the condition expression within a given for statement. If there is
64 /// none, or if the Statement is not a loop, then returns a NULL pointer.
65 const Expr *getCondExpr(const Stmt *Statement);
66 /// Returns True if the loop statement has known bounds.
67 bool hasKnownBounds(const Stmt *Statement, const IntegerLiteral *CXXLoopBound,
68 const ASTContext *Context);
69 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
72} // namespace clang::tidy::altera
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Finds inner loops that have not been unrolled, as well as fully unrolled loops with unknown loop boun...
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
llvm::StringMap< ClangTidyValue > OptionMap