1*3942f8e4SChris Bieneman //===-- DirectXAsmPrinter.cpp - DirectX assembly writer --------*- C++ -*--===// 2*3942f8e4SChris Bieneman // 3*3942f8e4SChris Bieneman // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*3942f8e4SChris Bieneman // See https://llvm.org/LICENSE.txt for license information. 5*3942f8e4SChris Bieneman // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*3942f8e4SChris Bieneman // 7*3942f8e4SChris Bieneman //===----------------------------------------------------------------------===// 8*3942f8e4SChris Bieneman // 9*3942f8e4SChris Bieneman // This file contains AsmPrinters for the DirectX backend. 10*3942f8e4SChris Bieneman // 11*3942f8e4SChris Bieneman //===----------------------------------------------------------------------===// 12*3942f8e4SChris Bieneman 13*3942f8e4SChris Bieneman #include "TargetInfo/DirectXTargetInfo.h" 14*3942f8e4SChris Bieneman #include "llvm/CodeGen/AsmPrinter.h" 15*3942f8e4SChris Bieneman #include "llvm/IR/GlobalVariable.h" 16*3942f8e4SChris Bieneman #include "llvm/IR/Module.h" 17*3942f8e4SChris Bieneman #include "llvm/MC/MCStreamer.h" 18*3942f8e4SChris Bieneman #include "llvm/MC/SectionKind.h" 19*3942f8e4SChris Bieneman #include "llvm/MC/TargetRegistry.h" 20*3942f8e4SChris Bieneman #include "llvm/Target/TargetLoweringObjectFile.h" 21*3942f8e4SChris Bieneman 22*3942f8e4SChris Bieneman using namespace llvm; 23*3942f8e4SChris Bieneman 24*3942f8e4SChris Bieneman #define DEBUG_TYPE "asm-printer" 25*3942f8e4SChris Bieneman 26*3942f8e4SChris Bieneman namespace { 27*3942f8e4SChris Bieneman 28*3942f8e4SChris Bieneman // The DXILAsmPrinter is mostly a stub because DXIL is just LLVM bitcode which 29*3942f8e4SChris Bieneman // gets embedded into a DXContainer file. 30*3942f8e4SChris Bieneman class DXILAsmPrinter : public AsmPrinter { 31*3942f8e4SChris Bieneman public: DXILAsmPrinter(TargetMachine & TM,std::unique_ptr<MCStreamer> Streamer)32*3942f8e4SChris Bieneman explicit DXILAsmPrinter(TargetMachine &TM, 33*3942f8e4SChris Bieneman std::unique_ptr<MCStreamer> Streamer) 34*3942f8e4SChris Bieneman : AsmPrinter(TM, std::move(Streamer)) {} 35*3942f8e4SChris Bieneman getPassName() const36*3942f8e4SChris Bieneman StringRef getPassName() const override { return "DXIL Assembly Printer"; } 37*3942f8e4SChris Bieneman void emitGlobalVariable(const GlobalVariable *GV) override; runOnMachineFunction(MachineFunction & MF)38*3942f8e4SChris Bieneman bool runOnMachineFunction(MachineFunction &MF) override { return false; } 39*3942f8e4SChris Bieneman }; 40*3942f8e4SChris Bieneman } // namespace 41*3942f8e4SChris Bieneman emitGlobalVariable(const GlobalVariable * GV)42*3942f8e4SChris Bienemanvoid DXILAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { 43*3942f8e4SChris Bieneman // If there is no initializer or the section is implicit, do nothing 44*3942f8e4SChris Bieneman if (!GV->hasInitializer() || GV->hasImplicitSection()) 45*3942f8e4SChris Bieneman return; 46*3942f8e4SChris Bieneman // Skip the LLVM metadata 47*3942f8e4SChris Bieneman if (GV->getSection() == "llvm.metadata") 48*3942f8e4SChris Bieneman return; 49*3942f8e4SChris Bieneman SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM); 50*3942f8e4SChris Bieneman MCSection *TheSection = getObjFileLowering().SectionForGlobal(GV, GVKind, TM); 51*3942f8e4SChris Bieneman OutStreamer->switchSection(TheSection); 52*3942f8e4SChris Bieneman emitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer()); 53*3942f8e4SChris Bieneman } 54*3942f8e4SChris Bieneman LLVMInitializeDirectXAsmPrinter()55*3942f8e4SChris Bienemanextern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXAsmPrinter() { 56*3942f8e4SChris Bieneman RegisterAsmPrinter<DXILAsmPrinter> X(getTheDirectXTarget()); 57*3942f8e4SChris Bieneman } 58