Поиск характерных шаблонов кода, приводящих к ошибкам функционирования в программах промышленного размера (1162573), страница 2
Текст из файла (страница 2)
h"#i n c l u d e" l l v m / S u p p o r t / raw_ostream . h"#i n c l u d e" l l v m / DebugInfo . h"#i n c l u d e" l l v m / Support / GraphWriter . h"#i n c l u d e" l l v m /CCD/ D e f . h "#i n c l u d e" l l v m /CCD/ P r o p e r t y . h "#i n c l u d e" l l v m / IR / I n s t r u c t i o n s . h "#i n c l u d e<map>#i n c l u d e<s e t >#i n c l u d e<c a s s e r t >#i n c l u d e<v e c t o r >#i n c l u d e<a l g o r i t h m >#i n c l u d e<s t r i n g >#i n c l u d e<f s t r e a m >#i n c l u d e<s s t r e a m >#i n c l u d e<i t e r a t o r >#i n c l u d e<e x c e p t i o n >namespaceclassllvm{DependenceGraph ;typedeftypedeftypedef*s t d : : v e c t o r <DepGraphNode >std : : s t r i n gDepNodeVectType ;String ;*s t d : : s e t <DepGraphNode >DepNodeSetType ;/// DependenceGraph Class - A representation of a dependence graph for function.class D e p e n d e n c e G r a p h {DepNodeVectTypedepNodeVect ;int>std : : vector<vector ;int>s t d : : v e c t o r <s t d : : s e t <StringAbsFP ;StringFunctionName ;unsignedunsignedunsignedunsignedunsignedunsignedunsignedintintintintintintint>charachteristicsBySource ;BBCount ;CallyFunctionsCount ;ControlDepCount ;TrueDepCount ;AntiDepCount ;OutputDepCount ;sourceLinesCount ;11float A v e r a g e D e g r e e ;bool Merged ;const int v e c t o r L e n g t hfriend classpublic :typedeftypedeftypedeftypedeftypedef=59;SerializePDG ;s t d : : v e c t o r <D e p e n d e n c e > : : i t e r a t o riterator ;s t d : : v e c t o r <D e p e n d e n c e > : : c o n s t _ i t e r a t o rDepNodeVectType : : i t e r a t o rconst_iterator ;vect_iterator ;DepNodeVectType : : c o n s t _ i t e r a t o rs t d : : map<s t d : : p a i r <DepGraphNodeconst_vect_iterator ;*,DepGraphNode*>,D e p e n d e n c e T y p e>EdgeListType ;typedeftypedefEdgeListType : : i t e r a t o rs t d : : map<DepGraphNodeedge_iterator ;*,*DepGraphNode >nodesMapType ;/// nodes_iterator class - iterator class for dependence graph.class n o d e s _ i t e r a t o r {DependenceGraph : : v e c t _ i t e r a t o rpublic :inlineinlinepos ;n o d e s _ i t e r a t o r ( DependenceGraph : : v e c t _ i t e r a t o rn o d e s _ i t e r a t o r&operator ++()it ):pos ( i t ){++p o s ;return * this ;}inline n o d e s _ i t e r a t o r operator++(int )return n o d e s _ i t e r a t o r (++p o s ) ;{}inline DepGraphNode& operator * ( )return * ( * p o s ) ;{}inline bool operator==(constreturn p o s == r h s .
p o s ;n o d e s _ i t e r a t o r&rhs ){n o d e s _ i t e r a t o r&rhs ){}inline bool operator ! = ( constreturn p o s != r h s . p o s ;}};/// Default constructor .DependenceGraph ( ):AbsFP (CallyFunctionsCount (0) ,AntiDepCount ( 0 ) ,"" ),FunctionName ("" )ControlDepCount ( 0 ) ,OutputDepCount ( 0 ) ,Merged (,BBCount ( 0 ) ,TrueDepCount ( 0 ) ,false )depNodeVect . c l e a r ( ) ;vector . r e s i z e ( vectorLength ) ;charachteristicsBySource . r e s i z e ( vectorLength ) ;}// FIXME: reserve vector for instruction/// Create graph for given llvm Function.D e p e n d e n c e G r a p h ( s t d : : v e c t o r <F u n c t i o n *> &f u n c L i s t12,{{}s t d : : map<F u n c t i o n*,s t d : : map<V a l u e*,*s t d : : v e c t o r <V a l u e > > &f u n c A r g s ,s t d : : map< I n s t r u c t i o n*,u i n t 6 4 _ t > &I n s t r T o N o d e N u m b e r ,u i n t 6 4 _ t > &v a l u e N o d e N u m b e r s ,unsigned> &g l o b a l V a r N u m b e r s )"" ) , Merged ( false ) {s t d : : map<u i n t 6 4 _ t ,FunctionName (:AbsFP ("" ),a s s e r t ( d e p N o d e V e c t .
empty ( ) && "Module 's PDG exists!" ) ;unsigned i d = static_cast <INST_IDs>(LANDINGPAD_ID) ;for ( unsigned i = 0 ; i < f u n c L i s t . s i z e ( ) ; ++i ) {Function * F = f u n c L i s t [ i ] ;int i n s t I n d = 0 ;int b b I n d e x = 0 ;s t d : : map<B a s i c B l o c k * , int> B B I D l i s t ;for(autoi= F ->b e g i n ( ) ,e= F ->e n d ( ) ;B B I D l i s t . i n s e r t ( s t d : : p a i r <B a s i c B l o c kforif( inst_iteratorI=i n s t _ b e g i n (F) ,i!=e ;* , int >( iE =++i ),b b I n d e x++) ) ;inst_end (F) ;I!=E;++I ){* c i = d y n _ c a s t<C a l l I n s t >(&(* I ) ) )* f = c i -> g e t C a l l e d F u n c t i o n ( ) )if ( f ->getName ( ) == "llvm.dbg.declare" )continue ;( CallInstif( Functionint l i n e N = - 1 ;if ( MDNode *N =DILocationif(* I ) .
g e t M e t a d a t a ( "dbg" ) )( Loc . getLineNumber ( )l i n e N={L o c (N) ;>0){Loc . getLineNumber ( ) ;}}* n o d e = new* I ) . getOpcode ( ) ) ;DepGraphNode(DepGraphNode ( I n s t r T o N o d e N u m b e r [ & (*I)],lineN ,n o d e ->s e t F u n c t i o n L i n e N ( i n s t I n d ) ;n o d e ->setBBID ( B B I D l i s t . f i n d ( I ->g e t P a r e n t ( ) ) ->s e c o n d ) ;n o d e ->s e t F u n c t i o n N a m e ( F ->getName ( ) ) ;if ( C a l l I n s t * c i = d y n _ c a s t<C a l l I n s t >(&(* I ) ) )if ( F u n c t i o n * f = c i -> g e t C a l l e d F u n c t i o n ( ) ) {std : : s t r i n gs=f ->getName ( ) ;if ( ! s . empty ( ) )n o d e ->s e t S o u r c e N a m e ( s ) ;}d e p N o d e V e c t .
push_back ( n o d e ) ;i n s t I n d ++;}for ( autoae=ai=funcArgs [ F ] . begin ( ) ,f u n c A r g s [ F ] . end ( ) ;DepGraphNode* node=newai!=ae ;++a i ){* ai ] , 0 ,static_cast <int > ( ( * a i ) ->DepGraphNode ( v a l u e N o d e N u m b e r s [id+1+g e t T y p e ( ) ->g e t T y p e I D ( ) ) ) ;n o d e ->s e t F u n c t i o n L i n e N ( - 2 ) ;n o d e ->s e t F u n c t i o n N a m e ("VAR" ) ;d e p N o d e V e c t . push_back ( n o d e ) ;13}}for(auto++i )i=globalVarNumbers .
b e g i n ( ) ,e=g l o b a l V a r N u m b e r s . end ( ) ;i!=e ;{* nodeDepGraphNode=newDepGraphNode ( i -> f i r s t ,0,id+1+i ->s e c o n d ) ;n o d e ->s e t F u n c t i o n L i n e N ( - 3 ) ;n o d e ->s e t F u n c t i o n N a m e ("VAR" ) ;d e p N o d e V e c t . push_back ( n o d e ) ;}BBCount =0;AverageDegree=0;ControlDepCountTrueDepCount=AntiDepCount=OutputDepCount=0;0;0;=0;CallyFunctionsCount=0;vector .
r e s i z e ( vectorLength ) ;charachteristicsBySource . r e s i z e ( vectorLength ) ;}/// Create graph from given node 's and edge 's sets.D e p e n d e n c e G r a p h ( DepNodeSetType&s e t ,EdgeListTypenodesMapType &nodesMap )false ):AbsFP (&e d g e L i s t ,"" ),FunctionName ("" ),Merged ({depNodeVect . c l e a r ( ) ;vector . r e s i z e ( vectorLength ) ;charachteristicsBySource .
r e s i z e ( vectorLength ) ;nodesMapTypeforpList ;( DepNodeSetType : : i t e r a t o r++ i t )it=set . begin () ,end=s e t . end ( ) ;it!=end ;{DepGraphNode* node=newDepGraphNode (* it ) ;d e p N o d e V e c t . push_back ( n o d e ) ;p L i s t . i n s e r t ( s t d : : p a i r <DepGraphNode*,DepGraphNode* >( * i t,node ) ) ;}for( edge_iterator++ i t r )itr=edgeList . begin () ,End =e d g e L i s t .
end ( ) ;itr!=End ;{DependenceTypedt=static_cast <D e p e n d e n c e T y p e >( i t rA d d S i m p l e D e p e n d e n c e ( p L i s t [ i t r -> f i r s t . f i r s t ] ,->s e c o n d ) ;p L i s t [ i t r -> f i r s t . s e c o n d ] ,;}nodesMap . i n s e r t ( p L i s t . b e g i n ( ) ,p L i s t . end ( ) ) ;}/// destructro~DependenceGraph ( ){for ( unsigned int i = 0 ;delete d e p N o d e V e c t [ i ] ;i<depNodeVect . s i z e ( ) ;}depNodeVect . c l e a r ( ) ;}14i ++){dt )/// Reset node 's marks.inline void r e s e t M a r k s ( )for ( unsigned i = 0 ; i{<depNodeVect . s i z e ( ) ;++i )d e p N o d e V e c t [ i ] ->s e t M a r k ( 0 ) ;}/// Give the same ID to similar nodes.void g r o u p N o d e s ( bool t y p e = false ) {for ( unsigned i = 0 ; i < d e p N o d e V e c t . s i z e ( ) ; ++i )for ( unsigned j = i + 1 ; j < d e p N o d e V e c t .
s i z e ( ) ; ++j )if ( NodeGroup : : hasTheSameGroup ( d e p N o d e V e c t [ i ] ->g e t N o d e I D ( ),d e p N o d e V e c t [ j ] ->g e t N o d e I D ( ) ,type ) ){d e p N o d e V e c t [ i ] ->s e t N o d e I D ( NodeGroup : : g e t L o w e s t I D ( d e p N o d e V e c t [ i ] ->getNodeID ( ) ,type ) ) ;d e p N o d e V e c t [ j ] ->s e t N o d e I D ( NodeGroup : : g e t L o w e s t I D ( d e p N o d e V e c t [ i ] ->getNodeID ( ) ,type ) ) ;}}/// Calculate count for specific edge type.void r e C a l c u l a t e P r o p e r t i e s ( ) {ControlDepCountTrueDepCount=AntiDepCount=OutputDepCountfor ( unsigned ifor ( i t e r a t o r=0;0;0;=0;=it0;=i<depNodeVect .
s i z e ( ) ;i ++)outDepBegin ( depNodeVect [ i ] ) ,{end= outDepEnd (depNodeVect [ i ] ) ;it!=end ;++ i t )switch ( i t ->g e t D e p T y p e ( ) )case T r u e D e p e n d e n c e :{++TrueDepCount ;break ;case A n t i D e p e n d e n c e:++A n t i D e p C o u n t ;break ;case C o n t r o l D e p e n d e n c e:++C o n t r o l D e p C o u n t ;break ;case O u t p u t D e p e n d e n c e:++OutputDepCount ;break ;default :break ;}}}/// Debug function , call all graph functions to check its correctness .void c h e c k P D G C o r r e c t n e s s ( ) {getAbsFP ( ) ;getBBCount ( ) ;getControlDepCount ( ) ;15getTrueDepCount ( ) ;getAntiDepCount ( ) ;getOutputDepCount ( ) ;getCallyFunctionsCount () ;for(unsignedi=0;i<depNodeVect .
s i z e ( ) ;i ++){d e p N o d e V e c t [ i ] ->c h e c k N o d e ( ) ;}}/// Return absolute path for the source code from which graph was constructed .inline S t r i n g getAbsFP ( ) {return AbsFP ;}/// Return the llvm Function name from which graph was constructed .inline S t r i n g g e t F u n c t i o n N a m e ( ) {return F u n c t i o n N a m e ;}/// Return only llvm Function name without module path.inline S t r i n g getName ( ) {std : : size_tf = F u n c t i o n N a m e .