blob: 46c2626f89fe3bd314b22545a2aac5b83d756167 [file] [log] [blame]
Eli Bendersky6aa4fc32013-02-19 16:47:59 +00001//===-- ARMAsmPrinter.h - ARM implementation of AsmPrinter ------*- C++ -*-===//
Jim Grosbachd0d13292010-12-01 03:45:07 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Jim Grosbachd0d13292010-12-01 03:45:07 +00009
10#ifndef ARMASMPRINTER_H
11#define ARMASMPRINTER_H
12
Craig Toppera9253262014-03-22 23:51:00 +000013#include "ARMSubtarget.h"
Jim Grosbachd0d13292010-12-01 03:45:07 +000014#include "llvm/CodeGen/AsmPrinter.h"
Craig Toppera9253262014-03-22 23:51:00 +000015#include "llvm/Target/TargetMachine.h"
Jim Grosbachd0d13292010-12-01 03:45:07 +000016
17namespace llvm {
18
Craig Toppera9253262014-03-22 23:51:00 +000019class ARMFunctionInfo;
Jim Grosbach95dee402011-07-08 17:40:42 +000020class MCOperand;
Craig Toppera9253262014-03-22 23:51:00 +000021class MachineConstantPool;
22class MachineOperand;
Jim Grosbach95dee402011-07-08 17:40:42 +000023
Jim Grosbachd0d13292010-12-01 03:45:07 +000024namespace ARM {
25 enum DW_ISA {
26 DW_ISA_ARM_thumb = 1,
27 DW_ISA_ARM_arm = 2
28 };
29}
30
31class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
32
33 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
34 /// make the right decision when printing asm code for different targets.
35 const ARMSubtarget *Subtarget;
36
37 /// AFI - Keep a pointer to ARMFunctionInfo for the current
38 /// MachineFunction.
39 ARMFunctionInfo *AFI;
40
41 /// MCP - Keep a pointer to constantpool entries of the current
42 /// MachineFunction.
43 const MachineConstantPool *MCP;
44
Jim Grosbach4b63d2a2012-05-18 19:12:01 +000045 /// InConstantPool - Maintain state when emitting a sequence of constant
46 /// pool entries so we can properly mark them as data regions.
47 bool InConstantPool;
Jim Grosbachd0d13292010-12-01 03:45:07 +000048public:
49 explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
Jim Grosbach4b63d2a2012-05-18 19:12:01 +000050 : AsmPrinter(TM, Streamer), AFI(NULL), MCP(NULL), InConstantPool(false) {
Jim Grosbachd0d13292010-12-01 03:45:07 +000051 Subtarget = &TM.getSubtarget<ARMSubtarget>();
52 }
53
Craig Topper24e685f2014-03-10 05:29:18 +000054 const char *getPassName() const override {
Eli Bendersky6aa4fc32013-02-19 16:47:59 +000055 return "ARM Assembly / Object Emitter";
Jim Grosbachd0d13292010-12-01 03:45:07 +000056 }
57
58 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
59 const char *Modifier = 0);
60
Craig Topper24e685f2014-03-10 05:29:18 +000061 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
62 unsigned AsmVariant, const char *ExtraCode,
63 raw_ostream &O) override;
64 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
65 unsigned AsmVariant, const char *ExtraCode,
66 raw_ostream &O) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000067
Craig Topper24e685f2014-03-10 05:29:18 +000068 void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
69 const MCSubtargetInfo *EndInfo) const override;
Rafael Espindola65fd0a82014-01-24 15:47:54 +000070
Jim Grosbachd0d13292010-12-01 03:45:07 +000071 void EmitJumpTable(const MachineInstr *MI);
72 void EmitJump2Table(const MachineInstr *MI);
Craig Topper24e685f2014-03-10 05:29:18 +000073 void EmitInstruction(const MachineInstr *MI) override;
74 bool runOnMachineFunction(MachineFunction &F) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000075
Craig Topper24e685f2014-03-10 05:29:18 +000076 void EmitConstantPool() override {
Craig Topperdb092d72012-10-09 04:23:49 +000077 // we emit constant pools customly!
78 }
Craig Topper24e685f2014-03-10 05:29:18 +000079 void EmitFunctionBodyEnd() override;
80 void EmitFunctionEntryLabel() override;
81 void EmitStartOfAsmFile(Module &M) override;
82 void EmitEndOfAsmFile(Module &M) override;
83 void EmitXXStructor(const Constant *CV) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +000084
Jim Grosbach95dee402011-07-08 17:40:42 +000085 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
86 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
87
Jim Grosbachd0d13292010-12-01 03:45:07 +000088private:
89 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
90 void emitAttributes();
91
Anton Korobeynikov62acecd2011-01-01 20:38:38 +000092 // Generic helper used to emit e.g. ARMv5 mul pseudos
93 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc);
94
Anton Korobeynikove7410dd2011-03-05 18:43:32 +000095 void EmitUnwindingInstruction(const MachineInstr *MI);
96
Jim Grosbach95dee402011-07-08 17:40:42 +000097 // emitPseudoExpansionLowering - tblgen'erated.
98 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
99 const MachineInstr *MI);
100
Jim Grosbachd0d13292010-12-01 03:45:07 +0000101public:
Craig Topper24e685f2014-03-10 05:29:18 +0000102 unsigned getISAEncoding() override {
Jim Grosbachd0d13292010-12-01 03:45:07 +0000103 // ARM/Darwin adds ISA to the DWARF info for each function.
Tim Northoverd6a729b2014-01-06 14:28:05 +0000104 if (!Subtarget->isTargetMachO())
Jim Grosbachd0d13292010-12-01 03:45:07 +0000105 return 0;
106 return Subtarget->isThumb() ?
Craig Topperf6e7e122012-03-27 07:21:54 +0000107 ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000108 }
109
Craig Topperdb092d72012-10-09 04:23:49 +0000110private:
Jim Grosbach95dee402011-07-08 17:40:42 +0000111 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
Jim Grosbachd0d13292010-12-01 03:45:07 +0000112 MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const;
113
Dmitri Gribenko0011bbf2012-11-15 16:51:49 +0000114 MCSymbol *GetARMSJLJEHLabel() const;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000115
Tim Northoverdb962e2c2013-11-25 16:24:52 +0000116 MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);
Jim Grosbach95dee402011-07-08 17:40:42 +0000117
Craig Topperdb092d72012-10-09 04:23:49 +0000118public:
Jim Grosbachd0d13292010-12-01 03:45:07 +0000119 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
120 /// the .s file.
Craig Topper24e685f2014-03-10 05:29:18 +0000121 void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
Jim Grosbachd0d13292010-12-01 03:45:07 +0000122};
123} // end namespace llvm
124
125#endif