LLVM  10.0.0
Macros | Functions | Variables
AArch64LoadStoreOptimizer.cpp File Reference
#include "AArch64InstrInfo.h"
#include "AArch64Subtarget.h"
#include "MCTargetDesc/AArch64AddressingModes.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugCounter.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdint>
#include <functional>
#include <iterator>
#include <limits>
Include dependency graph for AArch64LoadStoreOptimizer.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "aarch64-ldst-opt"
 
#define AARCH64_LOAD_STORE_OPT_NAME   "AArch64 load / store optimization pass"
 

Functions

 STATISTIC (NumPairCreated, "Number of load/store pair instructions generated")
 
 STATISTIC (NumPostFolded, "Number of post-index updates folded")
 
 STATISTIC (NumPreFolded, "Number of pre-index updates folded")
 
 STATISTIC (NumUnscaledPairCreated, "Number of load/store from unscaled generated")
 
 STATISTIC (NumZeroStoresPromoted, "Number of narrow zero stores promoted")
 
 STATISTIC (NumLoadsFromStoresPromoted, "Number of loads from stores promoted")
 
 DEBUG_COUNTER (RegRenamingCounter, DEBUG_TYPE "-reg-renaming", "Controls which pairs are considered for renaming")
 
 INITIALIZE_PASS (AArch64LoadStoreOpt, "aarch64-ldst-opt", AARCH64_LOAD_STORE_OPT_NAME, false, false) static bool isNarrowStore(unsigned Opc)
 
static bool isTagStore (const MachineInstr &MI)
 
static unsigned getMatchingNonSExtOpcode (unsigned Opc, bool *IsValidLdStrOpc=nullptr)
 
static unsigned getMatchingWideOpcode (unsigned Opc)
 
static unsigned getMatchingPairOpcode (unsigned Opc)
 
static unsigned isMatchingStore (MachineInstr &LoadInst, MachineInstr &StoreInst)
 
static unsigned getPreIndexedOpcode (unsigned Opc)
 
static unsigned getPostIndexedOpcode (unsigned Opc)
 
static bool isPairedLdSt (const MachineInstr &MI)
 
static void getPrePostIndexedMemOpInfo (const MachineInstr &MI, int &Scale, int &MinOffset, int &MaxOffset)
 
static MachineOperand & getLdStRegOp (MachineInstr &MI, unsigned PairedRegOp=0)
 
static const MachineOperand & getLdStBaseOp (const MachineInstr &MI)
 
static const MachineOperand & getLdStOffsetOp (const MachineInstr &MI)
 
static bool isLdOffsetInRangeOfSt (MachineInstr &LoadInst, MachineInstr &StoreInst, const AArch64InstrInfo *TII)
 
static bool isPromotableZeroStoreInst (MachineInstr &MI)
 
static bool isPromotableLoadFromStore (MachineInstr &MI)
 
static bool isMergeableLdStUpdate (MachineInstr &MI)
 
static bool forAllMIsUntilDef (MachineInstr &MI, MCPhysReg DefReg, const TargetRegisterInfo *TRI, unsigned Limit, std::function< bool(MachineInstr &, bool)> &Fn)
 
static void updateDefinedRegisters (MachineInstr &MI, LiveRegUnits &Units, const TargetRegisterInfo *TRI)
 
static bool inBoundsForPair (bool IsUnscaled, int Offset, int OffsetStride)
 
static int alignTo (int Num, int PowOf2)
 
static bool mayAlias (MachineInstr &MIa, MachineInstr &MIb, AliasAnalysis *AA)
 
static bool mayAlias (MachineInstr &MIa, SmallVectorImpl< MachineInstr *> &MemInsns, AliasAnalysis *AA)
 
static bool areCandidatesToMergeOrPair (MachineInstr &FirstMI, MachineInstr &MI, LdStPairFlags &Flags, const AArch64InstrInfo *TII)
 
static bool canRenameUpToDef (MachineInstr &FirstMI, LiveRegUnits &UsedInBetween, SmallPtrSetImpl< const TargetRegisterClass *> &RequiredClasses, const TargetRegisterInfo *TRI)
 
static Optional< MCPhysReg > tryToFindRegisterToRename (MachineInstr &FirstMI, MachineInstr &MI, LiveRegUnits &DefinedInBB, LiveRegUnits &UsedInBetween, SmallPtrSetImpl< const TargetRegisterClass *> &RequiredClasses, const TargetRegisterInfo *TRI)
 

Variables

static cl::opt< unsigned > LdStLimit ("aarch64-load-store-scan-limit", cl::init(20), cl::Hidden)
 
static cl::opt< unsigned > UpdateLimit ("aarch64-update-scan-limit", cl::init(100), cl::Hidden)
 
static cl::opt< bool > EnableRenaming ("aarch64-load-store-renaming", cl::init(false), cl::Hidden)
 

Macro Definition Documentation

◆ AARCH64_LOAD_STORE_OPT_NAME

