1//===- OpenMPCommon.cpp - Utils for translating MLIR dialect to LLVM IR----===//
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 defines general utilities for MLIR Dialect translations to LLVM IR.
10//
11//===----------------------------------------------------------------------===//
12
13#include "mlir/Target/LLVMIR/Dialect/OpenMPCommon.h"
14
15llvm::Constant *
16mlir::LLVM::createSourceLocStrFromLocation(Location loc,
17 llvm::OpenMPIRBuilder &builder,
18 StringRef name, uint32_t &strLen) {
19 if (auto fileLoc = dyn_cast<FileLineColLoc>(loc)) {
20 StringRef fileName = fileLoc.getFilename();
21 unsigned lineNo = fileLoc.getLine();
22 unsigned colNo = fileLoc.getColumn();
23 return builder.getOrCreateSrcLocStr(FunctionName: name, FileName: fileName, Line: lineNo, Column: colNo, SrcLocStrSize&: strLen);
24 }
25 std::string locStr;
26 llvm::raw_string_ostream locOS(locStr);
27 locOS << loc;
28 return builder.getOrCreateSrcLocStr(LocStr: locOS.str(), SrcLocStrSize&: strLen);
29}
30
31llvm::Constant *
32mlir::LLVM::createMappingInformation(Location loc,
33 llvm::OpenMPIRBuilder &builder) {
34 uint32_t strLen;
35 if (auto nameLoc = dyn_cast<NameLoc>(loc)) {
36 StringRef name = nameLoc.getName();
37 return createSourceLocStrFromLocation(nameLoc.getChildLoc(), builder, name,
38 strLen);
39 }
40 return createSourceLocStrFromLocation(loc, builder, name: "unknown", strLen);
41}
42

source code of mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp