MLIR  19.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 
15 llvm::Constant *
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(name, fileName, lineNo, colNo, strLen);
24  }
25  std::string locStr;
26  llvm::raw_string_ostream locOS(locStr);
27  locOS << loc;
28  return builder.getOrCreateSrcLocStr(locOS.str(), strLen);
29 }
30 
31 llvm::Constant *
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, "unknown", strLen);
41 }
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
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)
Create a constant string location from the MLIR Location information.