LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SystemZAsmPrinter.cpp
Go to the documentation of this file.
1 //===-- SystemZAsmPrinter.cpp - SystemZ LLVM assembly printer -------------===//
2 //
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 //===----------------------------------------------------------------------===//
9 //
10 // Streams SystemZ assembly language and associated data, in the form of
11 // MCInsts and MCExprs respectively.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "SystemZAsmPrinter.h"
18 #include "SystemZMCInstLower.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/MC/MCInstBuilder.h"
23 #include "llvm/MC/MCStreamer.h"
25 #include "llvm/Target/Mangler.h"
26 
27 using namespace llvm;
28 
29 // Return an RI instruction like MI with opcode Opcode, but with the
30 // GR64 register operands turned into GR32s.
31 static MCInst lowerRILow(const MachineInstr *MI, unsigned Opcode) {
32  if (MI->isCompare())
33  return MCInstBuilder(Opcode)
35  .addImm(MI->getOperand(1).getImm());
36  else
37  return MCInstBuilder(Opcode)
40  .addImm(MI->getOperand(2).getImm());
41 }
42 
43 // Return an RI instruction like MI with opcode Opcode, but with the
44 // GR64 register operands turned into GRH32s.
45 static MCInst lowerRIHigh(const MachineInstr *MI, unsigned Opcode) {
46  if (MI->isCompare())
47  return MCInstBuilder(Opcode)
49  .addImm(MI->getOperand(1).getImm());
50  else
51  return MCInstBuilder(Opcode)
54  .addImm(MI->getOperand(2).getImm());
55 }
56 
57 // Return an RI instruction like MI with opcode Opcode, but with the
58 // R2 register turned into a GR64.
59 static MCInst lowerRIEfLow(const MachineInstr *MI, unsigned Opcode) {
60  return MCInstBuilder(Opcode)
61  .addReg(MI->getOperand(0).getReg())
62  .addReg(MI->getOperand(1).getReg())
63  .addReg(SystemZMC::getRegAsGR64(MI->getOperand(2).getReg()))
64  .addImm(MI->getOperand(3).getImm())
65  .addImm(MI->getOperand(4).getImm())
66  .addImm(MI->getOperand(5).getImm());
67 }
68 
70  SystemZMCInstLower Lower(MF->getContext(), *this);
71  MCInst LoweredMI;
72  switch (MI->getOpcode()) {
73  case SystemZ::Return:
74  LoweredMI = MCInstBuilder(SystemZ::BR).addReg(SystemZ::R14D);
75  break;
76 
77  case SystemZ::CallBRASL:
78  LoweredMI = MCInstBuilder(SystemZ::BRASL)
79  .addReg(SystemZ::R14D)
80  .addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_PLT));
81  break;
82 
83  case SystemZ::CallBASR:
84  LoweredMI = MCInstBuilder(SystemZ::BASR)
85  .addReg(SystemZ::R14D)
86  .addReg(MI->getOperand(0).getReg());
87  break;
88 
89  case SystemZ::CallJG:
90  LoweredMI = MCInstBuilder(SystemZ::JG)
91  .addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_PLT));
92  break;
93 
94  case SystemZ::CallBR:
95  LoweredMI = MCInstBuilder(SystemZ::BR).addReg(SystemZ::R1D);
96  break;
97 
98  case SystemZ::IILF64:
99  LoweredMI = MCInstBuilder(SystemZ::IILF)
101  .addImm(MI->getOperand(2).getImm());
102  break;
103 
104  case SystemZ::IIHF64:
105  LoweredMI = MCInstBuilder(SystemZ::IIHF)
107  .addImm(MI->getOperand(2).getImm());
108  break;
109 
110  case SystemZ::RISBHH:
111  case SystemZ::RISBHL:
112  LoweredMI = lowerRIEfLow(MI, SystemZ::RISBHG);
113  break;
114 
115  case SystemZ::RISBLH:
116  case SystemZ::RISBLL:
117  LoweredMI = lowerRIEfLow(MI, SystemZ::RISBLG);
118  break;
119 
120 #define LOWER_LOW(NAME) \
121  case SystemZ::NAME##64: LoweredMI = lowerRILow(MI, SystemZ::NAME); break
122 
123  LOWER_LOW(IILL);
124  LOWER_LOW(IILH);
125  LOWER_LOW(TMLL);
126  LOWER_LOW(TMLH);
127  LOWER_LOW(NILL);
128  LOWER_LOW(NILH);
129  LOWER_LOW(NILF);
130  LOWER_LOW(OILL);
131  LOWER_LOW(OILH);
132  LOWER_LOW(OILF);
133  LOWER_LOW(XILF);
134 
135 #undef LOWER_LOW
136 
137 #define LOWER_HIGH(NAME) \
138  case SystemZ::NAME##64: LoweredMI = lowerRIHigh(MI, SystemZ::NAME); break
139 
140  LOWER_HIGH(IIHL);
141  LOWER_HIGH(IIHH);
142  LOWER_HIGH(TMHL);
143  LOWER_HIGH(TMHH);
144  LOWER_HIGH(NIHL);
145  LOWER_HIGH(NIHH);
146  LOWER_HIGH(NIHF);
147  LOWER_HIGH(OIHL);
148  LOWER_HIGH(OIHH);
149  LOWER_HIGH(OIHF);
150  LOWER_HIGH(XIHF);
151 
152 #undef LOWER_HIGH
153 
154  default:
155  Lower.lower(MI, LoweredMI);
156  break;
157  }
158  OutStreamer.EmitInstruction(LoweredMI);
159 }
160 
161 // Convert a SystemZ-specific constant pool modifier into the associated
162 // MCSymbolRefExpr variant kind.
165  switch (Modifier) {
167  }
168  llvm_unreachable("Invalid SystemCPModifier!");
169 }
170 
174  static_cast<SystemZConstantPoolValue*>(MCPV);
175 
176  const MCExpr *Expr =
179  OutContext);
180  uint64_t Size = TM.getDataLayout()->getTypeAllocSize(ZCPV->getType());
181 
182  OutStreamer.EmitValue(Expr, Size);
183 }
184 
186  unsigned OpNo,
187  unsigned AsmVariant,
188  const char *ExtraCode,
189  raw_ostream &OS) {
190  if (ExtraCode && *ExtraCode == 'n') {
191  if (!MI->getOperand(OpNo).isImm())
192  return true;
193  OS << -int64_t(MI->getOperand(OpNo).getImm());
194  } else {
195  SystemZMCInstLower Lower(MF->getContext(), *this);
196  MCOperand MO(Lower.lowerOperand(MI->getOperand(OpNo)));
198  }
199  return false;
200 }
201 
203  unsigned OpNo,
204  unsigned AsmVariant,
205  const char *ExtraCode,
206  raw_ostream &OS) {
208  MI->getOperand(OpNo + 1).getImm(),
209  MI->getOperand(OpNo + 2).getReg(), OS);
210  return false;
211 }
212 
214  if (Subtarget->isTargetELF()) {
215  const TargetLoweringObjectFileELF &TLOFELF =
216  static_cast<const TargetLoweringObjectFileELF &>(getObjFileLowering());
217 
219 
220  // Output stubs for external and common global variables.
222  if (!Stubs.empty()) {
224  const DataLayout *TD = TM.getDataLayout();
225 
226  for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
227  OutStreamer.EmitLabel(Stubs[i].first);
228  OutStreamer.EmitSymbolValue(Stubs[i].second.getPointer(),
229  TD->getPointerSize(0));
230  }
231  Stubs.clear();
232  }
233  }
234 }
235 
236 // Force static initialization.
239 }
#define LOWER_LOW(NAME)
static void printAddress(unsigned Base, int64_t Disp, unsigned Index, raw_ostream &O)
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:277
The main container class for the LLVM Intermediate Representation.
Definition: Module.h:112
MCContext & OutContext
Definition: AsmPrinter.h:72
unsigned getPointerSize(unsigned AS=0) const
Definition: DataLayout.h:261
void LLVMInitializeSystemZAsmPrinter()
const MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:81
virtual void EmitInstruction(const MCInst &Inst)=0
Target TheSystemZTarget
std::vector< std::pair< MCSymbol *, StubValueTy > > SymbolListTy
unsigned getRegAsGRH32(unsigned Reg)
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
unsigned getRegAsGR32(unsigned Reg)
#define llvm_unreachable(msg)
virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) LLVM_OVERRIDE
void SwitchSection(const MCSection *Section, const MCExpr *Subsection=0)
Definition: MCStreamer.h:284
int getOpcode() const
Definition: MachineInstr.h:261
MCStreamer & OutStreamer
Definition: AsmPrinter.h:78
int64_t getImm() const
MCContext & getContext() const
void EmitValue(const MCExpr *Value, unsigned Size)
Definition: MCStreamer.cpp:141
MachineModuleInfo * MMI
MMI - This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:84
MCInstBuilder & addExpr(const MCExpr *Val)
Add a new MCExpr operand.
Definition: MCInstBuilder.h:50
SymbolListTy GetGVStubList() const
Accessor methods to return the set of stubs in sorted order.
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:270
MCInstBuilder & addReg(unsigned Reg)
Add a new register operand.
Definition: MCInstBuilder.h:32
Control flow instructions. These all have token chains.
Definition: ISDOpcodes.h:475
static MCInst lowerRIEfLow(const MachineInstr *MI, unsigned Opcode)
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:267
TargetMachine & TM
Definition: AsmPrinter.h:62
static MCInst lowerRIHigh(const MachineInstr *MI, unsigned Opcode)
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) LLVM_OVERRIDE
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
Definition: MCInstBuilder.h:38
static void printOperand(const MCOperand &MO, raw_ostream &O)
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) LLVM_OVERRIDE
const GlobalValue * getGlobalValue() const
virtual void EmitLabel(MCSymbol *Symbol)
Definition: MCStreamer.cpp:212
uint64_t getTypeAllocSize(Type *Ty) const
Definition: DataLayout.h:326
Instr is a return instruction.
Definition: GCMetadata.h:52
static MCSymbolRefExpr::VariantKind getModifierVariantKind(SystemZCP::SystemZCPModifier Modifier)
unsigned getRegAsGR64(unsigned Reg)
bool isCompare(QueryType Type=IgnoreBundle) const
isCompare - Return true if this instruction is a comparison.
Definition: MachineInstr.h:411
static MCInst lowerRILow(const MachineInstr *MI, unsigned Opcode)
SystemZCP::SystemZCPModifier getModifier() const
virtual const DataLayout * getDataLayout() const
unsigned getReg() const
getReg - Returns the register number.
const TargetLoweringObjectFile & getObjFileLowering() const
getObjFileLowering - Return information about object file lowering.
Definition: AsmPrinter.cpp:129
#define LOWER_HIGH(NAME)
virtual void EmitInstruction(const MachineInstr *MI) LLVM_OVERRIDE
EmitInstruction - Targets should implement this to emit instructions.
virtual void EmitEndOfAsmFile(Module &M) LLVM_OVERRIDE
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size)
Definition: MCStreamer.cpp:145
const MCSection * getDataRelSection() const
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD