Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:45

0001 //===- BottomUpVec.h --------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // A Bottom-Up Vectorizer pass.
0010 //
0011 
0012 #ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOTTOMUPVEC_H
0013 #define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOTTOMUPVEC_H
0014 
0015 #include "llvm/ADT/ArrayRef.h"
0016 #include "llvm/ADT/StringRef.h"
0017 #include "llvm/SandboxIR/Constant.h"
0018 #include "llvm/SandboxIR/Pass.h"
0019 #include "llvm/SandboxIR/PassManager.h"
0020 #include "llvm/Support/raw_ostream.h"
0021 #include "llvm/Transforms/Vectorize/SandboxVectorizer/InstrMaps.h"
0022 #include "llvm/Transforms/Vectorize/SandboxVectorizer/Legality.h"
0023 
0024 namespace llvm::sandboxir {
0025 
0026 class BottomUpVec final : public FunctionPass {
0027   bool Change = false;
0028   std::unique_ptr<LegalityAnalysis> Legality;
0029   /// The original instructions that are potentially dead after vectorization.
0030   DenseSet<Instruction *> DeadInstrCandidates;
0031   /// Maps scalars to vectors.
0032   std::unique_ptr<InstrMaps> IMaps;
0033 
0034   /// Creates and returns a vector instruction that replaces the instructions in
0035   /// \p Bndl. \p Operands are the already vectorized operands.
0036   Value *createVectorInstr(ArrayRef<Value *> Bndl, ArrayRef<Value *> Operands);
0037   /// Erases all dead instructions from the dead instruction candidates
0038   /// collected during vectorization.
0039   void tryEraseDeadInstrs();
0040   /// Creates a shuffle instruction that shuffles \p VecOp according to \p Mask.
0041   /// \p UserBB is the block of the user bundle.
0042   Value *createShuffle(Value *VecOp, const ShuffleMask &Mask,
0043                        BasicBlock *UserBB);
0044   /// Packs all elements of \p ToPack into a vector and returns that vector. \p
0045   /// UserBB is the block of the user bundle.
0046   Value *createPack(ArrayRef<Value *> ToPack, BasicBlock *UserBB);
0047   /// After we create vectors for groups of instructions, the original
0048   /// instructions are potentially dead and may need to be removed. This
0049   /// function helps collect these instructions (along with the pointer operands
0050   /// for loads/stores) so that they can be cleaned up later.
0051   void collectPotentiallyDeadInstrs(ArrayRef<Value *> Bndl);
0052   /// Recursively try to vectorize \p Bndl and its operands.
0053   Value *vectorizeRec(ArrayRef<Value *> Bndl, ArrayRef<Value *> UserBndl,
0054                       unsigned Depth);
0055   /// Entry point for vectorization starting from \p Seeds.
0056   bool tryVectorize(ArrayRef<Value *> Seeds);
0057 
0058   /// The PM containing the pipeline of region passes.
0059   RegionPassManager RPM;
0060 
0061 public:
0062   BottomUpVec(StringRef Pipeline);
0063   bool runOnFunction(Function &F, const Analyses &A) final;
0064   void printPipeline(raw_ostream &OS) const final {
0065     OS << getName() << "\n";
0066     RPM.printPipeline(OS);
0067   }
0068 };
0069 
0070 } // namespace llvm::sandboxir
0071 
0072 #endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_BOTTOMUPVEC_H