1//===- Common.h - Shared types for IR2Vec/MIR2Vec tools -----------===//
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/// \file
10/// This file contains shared types and constants used by both the IR2Vec
11/// and MIR2Vec tool implementations. It has no dependency on either the
12/// LLVM IR or Machine IR APIs, making it safe to include from either side.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_TOOLS_LLVM_IR2VEC_UTILS_COMMON_H
17#define LLVM_TOOLS_LLVM_IR2VEC_UTILS_COMMON_H
18
19#include <string>
20#include <vector>
21
22namespace llvm {
23
24/// Tool name for error reporting
25static const char *ToolName = "llvm-ir2vec";
26
27/// Specifies the granularity at which embeddings are generated.
28enum EmbeddingLevel {
29 InstructionLevel, // Generate instruction-level embeddings
30 BasicBlockLevel, // Generate basic block-level embeddings
31 FunctionLevel // Generate function-level embeddings
32};
33
34/// Represents a single knowledge graph triplet (Head, Relation, Tail)
35/// where indices reference entities in an EntityList
36struct Triplet {
37 unsigned Head = 0; ///< Index of the head entity in the entity list
38 unsigned Tail = 0; ///< Index of the tail entity in the entity list
39 unsigned Relation = 0; ///< Relation type (see RelationType enum)
40};
41
42/// Result structure containing all generated triplets and metadata
43struct TripletResult {
44 unsigned MaxRelation =
45 0; ///< Highest relation index used (for ArgRelation + N)
46 std::vector<Triplet> Triplets; ///< Collection of all generated triplets
47};
48
49/// Entity mappings: [entity_name]
50using EntityList = std::vector<std::string>;
51
52} // namespace llvm
53
54#endif // LLVM_TOOLS_LLVM_IR2VEC_UTILS_COMMON_H
55