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"
22
23#include <optional>
24
25namespace llvm {
26
27class DataLayout;
28
29namespace sandboxir {
30
31class Context;
32class Function;
33class Value;
34class Instruction;
35class Type;
36class Constant;
37
38class LLVM_ABI LoadStoreVec final : public RegionPass {
39 const DataLayout *DL = nullptr;
40 /// The region saved by saveIR(), used by acceptOrRevert().
41 Region *Rgn = nullptr;
42 /// The region's cost at the time of saveIR().
43 InstructionCost CostBefore = 0;
44 const Analyses *A = nullptr;
45 Context *Ctx = nullptr;
46 std::unique_ptr<Scheduler> Sched;
47 VecUtils::DeadInstructionMorgue DeadInstrMorgue;
48
49 /// Saves the IR along with the current cost of \p Rgn, so that
50 /// acceptOrRevert() can tell whether vectorizing was profitable.
51 void saveIR(Region &Rgn);
52
53 /// Accepts the transaction saved by saveIR() if vectorizing was profitable,
54 /// reverts it otherwise. \returns true if the transaction was accepted.
55 bool acceptOrRevert();
56
57 /// Checks legality of vectorization and \returns the vector type on success,
58 /// nullopt otherwise.
59 std::optional<Type *> canVectorize(BndlRef<Instruction *> Bndl);
60
61 /// Builds a single vector load out of \p Loads. \returns the new load,
62 /// or nullptr if \p Loads are not a vectorizable.
63 LoadInst *createVectorLoad(BndlRef<Instruction *> Loads);
64
65 /// Builds a ConstantVector from per-lane constant store operands in \p
66 /// Constants. \returns the packed ConstantVector.
67 Constant *createConstantVector(BndlRef<Constant *> Constants);
68
69 /// Vectorizes \p Stores and their operands if constants or consecutive
70 /// loads. \returns true on success.
71 bool vectorizeStores(BndlRef<Instruction *> Stores, Region &Rgn);
72
73 /// Vectorizes \p Loads into a single load. \return the packed load.
74 LoadInst *vectorizeLoads(BndlRef<Instruction *> Loads, Region &Rgn);
75
76public:
77 LoadStoreVec(StringRef AuxArg) : RegionPass("load-store-vec") {
78 assert(AuxArg.empty() && "This pass ignores aux arg!");
79 }
80 bool runOnRegion(Region &Rgn, const Analyses &A) final;
81};
82
83} // namespace sandboxir
84
85} // namespace llvm
86
87#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_STRUCTINITVEC_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition Compiler.h:215
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:457
This is an optimization pass for GlobalISel generic memory operations.