Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp
Line
Count
Source
1
//===-- CodeGen/AsmPrinter/ARMException.cpp - ARM EHABI Exception Impl ----===//
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 support for writing DWARF exception info into asm files.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "DwarfException.h"
14
#include "llvm/ADT/Twine.h"
15
#include "llvm/CodeGen/AsmPrinter.h"
16
#include "llvm/CodeGen/MachineFunction.h"
17
#include "llvm/IR/DataLayout.h"
18
#include "llvm/IR/Mangler.h"
19
#include "llvm/IR/Module.h"
20
#include "llvm/MC/MCAsmInfo.h"
21
#include "llvm/MC/MCExpr.h"
22
#include "llvm/MC/MCSection.h"
23
#include "llvm/MC/MCStreamer.h"
24
#include "llvm/MC/MCSymbol.h"
25
#include "llvm/Support/FormattedStream.h"
26
#include "llvm/Target/TargetOptions.h"
27
using namespace llvm;
28
29
2.16k
ARMException::ARMException(AsmPrinter *A) : DwarfCFIExceptionBase(A) {}
30
31
2.14k
ARMException::~ARMException() {}
32
33
28.2k
ARMTargetStreamer &ARMException::getTargetStreamer() {
34
28.2k
  MCTargetStreamer &TS = *Asm->OutStreamer->getTargetStreamer();
35
28.2k
  return static_cast<ARMTargetStreamer &>(TS);
36
28.2k
}
37
38
14.1k
void ARMException::beginFunction(const MachineFunction *MF) {
39
14.1k
  if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
40
14.1k
    getTargetStreamer().emitFnStart();
41
14.1k
  // See if we need call frame info.
42
14.1k
  AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
43
14.1k
  assert(MoveType != AsmPrinter::CFI_M_EH &&
44
14.1k
         "non-EH CFI not yet supported in prologue with EHABI lowering");
45
14.1k
46
14.1k
  if (MoveType == AsmPrinter::CFI_M_Debug) {
47
60
    if (!hasEmittedCFISections) {
48
32
      if (Asm->needsOnlyDebugCFIMoves())
49
32
        Asm->OutStreamer->EmitCFISections(false, true);
50
32
      hasEmittedCFISections = true;
51
32
    }
52
60
53
60
    shouldEmitCFI = true;
54
60
    Asm->OutStreamer->EmitCFIStartProc(false);
55
60
  }
56
14.1k
}
57
58
/// endFunction - Gather and emit post-function exception information.
59
///
60
14.1k
void ARMException::endFunction(const MachineFunction *MF) {
61
14.1k
  ARMTargetStreamer &ATS = getTargetStreamer();
62
14.1k
  const Function &F = MF->getFunction();
63
14.1k
  const Function *Per = nullptr;
64
14.1k
  if (F.hasPersonalityFn())
65
31
    Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());
66
14.1k
  bool forceEmitPersonality =
67
14.1k
    F.hasPersonalityFn() && 
!isNoOpWithoutInvoke(classifyEHPersonality(Per))31
&&
68
14.1k
    
F.needsUnwindTableEntry()1
;
69
14.1k
  bool shouldEmitPersonality = forceEmitPersonality ||
70
14.1k
    
!MF->getLandingPads().empty()14.1k
;
71
14.1k
  if (!Asm->MF->getFunction().needsUnwindTableEntry() &&
72
14.1k
      
!shouldEmitPersonality4.34k
)
73
4.34k
    ATS.emitCantUnwind();
74
9.79k
  else if (shouldEmitPersonality) {
75
31
    // Emit references to personality.
76
31
    if (Per) {
77
31
      MCSymbol *PerSym = Asm->getSymbol(Per);
78
31
      Asm->OutStreamer->EmitSymbolAttribute(PerSym, MCSA_Global);
79
31
      ATS.emitPersonality(PerSym);
80
31
    }
81
31
82
31
    // Emit .handlerdata directive.
83
31
    ATS.emitHandlerData();
84
31
85
31
    // Emit actual exception table
86
31
    emitExceptionTable();
87
31
  }
88
14.1k
89
14.1k
  if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
90
14.1k
    ATS.emitFnEnd();
91
14.1k
}
92
93
void ARMException::emitTypeInfos(unsigned TTypeEncoding,
94
30
                                 MCSymbol *TTBaseLabel) {
95
30
  const MachineFunction *MF = Asm->MF;
96
30
  const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();
97
30
  const std::vector<unsigned> &FilterIds = MF->getFilterIds();
98
30
99
30
  bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
100
30
101
30
  int Entry = 0;
102
30
  // Emit the Catch TypeInfos.
103
30
  if (VerboseAsm && 
!TypeInfos.empty()29
) {
104
29
    Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");
105
29
    Asm->OutStreamer->AddBlankLine();
106
29
    Entry = TypeInfos.size();
107
29
  }
108
30
109
30
  for (const GlobalValue *GV : reverse(TypeInfos)) {
110
30
    if (VerboseAsm)
111
29
      Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
112
30
    Asm->EmitTTypeReference(GV, TTypeEncoding);
113
30
  }
114
30
115
30
  Asm->OutStreamer->EmitLabel(TTBaseLabel);
116
30
117
30
  // Emit the Exception Specifications.
118
30
  if (VerboseAsm && 
!FilterIds.empty()29
) {
119
1
    Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");
120
1
    Asm->OutStreamer->AddBlankLine();
121
1
    Entry = 0;
122
1
  }
123
30
  for (std::vector<unsigned>::const_iterator
124
32
         I = FilterIds.begin(), E = FilterIds.end(); I < E; 
++I2
) {
125
2
    unsigned TypeID = *I;
126
2
    if (VerboseAsm) {
127
2
      --Entry;
128
2
      if (TypeID != 0)
129
1
        Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));
130
2
    }
131
2
132
2
    Asm->EmitTTypeReference((TypeID == 0 ? 
nullptr1
:
TypeInfos[TypeID - 1]1
),
133
2
                            TTypeEncoding);
134
2
  }
135
30
}