1 //===- BPFCORE.h - Common info for Compile-Once Run-EveryWhere  -*- C++ -*-===//
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 #ifndef LLVM_LIB_TARGET_BPF_BPFCORE_H
10 #define LLVM_LIB_TARGET_BPF_BPFCORE_H
11 
12 #include "llvm/ADT/StringRef.h"
13 
14 namespace llvm {
15 
16 class BasicBlock;
17 class Instruction;
18 class Module;
19 
20 class BPFCoreSharedInfo {
21 public:
22   enum PatchableRelocKind : uint32_t {
23     FIELD_BYTE_OFFSET = 0,
24     FIELD_BYTE_SIZE,
25     FIELD_EXISTENCE,
26     FIELD_SIGNEDNESS,
27     FIELD_LSHIFT_U64,
28     FIELD_RSHIFT_U64,
29     BTF_TYPE_ID_LOCAL,
30     BTF_TYPE_ID_REMOTE,
31     TYPE_EXISTENCE,
32     TYPE_SIZE,
33     ENUM_VALUE_EXISTENCE,
34     ENUM_VALUE,
35     TYPE_MATCH,
36 
37     MAX_FIELD_RELOC_KIND,
38   };
39 
40   enum BTFTypeIdFlag : uint32_t {
41     BTF_TYPE_ID_LOCAL_RELOC = 0,
42     BTF_TYPE_ID_REMOTE_RELOC,
43 
44     MAX_BTF_TYPE_ID_FLAG,
45   };
46 
47   enum PreserveTypeInfo : uint32_t {
48     PRESERVE_TYPE_INFO_EXISTENCE = 0,
49     PRESERVE_TYPE_INFO_SIZE,
50     PRESERVE_TYPE_INFO_MATCH,
51 
52     MAX_PRESERVE_TYPE_INFO_FLAG,
53   };
54 
55   enum PreserveEnumValue : uint32_t {
56     PRESERVE_ENUM_VALUE_EXISTENCE = 0,
57     PRESERVE_ENUM_VALUE,
58 
59     MAX_PRESERVE_ENUM_VALUE_FLAG,
60   };
61 
62   /// The attribute attached to globals representing a field access
63   static constexpr StringRef AmaAttr = "btf_ama";
64   /// The attribute attached to globals representing a type id
65   static constexpr StringRef TypeIdAttr = "btf_type_id";
66 
67   /// llvm.bpf.passthrough builtin seq number
68   static uint32_t SeqNum;
69 
70   /// Insert a bpf passthrough builtin function.
71   static Instruction *insertPassThrough(Module *M, BasicBlock *BB,
72                                         Instruction *Input,
73                                         Instruction *Before);
74 };
75 
76 } // namespace llvm
77 
78 #endif
79