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