MLIR 23.0.0git
OpenMPCommon.cpp
Go to the documentation of this file.
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
14
16 Location loc, llvm::OpenMPIRBuilder &builder, StringRef name,
17 uint32_t &strLen, bool forOffloadMap) {
18 if (auto fileLoc = dyn_cast<FileLineColLoc>(loc)) {
19 StringRef fileName = fileLoc.getFilename();
20 unsigned lineNo = fileLoc.getLine();
21 unsigned colNo = fileLoc.getColumn();
22 if (forOffloadMap)
23 return builder.getOrCreateSrcLocStr(fileName, name, lineNo, colNo,
24 strLen);
25 return builder.getOrCreateSrcLocStr(name, fileName, lineNo, colNo, strLen);
26 }
27 std::string locStr;
28 llvm::raw_string_ostream locOS(locStr);
29 locOS << loc;
30 return builder.getOrCreateSrcLocStr(locStr, strLen);
31}
32
33llvm::Constant *
35 llvm::OpenMPIRBuilder &builder) {
36 uint32_t strLen;
37 if (auto nameLoc = dyn_cast<NameLoc>(loc)) {
38 StringRef name = nameLoc.getName();
39 return createSourceLocStrFromLocation(nameLoc.getChildLoc(), builder, name,
40 strLen, /*forOffloadMap=*/true);
41 }
42 return createSourceLocStrFromLocation(loc, builder, "unknown", strLen,
43 /*forOffloadMap=*/true);
44}
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
llvm::Constant * createMappingInformation(Location loc, llvm::OpenMPIRBuilder &builder)
Create a constant string representing the mapping information extracted from the MLIR location inform...
llvm::Constant * createSourceLocStrFromLocation(Location loc, llvm::OpenMPIRBuilder &builder, StringRef name, uint32_t &strLen, bool ForOffloadMap=false)
Create a constant string location from the MLIR Location information.