-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
[AIEX] NFC: Refactor Alternate Descriptor codebase
1 parent
562ccea
commit 9f8a55f
Showing
6 changed files
with
87 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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,71 @@ | ||
//== AIEAlternateDescriptor.h - Define Alternate descriptor Class *-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 2024 Advanced Micro Devices, Inc. or its affiliates | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file declares the AIEngine Alternate instruction descriptor class | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_SUPPORT_AIEALTERNATEDESCRIPTOR_H | ||
#define LLVM_SUPPORT_AIEALTERNATEDESCRIPTOR_H | ||
|
||
#include "AIEBaseSubtarget.h" | ||
#include "MCTargetDesc/AIEMCFormats.h" | ||
|
||
#include <unordered_map> | ||
|
||
namespace llvm { | ||
|
||
using MIAltDescsMap = std::unordered_map<MachineInstr *, const MCInstrDesc *>; | ||
|
||
class AIEAlternateDescriptor { | ||
MIAltDescsMap AlternateDescs; | ||
|
||
public: | ||
AIEAlternateDescriptor() = default; | ||
~AIEAlternateDescriptor() = default; | ||
|
||
// Construct an alternate descriptor with the given alternate descriptors. | ||
AIEAlternateDescriptor(const MIAltDescsMap &AltDescs) | ||
: AlternateDescs(AltDescs) {} | ||
|
||
// Set the alternate descriptor for the given multi-opcode instruction. | ||
void setAlternateDescriptor(MachineInstr *MI, const MCInstrDesc *AltDesc) { | ||
AlternateDescs[MI] = AltDesc; | ||
} | ||
|
||
// Return the alternate descriptor for the given multi-opcode instruction. | ||
std::optional<const MCInstrDesc *> | ||
getAlternateDescriptor(MachineInstr *MI) const { | ||
if (auto It = AlternateDescs.find(MI); It != AlternateDescs.end()) | ||
return It->second; | ||
return std::nullopt; | ||
} | ||
|
||
const MCInstrDesc *getDesc(MachineInstr *MI) { | ||
return getAlternateDescriptor(MI).value_or(&MI->getDesc()); | ||
} | ||
|
||
// Return the alternate opcode for the given multi-opcode instruction. | ||
std::optional<unsigned> getAlternateOpcode(MachineInstr *MI) const { | ||
if (auto It = AlternateDescs.find(MI); It != AlternateDescs.end()) | ||
return It->second->getOpcode(); | ||
return std::nullopt; | ||
} | ||
|
||
unsigned getOpcode(MachineInstr *MI) const { | ||
return getAlternateOpcode(MI).value_or(MI->getDesc().getOpcode()); | ||
} | ||
|
||
void clear() { AlternateDescs.clear(); } | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_SUPPORT_AIEALTERNATEDESCRIPTOR_H |
This file contains 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 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 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 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 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