LLVM 24.0.0git
LoadStoreVec.h
Go to the documentation of this file.
1//===- LoadStoreVec.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//
9// A pass that vectorizes short store-load chains.
10// Unlike generic bundle vectorization, this pass can vectorize instructions
11// of different types.
12//
13
14#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_LOADSTOREVEC_H
15#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_LOADSTOREVEC_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/SandboxIR/Pass.h"
23
24#include <optional>
25
26namespace llvm {
27
28class DataLayout;
29
30namespace sandboxir {
31
32class Context;
33class Function;
34class Value;
35class Instruction;
36class Type;
37class Constant;
38
39class LLVM_ABI LoadStoreVec final : public RegionPass {
40 const DataLayout *DL = nullptr;
41 /// The region saved by saveIR(), used by acceptOrRevert().
42 Region *Rgn = nullptr;
43 /// The region's cost at the time of saveIR().
44 InstructionCost CostBefore = 0;
45 const Analyses *A = nullptr;
46 Context *Ctx = nullptr;
47 std::unique_ptr<LegalityAnalysis> Legality;
48 VecUtils::DeadInstructionMorgue DeadInstrMorgue;
49
50 /// Saves the IR along with the current cost of \p Rgn, so that
51 /// acceptOrRevert() can tell whether vectorizing was profitable.
52 void saveIR(Region &Rgn);
53
54 /// Accepts the transaction saved by saveIR() if vectorizing was profitable,
55 /// reverts it otherwise. \returns true if the transaction was accepted.
56 bool acceptOrRevert();
57
58 /// Checks legality of vectorization and \returns the vector type on success,
59 /// nullopt otherwise.
60 std::optional<Type *> canVectorize(BndlRef<Instruction *> Bndl);
61
62 /// Builds a single vector load out of \p Loads. \returns the new load,
63 /// or nullptr if \p Loads are not a vectorizable.
64 LoadInst *createVectorLoad(BndlRef<Instruction *> Loads);
65
66 /// Reinterprets \p C as type \p DestTy without changing its bits, e.g.,
67 /// float 1.0 to i32 0x3f800000, or a null pointer to i64 0.
68 ///
69 /// \p DestTy must not be a pointer whose size is unknown.
70 Constant *getEquivalentConstantWithType(Constant *C, Type *DestTy);
71
72 /// Packs \p Constants into one constant vector. The element type is chosen
73 /// by VecUtils::getCombinedVectorTypeFor().
74 ///
75 /// \returns the packed constant vector, or nullptr if some constant cannot
76 /// be converted, e.g., a vector constant that is not yet flattened, or a
77 /// wide constant without a known bit pattern such as a ConstantExpr or a
78 /// global's address.
79 Constant *createConstantVector(BndlRef<Constant *> Constants);
80
81 /// Vectorizes \p Stores and their operands if constants or consecutive
82 /// loads. \returns true on success.
83 bool vectorizeStores(BndlRef<Instruction *> Stores, Region &Rgn);
84
85 /// Vectorizes \p Loads into a single load. \return the packed load.
86 LoadInst *vectorizeLoads(BndlRef<Instruction *> Loads, Region &Rgn);
87
88public:
89 LoadStoreVec(StringRef AuxArg) : RegionPass("load-store-vec") {
90 assert(AuxArg.empty() && "This pass ignores aux arg!");
91 }
92 bool runOnRegion(Region &Rgn, const Analyses &A) final;
93};
94
95} // namespace sandboxir
96
97} // namespace llvm
98
99#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_STRUCTINITVEC_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition Compiler.h:211
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
static bool canVectorize(const CharMatrix &DepMatrix, unsigned LoopId)
Return true if we can vectorize the loop specified by LoopId.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
An ArrayRef of Values or Instructions that we can print/dump for debugging.
Definition VecUtils.h:39
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition Instruction.h:43
LoadStoreVec(StringRef AuxArg)
RegionPass(StringRef Name)
Name can't contain any spaces or start with '-'.
Definition Pass.h:88
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition Type.h:49
A SandboxIR Value has users. This is the base class.
Definition Value.h:72
Utility class to collect and erase dead instructions.
Definition VecUtils.h:502
This is an optimization pass for GlobalISel generic memory operations.