LLVM 24.0.0git
DirectXAsmPrinter.cpp
Go to the documentation of this file.
1//===-- DirectXAsmPrinter.cpp - DirectX assembly writer --------*- 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// This file contains AsmPrinters for the DirectX backend.
10//
11//===----------------------------------------------------------------------===//
12
16#include "llvm/MC/MCStreamer.h"
17#include "llvm/MC/SectionKind.h"
20
21using namespace llvm;
22
23#define DEBUG_TYPE "asm-printer"
24
25namespace {
26
27// The DXILAsmPrinter is mostly a stub because DXIL is just LLVM bitcode which
28// gets embedded into a DXContainer file.
29class DXILAsmPrinter : public AsmPrinter {
30public:
31 explicit DXILAsmPrinter(TargetMachine &TM,
32 std::unique_ptr<MCStreamer> Streamer)
33 : AsmPrinter(TM, std::move(Streamer)) {}
34
35 StringRef getPassName() const override { return "DXIL Assembly Printer"; }
36 void emitGlobalVariable(const GlobalVariable *GV) override;
37 bool runOnMachineFunction(MachineFunction &MF) override { return false; }
38};
39} // namespace
40
41void DXILAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
42 // If there is no initializer, or no explicit section do nothing
43 if (!GV->hasInitializer() || GV->hasImplicitSection() || !GV->hasSection())
44 return;
45 // Skip the LLVM metadata
46 if (GV->getSection() == "llvm.metadata")
47 return;
48 SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
49 MCSection *TheSection = getObjFileLowering().SectionForGlobal(GV, GVKind, TM);
50 OutStreamer->switchSection(TheSection);
51 emitGlobalConstant(GV->getDataLayout(), GV->getInitializer());
52}
53
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXAsmPrinter()
std::unique_ptr< MCStreamer > && Streamer
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:95
StringRef getSection() const
Get the custom section of this global if it has one.
bool hasSection() const
Check if this global has a custom object file section.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition Globals.cpp:205
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
bool hasImplicitSection() const
Check if section name is present.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
Primary interface to the complete machine description for the target machine.
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheDirectXTarget()
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...