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