MLIR 24.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
34 Location loc, llvm::OpenMPIRBuilder &builder, StringRef mapName) {
35 uint32_t strLen;
36 Location childLoc = loc;
37 StringRef name = mapName;
38 if (auto nameLoc = dyn_cast<NameLoc>(loc)) {
39 childLoc = nameLoc.getChildLoc();
40 if (name.empty())
41 name = nameLoc.getName();
42 }
43 if (name.empty())
44 name = "unknown";
45 return createSourceLocStrFromLocation(childLoc, builder, name, strLen,
46 /*forOffloadMap=*/true);
47}
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, StringRef mapName={})
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.