/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/SystemZ/SystemZMCInstLower.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- SystemZMCInstLower.cpp - Lower MachineInstr to MCInst -------------===// |
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 | | #include "SystemZMCInstLower.h" |
10 | | #include "SystemZAsmPrinter.h" |
11 | | #include "llvm/IR/Mangler.h" |
12 | | #include "llvm/MC/MCExpr.h" |
13 | | #include "llvm/MC/MCInst.h" |
14 | | #include "llvm/MC/MCStreamer.h" |
15 | | |
16 | | using namespace llvm; |
17 | | |
18 | | // Return the VK_* enumeration for MachineOperand target flags Flags. |
19 | 2.81k | static MCSymbolRefExpr::VariantKind getVariantKind(unsigned Flags) { |
20 | 2.81k | switch (Flags & SystemZII::MO_SYMBOL_MODIFIER) { |
21 | 2.81k | case 0: |
22 | 2.58k | return MCSymbolRefExpr::VK_None; |
23 | 2.81k | case SystemZII::MO_GOT: |
24 | 230 | return MCSymbolRefExpr::VK_GOT; |
25 | 2.81k | case SystemZII::MO_INDNTPOFF: |
26 | 1 | return MCSymbolRefExpr::VK_INDNTPOFF; |
27 | 0 | } |
28 | 0 | llvm_unreachable("Unrecognised MO_ACCESS_MODEL"); |
29 | 0 | } |
30 | | |
31 | | SystemZMCInstLower::SystemZMCInstLower(MCContext &ctx, |
32 | | SystemZAsmPrinter &asmprinter) |
33 | 60.4k | : Ctx(ctx), AsmPrinter(asmprinter) {} |
34 | | |
35 | | const MCExpr * |
36 | | SystemZMCInstLower::getExpr(const MachineOperand &MO, |
37 | 3.80k | MCSymbolRefExpr::VariantKind Kind) const { |
38 | 3.80k | const MCSymbol *Symbol; |
39 | 3.80k | bool HasOffset = true; |
40 | 3.80k | switch (MO.getType()) { |
41 | 3.80k | case MachineOperand::MO_MachineBasicBlock: |
42 | 1.26k | Symbol = MO.getMBB()->getSymbol(); |
43 | 1.26k | HasOffset = false; |
44 | 1.26k | break; |
45 | 3.80k | |
46 | 3.80k | case MachineOperand::MO_GlobalAddress: |
47 | 1.26k | Symbol = AsmPrinter.getSymbol(MO.getGlobal()); |
48 | 1.26k | break; |
49 | 3.80k | |
50 | 3.80k | case MachineOperand::MO_ExternalSymbol: |
51 | 442 | Symbol = AsmPrinter.GetExternalSymbolSymbol(MO.getSymbolName()); |
52 | 442 | break; |
53 | 3.80k | |
54 | 3.80k | case MachineOperand::MO_JumpTableIndex: |
55 | 3 | Symbol = AsmPrinter.GetJTISymbol(MO.getIndex()); |
56 | 3 | HasOffset = false; |
57 | 3 | break; |
58 | 3.80k | |
59 | 3.80k | case MachineOperand::MO_ConstantPoolIndex: |
60 | 824 | Symbol = AsmPrinter.GetCPISymbol(MO.getIndex()); |
61 | 824 | break; |
62 | 3.80k | |
63 | 3.80k | case MachineOperand::MO_BlockAddress: |
64 | 1 | Symbol = AsmPrinter.GetBlockAddressSymbol(MO.getBlockAddress()); |
65 | 1 | break; |
66 | 3.80k | |
67 | 3.80k | default: |
68 | 0 | llvm_unreachable("unknown operand type"); |
69 | 3.80k | } |
70 | 3.80k | const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, Kind, Ctx); |
71 | 3.80k | if (HasOffset) |
72 | 2.53k | if (int64_t Offset = MO.getOffset()) { |
73 | 7 | const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, Ctx); |
74 | 7 | Expr = MCBinaryExpr::createAdd(Expr, OffsetExpr, Ctx); |
75 | 7 | } |
76 | 3.80k | return Expr; |
77 | 3.80k | } |
78 | | |
79 | 173k | MCOperand SystemZMCInstLower::lowerOperand(const MachineOperand &MO) const { |
80 | 173k | switch (MO.getType()) { |
81 | 173k | case MachineOperand::MO_Register: |
82 | 126k | return MCOperand::createReg(MO.getReg()); |
83 | 173k | |
84 | 173k | case MachineOperand::MO_Immediate: |
85 | 43.8k | return MCOperand::createImm(MO.getImm()); |
86 | 173k | |
87 | 173k | default: { |
88 | 2.81k | MCSymbolRefExpr::VariantKind Kind = getVariantKind(MO.getTargetFlags()); |
89 | 2.81k | return MCOperand::createExpr(getExpr(MO, Kind)); |
90 | 173k | } |
91 | 173k | } |
92 | 173k | } |
93 | | |
94 | 49.6k | void SystemZMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const { |
95 | 49.6k | OutMI.setOpcode(MI->getOpcode()); |
96 | 247k | for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I198k ) { |
97 | 198k | const MachineOperand &MO = MI->getOperand(I); |
98 | 198k | // Ignore all implicit register operands. |
99 | 198k | if (!MO.isReg() || !MO.isImplicit()151k ) |
100 | 173k | OutMI.addOperand(lowerOperand(MO)); |
101 | 198k | } |
102 | 49.6k | } |