clang-tools
20.0.0git
llvm-project
clang-tools-extra
clang-tidy
altera
UnrollLoopsCheck.h
Go to the documentation of this file.
1
//===--- UnrollLoopsCheck.h - clang-tidy ------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_UNROLLLOOPSCHECK_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_UNROLLLOOPSCHECK_H
11
12
#include "../ClangTidyCheck.h"
13
14
namespace
clang::tidy::altera
{
15
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.
18
///
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.
22
///
23
/// For the user-facing documentation see:
24
/// http://clang.llvm.org/extra/clang-tidy/checks/altera/unroll-loops.html
25
class
UnrollLoopsCheck
:
public
ClangTidyCheck
{
26
public
:
27
UnrollLoopsCheck
(StringRef
Name
,
ClangTidyContext
*Context);
28
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
29
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
30
31
private
:
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
;
70
};
71
72
}
// namespace clang::tidy::altera
73
74
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_UNROLLLOOPSCHECK_H
Name
llvm::SmallString< 256U > Name
Definition:
ChainedComparisonCheck.cpp:42
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:53
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:69
clang::tidy::altera::UnrollLoopsCheck
Finds inner loops that have not been unrolled, as well as fully unrolled loops with unknown loop boun...
Definition:
UnrollLoopsCheck.h:25
clang::tidy::altera::UnrollLoopsCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
UnrollLoopsCheck.cpp:37
clang::tidy::altera::UnrollLoopsCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
UnrollLoopsCheck.cpp:26
clang::tidy::altera
Definition:
AlteraTidyModule.cpp:21
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition:
ClangTidyOptions.h:126
Generated on Fri Feb 14 2025 23:16:35 for clang-tools by
1.9.6