LLVM 24.0.0git
PISAMCInstLower.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file declares lowering from PISA MachineInstrs to MCInsts.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_PISA_PISAMCINSTLOWER_H
15#define LLVM_LIB_TARGET_PISA_PISAMCINSTLOWER_H
16
17#include "PISADefines.h"
18#include "PISARegisterInfo.h"
20#include "llvm/MC/MCInst.h"
22#include <cassert>
23
24namespace llvm {
25class MCContext;
26class MCOperand;
27class MCSymbol;
28class MachineInstr;
29class MachineOperand;
30
31namespace PISA {
32class RegManager;
33} // namespace PISA
34
35struct PISAMCOpnd {
36 // given immediate value represents the index of a variable (.e.g, @R0).
38 // swizzle of given operand
39 unsigned Swizzle;
40};
41
42class PISAMCInst : public MCInst {
43public:
45
46 // Source line number in the original assembly file, used for debug info and
47 // error reporting
48 unsigned SourceLine = 0;
49 unsigned getSourceLine() const { return SourceLine; }
50 void setSourceLine(unsigned L) { SourceLine = L; }
51};
52
53// This class is used to lower a MachineInstr into an MCInst.
55public:
56 static void setVariableRef(MCInst &MI, unsigned OpNo) {
57 PISAMCInst *MC = static_cast<PISAMCInst *>(&MI);
58 auto Pair = MC->Opnds.try_emplace(OpNo, PISAMCOpnd{true, 0});
59 if (!Pair.second)
60 Pair.first->second.IsVariable = true;
61 }
62
63 static bool isVariableRef(const MCInst &MI, unsigned int OpNo) {
64 const PISAMCInst *MC = static_cast<const PISAMCInst *>(&MI);
66 MC->Opnds.find(OpNo);
67 if (It == MC->Opnds.end())
68 return false;
69 return It->second.IsVariable;
70 }
71
72 static void setSwizzle(MCInst &MI, unsigned OpNo, PISA::Swizzle Swizzle) {
73 static_assert(static_cast<unsigned>(PISA::Swizzle::NONE) <= 7);
74 PISAMCInst *MC = static_cast<PISAMCInst *>(&MI);
75 auto Pair = MC->Opnds.try_emplace(
76 OpNo, PISAMCOpnd{false, static_cast<unsigned>(Swizzle)});
77 if (!Pair.second)
78 Pair.first->second.Swizzle = static_cast<unsigned>(Swizzle);
79 }
80
81 static PISA::Swizzle getSwizzle(const MCInst &MI, unsigned OpNo) {
82 const PISAMCInst *MC = static_cast<const PISAMCInst *>(&MI);
84 MC->Opnds.find(OpNo);
85 if (It == MC->Opnds.end())
86 return static_cast<PISA::Swizzle>(PISA::Swizzle::NONE);
87 return static_cast<PISA::Swizzle>(It->second.Swizzle);
88 }
89
91 const PISA::RegManager &RegMgr, const AsmPrinter &AP)
92 : OutContext(Ctx), TRI(TRI), RegMgr(RegMgr), AP(AP) {}
93 void lower(const MachineInstr *MI, MCInst &OutMI) const;
94
95private:
97 MCSymbol &getGlobalAddressSymbol(const MachineOperand &MO) const;
98
99private:
100 MCContext &OutContext;
101 const PISARegisterInfo &TRI;
102 const PISA::RegManager &RegMgr;
103 const AsmPrinter &AP;
104};
105} // namespace llvm
106
107#endif // LLVM_LIB_TARGET_PISA_PISAMCINSTLOWER_H
bpf unwind lower
#define LLVM_LIBRARY_VISIBILITY
Definition Compiler.h:137
IRTranslator LLVM IR MI
static MCOperand lowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym, const AsmPrinter &AP)
Register const TargetRegisterInfo * TRI
This file declares definitions shared across the PISA backend.
This file declares register information for the PISA target.
static std::vector< std::pair< int, unsigned > > Swizzle(std::vector< std::pair< int, unsigned > > Src, R600InstrInfo::BankSwizzle Swz)
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:93
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Definition DenseMap.h:679
Context object for machine code objects.
Definition MCContext.h:84
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:207
MCInst()=default
Instances of this class represent operands of the MCInst class.
Definition MCInst.h:39
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
static PISA::Swizzle getSwizzle(const MCInst &MI, unsigned OpNo)
static bool isVariableRef(const MCInst &MI, unsigned int OpNo)
static void setSwizzle(MCInst &MI, unsigned OpNo, PISA::Swizzle Swizzle)
static void setVariableRef(MCInst &MI, unsigned OpNo)
PISAMCInstLower(MCContext &Ctx, const PISARegisterInfo &TRI, const PISA::RegManager &RegMgr, const AsmPrinter &AP)
void setSourceLine(unsigned L)
unsigned getSourceLine() const
SmallDenseMap< unsigned, PISAMCOpnd > Opnds
This is an optimization pass for GlobalISel generic memory operations.