Index: llvm/include/llvm/CodeGen/MachineMemOperand.h =================================================================== --- llvm/include/llvm/CodeGen/MachineMemOperand.h +++ llvm/include/llvm/CodeGen/MachineMemOperand.h @@ -31,6 +31,7 @@ class raw_ostream; class MachineFunction; class ModuleSlotTracker; +class TargetInstrInfo; /// This class contains a discriminated union of information about pointers in /// memory operands, relating them back to LLVM IR or to virtual locations (such Index: llvm/include/llvm/CodeGen/PseudoSourceValue.h =================================================================== --- llvm/include/llvm/CodeGen/PseudoSourceValue.h +++ llvm/include/llvm/CodeGen/PseudoSourceValue.h @@ -25,7 +25,7 @@ class MIRFormatter; class PseudoSourceValue; class raw_ostream; -class TargetInstrInfo; +class TargetMachine; raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV); @@ -59,7 +59,7 @@ virtual void printCustom(raw_ostream &O) const; public: - explicit PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII); + explicit PseudoSourceValue(unsigned Kind, const TargetMachine &TM); virtual ~PseudoSourceValue(); @@ -95,8 +95,8 @@ const int FI; public: - explicit FixedStackPseudoSourceValue(int FI, const TargetInstrInfo &TII) - : PseudoSourceValue(FixedStack, TII), FI(FI) {} + explicit FixedStackPseudoSourceValue(int FI, const TargetMachine &TM) + : PseudoSourceValue(FixedStack, TM), FI(FI) {} static bool classof(const PseudoSourceValue *V) { return V->kind() == FixedStack; @@ -115,7 +115,7 @@ class CallEntryPseudoSourceValue : public PseudoSourceValue { protected: - CallEntryPseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII); + CallEntryPseudoSourceValue(unsigned Kind, const TargetMachine &TM); public: bool isConstant(const MachineFrameInfo *) const override; @@ -128,8 +128,7 @@ const GlobalValue *GV; public: - GlobalValuePseudoSourceValue(const GlobalValue *GV, - const TargetInstrInfo &TII); + GlobalValuePseudoSourceValue(const GlobalValue *GV, const TargetMachine &TM); static bool classof(const PseudoSourceValue *V) { return V->kind() == GlobalValueCallEntry; @@ -143,7 +142,7 @@ const char *ES; public: - ExternalSymbolPseudoSourceValue(const char *ES, const TargetInstrInfo &TII); + ExternalSymbolPseudoSourceValue(const char *ES, const TargetMachine &TM); static bool classof(const PseudoSourceValue *V) { return V->kind() == ExternalSymbolCallEntry; @@ -154,7 +153,7 @@ /// Manages creation of pseudo source values. class PseudoSourceValueManager { - const TargetInstrInfo &TII; + const TargetMachine &TM; const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV; std::map> FSValues; StringMap> @@ -164,7 +163,7 @@ GlobalCallEntries; public: - PseudoSourceValueManager(const TargetInstrInfo &TII); + PseudoSourceValueManager(const TargetMachine &TM); /// Return a pseudo source value referencing the area below the stack frame of /// a function, e.g., the argument space. Index: llvm/include/llvm/CodeGen/TargetInstrInfo.h =================================================================== --- llvm/include/llvm/CodeGen/TargetInstrInfo.h +++ llvm/include/llvm/CodeGen/TargetInstrInfo.h @@ -1283,13 +1283,6 @@ } public: - /// getAddressSpaceForPseudoSourceKind - Given the kind of memory - /// (e.g. stack) the target returns the corresponding address space. - virtual unsigned - getAddressSpaceForPseudoSourceKind(unsigned Kind) const { - return 0; - } - /// unfoldMemoryOperand - Separate a single instruction which folded a load or /// a store or a load and a store into two or more instruction. If this is /// possible, returns true as well as the new instructions by reference. Index: llvm/include/llvm/Target/TargetMachine.h =================================================================== --- llvm/include/llvm/Target/TargetMachine.h +++ llvm/include/llvm/Target/TargetMachine.h @@ -397,6 +397,12 @@ virtual unsigned getSjLjDataSize() const { return DefaultSjLjDataSize; } static std::pair parseBinutilsVersion(StringRef Version); + + /// getAddressSpaceForPseudoSourceKind - Given the kind of memory + /// (e.g. stack) the target returns the corresponding address space. + virtual unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const { + return 0; + } }; /// This class describes a target machine that is implemented with the LLVM Index: llvm/lib/CodeGen/MachineFunction.cpp =================================================================== --- llvm/lib/CodeGen/MachineFunction.cpp +++ llvm/lib/CodeGen/MachineFunction.cpp @@ -229,9 +229,7 @@ "Can't create a MachineFunction using a Module with a " "Target-incompatible DataLayout attached\n"); - PSVManager = - std::make_unique(*(getSubtarget(). - getInstrInfo())); + PSVManager = std::make_unique(getTarget()); } MachineFunction::~MachineFunction() { Index: llvm/lib/CodeGen/PseudoSourceValue.cpp =================================================================== --- llvm/lib/CodeGen/PseudoSourceValue.cpp +++ llvm/lib/CodeGen/PseudoSourceValue.cpp @@ -12,18 +12,19 @@ #include "llvm/CodeGen/PseudoSourceValue.h" #include "llvm/CodeGen/MachineFrameInfo.h" -#include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetMachine.h" + using namespace llvm; static const char *const PSVNames[] = { "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack", "GlobalValueCallEntry", "ExternalSymbolCallEntry"}; -PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII) +PseudoSourceValue::PseudoSourceValue(unsigned Kind, const TargetMachine &TM) : Kind(Kind) { - AddressSpace = TII.getAddressSpaceForPseudoSourceKind(Kind); + AddressSpace = TM.getAddressSpaceForPseudoSourceKind(Kind); } PseudoSourceValue::~PseudoSourceValue() = default; @@ -75,9 +76,9 @@ OS << "FixedStack" << FI; } -CallEntryPseudoSourceValue::CallEntryPseudoSourceValue( - unsigned Kind, const TargetInstrInfo &TII) - : PseudoSourceValue(Kind, TII) {} +CallEntryPseudoSourceValue::CallEntryPseudoSourceValue(unsigned Kind, + const TargetMachine &TM) + : PseudoSourceValue(Kind, TM) {} bool CallEntryPseudoSourceValue::isConstant(const MachineFrameInfo *) const { return false; @@ -92,20 +93,17 @@ } GlobalValuePseudoSourceValue::GlobalValuePseudoSourceValue( - const GlobalValue *GV, - const TargetInstrInfo &TII) - : CallEntryPseudoSourceValue(GlobalValueCallEntry, TII), GV(GV) {} + const GlobalValue *GV, const TargetMachine &TM) + : CallEntryPseudoSourceValue(GlobalValueCallEntry, TM), GV(GV) {} ExternalSymbolPseudoSourceValue::ExternalSymbolPseudoSourceValue( - const char *ES, const TargetInstrInfo &TII) - : CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TII), ES(ES) {} + const char *ES, const TargetMachine &TM) + : CallEntryPseudoSourceValue(ExternalSymbolCallEntry, TM), ES(ES) {} -PseudoSourceValueManager::PseudoSourceValueManager( - const TargetInstrInfo &TIInfo) - : TII(TIInfo), - StackPSV(PseudoSourceValue::Stack, TII), - GOTPSV(PseudoSourceValue::GOT, TII), - JumpTablePSV(PseudoSourceValue::JumpTable, TII), - ConstantPoolPSV(PseudoSourceValue::ConstantPool, TII) {} +PseudoSourceValueManager::PseudoSourceValueManager(const TargetMachine &TMInfo) + : TM(TMInfo), StackPSV(PseudoSourceValue::Stack, TM), + GOTPSV(PseudoSourceValue::GOT, TM), + JumpTablePSV(PseudoSourceValue::JumpTable, TM), + ConstantPoolPSV(PseudoSourceValue::ConstantPool, TM) {} const PseudoSourceValue *PseudoSourceValueManager::getStack() { return &StackPSV; @@ -125,7 +123,7 @@ PseudoSourceValueManager::getFixedStack(int FI) { std::unique_ptr &V = FSValues[FI]; if (!V) - V = std::make_unique(FI, TII); + V = std::make_unique(FI, TM); return V.get(); } @@ -134,7 +132,7 @@ std::unique_ptr &E = GlobalCallEntries[GV]; if (!E) - E = std::make_unique(GV, TII); + E = std::make_unique(GV, TM); return E.get(); } @@ -143,6 +141,6 @@ std::unique_ptr &E = ExternalCallEntries[ES]; if (!E) - E = std::make_unique(ES, TII); + E = std::make_unique(ES, TM); return E.get(); } Index: llvm/lib/Target/AMDGPU/AMDGPUMIRFormatter.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUMIRFormatter.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUMIRFormatter.cpp @@ -21,17 +21,18 @@ StringRef Src, MachineFunction &MF, PerFunctionMIParsingState &PFS, const PseudoSourceValue *&PSV, ErrorCallbackType ErrorCallback) const { SIMachineFunctionInfo *MFI = MF.getInfo(); - const SIInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); + const AMDGPUTargetMachine &TM = + static_cast(MF.getTarget()); if (Src == "BufferResource") { - PSV = MFI->getBufferPSV(TII); + PSV = MFI->getBufferPSV(TM); return false; } if (Src == "ImageResource") { - PSV = MFI->getImagePSV(TII); + PSV = MFI->getImagePSV(TM); return false; } if (Src == "GWSResource") { - PSV = MFI->getGWSPSV(TII); + PSV = MFI->getGWSPSV(TM); return false; } llvm_unreachable("unknown MIR custom pseudo source value"); Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h +++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h @@ -64,6 +64,8 @@ std::pair getPredicatedAddrSpace(const Value *V) const override; + + unsigned getAddressSpaceForPseudoSourceKind(unsigned Kind) const override; }; //===----------------------------------------------------------------------===// Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -802,6 +802,23 @@ return std::make_pair(nullptr, -1); } +unsigned +AMDGPUTargetMachine::getAddressSpaceForPseudoSourceKind(unsigned Kind) const { + switch (Kind) { + case PseudoSourceValue::Stack: + case PseudoSourceValue::FixedStack: + return AMDGPUAS::PRIVATE_ADDRESS; + case PseudoSourceValue::ConstantPool: + case PseudoSourceValue::GOT: + case PseudoSourceValue::JumpTable: + case PseudoSourceValue::GlobalValueCallEntry: + case PseudoSourceValue::ExternalSymbolCallEntry: + case PseudoSourceValue::TargetCustom: + return AMDGPUAS::CONSTANT_ADDRESS; + } + return AMDGPUAS::FLAT_ADDRESS; +} + //===----------------------------------------------------------------------===// // GCN Target Machine (SI+) //===----------------------------------------------------------------------===// Index: llvm/lib/Target/AMDGPU/R600InstrInfo.h =================================================================== --- llvm/lib/Target/AMDGPU/R600InstrInfo.h +++ llvm/lib/Target/AMDGPU/R600InstrInfo.h @@ -320,9 +320,6 @@ bool isRegisterLoad(const MachineInstr &MI) const { return get(MI.getOpcode()).TSFlags & R600InstrFlags::REGISTER_LOAD; } - - unsigned getAddressSpaceForPseudoSourceKind( - unsigned Kind) const override; }; namespace R600 { Index: llvm/lib/Target/AMDGPU/R600InstrInfo.cpp =================================================================== --- llvm/lib/Target/AMDGPU/R600InstrInfo.cpp +++ llvm/lib/Target/AMDGPU/R600InstrInfo.cpp @@ -1470,21 +1470,3 @@ FlagOp.setImm(InstFlags); } } - -unsigned R600InstrInfo::getAddressSpaceForPseudoSourceKind( - unsigned Kind) const { - switch (Kind) { - case PseudoSourceValue::Stack: - case PseudoSourceValue::FixedStack: - return AMDGPUAS::PRIVATE_ADDRESS; - case PseudoSourceValue::ConstantPool: - case PseudoSourceValue::GOT: - case PseudoSourceValue::JumpTable: - case PseudoSourceValue::GlobalValueCallEntry: - case PseudoSourceValue::ExternalSymbolCallEntry: - case PseudoSourceValue::TargetCustom: - return AMDGPUAS::CONSTANT_ADDRESS; - } - - llvm_unreachable("Invalid pseudo source kind"); -} Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp =================================================================== --- llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -1134,13 +1134,14 @@ SIMachineFunctionInfo *MFI = MF.getInfo(); + const GCNTargetMachine &TM = + static_cast(getTargetMachine()); + if (RsrcIntr->IsImage) { - Info.ptrVal = - MFI->getImagePSV(*MF.getSubtarget().getInstrInfo()); + Info.ptrVal = MFI->getImagePSV(TM); Info.align.reset(); } else { - Info.ptrVal = - MFI->getBufferPSV(*MF.getSubtarget().getInstrInfo()); + Info.ptrVal = MFI->getBufferPSV(TM); } Info.flags |= MachineMemOperand::MODereferenceable; @@ -1218,10 +1219,12 @@ case Intrinsic::amdgcn_buffer_atomic_fadd: { SIMachineFunctionInfo *MFI = MF.getInfo(); + const GCNTargetMachine &TM = + static_cast(getTargetMachine()); + Info.opc = ISD::INTRINSIC_W_CHAIN; Info.memVT = MVT::getVT(CI.getOperand(0)->getType()); - Info.ptrVal = - MFI->getBufferPSV(*MF.getSubtarget().getInstrInfo()); + Info.ptrVal = MFI->getBufferPSV(TM); Info.align.reset(); Info.flags |= MachineMemOperand::MOLoad | MachineMemOperand::MOStore; @@ -1259,8 +1262,11 @@ SIMachineFunctionInfo *MFI = MF.getInfo(); Info.opc = ISD::INTRINSIC_W_CHAIN; Info.memVT = MVT::getVT(CI.getType()); // XXX: what is correct VT? - Info.ptrVal = - MFI->getImagePSV(*MF.getSubtarget().getInstrInfo()); + + const GCNTargetMachine &TM = + static_cast(getTargetMachine()); + + Info.ptrVal = MFI->getImagePSV(TM); Info.align.reset(); Info.flags |= MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable; @@ -1292,9 +1298,11 @@ case Intrinsic::amdgcn_ds_gws_sema_release_all: { Info.opc = ISD::INTRINSIC_VOID; + const GCNTargetMachine &TM = + static_cast(getTargetMachine()); + SIMachineFunctionInfo *MFI = MF.getInfo(); - Info.ptrVal = - MFI->getGWSPSV(*MF.getSubtarget().getInstrInfo()); + Info.ptrVal = MFI->getGWSPSV(TM); // This is an abstract access, but we need to specify a type and size. Info.memVT = MVT::i32; Index: llvm/lib/Target/AMDGPU/SIInstrInfo.h =================================================================== --- llvm/lib/Target/AMDGPU/SIInstrInfo.h +++ llvm/lib/Target/AMDGPU/SIInstrInfo.h @@ -328,9 +328,6 @@ Register SrcReg2, int64_t CmpMask, int64_t CmpValue, const MachineRegisterInfo *MRI) const override; - unsigned getAddressSpaceForPseudoSourceKind( - unsigned Kind) const override; - bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override; Index: llvm/lib/Target/AMDGPU/SIInstrInfo.cpp =================================================================== --- llvm/lib/Target/AMDGPU/SIInstrInfo.cpp +++ llvm/lib/Target/AMDGPU/SIInstrInfo.cpp @@ -2882,23 +2882,6 @@ } } -unsigned SIInstrInfo::getAddressSpaceForPseudoSourceKind( - unsigned Kind) const { - switch(Kind) { - case PseudoSourceValue::Stack: - case PseudoSourceValue::FixedStack: - return AMDGPUAS::PRIVATE_ADDRESS; - case PseudoSourceValue::ConstantPool: - case PseudoSourceValue::GOT: - case PseudoSourceValue::JumpTable: - case PseudoSourceValue::GlobalValueCallEntry: - case PseudoSourceValue::ExternalSymbolCallEntry: - case PseudoSourceValue::TargetCustom: - return AMDGPUAS::CONSTANT_ADDRESS; - } - return AMDGPUAS::FLAT_ADDRESS; -} - static void removeModOperands(MachineInstr &MI) { unsigned Opc = MI.getOpcode(); int Src0ModIdx = AMDGPU::getNamedOperandIdx(Opc, Index: llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h =================================================================== --- llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h +++ llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h @@ -15,6 +15,7 @@ #include "AMDGPUArgumentUsageInfo.h" #include "AMDGPUMachineFunction.h" +#include "AMDGPUTargetMachine.h" #include "MCTargetDesc/AMDGPUMCTargetDesc.h" #include "SIInstrInfo.h" #include "llvm/ADT/MapVector.h" @@ -39,8 +40,8 @@ }; protected: - AMDGPUPseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII) - : PseudoSourceValue(Kind, TII) {} + AMDGPUPseudoSourceValue(unsigned Kind, const AMDGPUTargetMachine &TM) + : PseudoSourceValue(Kind, TM) {} public: bool isConstant(const MachineFrameInfo *) const override { @@ -60,8 +61,8 @@ class AMDGPUBufferPseudoSourceValue final : public AMDGPUPseudoSourceValue { public: - explicit AMDGPUBufferPseudoSourceValue(const TargetInstrInfo &TII) - : AMDGPUPseudoSourceValue(PSVBuffer, TII) {} + explicit AMDGPUBufferPseudoSourceValue(const AMDGPUTargetMachine &TM) + : AMDGPUPseudoSourceValue(PSVBuffer, TM) {} static bool classof(const PseudoSourceValue *V) { return V->kind() == PSVBuffer; @@ -73,8 +74,8 @@ class AMDGPUImagePseudoSourceValue final : public AMDGPUPseudoSourceValue { public: // TODO: Is the img rsrc useful? - explicit AMDGPUImagePseudoSourceValue(const TargetInstrInfo &TII) - : AMDGPUPseudoSourceValue(PSVImage, TII) {} + explicit AMDGPUImagePseudoSourceValue(const AMDGPUTargetMachine &TM) + : AMDGPUPseudoSourceValue(PSVImage, TM) {} static bool classof(const PseudoSourceValue *V) { return V->kind() == PSVImage; @@ -85,8 +86,8 @@ class AMDGPUGWSResourcePseudoSourceValue final : public AMDGPUPseudoSourceValue { public: - explicit AMDGPUGWSResourcePseudoSourceValue(const TargetInstrInfo &TII) - : AMDGPUPseudoSourceValue(GWSResource, TII) {} + explicit AMDGPUGWSResourcePseudoSourceValue(const AMDGPUTargetMachine &TM) + : AMDGPUPseudoSourceValue(GWSResource, TM) {} static bool classof(const PseudoSourceValue *V) { return V->kind() == GWSResource; @@ -929,24 +930,26 @@ llvm_unreachable("unexpected dimension"); } - const AMDGPUBufferPseudoSourceValue *getBufferPSV(const SIInstrInfo &TII) { + const AMDGPUBufferPseudoSourceValue * + getBufferPSV(const AMDGPUTargetMachine &TM) { if (!BufferPSV) - BufferPSV = std::make_unique(TII); + BufferPSV = std::make_unique(TM); return BufferPSV.get(); } - const AMDGPUImagePseudoSourceValue *getImagePSV(const SIInstrInfo &TII) { + const AMDGPUImagePseudoSourceValue * + getImagePSV(const AMDGPUTargetMachine &TM) { if (!ImagePSV) - ImagePSV = std::make_unique(TII); + ImagePSV = std::make_unique(TM); return ImagePSV.get(); } - const AMDGPUGWSResourcePseudoSourceValue *getGWSPSV(const SIInstrInfo &TII) { + const AMDGPUGWSResourcePseudoSourceValue * + getGWSPSV(const AMDGPUTargetMachine &TM) { if (!GWSResourcePSV) { - GWSResourcePSV = - std::make_unique(TII); + GWSResourcePSV = std::make_unique(TM); } return GWSResourcePSV.get(); Index: llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp =================================================================== --- llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp +++ llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp @@ -1429,8 +1429,8 @@ // Generate a misaligned load that is guaranteed to cause a crash. class CrashPseudoSourceValue : public PseudoSourceValue { public: - CrashPseudoSourceValue(const TargetInstrInfo &TII) - : PseudoSourceValue(TargetCustom, TII) {} + CrashPseudoSourceValue(const TargetMachine &TM) + : PseudoSourceValue(TargetCustom, TM) {} bool isConstant(const MachineFrameInfo *) const override { return false; @@ -1446,7 +1446,7 @@ } }; - static const CrashPseudoSourceValue CrashPSV(*this); + static const CrashPseudoSourceValue CrashPSV(MF.getTarget()); MachineMemOperand *MMO = MF.getMachineMemOperand( MachinePointerInfo(&CrashPSV), MachineMemOperand::MOLoad | MachineMemOperand::MOVolatile, 8,