#define AARCH64_LOAD_STORE_OPT_NAME   "AArch64 load / store optimization pass"

Definition at line 73 of file AArch64LoadStoreOptimizer.cpp.

◆ DEBUG_TYPE

#define DEBUG_TYPE   "aarch64-ldst-opt"

Definition at line 47 of file AArch64LoadStoreOptimizer.cpp.

Function Documentation

◆ alignTo()

static int alignTo ( int  Num,
int  PowOf2 
)
static

Definition at line 1143 of file AArch64LoadStoreOptimizer.cpp.

◆ areCandidatesToMergeOrPair()

static bool areCandidatesToMergeOrPair ( MachineInstr &  FirstMI,
MachineInstr &  MI,
LdStPairFlags &  Flags,
const AArch64InstrInfo *  TII 
)
static

◆ canRenameUpToDef()

static bool canRenameUpToDef ( MachineInstr &  FirstMI,
LiveRegUnits &  UsedInBetween,
SmallPtrSetImpl< const TargetRegisterClass *> &  RequiredClasses,
const TargetRegisterInfo *  TRI 
)
static

◆ DEBUG_COUNTER()

DEBUG_COUNTER ( RegRenamingCounter  ,
DEBUG_TYPE "-reg-renaming"  ,
"Controls which pairs are considered for renaming"   
)

◆ forAllMIsUntilDef()

static bool forAllMIsUntilDef ( MachineInstr &  MI,
MCPhysReg  DefReg,
const TargetRegisterInfo *  TRI,
unsigned  Limit,
std::function< bool(MachineInstr &, bool)> &  Fn 
)
static

◆ getLdStBaseOp()

static const MachineOperand& getLdStBaseOp ( const MachineInstr &  MI)
static

◆ getLdStOffsetOp()

static const MachineOperand& getLdStOffsetOp ( const MachineInstr &  MI)
static

◆ getLdStRegOp()

static MachineOperand& getLdStRegOp ( MachineInstr &  MI,
unsigned  PairedRegOp = 0 
)
static

◆ getMatchingNonSExtOpcode()

static unsigned getMatchingNonSExtOpcode ( unsigned  Opc,
bool *  IsValidLdStrOpc = nullptr 
)
static

Definition at line 238 of file AArch64LoadStoreOptimizer.cpp.

References llvm::max().

Referenced by areCandidatesToMergeOrPair(), and updateDefinedRegisters().

◆ getMatchingPairOpcode()

static unsigned getMatchingPairOpcode ( unsigned  Opc)
static

◆ getMatchingWideOpcode()

static unsigned getMatchingWideOpcode ( unsigned  Opc)
static

Definition at line 279 of file AArch64LoadStoreOptimizer.cpp.

References llvm_unreachable.

Referenced by isMergeableLdStUpdate().

◆ getPostIndexedOpcode()

static unsigned getPostIndexedOpcode ( unsigned  Opc)
static

Definition at line 441 of file AArch64LoadStoreOptimizer.cpp.

References llvm_unreachable.

Referenced by tryToFindRegisterToRename().

◆ getPreIndexedOpcode()

static unsigned getPreIndexedOpcode ( unsigned  Opc)
static

Definition at line 368 of file AArch64LoadStoreOptimizer.cpp.

References llvm_unreachable.

Referenced by tryToFindRegisterToRename().

◆ getPrePostIndexedMemOpInfo()

static void getPrePostIndexedMemOpInfo ( const MachineInstr &  MI,
int &  Scale,
int &  MinOffset,
int &  MaxOffset 
)
static

◆ inBoundsForPair()

static bool inBoundsForPair ( bool  IsUnscaled,
int  Offset,
int  OffsetStride 
)
static

Definition at line 1126 of file AArch64LoadStoreOptimizer.cpp.

Referenced by tryToFindRegisterToRename().

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( AArch64LoadStoreOpt  ,
"aarch64-ldst-opt"  ,
AARCH64_LOAD_STORE_OPT_NAME  ,
false  ,
false   
)

Definition at line 209 of file AArch64LoadStoreOptimizer.cpp.

◆ isLdOffsetInRangeOfSt()

static bool isLdOffsetInRangeOfSt ( MachineInstr &  LoadInst,
MachineInstr &  StoreInst,
const AArch64InstrInfo *  TII 
)
static

◆ isMatchingStore()

static unsigned isMatchingStore ( MachineInstr &  LoadInst,
MachineInstr &  StoreInst 
)
static

◆ isMergeableLdStUpdate()

static bool isMergeableLdStUpdate ( MachineInstr &  MI)
static

◆ isPairedLdSt()

static bool isPairedLdSt ( const MachineInstr &  MI)
static

◆ isPromotableLoadFromStore()

static bool isPromotableLoadFromStore ( MachineInstr &  MI)
static

Definition at line 599 of file AArch64LoadStoreOptimizer.cpp.

References llvm::MachineInstr::getOpcode().

Referenced by tryToFindRegisterToRename().

