xref: /llvm-project/llvm/lib/Target/DirectX/MCTargetDesc/DirectXMCTargetDesc.cpp (revision eeb987f6f35aa614ed7a555be33d67c5cb1be230)
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 
142af61e62SChris Bieneman #include "DirectXMCTargetDesc.h"
152af61e62SChris Bieneman #include "DirectXContainerObjectWriter.h"
162af61e62SChris Bieneman #include "TargetInfo/DirectXTargetInfo.h"
172af61e62SChris Bieneman #include "llvm/MC/LaneBitmask.h"
1844a14a6aSChris Bieneman #include "llvm/MC/MCAsmBackend.h"
192af61e62SChris Bieneman #include "llvm/MC/MCAsmInfo.h"
2044a14a6aSChris Bieneman #include "llvm/MC/MCCodeEmitter.h"
212af61e62SChris Bieneman #include "llvm/MC/MCDXContainerWriter.h"
222af61e62SChris Bieneman #include "llvm/MC/MCInstPrinter.h"
2344a14a6aSChris Bieneman #include "llvm/MC/MCInstrInfo.h"
242af61e62SChris Bieneman #include "llvm/MC/MCRegisterInfo.h"
2544a14a6aSChris Bieneman #include "llvm/MC/MCSchedule.h"
2644a14a6aSChris Bieneman #include "llvm/MC/MCSubtargetInfo.h"
272af61e62SChris Bieneman #include "llvm/MC/TargetRegistry.h"
2844a14a6aSChris Bieneman #include "llvm/Support/Compiler.h"
2962c7f035SArchibald Elliott #include "llvm/TargetParser/Triple.h"
302af61e62SChris Bieneman #include <memory>
3144a14a6aSChris Bieneman 
3244a14a6aSChris Bieneman using namespace llvm;
3344a14a6aSChris Bieneman 
342af61e62SChris Bieneman #define GET_INSTRINFO_MC_DESC
352af61e62SChris Bieneman #define GET_INSTRINFO_MC_HELPERS
362af61e62SChris Bieneman #include "DirectXGenInstrInfo.inc"
372af61e62SChris Bieneman 
3844a14a6aSChris Bieneman #define GET_SUBTARGETINFO_MC_DESC
3944a14a6aSChris Bieneman #include "DirectXGenSubtargetInfo.inc"
4044a14a6aSChris Bieneman 
412af61e62SChris Bieneman #define GET_REGINFO_MC_DESC
422af61e62SChris Bieneman #include "DirectXGenRegisterInfo.inc"
432af61e62SChris Bieneman 
442af61e62SChris Bieneman namespace {
452af61e62SChris Bieneman 
462af61e62SChris Bieneman // DXILInstPrinter is a null stub because DXIL instructions aren't printed.
472af61e62SChris Bieneman class DXILInstPrinter : public MCInstPrinter {
482af61e62SChris Bieneman public:
492af61e62SChris Bieneman   DXILInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
502af61e62SChris Bieneman                   const MCRegisterInfo &MRI)
512af61e62SChris Bieneman       : MCInstPrinter(MAI, MII, MRI) {}
522af61e62SChris Bieneman 
532af61e62SChris Bieneman   void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
542af61e62SChris Bieneman                  const MCSubtargetInfo &STI, raw_ostream &O) override {}
552af61e62SChris Bieneman 
56*eeb987f6SSergei Barannikov   std::pair<const char *, uint64_t>
57*eeb987f6SSergei Barannikov   getMnemonic(const MCInst &MI) const override {
582af61e62SChris Bieneman     return std::make_pair<const char *, uint64_t>("", 0ull);
592af61e62SChris Bieneman   }
602af61e62SChris Bieneman 
612af61e62SChris Bieneman private:
622af61e62SChris Bieneman };
632af61e62SChris Bieneman 
642af61e62SChris Bieneman class DXILMCCodeEmitter : public MCCodeEmitter {
652af61e62SChris Bieneman public:
662af61e62SChris Bieneman   DXILMCCodeEmitter() {}
672af61e62SChris Bieneman 
687e39e2e5SFangrui Song   void encodeInstruction(const MCInst &Inst, SmallVectorImpl<char> &CB,
692af61e62SChris Bieneman                          SmallVectorImpl<MCFixup> &Fixups,
702af61e62SChris Bieneman                          const MCSubtargetInfo &STI) const override {}
712af61e62SChris Bieneman };
722af61e62SChris Bieneman 
732af61e62SChris Bieneman class DXILAsmBackend : public MCAsmBackend {
742af61e62SChris Bieneman 
752af61e62SChris Bieneman public:
764a0ccfa8SKazu Hirata   DXILAsmBackend(const MCSubtargetInfo &STI)
774a0ccfa8SKazu Hirata       : MCAsmBackend(llvm::endianness::little) {}
782af61e62SChris Bieneman   ~DXILAsmBackend() override = default;
792af61e62SChris Bieneman 
802af61e62SChris Bieneman   void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
812af61e62SChris Bieneman                   const MCValue &Target, MutableArrayRef<char> Data,
822af61e62SChris Bieneman                   uint64_t Value, bool IsResolved,
832af61e62SChris Bieneman                   const MCSubtargetInfo *STI) const override {}
842af61e62SChris Bieneman 
852af61e62SChris Bieneman   std::unique_ptr<MCObjectTargetWriter>
862af61e62SChris Bieneman   createObjectTargetWriter() const override {
872af61e62SChris Bieneman     return createDXContainerTargetObjectWriter();
882af61e62SChris Bieneman   }
892af61e62SChris Bieneman 
902af61e62SChris Bieneman   unsigned getNumFixupKinds() const override { return 0; }
912af61e62SChris Bieneman 
922af61e62SChris Bieneman   bool writeNopData(raw_ostream &OS, uint64_t Count,
932af61e62SChris Bieneman                     const MCSubtargetInfo *STI) const override {
942af61e62SChris Bieneman     return true;
952af61e62SChris Bieneman   }
962af61e62SChris Bieneman };
972af61e62SChris Bieneman 
982af61e62SChris Bieneman class DirectXMCAsmInfo : public MCAsmInfo {
992af61e62SChris Bieneman public:
1002af61e62SChris Bieneman   explicit DirectXMCAsmInfo(const Triple &TT, const MCTargetOptions &Options)
1012af61e62SChris Bieneman       : MCAsmInfo() {}
1022af61e62SChris Bieneman };
1032af61e62SChris Bieneman 
1042af61e62SChris Bieneman } // namespace
1052af61e62SChris Bieneman 
1062af61e62SChris Bieneman static MCInstPrinter *createDXILMCInstPrinter(const Triple &T,
1072af61e62SChris Bieneman                                               unsigned SyntaxVariant,
1082af61e62SChris Bieneman                                               const MCAsmInfo &MAI,
1092af61e62SChris Bieneman                                               const MCInstrInfo &MII,
1102af61e62SChris Bieneman                                               const MCRegisterInfo &MRI) {
1112af61e62SChris Bieneman   if (SyntaxVariant == 0)
1122af61e62SChris Bieneman     return new DXILInstPrinter(MAI, MII, MRI);
1132af61e62SChris Bieneman   return nullptr;
1142af61e62SChris Bieneman }
1152af61e62SChris Bieneman 
1162af61e62SChris Bieneman MCCodeEmitter *createDXILMCCodeEmitter(const MCInstrInfo &MCII,
1172af61e62SChris Bieneman                                        MCContext &Ctx) {
1182af61e62SChris Bieneman   return new DXILMCCodeEmitter();
1192af61e62SChris Bieneman }
1202af61e62SChris Bieneman 
1212af61e62SChris Bieneman MCAsmBackend *createDXILMCAsmBackend(const Target &T,
1222af61e62SChris Bieneman                                      const MCSubtargetInfo &STI,
1232af61e62SChris Bieneman                                      const MCRegisterInfo &MRI,
1242af61e62SChris Bieneman                                      const MCTargetOptions &Options) {
1252af61e62SChris Bieneman   return new DXILAsmBackend(STI);
1262af61e62SChris Bieneman }
1272af61e62SChris Bieneman 
1282af61e62SChris Bieneman static MCSubtargetInfo *
1292af61e62SChris Bieneman createDirectXMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
1302af61e62SChris Bieneman   return createDirectXMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
1312af61e62SChris Bieneman }
1322af61e62SChris Bieneman 
1332af61e62SChris Bieneman static MCRegisterInfo *createDirectXMCRegisterInfo(const Triple &Triple) {
1342af61e62SChris Bieneman   return new MCRegisterInfo();
1352af61e62SChris Bieneman }
1362af61e62SChris Bieneman 
1372af61e62SChris Bieneman static MCInstrInfo *createDirectXMCInstrInfo() { return new MCInstrInfo(); }
1382af61e62SChris Bieneman 
1392af61e62SChris Bieneman extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTargetMC() {
1402af61e62SChris Bieneman   Target &T = getTheDirectXTarget();
1412af61e62SChris Bieneman   RegisterMCAsmInfo<DirectXMCAsmInfo> X(T);
1422af61e62SChris Bieneman   TargetRegistry::RegisterMCInstrInfo(T, createDirectXMCInstrInfo);
1432af61e62SChris Bieneman   TargetRegistry::RegisterMCInstPrinter(T, createDXILMCInstPrinter);
1442af61e62SChris Bieneman   TargetRegistry::RegisterMCRegInfo(T, createDirectXMCRegisterInfo);
1452af61e62SChris Bieneman   TargetRegistry::RegisterMCSubtargetInfo(T, createDirectXMCSubtargetInfo);
1462af61e62SChris Bieneman   TargetRegistry::RegisterMCCodeEmitter(T, createDXILMCCodeEmitter);
1472af61e62SChris Bieneman   TargetRegistry::RegisterMCAsmBackend(T, createDXILMCAsmBackend);
1482af61e62SChris Bieneman }
149