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 MachineInstr;
28namespace GISelAddressing {
29/// Helper struct to store a base, index and offset that forms an address
31private:
32 Register BaseReg;
33 Register IndexReg;
34 std::optional<int64_t> Offset;
35
36public:
37 BaseIndexOffset() = default;
38 Register getBase() { return BaseReg; }
39 Register getBase() const { return BaseReg; }
40 Register getIndex() { return IndexReg; }
41 Register getIndex() const { return IndexReg; }
42 void setBase(Register NewBase) { BaseReg = NewBase; }
43 void setIndex(Register NewIndex) { IndexReg = NewIndex; }
44 void setOffset(std::optional<int64_t> NewOff) { Offset = NewOff; }
45 bool hasValidOffset() const { return Offset.has_value(); }
46 int64_t getOffset() const { return *Offset; }
47};
48
49/// Returns a BaseIndexOffset which describes the pointer in \p Ptr.
51
52/// Compute whether or not a memory access at \p MI1 aliases with an access at
53/// \p MI2 \returns true if either alias/no-alias is known. Sets \p IsAlias
54/// accordingly.
56 const MachineInstr &MI2, bool &IsAlias,
58
59/// Returns true if the instruction \p MI may alias \p Other.
60/// This function uses multiple strategies to detect aliasing, whereas
61/// aliasIsKnownForLoadStore just looks at the addresses of load/stores and is
62/// tries to reason about base/index/offsets.
65} // namespace GISelAddressing
66
68public:
69 static char ID;
70
72
73 StringRef getPassName() const override { return "LoadStoreOpt"; }
74
76 return MachineFunctionProperties().setIsSSA();
77 }
78
79 void getAnalysisUsage(AnalysisUsage &AU) const override;
80
81 bool runOnMachineFunction(MachineFunction &MF) override;
82};
83
93
94} // End namespace llvm.
95
96#endif
#define LLVM_ABI
Definition Compiler.h:211
IRTranslator LLVM IR MI
This header defines various interfaces for pass management in LLVM.
This file declares the MachineIRBuilder class.
MachineRegisterInfo & MRI
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)
MachineFunctionProperties getRequiredProperties() const override
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
MachineFunctionProperties getRequiredProperties() const
LLVM_ABI 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
Abstract Attribute helper functions.
Definition Attributor.h:166
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.
A CRTP mix-in for passes that should not be skipped.