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
13#include "DirectXAsmPrinter.h"
19#include "llvm/MC/MCStreamer.h"
20#include "llvm/MC/SectionKind.h"
23
24using namespace llvm;
25
26#define DEBUG_TYPE "asm-printer"
27
28namespace {
29
30// The DXILAsmPrinter is mostly a stub because DXIL is just LLVM bitcode which
31// gets embedded into a DXContainer file.
32class DXILAsmPrinter : public AsmPrinter {
33public:
34 explicit DXILAsmPrinter(TargetMachine &TM,
35 std::unique_ptr<MCStreamer> Streamer)
36 : AsmPrinter(TM, std::move(Streamer)) {}
37
38 StringRef getPassName() const override { return "DXIL Assembly Printer"; }
39 void emitGlobalVariable(const GlobalVariable *GV) override;
40 bool runOnMachineFunction(MachineFunction &MF) override { return false; }
41};
42} // namespace
43
44void DXILAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
45 // If there is no initializer, or no explicit section do nothing
46 if (!GV->hasInitializer() || GV->hasImplicitSection() || !GV->hasSection())
47 return;
48 // Skip the LLVM metadata
49 if (GV->getSection() == "llvm.metadata")
50 return;
51 SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
52 MCSection *TheSection = getObjFileLowering().SectionForGlobal(GV, GVKind, TM);
53 OutStreamer->switchSection(TheSection);
54 emitGlobalConstant(GV->getDataLayout(), GV->getInitializer());
55}
56
61
64 DXILAsmPrinter &AsmPrinter = static_cast<DXILAsmPrinter &>(
65 MAM.getResult<AsmPrinterAnalysis>(M).getPrinter());
69}
70
74 DXILAsmPrinter &AsmPrinter = static_cast<DXILAsmPrinter &>(
76 .getCachedResult<AsmPrinterAnalysis>(*MF.getFunction().getParent())
77 ->getPrinter());
81}
82
85 DXILAsmPrinter &AsmPrinter = static_cast<DXILAsmPrinter &>(
86 MAM.getResult<AsmPrinterAnalysis>(M).getPrinter());
90}
static const Function * getParent(const Value *V)
#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()
ModuleAnalysisManager MAM
std::unique_ptr< MCStreamer > && Streamer
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:95
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
bool doFinalization(Module &M) override
Shut down the asmprinter.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition AsmPrinter.h:478
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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.
Function & getFunction()
Return the LLVM function that this machine code represents.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
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.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
Target & getTheDirectXTarget()
LLVM_ABI void setupModuleAsmPrinter(Module &M, ModuleAnalysisManager &MAM, AsmPrinter &AsmPrinter)
LLVM_ABI void setupMachineFunctionAsmPrinter(MachineFunctionAnalysisManager &MFAM, MachineFunction &MF, AsmPrinter &AsmPrinter)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...