Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp
35271 views
//===-- CodeGen/AsmPrinter/ARMException.cpp - ARM EHABI Exception Impl ----===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains support for writing DWARF exception info into asm files.9//10//===----------------------------------------------------------------------===//1112#include "DwarfException.h"13#include "llvm/ADT/Twine.h"14#include "llvm/CodeGen/AsmPrinter.h"15#include "llvm/CodeGen/MachineFunction.h"16#include "llvm/IR/Function.h"17#include "llvm/MC/MCAsmInfo.h"18#include "llvm/MC/MCStreamer.h"19using namespace llvm;2021ARMException::ARMException(AsmPrinter *A) : EHStreamer(A) {}2223ARMException::~ARMException() = default;2425ARMTargetStreamer &ARMException::getTargetStreamer() {26MCTargetStreamer &TS = *Asm->OutStreamer->getTargetStreamer();27return static_cast<ARMTargetStreamer &>(TS);28}2930void ARMException::beginFunction(const MachineFunction *MF) {31if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)32getTargetStreamer().emitFnStart();33// See if we need call frame info.34AsmPrinter::CFISection CFISecType = Asm->getFunctionCFISectionType(*MF);35assert(CFISecType != AsmPrinter::CFISection::EH &&36"non-EH CFI not yet supported in prologue with EHABI lowering");3738if (CFISecType == AsmPrinter::CFISection::Debug) {39if (!hasEmittedCFISections) {40if (Asm->getModuleCFISectionType() == AsmPrinter::CFISection::Debug)41Asm->OutStreamer->emitCFISections(false, true);42hasEmittedCFISections = true;43}4445shouldEmitCFI = true;46Asm->OutStreamer->emitCFIStartProc(false);47}48}4950void ARMException::markFunctionEnd() {51if (shouldEmitCFI)52Asm->OutStreamer->emitCFIEndProc();53}5455/// endFunction - Gather and emit post-function exception information.56///57void ARMException::endFunction(const MachineFunction *MF) {58ARMTargetStreamer &ATS = getTargetStreamer();59const Function &F = MF->getFunction();60const Function *Per = nullptr;61if (F.hasPersonalityFn())62Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());63bool forceEmitPersonality =64F.hasPersonalityFn() && !isNoOpWithoutInvoke(classifyEHPersonality(Per)) &&65F.needsUnwindTableEntry();66bool shouldEmitPersonality = forceEmitPersonality ||67!MF->getLandingPads().empty();68if (!Asm->MF->getFunction().needsUnwindTableEntry() &&69!shouldEmitPersonality)70ATS.emitCantUnwind();71else if (shouldEmitPersonality) {72// Emit references to personality.73if (Per) {74MCSymbol *PerSym = Asm->getSymbol(Per);75ATS.emitPersonality(PerSym);76}7778// Emit .handlerdata directive.79ATS.emitHandlerData();8081// Emit actual exception table82emitExceptionTable();83}8485if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)86ATS.emitFnEnd();87}8889void ARMException::emitTypeInfos(unsigned TTypeEncoding,90MCSymbol *TTBaseLabel) {91const MachineFunction *MF = Asm->MF;92const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();93const std::vector<unsigned> &FilterIds = MF->getFilterIds();9495bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();9697int Entry = 0;98// Emit the Catch TypeInfos.99if (VerboseAsm && !TypeInfos.empty()) {100Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");101Asm->OutStreamer->addBlankLine();102Entry = TypeInfos.size();103}104105for (const GlobalValue *GV : reverse(TypeInfos)) {106if (VerboseAsm)107Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));108Asm->emitTTypeReference(GV, TTypeEncoding);109}110111Asm->OutStreamer->emitLabel(TTBaseLabel);112113// Emit the Exception Specifications.114if (VerboseAsm && !FilterIds.empty()) {115Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");116Asm->OutStreamer->addBlankLine();117Entry = 0;118}119for (std::vector<unsigned>::const_iterator120I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {121unsigned TypeID = *I;122if (VerboseAsm) {123--Entry;124if (TypeID != 0)125Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));126}127128Asm->emitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),129TTypeEncoding);130}131}132133134