diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2016-12-20 15:52:17 +0000 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2016-12-20 15:52:17 +0000 |
commit | 244891d1290f7387c996bdeec0fc5846576f3f42 (patch) | |
tree | aa0246cc940218897f1480e474eb669bb1713a3d /llvm/lib/Target | |
parent | f789f05ee2e39b5fee20b7dd1d0bd5141bbf662f (diff) | |
download | bcm5719-llvm-244891d1290f7387c996bdeec0fc5846576f3f42.tar.gz bcm5719-llvm-244891d1290f7387c996bdeec0fc5846576f3f42.zip |
AMDGPU/SI: Add a MachineMemOperand to MIMG instructions
Summary:
Without a MachineMemOperand, the scheduler was assuming MIMG instructions
were ordered memory references, so no loads or stores could be reordered
across them.
Reviewers: arsenm
Subscribers: arsenm, kzhuravl, wdng, nhaehnle, yaxunl, tony-tye
Differential Revision: https://reviews.llvm.org/D27536
llvm-svn: 290179
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r-- | llvm/lib/Target/AMDGPU/MIMGInstructions.td | 1 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 30 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h | 31 |
4 files changed, 57 insertions, 6 deletions
diff --git a/llvm/lib/Target/AMDGPU/MIMGInstructions.td b/llvm/lib/Target/AMDGPU/MIMGInstructions.td index 7b654425eda..46803e55571 100644 --- a/llvm/lib/Target/AMDGPU/MIMGInstructions.td +++ b/llvm/lib/Target/AMDGPU/MIMGInstructions.td @@ -25,6 +25,7 @@ class MIMG_Helper <dag outs, dag ins, string asm, let DecoderNamespace = dns; let isAsmParserOnly = !if(!eq(dns,""), 1, 0); let AsmMatchConverter = "cvtMIMG"; + let usesCustomInserter = 1; } class MIMG_NoSampler_Helper <bits<7> op, string asm, diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp index bfc67c9542b..82788ccecdd 100644 --- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -1697,9 +1697,32 @@ static MachineBasicBlock *emitIndirectDst(MachineInstr &MI, MachineBasicBlock *SITargetLowering::EmitInstrWithCustomInserter( MachineInstr &MI, MachineBasicBlock *BB) const { + + const SIInstrInfo *TII = getSubtarget()->getInstrInfo(); + MachineFunction *MF = BB->getParent(); + SIMachineFunctionInfo *MFI = MF->getInfo<SIMachineFunctionInfo>(); + + if (TII->isMIMG(MI)) { + if (!MI.memoperands_empty()) + return BB; + // Add a memoperand for mimg instructions so that they aren't assumed to + // be ordered memory instuctions. + + MachinePointerInfo PtrInfo(MFI->getImagePSV()); + MachineMemOperand::Flags Flags = MachineMemOperand::MODereferenceable; + if (MI.mayStore()) + Flags |= MachineMemOperand::MOStore; + + if (MI.mayLoad()) + Flags |= MachineMemOperand::MOLoad; + + auto MMO = MF->getMachineMemOperand(PtrInfo, Flags, 0, 0); + MI.addMemOperand(*MF, MMO); + return BB; + } + switch (MI.getOpcode()) { case AMDGPU::SI_INIT_M0: { - const SIInstrInfo *TII = getSubtarget()->getInstrInfo(); BuildMI(*BB, MI.getIterator(), MI.getDebugLoc(), TII->get(AMDGPU::S_MOV_B32), AMDGPU::M0) .addOperand(MI.getOperand(0)); @@ -1707,10 +1730,6 @@ MachineBasicBlock *SITargetLowering::EmitInstrWithCustomInserter( return BB; } case AMDGPU::GET_GROUPSTATICSIZE: { - const SIInstrInfo *TII = getSubtarget()->getInstrInfo(); - - MachineFunction *MF = BB->getParent(); - SIMachineFunctionInfo *MFI = MF->getInfo<SIMachineFunctionInfo>(); DebugLoc DL = MI.getDebugLoc(); BuildMI(*BB, MI, DL, TII->get(AMDGPU::S_MOV_B32)) .addOperand(MI.getOperand(0)) @@ -1734,7 +1753,6 @@ MachineBasicBlock *SITargetLowering::EmitInstrWithCustomInserter( return splitKillBlock(MI, BB); case AMDGPU::V_CNDMASK_B64_PSEUDO: { MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); - const SIInstrInfo *TII = getSubtarget()->getInstrInfo(); unsigned Dst = MI.getOperand(0).getReg(); unsigned Src0 = MI.getOperand(1).getReg(); diff --git a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp index e911817c451..8b511d4677b 100644 --- a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp @@ -52,6 +52,7 @@ SIMachineFunctionInfo::SIMachineFunctionInfo(const MachineFunction &MF) WavesPerEU(0, 0), DebuggerWorkGroupIDStackObjectIndices({{0, 0, 0}}), DebuggerWorkItemIDStackObjectIndices({{0, 0, 0}}), + ImagePSV(llvm::make_unique<AMDGPUImagePseudoSourceValue>()), LDSWaveSpillSize(0), PSInputEna(0), NumUserSGPRs(0), diff --git a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h index 7edac8950ec..0b92198f20a 100644 --- a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h +++ b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h @@ -23,6 +23,31 @@ namespace llvm { class MachineRegisterInfo; +class AMDGPUImagePseudoSourceValue : public PseudoSourceValue { +public: + explicit AMDGPUImagePseudoSourceValue() : + PseudoSourceValue(PseudoSourceValue::TargetCustom) { } + + bool isConstant(const MachineFrameInfo *) const override { + // This should probably be true for most images, but we will start by being + // conservative. + return false; + } + + bool isAliased(const MachineFrameInfo *) const override { + // FIXME: If we ever change image intrinsics to accept fat pointers, then + // this could be true for some cases. + return false; + } + + bool mayAlias(const MachineFrameInfo*) const override { + // FIXME: If we ever change image intrinsics to accept fat pointers, then + // this could be true for some cases. + return false; + } +}; + + /// This class keeps track of the SPI_SP_INPUT_ADDR config register, which /// tells the hardware which interpolation parameters to load. class SIMachineFunctionInfo final : public AMDGPUMachineFunction { @@ -73,6 +98,8 @@ class SIMachineFunctionInfo final : public AMDGPUMachineFunction { // Stack object indices for work item IDs. std::array<int, 3> DebuggerWorkItemIDStackObjectIndices; + std::unique_ptr<AMDGPUImagePseudoSourceValue> ImagePSV; + public: // FIXME: Make private unsigned LDSWaveSpillSize; @@ -434,6 +461,10 @@ public: } llvm_unreachable("unexpected dimension"); } + + AMDGPUImagePseudoSourceValue *getImagePSV() { + return ImagePSV.get(); + } }; } // End namespace llvm |