LLVM 20.0.0git
SandboxVectorizer.cpp
Go to the documentation of this file.
1//===- SandboxVectorizer.cpp - Vectorizer based on Sandbox IR -------------===//
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
14
15using namespace llvm;
16
17#define SV_NAME "sandbox-vectorizer"
18#define DEBUG_TYPE SV_NAME
19
20static cl::opt<bool>
21 PrintPassPipeline("sbvec-print-pass-pipeline", cl::init(false), cl::Hidden,
22 cl::desc("Prints the pass pipeline and returns."));
23
24/// A magic string for the default pass pipeline.
25static const char *DefaultPipelineMagicStr = "*";
26
29 cl::desc("Comma-separated list of vectorizer passes. If not set "
30 "we run the predefined pipeline."));
31
34 // TODO: Add region passes to the default pipeline.
36 "bottom-up-vec<>",
38 } else {
39 // Create the user-defined pipeline.
43 }
44}
45
47 default;
48
50
54 AA = &AM.getResult<AAManager>(F);
56
57 bool Changed = runImpl(F);
58 if (!Changed)
60
63 return PA;
64}
65
66bool SandboxVectorizerPass::runImpl(Function &LLVMF) {
67 if (Ctx == nullptr)
68 Ctx = std::make_unique<sandboxir::Context>(LLVMF.getContext());
69
71 FPM.printPipeline(outs());
72 return false;
73 }
74
75 // If the target claims to have no vector registers early return.
77 LLVM_DEBUG(dbgs() << "SBVec: Target has no vector registers, return.\n");
78 return false;
79 }
80 LLVM_DEBUG(dbgs() << "SBVec: Analyzing " << LLVMF.getName() << ".\n");
81 // Early return if the attribute NoImplicitFloat is used.
82 if (LLVMF.hasFnAttribute(Attribute::NoImplicitFloat)) {
83 LLVM_DEBUG(dbgs() << "SBVec: NoImplicitFloat attribute, return.\n");
84 return false;
85 }
86
87 // Create SandboxIR for LLVMF and run BottomUpVec on it.
88 sandboxir::Function &F = *Ctx->createFunction(&LLVMF);
89 sandboxir::Analyses A(*AA, *SE);
90 return FPM.runOnFunction(F, A);
91}
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DEBUG(...)
Definition: Debug.h:106
#define F(x, y, z)
Definition: MD5.cpp:55
static cl::opt< std::string > UserDefinedPassPipeline("sbvec-passes", cl::init(DefaultPipelineMagicStr), cl::Hidden, cl::desc("Comma-separated list of vectorizer passes. If not set " "we run the predefined pipeline."))
static const char * DefaultPipelineMagicStr
A magic string for the default pass pipeline.
static cl::opt< bool > PrintPassPipeline("sbvec-print-pass-pipeline", cl::init(false), cl::Hidden, cl::desc("Prints the pass pipeline and returns."))
This pass exposes codegen information to IR-level passes.
A manager for alias analyses.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:410
Represents analyses that only rely on functions' control flow.
Definition: Analysis.h:72
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:369
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:731
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
void preserveSet()
Mark an analysis set as preserved.
Definition: Analysis.h:146
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Analysis pass that exposes the ScalarEvolution for a function.
Analysis pass providing the TargetTransformInfo.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const
unsigned getNumberOfRegisters(unsigned ClassID) const
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
bool runOnFunction(Function &F, const Analyses &A) final
\Returns true if it modifies F.
Definition: PassManager.cpp:13
void printPipeline(raw_ostream &OS) const override
Similar to print() but prints one pass per line. Used for testing.
Definition: PassManager.h:197
void setPassPipeline(StringRef Pipeline, CreatePassFunc CreatePass)
Parses Pipeline as a comma-separated sequence of pass names and sets the pass pipeline,...
Definition: PassManager.h:76
static std::unique_ptr< FunctionPass > createFunctionPass(StringRef Name, StringRef Args)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163