LLVM 17.0.0git
DirectXMCTargetDesc.cpp
Go to the documentation of this file.
1//===- DirectXMCTargetDesc.cpp - DirectX Target Implementation --*- C++ -*-===//
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 contains DirectX target initializer.
11///
12//===----------------------------------------------------------------------===//
13
14#include "DirectXMCTargetDesc.h"
17#include "llvm/ADT/Triple.h"
18#include "llvm/MC/LaneBitmask.h"
20#include "llvm/MC/MCAsmInfo.h"
24#include "llvm/MC/MCInstrInfo.h"
26#include "llvm/MC/MCSchedule.h"
30#include <memory>
31
32using namespace llvm;
33
34#define GET_INSTRINFO_MC_DESC
35#define GET_INSTRINFO_MC_HELPERS
36#include "DirectXGenInstrInfo.inc"
37
38#define GET_SUBTARGETINFO_MC_DESC
39#include "DirectXGenSubtargetInfo.inc"
40
41#define GET_REGINFO_MC_DESC
42#include "DirectXGenRegisterInfo.inc"
43
44namespace {
45
46// DXILInstPrinter is a null stub because DXIL instructions aren't printed.
47class DXILInstPrinter : public MCInstPrinter {
48public:
49 DXILInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
50 const MCRegisterInfo &MRI)
51 : MCInstPrinter(MAI, MII, MRI) {}
52
53 void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
54 const MCSubtargetInfo &STI, raw_ostream &O) override {}
55
56 std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override {
57 return std::make_pair<const char *, uint64_t>("", 0ull);
58 }
59
60private:
61};
62
63class DXILMCCodeEmitter : public MCCodeEmitter {
64public:
65 DXILMCCodeEmitter() {}
66
67 void encodeInstruction(const MCInst &MI, raw_ostream &OS,
69 const MCSubtargetInfo &STI) const override {}
70};
71
72class DXILAsmBackend : public MCAsmBackend {
73
74public:
75 DXILAsmBackend(const MCSubtargetInfo &STI) : MCAsmBackend(support::little) {}
76 ~DXILAsmBackend() override = default;
77
78 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
80 uint64_t Value, bool IsResolved,
81 const MCSubtargetInfo *STI) const override {}
82
83 std::unique_ptr<MCObjectTargetWriter>
84 createObjectTargetWriter() const override {
86 }
87
88 unsigned getNumFixupKinds() const override { return 0; }
89
90 bool writeNopData(raw_ostream &OS, uint64_t Count,
91 const MCSubtargetInfo *STI) const override {
92 return true;
93 }
94
97 const MCAsmLayout &Layout) const override {
98 return true;
99 }
100};
101
102class DirectXMCAsmInfo : public MCAsmInfo {
103public:
104 explicit DirectXMCAsmInfo(const Triple &TT, const MCTargetOptions &Options)
105 : MCAsmInfo() {}
106};
107
108} // namespace
109
111 unsigned SyntaxVariant,
112 const MCAsmInfo &MAI,
113 const MCInstrInfo &MII,
114 const MCRegisterInfo &MRI) {
115 if (SyntaxVariant == 0)
116 return new DXILInstPrinter(MAI, MII, MRI);
117 return nullptr;
118}
119
121 MCContext &Ctx) {
122 return new DXILMCCodeEmitter();
123}
124
126 const MCSubtargetInfo &STI,
127 const MCRegisterInfo &MRI,
128 const MCTargetOptions &Options) {
129 return new DXILAsmBackend(STI);
130}
131
132static MCSubtargetInfo *
134 return createDirectXMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
135}
136
138 return new MCRegisterInfo();
139}
140
142
152}
unsigned const MachineRegisterInfo * MRI
This header is deprecated in favour of llvm/TargetParser/Triple.h.
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:127
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
MCAsmBackend * createDXILMCAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
static MCRegisterInfo * createDirectXMCRegisterInfo(const Triple &Triple)
static MCSubtargetInfo * createDirectXMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
static MCInstrInfo * createDirectXMCInstrInfo()
static MCInstPrinter * createDXILMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
MCCodeEmitter * createDXILMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTargetMC()
This file contains DirectX target interface.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
IRTranslator LLVM IR MI
static LVOptions Options
Definition: LVOptions.cpp:25
A common definition of LaneBitmask for use in TableGen and CodeGen.
PowerPC TLS Dynamic Call Fixup
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:41
virtual bool writeNopData(raw_ostream &OS, uint64_t Count, const MCSubtargetInfo *STI) const =0
Write an (optimal) nop sequence of Count bytes to the given output.
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const =0
Simple predicate for targets where !Resolved implies requiring relaxation.
virtual std::unique_ptr< MCObjectTargetWriter > createObjectTargetWriter() const =0
virtual unsigned getNumFixupKinds() const =0
Get the number of target specific fixup kinds.
virtual void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, MutableArrayRef< char > Data, uint64_t Value, bool IsResolved, const MCSubtargetInfo *STI) const =0
Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
Context object for machine code objects.
Definition: MCContext.h:76
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:44
virtual std::pair< const char *, uint64_t > getMnemonic(const MCInst *MI)=0
Returns a pair containing the mnemonic for MI and the number of bits left for further processing by p...
virtual void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS)=0
Print the specified MCInst to the specified raw_ostream.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:270
Generic base class for all target subtargets.
This represents an "assembler immediate".
Definition: MCValue.h:36
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:305
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Target & getTheDirectXTarget()
std::unique_ptr< MCObjectTargetWriter > createDXContainerTargetObjectWriter()
RegisterMCAsmInfo - Helper template for registering a target assembly info implementation.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.