LLVM  10.0.0
OMPConstants.cpp
Go to the documentation of this file.
1 //===- OMPConstants.cpp - Helpers related to OpenMP code generation ---===//
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 //===----------------------------------------------------------------------===//
10 
12 
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/IR/Module.h"
16 #include "llvm/IR/Type.h"
17 
18 using namespace llvm;
19 using namespace omp;
20 using namespace types;
21 
24 #define OMP_DIRECTIVE(Enum, Str) .Case(Str, Enum)
25 #include "llvm/Frontend/OpenMP/OMPKinds.def"
26  .Default(OMPD_unknown);
27 }
28 
30  switch (Kind) {
31 #define OMP_DIRECTIVE(Enum, Str) \
32  case Enum: \
33  return Str;
34 #include "llvm/Frontend/OpenMP/OMPKinds.def"
35  }
36  llvm_unreachable("Invalid OpenMP directive kind");
37 }
38 
39 /// Declarations for LLVM-IR types (simple, function and structure) are
40 /// generated below. Their names are defined and used in OpenMPKinds.def. Here
41 /// we provide the declarations, the initializeTypes function will provide the
42 /// values.
43 ///
44 ///{
45 
46 #define OMP_TYPE(VarName, InitValue) Type *llvm::omp::types::VarName = nullptr;
47 #define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
48  FunctionType *llvm::omp::types::VarName = nullptr; \
49  PointerType *llvm::omp::types::VarName##Ptr = nullptr;
50 #define OMP_STRUCT_TYPE(VarName, StrName, ...) \
51  StructType *llvm::omp::types::VarName = nullptr; \
52  PointerType *llvm::omp::types::VarName##Ptr = nullptr;
53 #include "llvm/Frontend/OpenMP/OMPKinds.def"
54 
55 ///}
56 
58  if (Void)
59  return;
60 
61  LLVMContext &Ctx = M.getContext();
62  // Create all simple and struct types exposed by the runtime and remember
63  // the llvm::PointerTypes of them for easy access later.
64  StructType *T;
65 #define OMP_TYPE(VarName, InitValue) VarName = InitValue;
66 #define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
67  VarName = FunctionType::get(ReturnType, {__VA_ARGS__}, IsVarArg); \
68  VarName##Ptr = PointerType::getUnqual(VarName);
69 #define OMP_STRUCT_TYPE(VarName, StructName, ...) \
70  T = M.getTypeByName(StructName); \
71  if (!T) \
72  T = StructType::create(Ctx, {__VA_ARGS__}, StructName); \
73  VarName = T; \
74  VarName##Ptr = PointerType::getUnqual(T);
75 #include "llvm/Frontend/OpenMP/OMPKinds.def"
76 }
77 
79 #define OMP_TYPE(VarName, InitValue) VarName = nullptr;
80 #define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
81  VarName = nullptr; \
82  VarName##Ptr = nullptr;
83 #define OMP_STRUCT_TYPE(VarName, StrName, ...) \
84  VarName = nullptr; \
85  VarName##Ptr = nullptr;
86 #include "llvm/Frontend/OpenMP/OMPKinds.def"
87 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
#define OMP_DIRECTIVE(Enum,...)
Make the enum values available in the llvm::omp namespace.
Definition: OMPConstants.h:40
Class to represent struct types.
Definition: DerivedTypes.h:238
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:245
void initializeTypes(Module &M)
Helper to initialize all types defined in OpenMP/OMPKinds.def.
Directive getOpenMPDirectiveKind(StringRef Str)
Parse Str and return the directive it matches or OMPD_unknown if none.
Directive
IDs for all OpenMP directives.
Definition: OMPConstants.h:31
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:63
This file defines constans and helpers used when dealing with OpenMP.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Module.h This file contains the declarations for the Module class.
StringRef getOpenMPDirectiveName(Directive D)
Return a textual representation of the directive D.
void uninitializeTypes()
Helper to uninitialize all types defined in OpenMP/OMPKinds.def.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54