-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[SPIRV] support for extension SPV_INTEL_maximum_registers #137229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0d2015b
187a8d9
25b8fe1
92bd0f1
9f46ca5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,9 @@ class SPIRVAsmPrinter : public AsmPrinter { | |
void outputExecutionModeFromNumthreadsAttribute( | ||
const MCRegister &Reg, const Attribute &Attr, | ||
SPIRV::ExecutionMode::ExecutionMode EM); | ||
void outputExecutionModeFromRegisterAllocMode(const MCRegister &Reg, | ||
const MDNode *Node, | ||
MachineFunction *MF); | ||
void outputExecutionMode(const Module &M); | ||
void outputAnnotations(const Module &M); | ||
void outputModuleSections(); | ||
|
@@ -492,6 +495,45 @@ void SPIRVAsmPrinter::outputExecutionModeFromNumthreadsAttribute( | |
outputMCInst(Inst); | ||
} | ||
|
||
// outputs the execution mode for the extension SPV_INTEL_maximum_registers | ||
void SPIRVAsmPrinter::outputExecutionModeFromRegisterAllocMode( | ||
const MCRegister &Reg, const MDNode *Node, MachineFunction *MF) { | ||
MCInst Inst; | ||
auto *RegisterAllocMode = Node->getOperand(0).get(); | ||
Inst.setOpcode(SPIRV::OpExecutionMode); | ||
Inst.addOperand(MCOperand::createReg(Reg)); | ||
|
||
if (auto *MDS = dyn_cast<MDString>(RegisterAllocMode)) { | ||
StringRef Str = MDS->getString(); | ||
if (Str.equals_insensitive("AutoINTEL")) { | ||
Inst.addOperand(MCOperand::createImm(static_cast<unsigned>( | ||
SPIRV::ExecutionMode::NamedMaximumRegistersINTEL))); | ||
Inst.addOperand(MCOperand::createImm(static_cast<unsigned>( | ||
SPIRV::NamedMaximumNumberOfRegisters::AutoINTEL))); | ||
} | ||
} else if (MDNode *NestedNode = dyn_cast<MDNode>(RegisterAllocMode)) { | ||
if (auto *CMD = dyn_cast<ConstantAsMetadata>(NestedNode->getOperand(0))) { | ||
if (ConstantInt *CI = dyn_cast<ConstantInt>(CMD->getValue())) { | ||
Inst.setOpcode(SPIRV::OpExecutionModeId); | ||
Inst.addOperand(MCOperand::createImm( | ||
SPIRV::ExecutionMode::MaximumRegistersIdINTEL)); | ||
auto *GR = ST->getSPIRVGlobalRegistry(); | ||
Register MaxOpConstantReg = GR->getMaxRegConstantExtMap(MF); | ||
MCRegister MaxRegister = MAI->getRegisterAlias(MF, MaxOpConstantReg); | ||
Inst.addOperand(MCOperand::createReg(MaxRegister)); | ||
} | ||
} | ||
} else { | ||
|
||
int64_t RegisterAllocVal = | ||
mdconst::dyn_extract<ConstantInt>(RegisterAllocMode)->getZExtValue(); | ||
Inst.addOperand( | ||
MCOperand::createImm(SPIRV::ExecutionMode::MaximumRegistersINTEL)); | ||
Inst.addOperand(MCOperand::createImm(RegisterAllocVal)); | ||
} | ||
outputMCInst(Inst); | ||
} | ||
|
||
void SPIRVAsmPrinter::outputExecutionMode(const Module &M) { | ||
NamedMDNode *Node = M.getNamedMetadata("spirv.ExecutionMode"); | ||
if (Node) { | ||
|
@@ -532,6 +574,10 @@ void SPIRVAsmPrinter::outputExecutionMode(const Module &M) { | |
Inst.addOperand(MCOperand::createImm(TypeCode)); | ||
outputMCInst(Inst); | ||
} | ||
if (MDNode *Node = F.getMetadata("RegisterAllocMode")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest not to rely on internal to internal https://github.com/intel/llvm metadata. Instead lets use !spirv.ExecutionMode metadata, see https://github.com/KhronosGroup/SPIRV-LLVM-Translator/blob/main/docs/SPIRVRepresentationInLLVM.rst as 'SPIR-V friendly LLVM IR' is also used in SPIR-V backend. |
||
MachineFunction *MF = MMI->getMachineFunction(F); | ||
outputExecutionModeFromRegisterAllocMode(FReg, Node, MF); | ||
} | ||
if (ST->isOpenCLEnv() && !M.getNamedMetadata("spirv.ExecutionMode") && | ||
!M.getNamedMetadata("opencl.enable.FP_CONTRACT")) { | ||
MCInst Inst; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Please fix the formatting issues.