#include "X86.h"
#include "X86InstrInfo.h"
#include "X86Subtarget.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/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/Function.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/MCInstrDesc.h"
usingnamespacellvm;
#define DEBUG_TYPE …
static cl::opt<bool> DisableX86AvoidStoreForwardBlocks(
"x86-disable-avoid-SFB", cl::Hidden,
cl::desc("X86: Disable Store Forwarding Blocks fixup."), cl::init(false));
static cl::opt<unsigned> X86AvoidSFBInspectionLimit(
"x86-sfb-inspection-limit",
cl::desc("X86: Number of instructions backward to "
"inspect for store forwarding blocks."),
cl::init(20), cl::Hidden);
namespace {
DisplacementSizeMap;
class X86AvoidSFBPass : public MachineFunctionPass { … };
}
char X86AvoidSFBPass::ID = …;
INITIALIZE_PASS_BEGIN(X86AvoidSFBPass, DEBUG_TYPE, "Machine code sinking",
false, false)
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
INITIALIZE_PASS_END(X86AvoidSFBPass, DEBUG_TYPE, "Machine code sinking", false,
false)
FunctionPass *llvm::createX86AvoidStoreForwardingBlocks() { … }
static bool isXMMLoadOpcode(unsigned Opcode) { … }
static bool isYMMLoadOpcode(unsigned Opcode) { … }
static bool isPotentialBlockedMemCpyLd(unsigned Opcode) { … }
static bool isPotentialBlockedMemCpyPair(unsigned LdOpcode, unsigned StOpcode) { … }
static bool isPotentialBlockingStoreInst(unsigned Opcode, unsigned LoadOpcode) { … }
static const int MOV128SZ = …;
static const int MOV64SZ = …;
static const int MOV32SZ = …;
static const int MOV16SZ = …;
static const int MOV8SZ = …;
static unsigned getYMMtoXMMLoadOpcode(unsigned LoadOpcode) { … }
static unsigned getYMMtoXMMStoreOpcode(unsigned StoreOpcode) { … }
static int getAddrOffset(const MachineInstr *MI) { … }
static MachineOperand &getBaseOperand(MachineInstr *MI) { … }
static MachineOperand &getDispOperand(MachineInstr *MI) { … }
static bool isRelevantAddressingMode(MachineInstr *MI) { … }
static SmallVector<MachineInstr *, 2>
findPotentialBlockers(MachineInstr *LoadInst) { … }
void X86AvoidSFBPass::buildCopy(MachineInstr *LoadInst, unsigned NLoadOpcode,
int64_t LoadDisp, MachineInstr *StoreInst,
unsigned NStoreOpcode, int64_t StoreDisp,
unsigned Size, int64_t LMMOffset,
int64_t SMMOffset) { … }
void X86AvoidSFBPass::buildCopies(int Size, MachineInstr *LoadInst,
int64_t LdDispImm, MachineInstr *StoreInst,
int64_t StDispImm, int64_t LMMOffset,
int64_t SMMOffset) { … }
static void updateKillStatus(MachineInstr *LoadInst, MachineInstr *StoreInst) { … }
bool X86AvoidSFBPass::alias(const MachineMemOperand &Op1,
const MachineMemOperand &Op2) const { … }
void X86AvoidSFBPass::findPotentiallylBlockedCopies(MachineFunction &MF) { … }
unsigned X86AvoidSFBPass::getRegSizeInBytes(MachineInstr *LoadInst) { … }
void X86AvoidSFBPass::breakBlockedCopies(
MachineInstr *LoadInst, MachineInstr *StoreInst,
const DisplacementSizeMap &BlockingStoresDispSizeMap) { … }
static bool hasSameBaseOpValue(MachineInstr *LoadInst,
MachineInstr *StoreInst) { … }
static bool isBlockingStore(int64_t LoadDispImm, unsigned LoadSize,
int64_t StoreDispImm, unsigned StoreSize) { … }
static void
updateBlockingStoresDispSizeMap(DisplacementSizeMap &BlockingStoresDispSizeMap,
int64_t DispImm, unsigned Size) { … }
static void
removeRedundantBlockingStores(DisplacementSizeMap &BlockingStoresDispSizeMap) { … }
bool X86AvoidSFBPass::runOnMachineFunction(MachineFunction &MF) { … }