144a14a6aSChris Bieneman //===- DirectXMCTargetDesc.cpp - DirectX Target Implementation --*- C++ -*-===//
244a14a6aSChris Bieneman //
344a14a6aSChris Bieneman // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
444a14a6aSChris Bieneman // See https://llvm.org/LICENSE.txt for license information.
544a14a6aSChris Bieneman // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
644a14a6aSChris Bieneman //
744a14a6aSChris Bieneman //===----------------------------------------------------------------------===//
844a14a6aSChris Bieneman ///
944a14a6aSChris Bieneman /// \file
1044a14a6aSChris Bieneman /// This file contains DirectX target initializer.
1144a14a6aSChris Bieneman ///
1244a14a6aSChris Bieneman //===----------------------------------------------------------------------===//
1344a14a6aSChris Bieneman
14*2af61e62SChris Bieneman #include "DirectXMCTargetDesc.h"
15*2af61e62SChris Bieneman #include "DirectXContainerObjectWriter.h"
16*2af61e62SChris Bieneman #include "TargetInfo/DirectXTargetInfo.h"
1744a14a6aSChris Bieneman #include "llvm/ADT/Triple.h"
18*2af61e62SChris Bieneman #include "llvm/MC/LaneBitmask.h"
1944a14a6aSChris Bieneman #include "llvm/MC/MCAsmBackend.h"
20*2af61e62SChris Bieneman #include "llvm/MC/MCAsmInfo.h"
2144a14a6aSChris Bieneman #include "llvm/MC/MCCodeEmitter.h"
22*2af61e62SChris Bieneman #include "llvm/MC/MCDXContainerWriter.h"
23*2af61e62SChris Bieneman #include "llvm/MC/MCInstPrinter.h"
2444a14a6aSChris Bieneman #include "llvm/MC/MCInstrInfo.h"
25*2af61e62SChris Bieneman #include "llvm/MC/MCRegisterInfo.h"
2644a14a6aSChris Bieneman #include "llvm/MC/MCSchedule.h"
2744a14a6aSChris Bieneman #include "llvm/MC/MCSubtargetInfo.h"
28*2af61e62SChris Bieneman #include "llvm/MC/TargetRegistry.h"
2944a14a6aSChris Bieneman #include "llvm/Support/Compiler.h"
30*2af61e62SChris Bieneman #include <memory>
3144a14a6aSChris Bieneman
3244a14a6aSChris Bieneman using namespace llvm;
3344a14a6aSChris Bieneman
34*2af61e62SChris Bieneman #define GET_INSTRINFO_MC_DESC
35*2af61e62SChris Bieneman #define GET_INSTRINFO_MC_HELPERS
36*2af61e62SChris Bieneman #include "DirectXGenInstrInfo.inc"
37*2af61e62SChris Bieneman
3844a14a6aSChris Bieneman #define GET_SUBTARGETINFO_MC_DESC
3944a14a6aSChris Bieneman #include "DirectXGenSubtargetInfo.inc"
4044a14a6aSChris Bieneman
41*2af61e62SChris Bieneman #define GET_REGINFO_MC_DESC
42*2af61e62SChris Bieneman #include "DirectXGenRegisterInfo.inc"
43*2af61e62SChris Bieneman
44*2af61e62SChris Bieneman namespace {
45*2af61e62SChris Bieneman
46*2af61e62SChris Bieneman // DXILInstPrinter is a null stub because DXIL instructions aren't printed.
47*2af61e62SChris Bieneman class DXILInstPrinter : public MCInstPrinter {
48*2af61e62SChris Bieneman public:
DXILInstPrinter(const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)49*2af61e62SChris Bieneman DXILInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
50*2af61e62SChris Bieneman const MCRegisterInfo &MRI)
51*2af61e62SChris Bieneman : MCInstPrinter(MAI, MII, MRI) {}
52*2af61e62SChris Bieneman
printInst(const MCInst * MI,uint64_t Address,StringRef Annot,const MCSubtargetInfo & STI,raw_ostream & O)53*2af61e62SChris Bieneman void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
54*2af61e62SChris Bieneman const MCSubtargetInfo &STI, raw_ostream &O) override {}
55*2af61e62SChris Bieneman
getMnemonic(const MCInst * MI)56*2af61e62SChris Bieneman std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override {
57*2af61e62SChris Bieneman return std::make_pair<const char *, uint64_t>("", 0ull);
58*2af61e62SChris Bieneman }
59*2af61e62SChris Bieneman
60*2af61e62SChris Bieneman private:
61*2af61e62SChris Bieneman };
62*2af61e62SChris Bieneman
63*2af61e62SChris Bieneman class DXILMCCodeEmitter : public MCCodeEmitter {
64*2af61e62SChris Bieneman public:
DXILMCCodeEmitter()65*2af61e62SChris Bieneman DXILMCCodeEmitter() {}
66*2af61e62SChris Bieneman
encodeInstruction(const MCInst & MI,raw_ostream & OS,SmallVectorImpl<MCFixup> & Fixups,const MCSubtargetInfo & STI) const67*2af61e62SChris Bieneman void encodeInstruction(const MCInst &MI, raw_ostream &OS,
68*2af61e62SChris Bieneman SmallVectorImpl<MCFixup> &Fixups,
69*2af61e62SChris Bieneman const MCSubtargetInfo &STI) const override {}
70*2af61e62SChris Bieneman };
71*2af61e62SChris Bieneman
72*2af61e62SChris Bieneman class DXILAsmBackend : public MCAsmBackend {
73*2af61e62SChris Bieneman
74*2af61e62SChris Bieneman public:
DXILAsmBackend(const MCSubtargetInfo & STI)75*2af61e62SChris Bieneman DXILAsmBackend(const MCSubtargetInfo &STI) : MCAsmBackend(support::little) {}
76*2af61e62SChris Bieneman ~DXILAsmBackend() override = default;
77*2af61e62SChris Bieneman
applyFixup(const MCAssembler & Asm,const MCFixup & Fixup,const MCValue & Target,MutableArrayRef<char> Data,uint64_t Value,bool IsResolved,const MCSubtargetInfo * STI) const78*2af61e62SChris Bieneman void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
79*2af61e62SChris Bieneman const MCValue &Target, MutableArrayRef<char> Data,
80*2af61e62SChris Bieneman uint64_t Value, bool IsResolved,
81*2af61e62SChris Bieneman const MCSubtargetInfo *STI) const override {}
82*2af61e62SChris Bieneman
83*2af61e62SChris Bieneman std::unique_ptr<MCObjectTargetWriter>
createObjectTargetWriter() const84*2af61e62SChris Bieneman createObjectTargetWriter() const override {
85*2af61e62SChris Bieneman return createDXContainerTargetObjectWriter();
86*2af61e62SChris Bieneman }
87*2af61e62SChris Bieneman
getNumFixupKinds() const88*2af61e62SChris Bieneman unsigned getNumFixupKinds() const override { return 0; }
89*2af61e62SChris Bieneman
writeNopData(raw_ostream & OS,uint64_t Count,const MCSubtargetInfo * STI) const90*2af61e62SChris Bieneman bool writeNopData(raw_ostream &OS, uint64_t Count,
91*2af61e62SChris Bieneman const MCSubtargetInfo *STI) const override {
92*2af61e62SChris Bieneman return true;
93*2af61e62SChris Bieneman }
94*2af61e62SChris Bieneman
fixupNeedsRelaxation(const MCFixup & Fixup,uint64_t Value,const MCRelaxableFragment * DF,const MCAsmLayout & Layout) const95*2af61e62SChris Bieneman bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
96*2af61e62SChris Bieneman const MCRelaxableFragment *DF,
97*2af61e62SChris Bieneman const MCAsmLayout &Layout) const override {
98*2af61e62SChris Bieneman return true;
99*2af61e62SChris Bieneman }
100*2af61e62SChris Bieneman };
101*2af61e62SChris Bieneman
102*2af61e62SChris Bieneman class DirectXMCAsmInfo : public MCAsmInfo {
103*2af61e62SChris Bieneman public:
DirectXMCAsmInfo(const Triple & TT,const MCTargetOptions & Options)104*2af61e62SChris Bieneman explicit DirectXMCAsmInfo(const Triple &TT, const MCTargetOptions &Options)
105*2af61e62SChris Bieneman : MCAsmInfo() {}
106*2af61e62SChris Bieneman };
107*2af61e62SChris Bieneman
108*2af61e62SChris Bieneman } // namespace
109*2af61e62SChris Bieneman
createDXILMCInstPrinter(const Triple & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)110*2af61e62SChris Bieneman static MCInstPrinter *createDXILMCInstPrinter(const Triple &T,
111*2af61e62SChris Bieneman unsigned SyntaxVariant,
112*2af61e62SChris Bieneman const MCAsmInfo &MAI,
113*2af61e62SChris Bieneman const MCInstrInfo &MII,
114*2af61e62SChris Bieneman const MCRegisterInfo &MRI) {
115*2af61e62SChris Bieneman if (SyntaxVariant == 0)
116*2af61e62SChris Bieneman return new DXILInstPrinter(MAI, MII, MRI);
117*2af61e62SChris Bieneman return nullptr;
118*2af61e62SChris Bieneman }
119*2af61e62SChris Bieneman
createDXILMCCodeEmitter(const MCInstrInfo & MCII,MCContext & Ctx)120*2af61e62SChris Bieneman MCCodeEmitter *createDXILMCCodeEmitter(const MCInstrInfo &MCII,
121*2af61e62SChris Bieneman MCContext &Ctx) {
122*2af61e62SChris Bieneman return new DXILMCCodeEmitter();
123*2af61e62SChris Bieneman }
124*2af61e62SChris Bieneman
createDXILMCAsmBackend(const Target & T,const MCSubtargetInfo & STI,const MCRegisterInfo & MRI,const MCTargetOptions & Options)125*2af61e62SChris Bieneman MCAsmBackend *createDXILMCAsmBackend(const Target &T,
126*2af61e62SChris Bieneman const MCSubtargetInfo &STI,
127*2af61e62SChris Bieneman const MCRegisterInfo &MRI,
128*2af61e62SChris Bieneman const MCTargetOptions &Options) {
129*2af61e62SChris Bieneman return new DXILAsmBackend(STI);
130*2af61e62SChris Bieneman }
131*2af61e62SChris Bieneman
132*2af61e62SChris Bieneman static MCSubtargetInfo *
createDirectXMCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)133*2af61e62SChris Bieneman createDirectXMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
134*2af61e62SChris Bieneman return createDirectXMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
135*2af61e62SChris Bieneman }
136*2af61e62SChris Bieneman
createDirectXMCRegisterInfo(const Triple & Triple)137*2af61e62SChris Bieneman static MCRegisterInfo *createDirectXMCRegisterInfo(const Triple &Triple) {
138*2af61e62SChris Bieneman return new MCRegisterInfo();
139*2af61e62SChris Bieneman }
140*2af61e62SChris Bieneman
createDirectXMCInstrInfo()141*2af61e62SChris Bieneman static MCInstrInfo *createDirectXMCInstrInfo() { return new MCInstrInfo(); }
142*2af61e62SChris Bieneman
LLVMInitializeDirectXTargetMC()143*2af61e62SChris Bieneman extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTargetMC() {
144*2af61e62SChris Bieneman Target &T = getTheDirectXTarget();
145*2af61e62SChris Bieneman RegisterMCAsmInfo<DirectXMCAsmInfo> X(T);
146*2af61e62SChris Bieneman TargetRegistry::RegisterMCInstrInfo(T, createDirectXMCInstrInfo);
147*2af61e62SChris Bieneman TargetRegistry::RegisterMCInstPrinter(T, createDXILMCInstPrinter);
148*2af61e62SChris Bieneman TargetRegistry::RegisterMCRegInfo(T, createDirectXMCRegisterInfo);
149*2af61e62SChris Bieneman TargetRegistry::RegisterMCSubtargetInfo(T, createDirectXMCSubtargetInfo);
150*2af61e62SChris Bieneman TargetRegistry::RegisterMCCodeEmitter(T, createDXILMCCodeEmitter);
151*2af61e62SChris Bieneman TargetRegistry::RegisterMCAsmBackend(T, createDXILMCAsmBackend);
152*2af61e62SChris Bieneman }
153