- Notifications
You must be signed in to change notification settings - Fork 15.3k
[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
Open
VishMCW wants to merge 5 commits into llvm:main Choose a base branch from VishMCW:extension_max_reg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits Select commit Hold shift + click to select a range
0d2015b FEAT:
VishMCW 187a8d9 formatting and documentation
VishMCW 25b8fe1 Merge branch 'main' into extension_max_reg
VishMCW 92bd0f1 Merge branch 'main' into extension_max_reg
VishMCW 9f46ca5 Merge branch 'main' into extension_max_reg
michalpaszkowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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")) { | ||
| Contributor 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; | ||
| | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.