-
Notifications
You must be signed in to change notification settings - Fork 0
/
Structure.h
1745 lines (1439 loc) · 54.8 KB
/
Structure.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef STRUCTURE_H
#define STRUCTURE_H
#include <iostream>
#include <set>
#include "llvm/IR/Instructions.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/Support/raw_ostream.h"
#include "cereal/archives/json.hpp"
#include "cereal/types/vector.hpp"
#include <cereal/types/memory.hpp>
namespace cereal {
[[noreturn]] void throw_exception(std::exception const &e);
template <class T>
void save(cereal::JSONOutputArchive &archive, std::shared_ptr<T> const &ptr) {
ptr->serialize(archive);
}
template <class T1, class T2>
void save(cereal::JSONOutputArchive &archive, std::pair<T1, T2> const &p) {
archive.makeArray();
archive.writeName();
archive(p.first);
archive(p.second);
}
} // cereal
namespace crellvm {
enum TyScope { Source = 0, Target };
enum TyFloatType {
HalfType = 0,
FloatType,
DoubleType,
FP128Type,
PPC_FP128Type,
X86_FP80Type
};
enum TyTag { Physical = 0, Previous, Ghost };
enum TyBop {
BopAdd,
BopSub,
BopMul,
BopUdiv,
BopSdiv,
BopUrem,
BopSrem,
BopShl,
BopLshr,
BopAshr,
BopAnd,
BopOr,
BopXor,
};
enum TyFbop { BopFadd, BopFsub, BopFmul, BopFdiv, BopFrem };
enum TyIcmpPred {
CondEq,
CondNe,
CondUgt,
CondUge,
CondUlt,
CondUle,
CondSgt,
CondSge,
CondSlt,
CondSle
};
enum TyFcmpPred {
CondFfalse,
CondFoeq,
CondFogt,
CondFoge,
CondFolt,
CondFole,
CondFone,
CondFord,
CondFuno,
CondFueq,
CondFugt,
CondFuge,
CondFult,
CondFule,
CondFune,
CondFtrue
};
class CoreHint;
std::string getBasicBlockIndex(const llvm::BasicBlock *block);
std::string getVariable(const llvm::Value &value);
llvm::Instruction *getPHIResolved(llvm::Instruction *I, llvm::BasicBlock *PB);
int getCommandIndex(const llvm::Value &value);
int getTerminatorIndex(const llvm::TerminatorInst *instr);
bool name_instructions(llvm::Function &F);
bool name_instruction(llvm::Instruction &I);
std::string toString(crellvm::TyBop bop);
std::string toString(crellvm::TyFbop bop);
std::string toString(crellvm::TyFloatType bop);
std::string toString(crellvm::TyIcmpPred cond);
std::string toString(crellvm::TyFcmpPred fcond);
bool isFloatOpcode(llvm::Instruction::BinaryOps ops);
TyFloatType getFloatType(llvm::Type *typ);
TyFbop getFbop(llvm::Instruction::BinaryOps ops);
TyBop getBop(llvm::Instruction::BinaryOps ops);
TyIcmpPred getIcmpPred(llvm::ICmpInst::Predicate prd);
TyFcmpPred getFcmpPred(llvm::FCmpInst::Predicate prd);
/*
* position
*/
struct TyPositionPhinode {
public:
TyPositionPhinode(std::string _prev_block_name);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::string prev_block_name;
};
struct TyPositionCommand {
public:
TyPositionCommand(int _index, std::string _register_name);
void serialize(cereal::JSONOutputArchive &archive) const;
public:
int getIndex() const
{ return index; }
const std::string getRegisterName() const
{ return register_name; }
private:
int index;
std::string register_name;
};
struct TyInstrIndex {
public:
virtual void serialize(cereal::JSONOutputArchive &archive) const = 0;
};
struct ConsPhinode : public TyInstrIndex {
public:
ConsPhinode(std::shared_ptr<TyPositionPhinode> _position_phinode);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyPositionPhinode> position_phinode;
};
struct ConsCommand : public TyInstrIndex {
public:
ConsCommand(std::shared_ptr<TyPositionCommand> _position_command);
void serialize(cereal::JSONOutputArchive &archive) const;
/* static std::shared_ptr<TyPosition> make(const llvm::Instruction &I, */
/* enum TyScope _scope); */
std::shared_ptr<TyPositionCommand> getPositionCommand() const
{ return position_command; }
private:
std::shared_ptr<TyPositionCommand> position_command;
};
struct TyPosition {
public:
TyPosition(enum TyScope _scope, std::string _block_name,
std::shared_ptr<TyInstrIndex> _instr_index);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyPosition> make(enum TyScope _scope,
const llvm::Instruction &I);
static std::shared_ptr<TyPosition>
make_end_of_block(enum TyScope _scope, const llvm::BasicBlock &BB);
static std::shared_ptr<TyPosition>
make_end_of_block(enum TyScope _scope, const llvm::BasicBlock &BB,
int index);
static std::shared_ptr<TyPosition>
make_start_of_block(enum TyScope _scope, std::string _block_name);
static std::shared_ptr<TyPosition> make(enum TyScope _scope,
std::string _block_name,
std::string _prev_block_name);
static std::shared_ptr<TyPosition> make(enum TyScope _scope,
const llvm::Instruction &I,
std::string _prev_block_name);
static std::shared_ptr<TyPosition> make(enum TyScope _scope,
const llvm::Instruction &I, int index,
std::string _prev_block_name);
public:
enum TyScope getScope() const
{ return scope; }
const std::string &getBlockName() const
{ return block_name; }
std::shared_ptr<TyInstrIndex> getInstrIndex() const
{ return instr_index; }
static std::shared_ptr<TyPosition> make(enum TyScope _scope,
const llvm::BasicBlock &BB,
int index);
private:
enum TyScope scope;
std::string block_name;
std::shared_ptr<TyInstrIndex> instr_index;
};
/*
* register
*/
struct TyRegister {
public:
TyRegister(const std::string &_name, enum TyTag _tag);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyRegister> make(const std::string &_name,
enum TyTag _tag);
static std::shared_ptr<TyRegister> make(const llvm::Value &_val,
enum TyTag _tag);
static bool isSame(std::shared_ptr<TyRegister> r1,
std::shared_ptr<TyRegister> r2);
std::string getName();
private:
std::string name;
enum TyTag tag;
};
/*
* type
*/
struct TyIntType {
public:
virtual void serialize(cereal::JSONOutputArchive &archive) const = 0;
};
struct ConsIntType : public TyIntType {
public:
ConsIntType(int _value);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
int value;
};
struct TyValueType {
public:
virtual void serialize(cereal::JSONOutputArchive &archive) const = 0;
static std::shared_ptr<TyValueType> make(const llvm::Type &type);
};
struct ConsVoidType : public TyValueType {
public:
ConsVoidType();
void serialize(cereal::JSONOutputArchive &archive) const;
};
struct ConsIntValueType : public TyValueType {
public:
ConsIntValueType(std::shared_ptr<TyIntType> _int_type);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyIntType> int_type;
};
struct ConsFloatValueType : public TyValueType {
public:
ConsFloatValueType(TyFloatType _float_type);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
TyFloatType float_type;
};
struct ConsNamedType : public TyValueType {
public:
ConsNamedType(std::string _s);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::string s;
};
struct ConsPtrType : public TyValueType {
public:
ConsPtrType(int _address_space, std::shared_ptr<TyValueType> _valuetype);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
int address_space;
std::shared_ptr<TyValueType> valuetype;
};
struct ConsArrayType : public TyValueType {
public:
ConsArrayType(uint64_t _array_size, std::shared_ptr<TyValueType> _valuetype);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
uint64_t array_size;
std::shared_ptr<TyValueType> valuetype;
};
struct ConsVectorType : public TyValueType {
public:
ConsVectorType(uint64_t _array_size, std::shared_ptr<TyValueType> _valuetype);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
uint64_t array_size;
std::shared_ptr<TyValueType> valuetype;
};
struct ConsFunctionType : public TyValueType {
public:
ConsFunctionType(std::shared_ptr<TyValueType> _ret_type,
std::vector<std::shared_ptr<TyValueType>> &_arg_ty_list,
bool _is_vararg, int _vararg_size);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyValueType> ret_type;
std::vector<std::shared_ptr<TyValueType>> arg_ty_list;
bool is_vararg;
int vararg_size;
};
struct ConsStructType : public TyValueType{
public :
ConsStructType(std::vector<std::shared_ptr<TyValueType>> &_vec_value_type);
void serialize(cereal::JSONOutputArchive& archive) const;
private :
std::vector<std::shared_ptr<TyValueType>> vec_value_type;
};
/*
* size
*/
struct TySize {
public:
virtual void serialize(cereal::JSONOutputArchive &archive) const = 0;
};
struct ConsSize : public TySize {
public:
ConsSize(int _size);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TySize> make(int _size);
// Use bitsize from ci
// ex) If ci's type is 64-bit integer, then make TySize(64)
static std::shared_ptr<TySize> make(const llvm::Value &ci);
private:
int size;
};
/*
* constants
*/
struct TyConstInt {
public:
TyConstInt(int64_t _int_value, std::shared_ptr<TyIntType> _int_type);
TyConstInt(int64_t _int_value, int _bitwidth);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyConstInt> make(int64_t _int_value, int _bitwidth);
static std::shared_ptr<TyConstInt> make(const llvm::ConstantInt &ci);
private:
int64_t int_value;
std::shared_ptr<TyIntType> int_type;
};
struct TyConstFloat {
public:
TyConstFloat(double _float_value, enum TyFloatType _float_type);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyConstFloat> make(double _float_value,
enum TyFloatType _float_type);
private:
double float_value;
enum TyFloatType float_type;
};
struct TyConstGlobalVarAddr {
public:
TyConstGlobalVarAddr(std::string _var_id,
std::shared_ptr<TyValueType> _var_type);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyConstGlobalVarAddr>
make(const llvm::GlobalObject &gv);
private:
std::string var_id;
std::shared_ptr<TyValueType> var_type;
};
// constant exprs
class TyConstant;
struct TyConstantExpr {
public:
virtual void serialize(cereal::JSONOutputArchive &archive) const = 0;
static std::shared_ptr<TyConstantExpr> make(const llvm::ConstantExpr &ce);
};
struct TyConstExprGetElementPtr {
public:
TyConstExprGetElementPtr(std::shared_ptr<TyValueType> _srcelemty,
std::shared_ptr<TyConstant> _v,
std::vector<std::shared_ptr<TyConstant>> _idxlist,
std::shared_ptr<TyValueType> _dstty,
bool _is_inbounds);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyValueType> srcelemty;
std::shared_ptr<TyConstant> v;
std::vector<std::shared_ptr<TyConstant>> idxlist;
std::shared_ptr<TyValueType> dstty;
bool is_inbounds;
};
struct ConsConstExprGetElementPtr : public TyConstantExpr {
public:
ConsConstExprGetElementPtr(
std::shared_ptr<TyConstExprGetElementPtr> _const_expr_get_element_ptr);
static std::shared_ptr<TyConstantExpr>
make(std::shared_ptr<TyValueType> _srcelemty, std::shared_ptr<TyConstant> _v,
std::vector<std::shared_ptr<TyConstant>> _idxlist,
std::shared_ptr<TyValueType> _dstty, bool _is_inbounds);
static std::shared_ptr<TyConstantExpr> make(const llvm::ConstantExpr &ce);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyConstExprGetElementPtr> const_expr_get_element_ptr;
};
struct TyConstExprBitcast {
public:
TyConstExprBitcast(std::shared_ptr<TyConstant> _v,
std::shared_ptr<TyValueType> _dstty);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyConstant> v;
std::shared_ptr<TyValueType> dstty;
};
struct ConsConstExprBitcast : public TyConstantExpr {
public:
ConsConstExprBitcast(std::shared_ptr<TyConstExprBitcast> _const_expr_bitcast);
static std::shared_ptr<TyConstantExpr>
make(std::shared_ptr<TyConstant> _v, std::shared_ptr<TyValueType> _dstty);
static std::shared_ptr<TyConstantExpr> make(const llvm::ConstantExpr &ce);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyConstExprBitcast> const_expr_bitcast;
};
struct TyConstExprInttoptr{
public :
TyConstExprInttoptr(std::shared_ptr<TyConstant> _v, std::shared_ptr<TyValueType> _dstty);
void serialize(cereal::JSONOutputArchive& archive) const;
private :
std::shared_ptr<TyConstant> v;
std::shared_ptr<TyValueType> dstty;
};
struct ConsConstExprInttoptr : public TyConstantExpr{
public :
ConsConstExprInttoptr(std::shared_ptr<TyConstExprInttoptr> _const_expr_inttoptr);
static std::shared_ptr<TyConstantExpr> make(std::shared_ptr<TyConstant> _v, std::shared_ptr<TyValueType> _dstty);
static std::shared_ptr<TyConstantExpr> make(const llvm::ConstantExpr &ce);
void serialize(cereal::JSONOutputArchive& archive) const;
private :
std::shared_ptr<TyConstExprInttoptr> const_expr_inttoptr;
};
struct TyConstExprPtrtoint{
public :
TyConstExprPtrtoint(std::shared_ptr<TyConstant> _v, std::shared_ptr<TyValueType> _dstty);
void serialize(cereal::JSONOutputArchive& archive) const;
private :
std::shared_ptr<TyConstant> v;
std::shared_ptr<TyValueType> dstty;
};
struct ConsConstExprPtrtoint : public TyConstantExpr{
public :
ConsConstExprPtrtoint(std::shared_ptr<TyConstExprPtrtoint> _const_expr_ptrtoint);
static std::shared_ptr<TyConstantExpr> make(std::shared_ptr<TyConstant> _v, std::shared_ptr<TyValueType> _dstty);
static std::shared_ptr<TyConstantExpr> make(const llvm::ConstantExpr &ce);
void serialize(cereal::JSONOutputArchive& archive) const;
private :
std::shared_ptr<TyConstExprPtrtoint> const_expr_ptrtoint;
};
struct TyConstExprBinaryOp {
public:
TyConstExprBinaryOp(TyBop _opcode, std::shared_ptr<TyConstant> _v1,
std::shared_ptr<TyConstant> _v2);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
TyBop opcode;
std::shared_ptr<TyConstant> v1;
std::shared_ptr<TyConstant> v2;
};
struct ConsConstExprBinaryOp : public TyConstantExpr {
public:
ConsConstExprBinaryOp(std::shared_ptr<TyConstExprBinaryOp> _const_expr_binaryop);
static std::shared_ptr<TyConstantExpr> make(TyBop _opcode, std::shared_ptr<TyConstant> _v1, std::shared_ptr<TyConstant> _v2);
static std::shared_ptr<TyConstantExpr> make(const llvm::ConstantExpr &ce);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyConstExprBinaryOp> const_expr_binaryop;
};
// constants
struct TyConstant {
public:
virtual void serialize(cereal::JSONOutputArchive &archive) const = 0;
static std::shared_ptr<TyConstant> make(const llvm::Constant &c);
};
struct ConsConstInt : public TyConstant {
public:
ConsConstInt(std::shared_ptr<TyConstInt> _const_int);
ConsConstInt(int64_t _int_value, int _bitwidth);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyConstInt> const_int;
};
struct ConsConstFloat : public TyConstant {
public:
ConsConstFloat(std::shared_ptr<TyConstFloat> _const_float);
ConsConstFloat(float _float_value, enum TyFloatType _float_type);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyConstFloat> const_float;
};
struct ConsConstUndef : public TyConstant {
public:
ConsConstUndef(std::shared_ptr<TyValueType> _value_type);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyValueType> value_type;
};
struct ConsConstNull : public TyConstant {
public:
ConsConstNull(int _address_space, std::shared_ptr<TyValueType> _value_type);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
int address_space;
std::shared_ptr<TyValueType> value_type;
};
struct ConsConstDataVector : public TyConstant {
public:
ConsConstDataVector(std::shared_ptr<TyValueType> _elem_type,
std::vector<std::shared_ptr<TyConstant> > &_elements);
void serialize(cereal::JSONOutputArchive &archive) const;
private:
std::shared_ptr<TyValueType> elem_type;
std::vector<std::shared_ptr<TyConstant> > elements;
};
struct ConsConstGlobalVarAddr : public TyConstant {
public:
ConsConstGlobalVarAddr(
std::shared_ptr<TyConstGlobalVarAddr> _const_global_var_addr);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyConstant>
make(std::string _var_id, std::shared_ptr<TyValueType> _var_type);
static std::shared_ptr<TyConstant> make(const llvm::GlobalVariable &gv);
private:
std::shared_ptr<TyConstGlobalVarAddr> const_global_var_addr;
};
struct ConsConstZeroInitializer : public TyConstant{
public :
ConsConstZeroInitializer(std::shared_ptr<TyValueType> _value_type);
void serialize(cereal::JSONOutputArchive& archive) const;
private :
std::shared_ptr<TyValueType> value_type;
};
struct ConsConstExpr : public TyConstant {
public:
ConsConstExpr(std::shared_ptr<TyConstantExpr> _constant_expr);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyConstant> make(const llvm::ConstantExpr &gv);
private:
std::shared_ptr<TyConstantExpr> constant_expr;
};
/*
* Value
*/
struct TyValue {
public:
virtual void serialize(cereal::JSONOutputArchive &archive) const = 0;
static std::shared_ptr<TyValue> make(const llvm::Value &value,
enum TyTag _tag = crellvm::Physical);
};
struct ConsId : public TyValue {
public:
ConsId(std::shared_ptr<TyRegister> _register);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyValue> make(std::string _name, enum TyTag _tag);
std::shared_ptr<TyRegister> reg;
};
struct ConsConstVal : public TyValue {
public:
ConsConstVal(std::shared_ptr<TyConstant> _constant);
void serialize(cereal::JSONOutputArchive &archive) const;
std::shared_ptr<TyConstant> constant;
};
/*
* Pointer
*/
struct TyPointer {
public:
TyPointer(std::shared_ptr<TyValue> _v, std::shared_ptr<TyValueType> _ty);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyPointer> make(const llvm::Value &v);
static std::shared_ptr<TyPointer> makeWithElementType(const llvm::Value &v);
private:
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> ty;
};
/*
* instruction
*/
struct TyInstruction {
public:
virtual void serialize(cereal::JSONOutputArchive &archive) const = 0;
static std::shared_ptr<TyInstruction> make(const llvm::Instruction &inst);
static bool isSupported(const llvm::Instruction &inst);
virtual std::shared_ptr<TyValue> get_op(int i) = 0;
virtual void replace_op(int i, std::shared_ptr<TyValue> val) = 0;
};
struct TyBinaryOperator {
public:
TyBinaryOperator(TyBop _opcode, std::shared_ptr<TyValueType> _operandtype,
std::shared_ptr<TyValue> _operand1,
std::shared_ptr<TyValue> _operand2);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyBinaryOperator>
make(const llvm::BinaryOperator &bop);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private:
TyBop opcode;
std::shared_ptr<TyValueType> operandtype;
std::shared_ptr<TyValue> operand1;
std::shared_ptr<TyValue> operand2;
};
struct TyFloatBinaryOperator {
public:
TyFloatBinaryOperator(TyFbop _opcode,
std::shared_ptr<TyValueType> _operandtype,
std::shared_ptr<TyValue> _operand1,
std::shared_ptr<TyValue> _operand2);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyFloatBinaryOperator>
make(const llvm::BinaryOperator &bop);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private:
TyFbop opcode;
std::shared_ptr<TyValueType> operandtype;
std::shared_ptr<TyValue> operand1;
std::shared_ptr<TyValue> operand2;
};
struct TyICmpInst {
public:
TyICmpInst(TyIcmpPred _predicate, std::shared_ptr<TyValueType> _operandtype,
std::shared_ptr<TyValue> _operand1,
std::shared_ptr<TyValue> _operand2);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyICmpInst> make(const llvm::ICmpInst &iCmpInst);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private:
TyIcmpPred predicate;
std::shared_ptr<TyValueType> operandtype;
std::shared_ptr<TyValue> operand1;
std::shared_ptr<TyValue> operand2;
};
struct TyFCmpInst {
public:
TyFCmpInst(TyFcmpPred _predicate, std::shared_ptr<TyValueType> _operandtype,
std::shared_ptr<TyValue> _operand1,
std::shared_ptr<TyValue> _operand2);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyFCmpInst> make(const llvm::FCmpInst &fCmpInst);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private:
TyFcmpPred predicate;
std::shared_ptr<TyValueType> operandtype;
std::shared_ptr<TyValue> operand1;
std::shared_ptr<TyValue> operand2;
};
struct TyLoadInst {
public:
TyLoadInst(std::shared_ptr<TyValueType> _pointertype,
std::shared_ptr<TyValueType> _valtype,
std::shared_ptr<TyValue> _ptrvalue, int _align);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyLoadInst> make(const llvm::AllocaInst &ai);
static std::shared_ptr<TyLoadInst> make(const llvm::LoadInst &li);
static std::shared_ptr<TyLoadInst> make(const llvm::StoreInst &si);
static std::shared_ptr<TyLoadInst> makeAlignOne(llvm::Instruction *i);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
std::shared_ptr<TyValue> getPtrValue();
private:
std::shared_ptr<TyValueType> pointertype;
std::shared_ptr<TyValueType> valtype;
std::shared_ptr<TyValue> ptrvalue;
int align;
};
struct TySelectInst{
public :
TySelectInst(std::shared_ptr<TyValue> _cond, std::shared_ptr<TyValueType> _valty, std::shared_ptr<TyValue> _trueval, std::shared_ptr<TyValue> _falseval);
void serialize(cereal::JSONOutputArchive& archive) const;
static std::shared_ptr<TySelectInst> make(const llvm::SelectInst &si);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private :
std::shared_ptr<TyValue> cond;
std::shared_ptr<TyValueType> valty;
std::shared_ptr<TyValue> trueval;
std::shared_ptr<TyValue> falseval;
};
struct TyBitCastInst {
public:
TyBitCastInst(std::shared_ptr<TyValueType> _fromty,
std::shared_ptr<TyValue> _v,
std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyBitCastInst> make(const llvm::BitCastInst &li);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private:
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TyIntToPtrInst {
public:
TyIntToPtrInst(std::shared_ptr<TyValueType> _fromty,
std::shared_ptr<TyValue> _v,
std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyIntToPtrInst> make(const llvm::IntToPtrInst &li);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private:
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TyPtrToIntInst {
public:
TyPtrToIntInst(std::shared_ptr<TyValueType> _fromty,
std::shared_ptr<TyValue> _v,
std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyPtrToIntInst> make(const llvm::PtrToIntInst &li);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private:
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TyGetElementPtrInst {
public:
TyGetElementPtrInst(
std::shared_ptr<TyValueType> _ty, std::shared_ptr<TyValueType> _retty,
std::shared_ptr<TyValue> _ptr,
std::vector<std::pair<std::shared_ptr<TySize>, std::shared_ptr<TyValue>>>
&_indexes,
bool is_inbounds);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyGetElementPtrInst>
make(const llvm::GetElementPtrInst &li);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
bool inbounds() { return is_inbounds; }
private:
std::shared_ptr<TyValueType> ty;
std::shared_ptr<TyValueType> retty;
std::shared_ptr<TyValue> ptr;
std::vector<std::pair<std::shared_ptr<TySize>, std::shared_ptr<TyValue>>>
indexes;
bool is_inbounds;
};
struct TyFpextInst{
public :
TyFpextInst(std::shared_ptr<TyValueType> _fromty, std::shared_ptr<TyValue> _v, std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive& archive) const;
static std::shared_ptr<TyFpextInst> make(const llvm::FPExtInst &fpti);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private :
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TyFptruncInst{
public :
TyFptruncInst(std::shared_ptr<TyValueType> _fromty, std::shared_ptr<TyValue> _v, std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive& archive) const;
static std::shared_ptr<TyFptruncInst> make(const llvm::FPTruncInst &fpti);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private :
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TyZextInst{
public :
TyZextInst(std::shared_ptr<TyValueType> _fromty, std::shared_ptr<TyValue> _v, std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive& archive) const;
static std::shared_ptr<TyZextInst> make(const llvm::ZExtInst &zei);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private :
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TySextInst{
public :
TySextInst(std::shared_ptr<TyValueType> _fromty, std::shared_ptr<TyValue> _v, std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive& archive) const;
static std::shared_ptr<TySextInst> make(const llvm::SExtInst &sei);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private :
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TyTruncInst{
public :
TyTruncInst(std::shared_ptr<TyValueType> _fromty, std::shared_ptr<TyValue> _v, std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive& archive) const;
static std::shared_ptr<TyTruncInst> make(const llvm::TruncInst &ti);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private :
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TyFptosiInst {
public:
TyFptosiInst(std::shared_ptr<TyValueType> _fromty,
std::shared_ptr<TyValue> _v, std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive &archive) const;
static std::shared_ptr<TyFptosiInst> make(const llvm::FPToSIInst &ftsi);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private:
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TySitofpInst{
public :
TySitofpInst(std::shared_ptr<TyValueType> _fromty, std::shared_ptr<TyValue> _v, std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive& archive) const;
static std::shared_ptr<TySitofpInst> make(const llvm::SIToFPInst &stfi);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private :
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TyUitofpInst{
public :
TyUitofpInst(std::shared_ptr<TyValueType> _fromty, std::shared_ptr<TyValue> _v, std::shared_ptr<TyValueType> _toty);
void serialize(cereal::JSONOutputArchive& archive) const;
static std::shared_ptr<TyUitofpInst> make(const llvm::UIToFPInst &utfi);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);
private :
std::shared_ptr<TyValueType> fromty;
std::shared_ptr<TyValue> v;
std::shared_ptr<TyValueType> toty;
};
struct TyInsertValueInst{
public :
TyInsertValueInst(std::shared_ptr<TyValueType> _aggrty, std::shared_ptr<TyValue> _aggrv, std::shared_ptr<TyValueType> _argty, std::shared_ptr<TyValue> _argv, std::vector<unsigned> _idx);
void serialize(cereal::JSONOutputArchive& archive) const;
static std::shared_ptr<TyInsertValueInst> make(const llvm::InsertValueInst &ivi);
std::shared_ptr<TyValue> get_op(int i);
void replace_op(int i, std::shared_ptr<TyValue> val);