1//===- SandboxVectorizer.h --------------------------------------*- 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#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SANDBOXVECTORIZER_H
9#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SANDBOXVECTORIZER_H
10
11#include "llvm/Support/Compiler.h"
12#include <memory>
13
14#include "llvm/Analysis/AliasAnalysis.h"
15#include "llvm/Analysis/ScalarEvolution.h"
16#include "llvm/IR/PassManager.h"
17#include "llvm/SandboxIR/Context.h"
18#include "llvm/SandboxIR/PassManager.h"
19
20namespace llvm {
21
22class TargetTransformInfo;
23
24class SandboxVectorizerPass
25 : public OptionalPassInfoMixin<SandboxVectorizerPass> {
26 TargetTransformInfo *TTI = nullptr;
27 AAResults *AA = nullptr;
28 ScalarEvolution *SE = nullptr;
29 // NOTE: We define the Context as a pass-scope object instead of local object
30 // in runOnFunction() because the passes defined in the pass-manager need
31 // access to it for registering/deregistering callbacks during construction
32 // and destruction.
33 std::unique_ptr<sandboxir::Context> Ctx;
34
35 // A pipeline of SandboxIR function passes run by the vectorizer.
36 // NOTE: We define this as a pass-scope object to avoid recreating the
37 // pass-pipeline every time in runOnFunction(). The downside is that the
38 // Context also needs to be defined as a pass-scope object because the passes
39 // within FPM may register/unregister callbacks, so they need access to
40 // Context.
41 sandboxir::FunctionPassManager FPM;
42 /// \Returns true if we should attempt to vectorize \p SrcFilePath based on
43 /// `AllowFiles` option.
44 bool allowFile(const std::string &SrcFilePath);
45
46 bool runImpl(Function &F);
47
48public:
49 // Make sure the constructors/destructors are out-of-line. This works around a
50 // problem with -DBUILD_SHARED_LIBS=on where components that depend on the
51 // Vectorizer component can't find the vtable for classes like
52 // sandboxir::Pass. This way we don't have to make LLVMPasses add a direct
53 // dependency on SandboxIR.
54 LLVM_ABI SandboxVectorizerPass();
55 LLVM_ABI SandboxVectorizerPass(SandboxVectorizerPass &&);
56 LLVM_ABI ~SandboxVectorizerPass();
57
58 LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
59};
60
61} // namespace llvm
62
63#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SANDBOXVECTORIZER_H
64