LLVM  16.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 
15 #include "llvm/IR/GlobalVariable.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/MC/MCStreamer.h"
18 #include "llvm/MC/SectionKind.h"
19 #include "llvm/MC/TargetRegistry.h"
21 
22 using namespace llvm;
23 
24 #define DEBUG_TYPE "asm-printer"
25 
26 namespace {
27 
28 // The DXILAsmPrinter is mostly a stub because DXIL is just LLVM bitcode which
29 // gets embedded into a DXContainer file.
30 class DXILAsmPrinter : public AsmPrinter {
31 public:
32  explicit DXILAsmPrinter(TargetMachine &TM,
33  std::unique_ptr<MCStreamer> Streamer)
34  : AsmPrinter(TM, std::move(Streamer)) {}
35 
36  StringRef getPassName() const override { return "DXIL Assembly Printer"; }
37  void emitGlobalVariable(const GlobalVariable *GV) override;
38  bool runOnMachineFunction(MachineFunction &MF) override { return false; }
39 };
40 } // namespace
41 
42 void DXILAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
43  // If there is no initializer, or no explicit section do nothing
44  if (!GV->hasInitializer() || GV->hasImplicitSection() || !GV->hasSection())
45  return;
46  // Skip the LLVM metadata
47  if (GV->getSection() == "llvm.metadata")
48  return;
50  MCSection *TheSection = getObjFileLowering().SectionForGlobal(GV, GVKind, TM);
51  OutStreamer->switchSection(TheSection);
52  emitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer());
53 }
54 
57 }
AsmPrinter.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::GlobalObject::getSection
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:111
llvm::GlobalVariable
Definition: GlobalVariable.h:39
Module.h
llvm::GlobalVariable::hasInitializer
bool hasInitializer() const
Definitions have initializers, declarations don't.
Definition: GlobalVariable.h:91
llvm::TargetLoweringObjectFile::getKindForGlobal
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
Definition: TargetLoweringObjectFile.cpp:200
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::GlobalObject::hasSection
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:103
LLVMInitializeDirectXAsmPrinter
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXAsmPrinter()
Definition: DirectXAsmPrinter.cpp:55
llvm::GlobalVariable::getInitializer
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition: GlobalVariable.h:135
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
LLVM_EXTERNAL_VISIBILITY
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:127
llvm::GlobalVariable::hasImplicitSection
bool hasImplicitSection() const
Check if section name is present.
Definition: GlobalVariable.h:242
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
TargetLoweringObjectFile.h
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::getTheDirectXTarget
Target & getTheDirectXTarget()
Definition: DirectXTargetInfo.cpp:19
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
GlobalVariable.h
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
SectionKind.h
MCStreamer.h
DirectXTargetInfo.h
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:399
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::RegisterAsmPrinter
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...
Definition: TargetRegistry.h:1419
TargetRegistry.h