| 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 | |
| 15 | llvm::Constant *mlir::LLVM::createSourceLocStrFromLocation( |
| 16 | Location loc, llvm::OpenMPIRBuilder &builder, StringRef name, |
| 17 | uint32_t &strLen, bool forOffloadMap) { |
| 18 | if (auto fileLoc = dyn_cast<FileLineColLoc>(Val&: loc)) { |
| 19 | StringRef fileName = fileLoc.getFilename(); |
| 20 | unsigned lineNo = fileLoc.getLine(); |
| 21 | unsigned colNo = fileLoc.getColumn(); |
| 22 | if (forOffloadMap) |
| 23 | return builder.getOrCreateSrcLocStr(FunctionName: fileName, FileName: name, Line: lineNo, Column: colNo, |
| 24 | SrcLocStrSize&: strLen); |
| 25 | return builder.getOrCreateSrcLocStr(FunctionName: name, FileName: fileName, Line: lineNo, Column: colNo, SrcLocStrSize&: strLen); |
| 26 | } |
| 27 | std::string locStr; |
| 28 | llvm::raw_string_ostream locOS(locStr); |
| 29 | locOS << loc; |
| 30 | return builder.getOrCreateSrcLocStr(LocStr: locStr, SrcLocStrSize&: strLen); |
| 31 | } |
| 32 | |
| 33 | llvm::Constant *mlir::LLVM::createMappingInformation( |
| 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>(Val&: loc)) { |
| 39 | childLoc = nameLoc.getChildLoc(); |
| 40 | if (name.empty()) |
| 41 | name = nameLoc.getName(); |
| 42 | } |
| 43 | if (name.empty()) |
| 44 | name = "unknown" ; |
| 45 | return createSourceLocStrFromLocation(loc: childLoc, builder, name, strLen, |
| 46 | /*forOffloadMap=*/true); |
| 47 | } |
| 48 | |