Path: blob/main/contrib/llvm-project/llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
35266 views
//===-- DirectXAsmPrinter.cpp - DirectX assembly writer --------*- C++ -*--===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains AsmPrinters for the DirectX backend.9//10//===----------------------------------------------------------------------===//1112#include "TargetInfo/DirectXTargetInfo.h"13#include "llvm/CodeGen/AsmPrinter.h"14#include "llvm/IR/GlobalVariable.h"15#include "llvm/IR/Module.h"16#include "llvm/MC/MCStreamer.h"17#include "llvm/MC/SectionKind.h"18#include "llvm/MC/TargetRegistry.h"19#include "llvm/Target/TargetLoweringObjectFile.h"2021using namespace llvm;2223#define DEBUG_TYPE "asm-printer"2425namespace {2627// The DXILAsmPrinter is mostly a stub because DXIL is just LLVM bitcode which28// gets embedded into a DXContainer file.29class DXILAsmPrinter : public AsmPrinter {30public:31explicit DXILAsmPrinter(TargetMachine &TM,32std::unique_ptr<MCStreamer> Streamer)33: AsmPrinter(TM, std::move(Streamer)) {}3435StringRef getPassName() const override { return "DXIL Assembly Printer"; }36void emitGlobalVariable(const GlobalVariable *GV) override;37bool runOnMachineFunction(MachineFunction &MF) override { return false; }38};39} // namespace4041void DXILAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {42// If there is no initializer, or no explicit section do nothing43if (!GV->hasInitializer() || GV->hasImplicitSection() || !GV->hasSection())44return;45// Skip the LLVM metadata46if (GV->getSection() == "llvm.metadata")47return;48SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);49MCSection *TheSection = getObjFileLowering().SectionForGlobal(GV, GVKind, TM);50OutStreamer->switchSection(TheSection);51emitGlobalConstant(GV->getDataLayout(), GV->getInitializer());52}5354extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXAsmPrinter() {55RegisterAsmPrinter<DXILAsmPrinter> X(getTheDirectXTarget());56}575859