-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[TableGen] Add support for DefaultMode in per-HwMode encode/decode. #83029
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
Merged
wangpc-pp
merged 2 commits into
llvm:main
from
nvjle:jle-support-defaultmode-for-perhw-encdec
Feb 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| // RUN: llvm-tblgen -gen-emitter -I %p/../../include %s | \ | ||
| // RUN: FileCheck %s --check-prefix=ENCODER | ||
| // RUN: llvm-tblgen -gen-disassembler -I %p/../../include %s | \ | ||
| // RUN: FileCheck %s --check-prefix=DECODER | ||
| // RUN: llvm-tblgen -gen-disassembler --suppress-per-hwmode-duplicates -I \ | ||
| // RUN: %p/../../include %s | FileCheck %s --check-prefix=DECODER-SUPPRESS | ||
|
|
||
| include "llvm/Target/Target.td" | ||
|
|
||
| def archInstrInfo : InstrInfo { } | ||
|
|
||
| def arch : Target { | ||
| let InstructionSet = archInstrInfo; | ||
| } | ||
|
|
||
| def Myi32 : Operand<i32> { | ||
| let DecoderMethod = "DecodeMyi32"; | ||
| } | ||
|
|
||
| def HasA : Predicate<"Subtarget->hasA()">; | ||
| def HasB : Predicate<"Subtarget->hasB()">; | ||
|
|
||
| def ModeA : HwMode<"+a", [HasA]>; | ||
| def ModeB : HwMode<"+b", [HasB]>; | ||
|
|
||
|
|
||
| def fooTypeEncDefault : InstructionEncoding { | ||
| let Size = 8; | ||
| field bits<64> SoftFail = 0; | ||
| bits<64> Inst; | ||
| bits<8> factor; | ||
| let Inst{7...0} = factor; | ||
| let Inst{3...2} = 0b10; | ||
| let Inst{1...0} = 0b00; | ||
| } | ||
|
|
||
| def fooTypeEncA : InstructionEncoding { | ||
| let Size = 4; | ||
| field bits<32> SoftFail = 0; | ||
| bits<32> Inst; | ||
| bits<8> factor; | ||
| let Inst{7...0} = factor; | ||
| let Inst{3...2} = 0b11; | ||
| let Inst{1...0} = 0b00; | ||
| } | ||
|
|
||
| def fooTypeEncB : InstructionEncoding { | ||
| let Size = 4; | ||
| field bits<32> SoftFail = 0; | ||
| bits<32> Inst; | ||
| bits<8> factor; | ||
| let Inst{15...8} = factor; | ||
| let Inst{1...0} = 0b11; | ||
| } | ||
|
|
||
| // Test for DefaultMode as a selector. | ||
| def foo : Instruction { | ||
| let OutOperandList = (outs); | ||
| let InOperandList = (ins i32imm:$factor); | ||
| let EncodingInfos = EncodingByHwMode< | ||
| [ModeA, ModeB, DefaultMode], [fooTypeEncA, fooTypeEncB, fooTypeEncDefault] | ||
| >; | ||
| let AsmString = "foo $factor"; | ||
| } | ||
|
|
||
| def bar: Instruction { | ||
| let OutOperandList = (outs); | ||
| let InOperandList = (ins i32imm:$factor); | ||
| let Size = 4; | ||
| bits<32> Inst; | ||
| bits<32> SoftFail; | ||
| bits<8> factor; | ||
| let Inst{31...24} = factor; | ||
| let Inst{1...0} = 0b10; | ||
| let AsmString = "bar $factor"; | ||
| } | ||
|
|
||
| def baz : Instruction { | ||
| let OutOperandList = (outs); | ||
| let InOperandList = (ins i32imm:$factor); | ||
| bits<32> Inst; | ||
| let EncodingInfos = EncodingByHwMode< | ||
| [ModeB], [fooTypeEncA] | ||
| >; | ||
| let AsmString = "foo $factor"; | ||
| } | ||
|
|
||
| def unrelated: Instruction { | ||
| let OutOperandList = (outs); | ||
| let DecoderNamespace = "Alt"; | ||
| let InOperandList = (ins i32imm:$factor); | ||
| let Size = 4; | ||
| bits<32> Inst; | ||
| bits<32> SoftFail; | ||
| bits<8> factor; | ||
| let Inst{31...24} = factor; | ||
| let Inst{1...0} = 0b10; | ||
| let AsmString = "unrelated $factor"; | ||
| } | ||
|
|
||
|
|
||
| // DECODER-LABEL: DecoderTableAlt_DefaultMode32[] = | ||
| // DECODER-DAG: Opcode: unrelated | ||
| // DECODER-LABEL: DecoderTableAlt_ModeA32[] = | ||
| // DECODER-DAG: Opcode: unrelated | ||
| // DECODER-LABEL: DecoderTableAlt_ModeB32[] = | ||
| // DECODER-DAG: Opcode: unrelated | ||
| // DECODER-LABEL: DecoderTable_DefaultMode32[] = | ||
| // DECODER-DAG: Opcode: bar | ||
| // DECODER-LABEL: DecoderTable_DefaultMode64[] = | ||
| // DECODER-DAG: Opcode: fooTypeEncDefault:foo | ||
| // DECODER-LABEL: DecoderTable_ModeA32[] = | ||
| // DECODER-DAG: Opcode: fooTypeEncA:foo | ||
| // DECODER-DAG: Opcode: bar | ||
| // DECODER-LABEL: DecoderTable_ModeB32[] = | ||
| // DECODER-DAG: Opcode: fooTypeEncB:foo | ||
| // DECODER-DAG: Opcode: fooTypeEncA:baz | ||
| // DECODER-DAG: Opcode: bar | ||
|
|
||
|
|
||
| // DECODER-SUPPRESS-LABEL: DecoderTableAlt_AllModes32[] = | ||
| // DECODER-SUPPRESS-DAG: Opcode: unrelated | ||
| // DECODER-SUPPRESS-LABEL: DecoderTable_AllModes32[] = | ||
| // DECODER-SUPPRESS-DAG: Opcode: bar | ||
| // DECODER-SUPPRESS-LABEL: DecoderTable_DefaultMode64[] = | ||
| // DECODER-SUPPRESS-NOT: Opcode: bar | ||
| // DECODER-SUPPRESS-DAG: Opcode: fooTypeEncDefault:foo | ||
| // DECODER-SUPPRESS-LABEL: DecoderTable_ModeA32[] = | ||
| // DECODER-SUPPRESS-DAG: Opcode: fooTypeEncA:foo | ||
| // DECODER-SUPPRESS-NOT: Opcode: bar | ||
| // DECODER-SUPPRESS-LABEL: DecoderTable_ModeB32[] = | ||
| // DECODER-SUPPRESS-DAG: Opcode: fooTypeEncB:foo | ||
| // DECODER-SUPPRESS-DAG: Opcode: fooTypeEncA:baz | ||
| // DECODER-SUPPRESS-NOT: Opcode: bar | ||
|
|
||
| // ENCODER-LABEL: static const uint64_t InstBits_DefaultMode[] = { | ||
| // ENCODER: UINT64_C(2), // bar | ||
| // ENCODER: UINT64_C(0), // baz | ||
| // ENCODER: UINT64_C(8), // foo | ||
| // ENCODER: UINT64_C(2), // unrelated | ||
|
|
||
| // ENCODER-LABEL: static const uint64_t InstBits_ModeA[] = { | ||
| // ENCODER: UINT64_C(2), // bar | ||
| // ENCODER: UINT64_C(0), // baz | ||
| // ENCODER: UINT64_C(12), // foo | ||
| // ENCODER: UINT64_C(2), // unrelated | ||
|
|
||
| // ENCODER-LABEL: static const uint64_t InstBits_ModeB[] = { | ||
| // ENCODER: UINT64_C(2), // bar | ||
| // ENCODER: UINT64_C(12), // baz | ||
| // ENCODER: UINT64_C(3), // foo | ||
| // ENCODER: UINT64_C(2), // unrelated | ||
|
|
||
| // ENCODER: unsigned HwMode = STI.getHwMode(); | ||
| // ENCODER: switch (HwMode) { | ||
| // ENCODER: default: llvm_unreachable("Unknown hardware mode!"); break; | ||
| // ENCODER: case 0: InstBits = InstBits_DefaultMode; break; | ||
| // ENCODER: case 1: InstBits = InstBits_ModeA; break; | ||
| // ENCODER: case 2: InstBits = InstBits_ModeB; break; | ||
| // ENCODER: }; | ||
|
|
||
| // ENCODER: case ::foo: { | ||
| // ENCODER: switch (HwMode) { | ||
| // ENCODER: default: llvm_unreachable("Unhandled HwMode"); | ||
| // ENCODER: case 0: { | ||
| // ENCODER: case 1: { | ||
| // ENCODER: case 2: { | ||
|
|
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
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.
Drop
const. It doesn't do anything since it's returning by value.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.
Done.
And could I again trouble you (I'll soon ask for write privs) to merge on my behalf?