[NFC][MLIR][Linalg] Refactor linalg.matmul tablegen ODS and related C++ code. (#116377)
[llvm-project.git] / llvm / unittests / DebugInfo / DWARF / DwarfUtils.cpp
blobc35b3b6f5365b33dfba0a44b2a9af84aaca0f2c7
1 //===--- unittests/DebugInfo/DWARF/DwarfUtils.cpp ---------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #include "DwarfUtils.h"
10 #include "llvm/Config/llvm-config.h"
11 #include "llvm/MC/TargetRegistry.h"
12 #include "llvm/Support/TargetSelect.h"
13 #include "llvm/TargetParser/Host.h"
14 #include "llvm/TargetParser/Triple.h"
16 using namespace llvm;
18 static void initLLVMIfNeeded() {
19 static bool gInitialized = false;
20 if (!gInitialized) {
21 gInitialized = true;
22 InitializeAllTargets();
23 InitializeAllTargetMCs();
24 InitializeAllAsmPrinters();
25 InitializeAllAsmParsers();
29 Triple llvm::dwarf::utils::getNormalizedDefaultTargetTriple() {
30 Triple T(Triple::normalize(sys::getDefaultTargetTriple()));
32 return T;
35 Triple llvm::dwarf::utils::getDefaultTargetTripleForAddrSize(uint8_t AddrSize) {
36 Triple T = getNormalizedDefaultTargetTriple();
38 assert((AddrSize == 4 || AddrSize == 8) &&
39 "Only 32-bit/64-bit address size variants are supported");
41 // If a 32-bit/64-bit address size was specified, try to convert the triple
42 // if it is for the wrong variant.
43 if (AddrSize == 8 && T.isArch32Bit())
44 return T.get64BitArchVariant();
45 if (AddrSize == 4 && T.isArch64Bit())
46 return T.get32BitArchVariant();
47 return T;
50 bool llvm::dwarf::utils::isConfigurationSupported(Triple &T) {
51 initLLVMIfNeeded();
52 std::string Err;
53 const Target *TheTarget = TargetRegistry::lookupTarget(T.getTriple(), Err);
54 return TheTarget && TheTarget->hasMCAsmBackend();