30#define DEBUG_TYPE "aarch64-fix-cortex-a53-835769"
32STATISTIC(NumNopsAdded,
"Number of Nops added to work around erratum 835769");
41 switch (
MI->getOpcode()) {
43 case AArch64::PRFMroW:
44 case AArch64::PRFMroX:
49 return MI->mayLoadOrStore();
58 switch (
MI->getOpcode()) {
61 case AArch64::MSUBXrrr:
62 case AArch64::MADDXrrr:
63 case AArch64::SMADDLrrr:
64 case AArch64::SMSUBLrrr:
65 case AArch64::UMADDLrrr:
66 case AArch64::UMSUBLrrr:
69 return MI->getOperand(3).getReg() != AArch64::XZR;
79class AArch64A53Fix835769Impl {
81 bool run(MachineFunction &MF);
84 const TargetInstrInfo *TII;
91 explicit AArch64A53Fix835769Legacy() : MachineFunctionPass(ID) {}
93 bool runOnMachineFunction(MachineFunction &
F)
override;
95 MachineFunctionProperties getRequiredProperties()
const override {
96 return MachineFunctionProperties().setNoVRegs();
99 StringRef getPassName()
const override {
100 return "Workaround A53 erratum 835769 pass";
103 void getAnalysisUsage(AnalysisUsage &AU)
const override {
108char AArch64A53Fix835769Legacy::ID = 0;
113 "AArch64 fix for A53 erratum 835769",
false,
false)
120 bool Changed = AArch64A53Fix835769Impl().run(MF);
129 return AArch64A53Fix835769Impl().run(
F);
132bool AArch64A53Fix835769Impl::run(MachineFunction &MF) {
136 if (!STI.fixCortexA53_835769())
140 TII = STI.getInstrInfo();
142 for (
auto &
MBB : MF) {
156 if (
MBBI ==
MBB->getParent()->begin())
164 if (S == PrevBB && !
TII->analyzeBranch(*PrevBB,
TBB, FBB,
Cond) && !
TBB &&
195 if (
MI == &
MBB.front()) {
197 assert(
I &&
"Expected instruction");
208bool AArch64A53Fix835769Impl::runOnBasicBlock(MachineBasicBlock &
MBB) {
211 <<
" - scanning instructions...\n");
217 std::vector<MachineInstr*> Sequences;
219 MachineInstr *PrevInstr =
nullptr;
225 for (
auto &
MI :
MBB) {
226 MachineInstr *CurrInstr = &
MI;
230 <<
" CurrInstr: " << *CurrInstr
231 <<
" isFirstInstructionInSequence(PrevInstr): "
233 <<
" isSecondInstructionInSequence(CurrInstr): "
237 LLVM_DEBUG(
dbgs() <<
" ** pattern found at Idx " << Idx <<
"!\n");
239 Sequences.push_back(CurrInstr);
243 PrevInstr = CurrInstr;
248 <<
" occurrences of pattern found.\n");
251 for (
auto &
MI : Sequences) {
262 return new AArch64A53Fix835769Legacy();
static MachineBasicBlock * getBBFallenThrough(MachineBasicBlock *MBB, const TargetInstrInfo *TII)
static MachineInstr * getLastNonPseudo(MachineBasicBlock &MBB, const TargetInstrInfo *TII)
static void insertNopBeforeInstruction(MachineBasicBlock &MBB, MachineInstr *MI, const TargetInstrInfo *TII)
static bool isFirstInstructionInSequence(MachineInstr *MI)
static bool isSecondInstructionInSequence(MachineInstr *MI)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
static bool runOnBasicBlock(MachineBasicBlock *MBB, unsigned BasicBlockNum, VRegRenamer &Renamer)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
BasicBlockListType::iterator iterator
Representation of each machine instruction.
bool isPseudo(QueryType Type=IgnoreBundle) const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createAArch64A53Fix835769LegacyPass()
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.