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