LLVM  14.0.0git
ARCAsmPrinter.cpp
Go to the documentation of this file.
1 //===- ARCAsmPrinter.cpp - ARC LLVM 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 a printer that converts from our internal representation
10 // of machine-dependent LLVM code to GNU format ARC assembly language.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "ARC.h"
15 #include "ARCMCInstLower.h"
16 #include "ARCSubtarget.h"
17 #include "ARCTargetMachine.h"
22 #include "llvm/MC/MCAsmInfo.h"
23 #include "llvm/MC/MCInst.h"
24 #include "llvm/MC/MCStreamer.h"
27 
28 using namespace llvm;
29 
30 #define DEBUG_TYPE "asm-printer"
31 
32 namespace {
33 
34 class ARCAsmPrinter : public AsmPrinter {
35  ARCMCInstLower MCInstLowering;
36 
37 public:
38  explicit ARCAsmPrinter(TargetMachine &TM,
39  std::unique_ptr<MCStreamer> Streamer)
40  : AsmPrinter(TM, std::move(Streamer)),
41  MCInstLowering(&OutContext, *this) {}
42 
43  StringRef getPassName() const override { return "ARC Assembly Printer"; }
44  void emitInstruction(const MachineInstr *MI) override;
45 
46  bool runOnMachineFunction(MachineFunction &MF) override;
47 };
48 
49 } // end anonymous namespace
50 
51 void ARCAsmPrinter::emitInstruction(const MachineInstr *MI) {
52  SmallString<128> Str;
54 
55  switch (MI->getOpcode()) {
56  case ARC::DBG_VALUE:
57  llvm_unreachable("Should be handled target independently");
58  break;
59  }
60 
61  MCInst TmpInst;
62  MCInstLowering.Lower(MI, TmpInst);
63  EmitToStreamer(*OutStreamer, TmpInst);
64 }
65 
66 bool ARCAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
67  // Functions are 4-byte aligned.
68  MF.ensureAlignment(Align(4));
70 }
71 
72 // Force static initialization.
75 }
AsmPrinter.h
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
MachineInstr.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MachineFunction::ensureAlignment
void ensureAlignment(Align A)
ensureAlignment - Make sure the function is at least A bytes aligned.
Definition: MachineFunction.h:680
ARCSubtarget.h
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
ARCInstPrinter.h
MCInst.h
llvm::getTheARCTarget
Target & getTheARCTarget()
Definition: ARCTargetInfo.cpp:14
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::ARCMCInstLower
This class is used to lower an MachineInstr into an MCInst.
Definition: ARCMCInstLower.h:26
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::SmallString< 128 >
LLVMInitializeARCAsmPrinter
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCAsmPrinter()
Definition: ARCAsmPrinter.cpp:73
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:192
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
LLVM_EXTERNAL_VISIBILITY
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:132
ARCTargetInfo.h
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:79
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::AsmPrinter::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: AsmPrinter.h:341
MCAsmInfo.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
ARCTargetMachine.h
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
MCStreamer.h
ARC.h
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:658
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::RegisterAsmPrinter
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...
Definition: TargetRegistry.h:1338
ARCMCInstLower.h
raw_ostream.h
TargetRegistry.h