-
Notifications
You must be signed in to change notification settings - Fork 41
[AIEX] Unified Opcodes across Subtargets #766
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
Draft
F-Stuckmann
wants to merge
3
commits into
aie-public
Choose a base branch
from
stuckmann.unified.opcodes
base: aie-public
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.
Draft
Changes from 1 commit
Commits
Show all changes
3 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,83 @@ | ||
| //===-- AIEBaseTarget.td - Shared AIE target definition ----*- tablegen -*-===// | ||
| // | ||
| // This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| // (c) Copyright 2026 Advanced Micro Devices, Inc. or its affiliates | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Shared TableGen compilation for the canonical AIE:: opcode namespace. | ||
| // All architecture-specific AIE targets are expected to produce identical | ||
| // enum values for: | ||
| // 1. LLVM generic opcodes from TargetOpcodes.def | ||
| // 2. AIE generic opcodes from AIEInstrGISel.td | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| include "llvm/Target/Target.td" | ||
| include "llvm/Target/AIETarget.td" | ||
| include "llvm/Target/CodeGenFormat.td" | ||
|
|
||
| // Minimal register definition required by the gen-instr-info backend. | ||
| // Only enum values from this compilation are consumed. | ||
| def AIEBaseTargetReg : Register<"r0">; | ||
| def AIEBaseTargetGPR | ||
| : RegisterClass<"AIE", [i32], 32, (add AIEBaseTargetReg)>; | ||
|
|
||
| class AIEGenericInstruction : GenericInstruction { | ||
| let Namespace = "AIEBase"; | ||
| } | ||
| include "AIEInstrGISel.td" | ||
|
|
||
| // Shared pseudo instructions present in all AIE targets. | ||
| // Must be defined here so AIEBase enum values match the subtargets. | ||
| let Namespace = "AIEBase", isPseudo = true, isCodeGenOnly = true in { | ||
| def ADJCALLSTACKDOWN : Instruction { | ||
| let hasSideEffects = false; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| let OutOperandList = (outs); | ||
| let InOperandList = (ins i32imm:$amt1, i32imm:$amt2); | ||
| let AsmString = ""; | ||
| let Pattern = []; | ||
| } | ||
| def ADJCALLSTACKUP : Instruction { | ||
| let hasSideEffects = false; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| let OutOperandList = (outs); | ||
| let InOperandList = (ins i32imm:$amt1, i32imm:$amt2); | ||
| let AsmString = ""; | ||
| let Pattern = []; | ||
| } | ||
| def CYCLE_SEPARATOR : Instruction { | ||
| let hasSideEffects = false; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| let OutOperandList = (outs); | ||
| let InOperandList = (ins); | ||
| let AsmString = ""; | ||
| let Pattern = []; | ||
| let isMeta = true; | ||
| } | ||
| def DelayedSchedBarrier : Instruction { | ||
| let hasSideEffects = false; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| let OutOperandList = (outs); | ||
| let InOperandList = (ins); | ||
| let AsmString = ""; | ||
| let Pattern = []; | ||
| let isMeta = true; | ||
| } | ||
| } | ||
|
|
||
| def AIEBaseTargetInstrInfo : InstrInfo { | ||
| let guessInstructionProperties = 0; | ||
| } | ||
|
|
||
| def AIEBaseTarget : Target { | ||
| let InstructionSet = AIEBaseTargetInstrInfo; | ||
| } |
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,22 @@ | ||
| //===-- AIEBaseTargetOpcodes.h - Shared opcode namespace -----*- C++ -*-===// | ||
| // | ||
| // This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| // (c) Copyright 2026 Advanced Micro Devices, Inc. or its affiliates | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Exposes the canonical AIE:: namespace enum values produced by | ||
| // AIEBaseTarget.td. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIB_TARGET_AIE_AIEBASETARGETOPCODES_H | ||
| #define LLVM_LIB_TARGET_AIE_AIEBASETARGETOPCODES_H | ||
|
|
||
| #define GET_INSTRINFO_ENUM | ||
| #include "AIEBaseTargetGenInstrInfo.inc" | ||
|
|
||
| #endif // LLVM_LIB_TARGET_AIE_AIEBASETARGETOPCODES_H |
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,53 @@ | ||
| //===-- AIEGenericOpcode.h - Cross-target opcode parity --------*- C++ -*-===// | ||
| // | ||
| // This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| // (c) Copyright 2026 Advanced Micro Devices, Inc. or its affiliates | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Always-on opcode parity validation between AIEBaseTarget and each AIE | ||
| // subtarget. Provides the AIE_CHECK_OPCODE_ macro used by each target's | ||
| // InstrInfo constructor to verify enum value equality. | ||
| // | ||
| // Usage in each target's InstrInfo.cpp: | ||
| // | ||
| // #include "AIEGenericOpcode.h" | ||
| // | ||
| // namespace { | ||
| // void verifyOpcodeParity() { | ||
| // #define HANDLE_TARGET_OPCODE(OPC) \ | ||
| // AIE_CHECK_OPCODE_(AIEBase, MyTargetNS, OPC) | ||
| // #define HANDLE_TARGET_OPCODE_MARKER(IDENT, OPC) | ||
| // #include "llvm/Support/TargetOpcodes.def" | ||
| // | ||
| // #define AIE_GENERIC_OPCODE(OPC) \ | ||
| // AIE_CHECK_OPCODE_(AIEBase, MyTargetNS, OPC) | ||
| // #include "AIEGenericOpcodeList.def" | ||
| // } | ||
| // } // anonymous namespace | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIB_TARGET_AIE_AIEGENERICOPCODE_H | ||
| #define LLVM_LIB_TARGET_AIE_AIEGENERICOPCODE_H | ||
|
|
||
| #include "AIEBaseTargetOpcodes.h" | ||
| #include "llvm/ADT/Twine.h" | ||
| #include "llvm/Support/ErrorHandling.h" | ||
|
|
||
| /// Check a single opcode for parity between BASE_NS and TARGET_NS. | ||
| /// Hard-fails via report_fatal_error on mismatch in all build modes. | ||
| #define AIE_CHECK_OPCODE_(BASE_NS, TARGET_NS, OPC) \ | ||
| if (static_cast<unsigned>(BASE_NS::OPC) != \ | ||
| static_cast<unsigned>(TARGET_NS::OPC)) \ | ||
| llvm::report_fatal_error( \ | ||
| llvm::Twine("opcode parity mismatch: " #BASE_NS "::" #OPC " (") + \ | ||
| llvm::Twine(static_cast<unsigned>(BASE_NS::OPC)) + \ | ||
| ") != " #TARGET_NS "::" #OPC " (" + \ | ||
| llvm::Twine(static_cast<unsigned>(TARGET_NS::OPC)) + ")", \ | ||
| /*gen_crash_diag=*/false); | ||
|
|
||
| #endif // LLVM_LIB_TARGET_AIE_AIEGENERICOPCODE_H |
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,48 @@ | ||
| //===-- AIEGenericOpcodeList.def ----------------------------------------===// | ||
| // | ||
| // This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| // (c) Copyright 2026 Advanced Micro Devices, Inc. or its affiliates | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // List of AIE generic opcodes from AIEInstrGISel.td. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef AIE_GENERIC_OPCODE | ||
| #define AIE_GENERIC_OPCODE(OPC) | ||
| #endif | ||
|
|
||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_LOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_ZEXTLOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_SEXTLOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_OFFSET_LOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_OFFSET_ZEXTLOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_OFFSET_SEXTLOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_2D_LOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_2D_ZEXTLOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_2D_SEXTLOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_3D_LOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_3D_ZEXTLOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_3D_SEXTLOAD) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_STORE) | ||
| AIE_GENERIC_OPCODE(G_AIE_OFFSET_STORE) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_2D_STORE) | ||
| AIE_GENERIC_OPCODE(G_AIE_POSTINC_3D_STORE) | ||
| AIE_GENERIC_OPCODE(G_AIE_ZEXT_EXTRACT_VECTOR_ELT) | ||
| AIE_GENERIC_OPCODE(G_AIE_SEXT_EXTRACT_VECTOR_ELT) | ||
| AIE_GENERIC_OPCODE(G_AIE_INSERT_VECTOR_ELT) | ||
| AIE_GENERIC_OPCODE(G_AIE_ADD_VECTOR_ELT_HI) | ||
| AIE_GENERIC_OPCODE(G_AIE_BROADCAST_VECTOR) | ||
| AIE_GENERIC_OPCODE(G_AIE_PAD_VECTOR_UNDEF) | ||
| AIE_GENERIC_OPCODE(G_AIE_UNPAD_VECTOR) | ||
| AIE_GENERIC_OPCODE(G_AIE_VSEL) | ||
| AIE_GENERIC_OPCODE(G_AIE_VSHIFT_RIGHT) | ||
| AIE_GENERIC_OPCODE(G_AIE_EXTRACT_SUBVECTOR) | ||
| AIE_GENERIC_OPCODE(G_AIE_SHUFFLE_VECTOR) | ||
| AIE_GENERIC_OPCODE(G_AIE_VECTOR_ICMP) | ||
|
|
||
| #undef AIE_GENERIC_OPCODE |
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 |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| //===-- AIESharedPseudos.td - Shared pseudo instructions ---*- tablegen -*-===// | ||
| // | ||
| // This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| // (c) Copyright 2026 Advanced Micro Devices, Inc. or its affiliates | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Shared pseudo instruction classes for instructions that exist with the same | ||
| // name across AIE targets. These classes share the same name across AIE targets to be in | ||
| // Layer 2 of the enum layout, guaranteeing identical enum values across all | ||
| // target compilations. | ||
| // | ||
| // This file must be included AFTER the target's InstrFormats.td, so that | ||
| // `Pseudo` resolves to the target-specific class (e.g., AIE2Inst or AIE2PInst | ||
| // based). | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // Base class for all shared pseudos. Provides a base class for shared pseudo instructions in | ||
| // enum placement in Layer 2. | ||
| class AIESharedPseudo<dag outs, dag ins, string opcodestr = "", | ||
| string argstr = ""> | ||
| : Pseudo<outs, ins, opcodestr, argstr> { | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Identical across targets (no parameters needed) | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class AIEDelayedSchedBarrier : AIESharedPseudo<(outs), (ins)> { | ||
| let isMeta = true; | ||
| let hasSideEffects = false; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| } | ||
|
|
||
| class AIECycleSeparator : AIESharedPseudo<(outs), (ins)> { | ||
| let isMeta = true; | ||
| let hasSideEffects = false; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| } | ||
|
|
||
| class AIELoopDec | ||
| : AIESharedPseudo<(outs eR:$dst), (ins eR:$src), | ||
| "loop_dec", "${dst}, ${src}"> { | ||
| let hasSideEffects = false; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| let Defs = [srCarry]; | ||
| } | ||
|
|
||
| class AIELoopJNZ | ||
| : AIESharedPseudo<(outs), (ins eR:$tc, eP:$target), | ||
| "loop_jnz", "${tc}, ${target}"> { | ||
| let hasSideEffects = false; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| let isBranch = true; | ||
| let isIndirectBranch = true; | ||
| let isTerminator = true; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Parameterized (operand types differ per target) | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class AIELoopStart<Operand adj_type> | ||
| : AIESharedPseudo<(outs), (ins eR:$src, adj_type:$adj), | ||
| "loop_start", "${src}, ${adj}"> { | ||
| let hasSideEffects = true; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| let isNotDuplicable = true; | ||
| } | ||
|
|
||
| class AIEPseudoLoopEnd<Operand addr_type> | ||
| : AIESharedPseudo<(outs), (ins addr_type:$lastInstr, addr_type:$target), | ||
| "pseudo_loop_end", "${lastInstr}, ${target}"> { | ||
| let hasSideEffects = true; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| let isNotDuplicable = true; | ||
| let isBranch = true; | ||
| let isTerminator = true; | ||
| let isMeta = true; | ||
| } | ||
|
|
||
| class AIEAdjCallStackDown<Register sp_reg> | ||
| : AIESharedPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2)> { | ||
| let hasSideEffects = false; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| let Defs = [sp_reg]; | ||
| let Uses = [sp_reg]; | ||
| } | ||
|
|
||
| class AIEAdjCallStackUp<Register sp_reg> | ||
| : AIESharedPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2)> { | ||
| let hasSideEffects = false; | ||
| let mayLoad = false; | ||
| let mayStore = false; | ||
| let Defs = [sp_reg]; | ||
| let Uses = [sp_reg]; | ||
| } |
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.
Maybe move this to the next commit? Keep this as an aligning opcodes between targets commit and then in the next one add the checks that enforce this.