Skip to content

Commit 2d13ad5

Browse files
committed
Revamp edge connection
1 parent aa1502c commit 2d13ad5

File tree

13 files changed

+415
-360
lines changed

13 files changed

+415
-360
lines changed

include/Builder.h

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,20 @@ class Builder {
1414
public:
1515
Builder();
1616

17-
Node *newModuleNode();
18-
Node *newFunctionNode();
19-
Node *newBasicBlockNode();
20-
Node *newInstructionNode();
21-
Node *newValueNode();
22-
Node *newTypeNode();
23-
24-
void connectModule(Node *moduleNode, Node *anyNode);
25-
void connectFunction(Node *functionNode, Node *anyNode);
26-
void connectArgument(Node *functionNode, Node *argumentNode, unsigned order);
27-
void connectInstruction(Node *instructionNode, Node *anyNode);
28-
void connectBasicBlocks(Node *successor, Node *predecessor);
29-
void connectOperand(Node *instructionNode, Node *anyValue, unsigned order);
30-
void connectPointeeType(Node *pointerNode, Node *pointeeNode);
31-
void connectFunctionReturnType(Node *functionType, Node *returnType);
32-
void connectFunctionParameterType(Node *functionType, Node *parameterType, unsigned order);
33-
void connectStructElementType(Node *structType, Node *elementType, unsigned order);
34-
void connectElementType(Node *type, Node *elementType);
35-
void connectType(Node *type, Node *node);
17+
Node &newModuleNode();
18+
Node &newFunctionNode();
19+
Node &newBasicBlockNode();
20+
Node &newInstructionNode();
21+
Node &newValueNode();
22+
Node &newTypeNode();
23+
24+
Edge &newEdge(uint64_t source, uint64_t target);
3625

3726
const std::vector<std::unique_ptr<Node>> &getNodes() const;
3827
const std::vector<std::unique_ptr<Edge>> &getEdges() const;
3928

4029
private:
41-
Node *newNode(NodeKind kind);
42-
Edge *newEdge(uint64_t source, uint64_t target);
30+
Node &newNode(NodeKind kind);
4331

4432
uint64_t currentId;
4533

include/Edge.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace llvm2graphml {
88
enum class EdgeKind {
99
Module,
1010
Function,
11+
BasicBlock,
1112
Argument,
1213
Successor,
1314
Predecessor,
@@ -24,8 +25,8 @@ class Edge {
2425
public:
2526
Edge(uint64_t id, uint64_t source, uint64_t target);
2627

27-
void setKind(EdgeKind kind);
28-
void setOrder(unsigned order);
28+
Edge &setKind(EdgeKind kind);
29+
Edge &setOrder(unsigned order);
2930

3031
const Properties &getProperties() const;
3132
uint64_t getID() const;

include/EdgeConnector.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
namespace llvm2graphml {
6+
7+
class Builder;
8+
class Node;
9+
class Edge;
10+
enum class EdgeKind;
11+
12+
class EdgeConnector {
13+
public:
14+
friend Node;
15+
16+
EdgeConnector *operator->();
17+
Edge &module(Node &to);
18+
Edge &function(Node &to);
19+
Edge &argument(const Node &to);
20+
Edge &instruction(const Node &to);
21+
Edge &basicBlock(const Node &to);
22+
Edge &successor(const Node &to);
23+
Edge &predecessor(const Node &to);
24+
Edge &operand(const Node &to);
25+
Edge &pointeeType(const Node &to);
26+
Edge &returnType(const Node &to);
27+
Edge &parameterType(const Node &to);
28+
Edge &elementType(const Node &to);
29+
Edge &type(const Node &to);
30+
31+
private:
32+
EdgeConnector(Builder &builder, Node &from);
33+
Edge &edge(uint64_t to, EdgeKind kind);
34+
35+
Builder &builder;
36+
Node &from;
37+
};
38+
39+
} // namespace llvm2graphml

include/Emitter.h

Lines changed: 80 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -29,88 +29,90 @@ class Emitter {
2929
TypeEmitter &typeEmitter;
3030
std::unordered_map<const llvm::Value *, Node *> emittedValues;
3131

32-
void dispatchInstruction(const llvm::Instruction *instruction, Node *node);
33-
Node *emit(const llvm::Value *value);
32+
void dispatchInstruction(const llvm::Instruction *instruction, Node &node);
33+
Node &emit(const llvm::Value *value);
3434

35-
Node *functionNode(const llvm::Value *value);
36-
Node *basicBlockNode(const llvm::Value *value);
37-
Node *instructionNode(const llvm::Value *value);
38-
Node *valueNode(const llvm::Value *value);
35+
Node &newFunctionNode(const llvm::Value *value);
36+
Node &newBasicBlockNode(const llvm::Value *value);
37+
Node &newInstructionNode(const llvm::Value *value);
38+
Node &newValueNode(const llvm::Value *value);
39+
40+
Node &node(const llvm::Value *value);
3941

4042
/// Extension points
4143

42-
void fillIn(const llvm::Module *module, Node *node);
43-
void fillIn(const llvm::Function *function, Node *node);
44-
void fillIn(const llvm::BasicBlock *basicBlock, Node *node);
45-
46-
void fillIn(const llvm::Argument *argument, Node *node);
47-
void fillIn(const llvm::ConstantInt *constant, Node *node);
48-
void fillIn(const llvm::ConstantFP *constant, Node *node);
49-
void fillIn(const llvm::ConstantPointerNull *constant, Node *node);
50-
void fillIn(const llvm::ConstantTokenNone *constant, Node *node);
51-
void fillIn(const llvm::UndefValue *undefValue, Node *node);
52-
void fillIn(const llvm::InlineAsm *inlineAsm, Node *node);
53-
void fillIn(const llvm::MetadataAsValue *metadataAsValue, llvm2graphml::Node *node);
54-
void fillIn(const llvm::BlockAddress *blockAddress, llvm2graphml::Node *node);
55-
void fillIn(const llvm::ConstantArray *constantArray, llvm2graphml::Node *node);
56-
void fillIn(const llvm::ConstantDataArray *constantArray, llvm2graphml::Node *node);
57-
void fillIn(const llvm::GlobalAlias *globalAlias, llvm2graphml::Node *node);
58-
void fillIn(const llvm::GlobalIFunc *globalIFunc, llvm2graphml::Node *node);
59-
void fillIn(const llvm::GlobalVariable *globalVariable, llvm2graphml::Node *node);
60-
void fillIn(const llvm::ConstantExpr *constantExpr, llvm2graphml::Node *node);
61-
void fillIn(const llvm::ConstantStruct *constantStruct, llvm2graphml::Node *node);
62-
void fillIn(const llvm::ConstantVector *constantVector, llvm2graphml::Node *node);
63-
void fillIn(const llvm::ConstantAggregateZero *constantZero, llvm2graphml::Node *node);
64-
void fillIn(const llvm::ConstantDataVector *constantVector, llvm2graphml::Node *node);
65-
66-
void fillIn(const llvm::Instruction *instruction, Node *node);
67-
void fillIn(const llvm::ReturnInst *instruction, Node *node);
68-
void fillIn(const llvm::BranchInst *instruction, Node *node);
69-
void fillIn(const llvm::SwitchInst *instruction, Node *node);
70-
void fillIn(const llvm::IndirectBrInst *instruction, Node *node);
71-
void fillIn(const llvm::InvokeInst *instruction, Node *node);
72-
void fillIn(const llvm::ResumeInst *instruction, Node *node);
73-
void fillIn(const llvm::UnreachableInst *instruction, Node *node);
74-
void fillIn(const llvm::CleanupReturnInst *instruction, Node *node);
75-
void fillIn(const llvm::CatchReturnInst *instruction, Node *node);
76-
void fillIn(const llvm::CatchSwitchInst *instruction, Node *node);
77-
void fillIn(const llvm::CallBrInst *instruction, Node *node);
78-
void fillIn(const llvm::UnaryOperator *instruction, Node *node);
79-
void fillIn(const llvm::BinaryOperator *instruction, Node *node);
80-
void fillIn(const llvm::AllocaInst *instruction, Node *node);
81-
void fillIn(const llvm::LoadInst *instruction, Node *node);
82-
void fillIn(const llvm::StoreInst *instruction, Node *node);
83-
void fillIn(const llvm::GetElementPtrInst *instruction, Node *node);
84-
void fillIn(const llvm::FenceInst *instruction, Node *node);
85-
void fillIn(const llvm::AtomicCmpXchgInst *instruction, Node *node);
86-
void fillIn(const llvm::AtomicRMWInst *instruction, Node *node);
87-
void fillIn(const llvm::TruncInst *instruction, Node *node);
88-
void fillIn(const llvm::ZExtInst *instruction, Node *node);
89-
void fillIn(const llvm::SExtInst *instruction, Node *node);
90-
void fillIn(const llvm::FPToUIInst *instruction, Node *node);
91-
void fillIn(const llvm::FPToSIInst *instruction, Node *node);
92-
void fillIn(const llvm::UIToFPInst *instruction, Node *node);
93-
void fillIn(const llvm::SIToFPInst *instruction, Node *node);
94-
void fillIn(const llvm::FPTruncInst *instruction, Node *node);
95-
void fillIn(const llvm::FPExtInst *instruction, Node *node);
96-
void fillIn(const llvm::PtrToIntInst *instruction, Node *node);
97-
void fillIn(const llvm::IntToPtrInst *instruction, Node *node);
98-
void fillIn(const llvm::BitCastInst *instruction, Node *node);
99-
void fillIn(const llvm::AddrSpaceCastInst *instruction, Node *node);
100-
void fillIn(const llvm::CleanupPadInst *instruction, Node *node);
101-
void fillIn(const llvm::CatchPadInst *instruction, Node *node);
102-
void fillIn(const llvm::ICmpInst *instruction, Node *node);
103-
void fillIn(const llvm::FCmpInst *instruction, Node *node);
104-
void fillIn(const llvm::PHINode *instruction, Node *node);
105-
void fillIn(const llvm::CallInst *instruction, Node *node);
106-
void fillIn(const llvm::SelectInst *instruction, Node *node);
107-
void fillIn(const llvm::VAArgInst *instruction, Node *node);
108-
void fillIn(const llvm::ExtractElementInst *instruction, Node *node);
109-
void fillIn(const llvm::InsertElementInst *instruction, Node *node);
110-
void fillIn(const llvm::ShuffleVectorInst *instruction, Node *node);
111-
void fillIn(const llvm::ExtractValueInst *instruction, Node *node);
112-
void fillIn(const llvm::InsertValueInst *instruction, Node *node);
113-
void fillIn(const llvm::LandingPadInst *instruction, Node *node);
44+
void fillIn(const llvm::Module *module, Node &node);
45+
void fillIn(const llvm::Function *function, Node &node);
46+
void fillIn(const llvm::BasicBlock *basicBlock, Node &node);
47+
48+
void fillIn(const llvm::Argument *argument, Node &node);
49+
void fillIn(const llvm::ConstantInt *constant, Node &node);
50+
void fillIn(const llvm::ConstantFP *constant, Node &node);
51+
void fillIn(const llvm::ConstantPointerNull *constant, Node &node);
52+
void fillIn(const llvm::ConstantTokenNone *constant, Node &node);
53+
void fillIn(const llvm::UndefValue *undefValue, Node &node);
54+
void fillIn(const llvm::InlineAsm *inlineAsm, Node &node);
55+
void fillIn(const llvm::MetadataAsValue *metadataAsValue, llvm2graphml::Node &node);
56+
void fillIn(const llvm::BlockAddress *blockAddress, llvm2graphml::Node &node);
57+
void fillIn(const llvm::ConstantArray *constantArray, llvm2graphml::Node &node);
58+
void fillIn(const llvm::ConstantDataArray *constantArray, llvm2graphml::Node &node);
59+
void fillIn(const llvm::GlobalAlias *globalAlias, llvm2graphml::Node &node);
60+
void fillIn(const llvm::GlobalIFunc *globalIFunc, llvm2graphml::Node &node);
61+
void fillIn(const llvm::GlobalVariable *globalVariable, llvm2graphml::Node &node);
62+
void fillIn(const llvm::ConstantExpr *constantExpr, llvm2graphml::Node &node);
63+
void fillIn(const llvm::ConstantStruct *constantStruct, llvm2graphml::Node &node);
64+
void fillIn(const llvm::ConstantVector *constantVector, llvm2graphml::Node &node);
65+
void fillIn(const llvm::ConstantAggregateZero *constantZero, llvm2graphml::Node &node);
66+
void fillIn(const llvm::ConstantDataVector *constantVector, llvm2graphml::Node &node);
67+
68+
void fillIn(const llvm::Instruction *instruction, Node &node);
69+
void fillIn(const llvm::ReturnInst *instruction, Node &node);
70+
void fillIn(const llvm::BranchInst *instruction, Node &node);
71+
void fillIn(const llvm::SwitchInst *instruction, Node &node);
72+
void fillIn(const llvm::IndirectBrInst *instruction, Node &node);
73+
void fillIn(const llvm::InvokeInst *instruction, Node &node);
74+
void fillIn(const llvm::ResumeInst *instruction, Node &node);
75+
void fillIn(const llvm::UnreachableInst *instruction, Node &node);
76+
void fillIn(const llvm::CleanupReturnInst *instruction, Node &node);
77+
void fillIn(const llvm::CatchReturnInst *instruction, Node &node);
78+
void fillIn(const llvm::CatchSwitchInst *instruction, Node &node);
79+
void fillIn(const llvm::CallBrInst *instruction, Node &node);
80+
void fillIn(const llvm::UnaryOperator *instruction, Node &node);
81+
void fillIn(const llvm::BinaryOperator *instruction, Node &node);
82+
void fillIn(const llvm::AllocaInst *instruction, Node &node);
83+
void fillIn(const llvm::LoadInst *instruction, Node &node);
84+
void fillIn(const llvm::StoreInst *instruction, Node &node);
85+
void fillIn(const llvm::GetElementPtrInst *instruction, Node &node);
86+
void fillIn(const llvm::FenceInst *instruction, Node &node);
87+
void fillIn(const llvm::AtomicCmpXchgInst *instruction, Node &node);
88+
void fillIn(const llvm::AtomicRMWInst *instruction, Node &node);
89+
void fillIn(const llvm::TruncInst *instruction, Node &node);
90+
void fillIn(const llvm::ZExtInst *instruction, Node &node);
91+
void fillIn(const llvm::SExtInst *instruction, Node &node);
92+
void fillIn(const llvm::FPToUIInst *instruction, Node &node);
93+
void fillIn(const llvm::FPToSIInst *instruction, Node &node);
94+
void fillIn(const llvm::UIToFPInst *instruction, Node &node);
95+
void fillIn(const llvm::SIToFPInst *instruction, Node &node);
96+
void fillIn(const llvm::FPTruncInst *instruction, Node &node);
97+
void fillIn(const llvm::FPExtInst *instruction, Node &node);
98+
void fillIn(const llvm::PtrToIntInst *instruction, Node &node);
99+
void fillIn(const llvm::IntToPtrInst *instruction, Node &node);
100+
void fillIn(const llvm::BitCastInst *instruction, Node &node);
101+
void fillIn(const llvm::AddrSpaceCastInst *instruction, Node &node);
102+
void fillIn(const llvm::CleanupPadInst *instruction, Node &node);
103+
void fillIn(const llvm::CatchPadInst *instruction, Node &node);
104+
void fillIn(const llvm::ICmpInst *instruction, Node &node);
105+
void fillIn(const llvm::FCmpInst *instruction, Node &node);
106+
void fillIn(const llvm::PHINode *instruction, Node &node);
107+
void fillIn(const llvm::CallInst *instruction, Node &node);
108+
void fillIn(const llvm::SelectInst *instruction, Node &node);
109+
void fillIn(const llvm::VAArgInst *instruction, Node &node);
110+
void fillIn(const llvm::ExtractElementInst *instruction, Node &node);
111+
void fillIn(const llvm::InsertElementInst *instruction, Node &node);
112+
void fillIn(const llvm::ShuffleVectorInst *instruction, Node &node);
113+
void fillIn(const llvm::ExtractValueInst *instruction, Node &node);
114+
void fillIn(const llvm::InsertValueInst *instruction, Node &node);
115+
void fillIn(const llvm::LandingPadInst *instruction, Node &node);
114116
};
115117

116118
} // namespace llvm2graphml

include/Node.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "EdgeConnector.h"
34
#include "Properties.h"
45
#include <string>
56

@@ -28,6 +29,7 @@ enum class ValueKind {
2829
ConstantAggregateZero,
2930
ConstantDataVector,
3031
};
32+
3133
enum class TypeKind {
3234
Integer,
3335
Void,
@@ -48,9 +50,14 @@ enum class TypeKind {
4850
Label
4951
};
5052

53+
class Builder;
54+
55+
class Edge;
56+
class Node;
57+
5158
class Node {
5259
public:
53-
explicit Node(uint64_t id, NodeKind kind);
60+
explicit Node(Builder &builder, uint64_t id, NodeKind kind);
5461

5562
Node &setModuleIdentifier(std::string identifier);
5663
Node &setName(std::string name);
@@ -70,7 +77,10 @@ class Node {
7077
uint64_t getID() const;
7178
NodeKind getKind() const;
7279

80+
EdgeConnector operator->();
81+
7382
private:
83+
Builder &builder;
7484
uint64_t id;
7585
NodeKind kind;
7686
Properties properties;

include/TypeEmitter.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ class Builder;
1717
class TypeEmitter {
1818
public:
1919
explicit TypeEmitter(Builder &builder);
20-
Node *emitType(const llvm::Type *type);
20+
Node &emitType(const llvm::Type *type);
2121

2222
private:
2323
Builder &builder;
2424
std::unordered_map<const llvm::Type *, Node *> emittedTypes;
2525

26-
void dispatchType(const llvm::Type *type, Node *node);
26+
void dispatchType(const llvm::Type *type, Node &node);
2727

2828
// Extension Points
29-
void fillIn(const llvm::IntegerType *type, Node *node);
30-
void fillIn(const llvm::FunctionType *type, Node *node);
31-
void fillIn(const llvm::StructType *type, Node *node);
32-
void fillIn(const llvm::ArrayType *type, Node *node);
33-
void fillIn(const llvm::PointerType *type, Node *node);
34-
void fillIn(const llvm::VectorType *type, Node *node);
29+
void fillIn(const llvm::IntegerType *type, Node &node);
30+
void fillIn(const llvm::FunctionType *type, Node &node);
31+
void fillIn(const llvm::StructType *type, Node &node);
32+
void fillIn(const llvm::ArrayType *type, Node &node);
33+
void fillIn(const llvm::PointerType *type, Node &node);
34+
void fillIn(const llvm::VectorType *type, Node &node);
3535
};
3636

3737
} // namespace llvm2graphml

0 commit comments

Comments
 (0)