LLVM 24.0.0git
LoadStoreOpt.h
Go to the documentation of this file.
1//== llvm/CodeGen/GlobalISel/LoadStoreOpt.h - LoadStoreOpt -------*- 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/// This is an optimization pass for GlobalISel generic memory operations.
10/// Specifically, it focuses on merging stores and loads to consecutive
11/// addresses.
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CODEGEN_GLOBALISEL_LOADSTOREOPT_H
15#define LLVM_CODEGEN_GLOBALISEL_LOADSTOREOPT_H
16
20#include "llvm/IR/PassManager.h"
22
23namespace llvm {
24// Forward declarations.
25class AnalysisUsage;
26class GStore;
27class LegalizerInfo;
29class MachineInstr;
30class TargetLowering;
31struct LegalityQuery;
33namespace GISelAddressing {
34/// Helper struct to store a base, index and offset that forms an address
36private:
37 Register BaseReg;
38 Register IndexReg;
39 std::optional<int64_t> Offset;
40
41public:
42 BaseIndexOffset() = default;
43 Register getBase() { return BaseReg; }
44 Register getBase() const { return BaseReg; }
45 Register getIndex() { return IndexReg; }
46 Register getIndex() const { return IndexReg; }
47 void setBase(Register NewBase) { BaseReg = NewBase; }
48 void setIndex(Register NewIndex) { IndexReg = NewIndex; }
49 void setOffset(std::optional<int64_t> NewOff) { Offset = NewOff; }
50 bool hasValidOffset() const { return Offset.has_value(); }
51 int64_t getOffset() const { return *Offset; }
52};
53
54/// Returns a BaseIndexOffset which describes the pointer in \p Ptr.
56
57/// Compute whether or not a memory access at \p MI1 aliases with an access at
58/// \p MI2 \returns true if either alias/no-alias is known. Sets \p IsAlias
59/// accordingly.
61 const MachineInstr &MI2, bool &IsAlias,
63
64/// Returns true if the instruction \p MI may alias \p Other.
65/// This function uses multiple strategies to detect aliasing, whereas
66/// aliasIsKnownForLoadStore just looks at the addresses of load/stores and is
67/// tries to reason about base/index/offsets.
70} // namespace GISelAddressing
71
73public:
74 static char ID;
75
77
78 StringRef getPassName() const override { return "LoadStoreOpt"; }
79
81 return MachineFunctionProperties().setIsSSA();
82 }
83
84 void getAnalysisUsage(AnalysisUsage &AU) const override;
85
86 bool runOnMachineFunction(MachineFunction &MF) override;
87};
88
89class LoadStoreOptPass : public RequiredPassInfoMixin<LoadStoreOptPass> {
90public:
93
97};
98
99} // End namespace llvm.
100
101#endif
#define LLVM_ABI
Definition Compiler.h:215
IRTranslator LLVM IR MI
This header defines various interfaces for pass management in LLVM.
This file declares the MachineIRBuilder class.
Represent the analysis usage information of a pass.
Helper struct to parse and store a memory address as base + index + offset.
void setOffset(std::optional< int64_t > NewOff)
Represents a G_STORE.
MachineFunctionProperties getRequiredProperties() const override
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
MachineFunctionProperties getRequiredProperties() const
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Properties which a MachineFunction may have at a given point in time.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Abstract Attribute helper functions.
Definition Attributor.h:165
LLVM_ABI bool aliasIsKnownForLoadStore(const MachineInstr &MI1, const MachineInstr &MI2, bool &IsAlias, MachineRegisterInfo &MRI)
Compute whether or not a memory access at MI1 aliases with an access at MI2.
LLVM_ABI BaseIndexOffset getPointerInfo(Register Ptr, MachineRegisterInfo &MRI)
Returns a BaseIndexOffset which describes the pointer in Ptr.
LLVM_ABI bool instMayAlias(const MachineInstr &MI, const MachineInstr &Other, MachineRegisterInfo &MRI, AliasAnalysis *AA)
Returns true if the instruction MI may alias Other.
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
@ Other
Any other memory.
Definition ModRef.h:68
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
A CRTP mix-in for passes that should not be skipped.