@@ -11,6 +11,8 @@ use super::InstMatcher;
1111
1212#[ derive( PartialEq , Clone ) ]
1313pub enum BinaryOperator {
14+ Any ,
15+
1416 Add ,
1517 Sub ,
1618 Mul ,
@@ -33,26 +35,50 @@ pub enum BinaryOperator {
3335}
3436
3537impl BinaryOperator {
36- pub fn match_llvm_opcode ( & self , op : LLVMOpcode ) -> bool {
37- match op {
38- LLVMOpcode :: LLVMAdd => matches ! ( self , BinaryOperator :: Add ) ,
39- LLVMOpcode :: LLVMSub => matches ! ( self , BinaryOperator :: Sub ) ,
40- LLVMOpcode :: LLVMMul => matches ! ( self , BinaryOperator :: Mul ) ,
41- LLVMOpcode :: LLVMSDiv => matches ! ( self , BinaryOperator :: SDiv ) ,
42- LLVMOpcode :: LLVMSRem => matches ! ( self , BinaryOperator :: SRem ) ,
43- LLVMOpcode :: LLVMFAdd => matches ! ( self , BinaryOperator :: FAdd ) ,
44- LLVMOpcode :: LLVMFSub => matches ! ( self , BinaryOperator :: FSub ) ,
45- LLVMOpcode :: LLVMFMul => matches ! ( self , BinaryOperator :: FMul ) ,
46- LLVMOpcode :: LLVMFDiv => matches ! ( self , BinaryOperator :: FDiv ) ,
47- LLVMOpcode :: LLVMFRem => matches ! ( self , BinaryOperator :: FRem ) ,
48-
49- LLVMOpcode :: LLVMAnd => matches ! ( self , BinaryOperator :: And ) ,
50- LLVMOpcode :: LLVMOr => matches ! ( self , BinaryOperator :: Or | BinaryOperator :: OrDisjoint ) ,
51- LLVMOpcode :: LLVMXor => matches ! ( self , BinaryOperator :: Xor ) ,
52-
53- LLVMOpcode :: LLVMShl => matches ! ( self , BinaryOperator :: LogicalShiftLeft ) ,
54- LLVMOpcode :: LLVMLShr => matches ! ( self , BinaryOperator :: LogicalShiftRight ) ,
55- LLVMOpcode :: LLVMAShr => matches ! ( self , BinaryOperator :: ArithmeticShiftRight ) ,
38+ pub fn match_llvm_opcode ( & self , llvm_op : LLVMOpcode ) -> bool {
39+ match llvm_op {
40+ LLVMOpcode :: LLVMAdd => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: Add ) ,
41+
42+ LLVMOpcode :: LLVMSub => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: Sub ) ,
43+
44+ LLVMOpcode :: LLVMMul => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: Mul ) ,
45+
46+ LLVMOpcode :: LLVMSDiv => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: SDiv ) ,
47+
48+ LLVMOpcode :: LLVMSRem => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: SRem ) ,
49+
50+ LLVMOpcode :: LLVMFAdd => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: FAdd ) ,
51+
52+ LLVMOpcode :: LLVMFSub => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: FSub ) ,
53+
54+ LLVMOpcode :: LLVMFMul => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: FMul ) ,
55+
56+ LLVMOpcode :: LLVMFDiv => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: FDiv ) ,
57+
58+ LLVMOpcode :: LLVMFRem => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: FRem ) ,
59+
60+ LLVMOpcode :: LLVMAnd => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: And ) ,
61+
62+ LLVMOpcode :: LLVMOr => matches ! (
63+ self ,
64+ BinaryOperator :: Any | BinaryOperator :: Or | BinaryOperator :: OrDisjoint
65+ ) ,
66+
67+ LLVMOpcode :: LLVMXor => matches ! ( self , BinaryOperator :: Any | BinaryOperator :: Xor ) ,
68+
69+ LLVMOpcode :: LLVMShl => {
70+ matches ! ( self , BinaryOperator :: Any | BinaryOperator :: LogicalShiftLeft )
71+ }
72+
73+ LLVMOpcode :: LLVMLShr => matches ! (
74+ self ,
75+ BinaryOperator :: Any | BinaryOperator :: LogicalShiftRight
76+ ) ,
77+
78+ LLVMOpcode :: LLVMAShr => matches ! (
79+ self ,
80+ BinaryOperator :: Any | BinaryOperator :: ArithmeticShiftRight
81+ ) ,
5682
5783 _ => false ,
5884 }
@@ -69,6 +95,30 @@ pub struct BinaryInstMatcher {
6995}
7096
7197impl BinaryInstMatcher {
98+ pub fn create_any (
99+ lhs : Box < dyn InstMatcher > ,
100+ rhs : Box < dyn InstMatcher > ,
101+ ) -> Box < dyn InstMatcher > {
102+ Box :: new ( BinaryInstMatcher {
103+ lhs_matcher : lhs,
104+ rhs_matcher : rhs,
105+ operator : BinaryOperator :: Any ,
106+ commutatively : false ,
107+ } )
108+ }
109+
110+ pub fn create_commutatively_any (
111+ lhs : Box < dyn InstMatcher > ,
112+ rhs : Box < dyn InstMatcher > ,
113+ ) -> Box < dyn InstMatcher > {
114+ Box :: new ( BinaryInstMatcher {
115+ lhs_matcher : lhs,
116+ rhs_matcher : rhs,
117+ operator : BinaryOperator :: Any ,
118+ commutatively : true ,
119+ } )
120+ }
121+
72122 pub fn create_add (
73123 lhs : Box < dyn InstMatcher > ,
74124 rhs : Box < dyn InstMatcher > ,
@@ -494,8 +544,8 @@ impl InstMatcher for BinaryInstMatcher {
494544 }
495545 }
496546
497- let rhs = LLVMGetOperand ( instruction, 1 ) ;
498547 let lhs = LLVMGetOperand ( instruction, 0 ) ;
548+ let rhs = LLVMGetOperand ( instruction, 1 ) ;
499549
500550 if self . lhs_matcher . is_match ( lhs) && self . rhs_matcher . is_match ( rhs) {
501551 return true ;
0 commit comments