◆ isPromotableZeroStoreInst()

static bool isPromotableZeroStoreInst ( MachineInstr &  MI)
static

◆ isTagStore()

static bool isTagStore ( const MachineInstr &  MI)
static

◆ mayAlias() [1/2]

static bool mayAlias ( MachineInstr &  MIa,
MachineInstr &  MIb,
AliasAnalysis *  AA 
)
static

◆ mayAlias() [2/2]

static bool mayAlias ( MachineInstr &  MIa,
SmallVectorImpl< MachineInstr *> &  MemInsns,
AliasAnalysis *  AA 
)
static

◆ STATISTIC() [1/6]

STATISTIC ( NumPairCreated  ,
"Number of load/store pair instructions generated"   
)

◆ STATISTIC() [2/6]

STATISTIC ( NumPostFolded  ,
"Number of post-index updates folded"   
)

◆ STATISTIC() [3/6]

STATISTIC ( NumPreFolded  ,
"Number of pre-index updates folded"   
)

◆ STATISTIC() [4/6]

STATISTIC ( NumUnscaledPairCreated  ,
"Number of load/store from unscaled generated"   
)

◆ STATISTIC() [5/6]

STATISTIC ( NumZeroStoresPromoted  ,
"Number of narrow zero stores promoted"   
)

◆ STATISTIC() [6/6]

STATISTIC ( NumLoadsFromStoresPromoted  ,
"Number of loads from stores promoted"   
)

◆ tryToFindRegisterToRename()

static Optional<MCPhysReg> tryToFindRegisterToRename ( MachineInstr &  FirstMI,
MachineInstr &  MI,
LiveRegUnits &  DefinedInBB,
LiveRegUnits &  UsedInBetween,
SmallPtrSetImpl< const TargetRegisterClass *> &  RequiredClasses,
const TargetRegisterInfo *  TRI 
)
static

Definition at line 1389 of file AArch64LoadStoreOptimizer.cpp.

References llvm::LiveRegUnits::accumulate(), llvm::LiveRegUnits::accumulateUsedDefed(), add(), llvm::LiveRegUnits::addReg(), llvm::alignTo(), llvm::all_of(), llvm::any_of(), areCandidatesToMergeOrPair(), assert(), llvm::LiveRegUnits::available(), B, llvm::MachineBasicBlock::begin(), llvm::BuildMI(), C, canRenameUpToDef(), llvm::dbgs(), llvm::numbers::e, E, EnableRenaming, llvm::MachineBasicBlock::end(), llvm::MachineFunction::getFunction(), llvm::MachineOperand::getImm(), getLdStBaseOp(), getLdStOffsetOp(), getLdStRegOp(), llvm::TargetRegisterInfo::getMinimalPhysRegClass(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::MachineBasicBlock::getParent(), llvm::MachineInstr::getParent(), getPostIndexedOpcode(), getPreIndexedOpcode(), getPrePostIndexedMemOpInfo(), llvm::MachineOperand::getReg(), getReg(), llvm::TargetRegisterInfo::getRegClassName(), llvm::MachineFunction::getRegInfo(), llvm::AArch64_AM::getShiftValue(), llvm::MachineFunction::getSubtarget(), llvm::MachineInstr::hasOrderedMemoryRef(), I, inBoundsForPair(), llvm::LiveRegUnits::init(), llvm::MachineInstr::isCall(), llvm::TargetRegisterInfo::isCalleeSavedPhysReg(), llvm::MachineOperand::isImm(), isMergeableLdStUpdate(), isPairedLdSt(), isPromotableLoadFromStore(), isPromotableZeroStoreInst(), llvm::MachineRegisterInfo::isReserved(), llvm::MCRegisterInfo::isSubRegister(), isTagStore(), llvm::MachineInstr::isTransient(), LdStLimit, LLVM_DEBUG, mayAlias(), llvm::MCID::MayLoad, llvm::MachineInstr::mayLoad(), llvm::MachineInstr::mayLoadOrStore(), Modified, llvm::None, print(), llvm::printReg(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), Reg, llvm::DebugCounter::shouldExecute(), llvm::MCRegisterInfo::sub_and_superregs_inclusive(), TII, llvm::MachineRegisterInfo::tracksLiveness(), TRI, updateDefinedRegisters(), and UpdateLimit.

◆ updateDefinedRegisters()

static void updateDefinedRegisters ( MachineInstr &  MI,
LiveRegUnits &  Units,
const TargetRegisterInfo *  TRI 
)
static

Variable Documentation

◆ EnableRenaming

cl::opt<bool> EnableRenaming("aarch64-load-store-renaming", cl::init(false), cl::Hidden)
static

◆ LdStLimit

cl::opt<unsigned> LdStLimit("aarch64-load-store-scan-limit", cl::init(20), cl::Hidden)
static

◆ UpdateLimit

cl::opt<unsigned> UpdateLimit("aarch64-update-scan-limit", cl::init(100), cl::Hidden)
static