1 //===------ JITSymbolFlags.h - Flags for symbols in the JIT -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Symbol flags for symbols in the JIT (e.g. weak, exported).
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_EXECUTIONENGINE_JITSYMBOLFLAGS_H
15 #define LLVM_EXECUTIONENGINE_JITSYMBOLFLAGS_H
16 
17 #include "llvm/IR/GlobalValue.h"
18 
19 namespace llvm {
20 
21 /// @brief Flags for symbols in the JIT.
22 enum class JITSymbolFlags : char {
23   None = 0,
24   Weak = 1U << 0,
25   Exported = 1U << 1
26 };
27 
28 inline JITSymbolFlags operator|(JITSymbolFlags LHS, JITSymbolFlags RHS) {
29   typedef std::underlying_type<JITSymbolFlags>::type UT;
30   return static_cast<JITSymbolFlags>(
31            static_cast<UT>(LHS) | static_cast<UT>(RHS));
32 }
33 
34 inline JITSymbolFlags& operator |=(JITSymbolFlags &LHS, JITSymbolFlags RHS) {
35   LHS = LHS | RHS;
36   return LHS;
37 }
38 
39 inline JITSymbolFlags operator&(JITSymbolFlags LHS, JITSymbolFlags RHS) {
40   typedef std::underlying_type<JITSymbolFlags>::type UT;
41   return static_cast<JITSymbolFlags>(
42            static_cast<UT>(LHS) & static_cast<UT>(RHS));
43 }
44 
45 inline JITSymbolFlags& operator &=(JITSymbolFlags &LHS, JITSymbolFlags RHS) {
46   LHS = LHS & RHS;
47   return LHS;
48 }
49 
50 /// @brief Base class for symbols in the JIT.
51 class JITSymbolBase {
52 public:
JITSymbolBase(JITSymbolFlags Flags)53   JITSymbolBase(JITSymbolFlags Flags) : Flags(Flags) {}
54 
getFlags()55   JITSymbolFlags getFlags() const { return Flags; }
56 
isWeak()57   bool isWeak() const {
58     return (Flags & JITSymbolFlags::Weak) == JITSymbolFlags::Weak;
59   }
60 
isExported()61   bool isExported() const {
62     return (Flags & JITSymbolFlags::Exported) == JITSymbolFlags::Exported;
63   }
64 
flagsFromGlobalValue(const GlobalValue & GV)65   static JITSymbolFlags flagsFromGlobalValue(const GlobalValue &GV) {
66     JITSymbolFlags Flags = JITSymbolFlags::None;
67     if (GV.hasWeakLinkage())
68       Flags |= JITSymbolFlags::Weak;
69     if (!GV.hasLocalLinkage() && !GV.hasHiddenVisibility())
70       Flags |= JITSymbolFlags::Exported;
71     return Flags;
72 
73   }
74 
75 private:
76   JITSymbolFlags Flags;
77 };
78 
79 } // end namespace llvm
80 
81 #endif
82