257 void DUIterator_Last::verify_step(uint num_edges) { 258 assert((int)num_edges > 0, "need non-zero edge count for loop progress"); 259 _outcnt -= num_edges; 260 _del_tick += num_edges; 261 // Make sure we are still in sync, possibly with no more out-edges: 262 const Node* node = _node; 263 verify(node, true); 264 assert(node->_last_del == _last, "must have deleted the edge just produced"); 265 } 266 267 #endif //OPTO_DU_ITERATOR_ASSERT 268 269 270 #endif //ASSERT 271 272 273 // This constant used to initialize _out may be any non-null value. 274 // The value NULL is reserved for the top node only. 275 #define NO_OUT_ARRAY ((Node**)-1) 276 277 // This funny expression handshakes with Node::operator new 278 // to pull Compile::current out of the new node's _out field, 279 // and then calls a subroutine which manages most field 280 // initializations. The only one which is tricky is the 281 // _idx field, which is const, and so must be initialized 282 // by a return value, not an assignment. 283 // 284 // (Aren't you thankful that Java finals don't require so many tricks?) 285 #define IDX_INIT(req) this->Init((req), (Compile*) this->_out) 286 #ifdef _MSC_VER // the IDX_INIT hack falls foul of warning C4355 287 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list 288 #endif 289 #ifdef __clang__ 290 #pragma clang diagnostic push 291 #pragma GCC diagnostic ignored "-Wuninitialized" 292 #endif 293 294 // Out-of-line code from node constructors. 295 // Executed only when extra debug info. is being passed around. 296 static void init_node_notes(Compile* C, int idx, Node_Notes* nn) { 297 C->set_node_notes_at(idx, nn); 298 } 299 300 // Shared initialization code. 301 inline int Node::Init(int req, Compile* C) { 302 assert(Compile::current() == C, "must use operator new(Compile*)"); 303 int idx = C->next_unique(); 304 305 // Allocate memory for the necessary number of edges. 306 if (req > 0) { 307 // Allocate space for _in array to have double alignment. 308 _in = (Node **) ((char *) (C->node_arena()->Amalloc_D(req * sizeof(void*)))); 309 #ifdef ASSERT 310 _in[req-1] = this; // magic cookie for assertion check 311 #endif 312 } 313 // If there are default notes floating around, capture them: 314 Node_Notes* nn = C->default_node_notes(); 315 if (nn != NULL) init_node_notes(C, idx, nn); 316 317 // Note: At this point, C is dead, 318 // and we begin to initialize the new Node. 319 320 _cnt = _max = req; 321 _outcnt = _outmax = 0; 322 _class_id = Class_Node; 323 _flags = 0; 324 _out = NO_OUT_ARRAY; 325 return idx; 326 } 327 328 //------------------------------Node------------------------------------------- 329 // Create a Node, with a given number of required edges. 330 Node::Node(uint req) 331 : _idx(IDX_INIT(req)) 332 { 333 assert( req < (uint)(MaxNodeLimit - NodeLimitFudgeFactor), "Input limit exceeded" ); 334 debug_only( verify_construction() ); 335 NOT_PRODUCT(nodes_created++); 336 if (req == 0) { 337 assert( _in == (Node**)this, "Must not pass arg count to 'new'" ); 338 _in = NULL; 339 } else { 340 assert( _in[req-1] == this, "Must pass arg count to 'new'" ); 341 Node** to = _in; 342 for(uint i = 0; i < req; i++) { 343 to[i] = NULL; 344 } 345 } 346 } 347 348 //------------------------------Node------------------------------------------- 349 Node::Node(Node *n0) 350 : _idx(IDX_INIT(1)) 351 { 352 debug_only( verify_construction() ); 353 NOT_PRODUCT(nodes_created++); 354 // Assert we allocated space for input array already 355 assert( _in[0] == this, "Must pass arg count to 'new'" ); 356 assert( is_not_dead(n0), "can not use dead node"); 357 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 358 } 359 360 //------------------------------Node------------------------------------------- 361 Node::Node(Node *n0, Node *n1) 362 : _idx(IDX_INIT(2)) 363 { 364 debug_only( verify_construction() ); 365 NOT_PRODUCT(nodes_created++); 366 // Assert we allocated space for input array already 367 assert( _in[1] == this, "Must pass arg count to 'new'" ); 368 assert( is_not_dead(n0), "can not use dead node"); 369 assert( is_not_dead(n1), "can not use dead node"); 370 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 371 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 372 } 373 374 //------------------------------Node------------------------------------------- 375 Node::Node(Node *n0, Node *n1, Node *n2) 376 : _idx(IDX_INIT(3)) 377 { 378 debug_only( verify_construction() ); 379 NOT_PRODUCT(nodes_created++); 380 // Assert we allocated space for input array already 381 assert( _in[2] == this, "Must pass arg count to 'new'" ); 382 assert( is_not_dead(n0), "can not use dead node"); 383 assert( is_not_dead(n1), "can not use dead node"); 384 assert( is_not_dead(n2), "can not use dead node"); 385 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 386 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 387 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); 388 } 389 390 //------------------------------Node------------------------------------------- 391 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3) 392 : _idx(IDX_INIT(4)) 393 { 394 debug_only( verify_construction() ); 395 NOT_PRODUCT(nodes_created++); 396 // Assert we allocated space for input array already 397 assert( _in[3] == this, "Must pass arg count to 'new'" ); 398 assert( is_not_dead(n0), "can not use dead node"); 399 assert( is_not_dead(n1), "can not use dead node"); 400 assert( is_not_dead(n2), "can not use dead node"); 401 assert( is_not_dead(n3), "can not use dead node"); 402 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 403 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 404 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); 405 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); 406 } 407 408 //------------------------------Node------------------------------------------- 409 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, Node *n4) 410 : _idx(IDX_INIT(5)) 411 { 412 debug_only( verify_construction() ); 413 NOT_PRODUCT(nodes_created++); 414 // Assert we allocated space for input array already 415 assert( _in[4] == this, "Must pass arg count to 'new'" ); 416 assert( is_not_dead(n0), "can not use dead node"); 417 assert( is_not_dead(n1), "can not use dead node"); 418 assert( is_not_dead(n2), "can not use dead node"); 419 assert( is_not_dead(n3), "can not use dead node"); 420 assert( is_not_dead(n4), "can not use dead node"); 421 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 422 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 423 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); 424 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); 425 _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); 426 } 427 428 //------------------------------Node------------------------------------------- 429 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, 430 Node *n4, Node *n5) 431 : _idx(IDX_INIT(6)) 432 { 433 debug_only( verify_construction() ); 434 NOT_PRODUCT(nodes_created++); 435 // Assert we allocated space for input array already 436 assert( _in[5] == this, "Must pass arg count to 'new'" ); 437 assert( is_not_dead(n0), "can not use dead node"); 438 assert( is_not_dead(n1), "can not use dead node"); 439 assert( is_not_dead(n2), "can not use dead node"); 440 assert( is_not_dead(n3), "can not use dead node"); 441 assert( is_not_dead(n4), "can not use dead node"); 442 assert( is_not_dead(n5), "can not use dead node"); 443 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 444 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 445 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); 446 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); 447 _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); 448 _in[5] = n5; if (n5 != NULL) n5->add_out((Node *)this); 449 } 450 451 //------------------------------Node------------------------------------------- 452 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, 453 Node *n4, Node *n5, Node *n6) 454 : _idx(IDX_INIT(7)) 455 { 456 debug_only( verify_construction() ); 457 NOT_PRODUCT(nodes_created++); 458 // Assert we allocated space for input array already 459 assert( _in[6] == this, "Must pass arg count to 'new'" ); 460 assert( is_not_dead(n0), "can not use dead node"); 461 assert( is_not_dead(n1), "can not use dead node"); 462 assert( is_not_dead(n2), "can not use dead node"); 463 assert( is_not_dead(n3), "can not use dead node"); 464 assert( is_not_dead(n4), "can not use dead node"); 465 assert( is_not_dead(n5), "can not use dead node"); 466 assert( is_not_dead(n6), "can not use dead node"); 467 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 468 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 469 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); 470 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); 471 _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); 472 _in[5] = n5; if (n5 != NULL) n5->add_out((Node *)this); 473 _in[6] = n6; if (n6 != NULL) n6->add_out((Node *)this); 474 } 1049 // Example: AddINode::Ideal must check for add of zero; in this case it 1050 // returns NULL instead of doing any graph reshaping. 1051 // 1052 // You cannot modify any old Nodes except for the 'this' pointer. Due to 1053 // sharing there may be other users of the old Nodes relying on their current 1054 // semantics. Modifying them will break the other users. 1055 // Example: when reshape "(X+3)+4" into "X+7" you must leave the Node for 1056 // "X+3" unchanged in case it is shared. 1057 // 1058 // If you modify the 'this' pointer's inputs, you should use 1059 // 'set_req'. If you are making a new Node (either as the new root or 1060 // some new internal piece) you may use 'init_req' to set the initial 1061 // value. You can make a new Node with either 'new' or 'clone'. In 1062 // either case, def-use info is correctly maintained. 1063 // 1064 // Example: reshape "(X+3)+4" into "X+7": 1065 // set_req(1, in(1)->in(1)); 1066 // set_req(2, phase->intcon(7)); 1067 // return this; 1068 // Example: reshape "X*4" into "X<<2" 1069 // return new (C) LShiftINode(in(1), phase->intcon(2)); 1070 // 1071 // You must call 'phase->transform(X)' on any new Nodes X you make, except 1072 // for the returned root node. Example: reshape "X*31" with "(X<<5)-X". 1073 // Node *shift=phase->transform(new(C)LShiftINode(in(1),phase->intcon(5))); 1074 // return new (C) AddINode(shift, in(1)); 1075 // 1076 // When making a Node for a constant use 'phase->makecon' or 'phase->intcon'. 1077 // These forms are faster than 'phase->transform(new (C) ConNode())' and Do 1078 // The Right Thing with def-use info. 1079 // 1080 // You cannot bury the 'this' Node inside of a graph reshape. If the reshaped 1081 // graph uses the 'this' Node it must be the root. If you want a Node with 1082 // the same Opcode as the 'this' pointer use 'clone'. 1083 // 1084 Node *Node::Ideal(PhaseGVN *phase, bool can_reshape) { 1085 return NULL; // Default to being Ideal already 1086 } 1087 1088 // Some nodes have specific Ideal subgraph transformations only if they are 1089 // unique users of specific nodes. Such nodes should be put on IGVN worklist 1090 // for the transformations to happen. 1091 bool Node::has_special_unique_user() const { 1092 assert(outcnt() == 1, "match only for unique out"); 1093 Node* n = unique_out(); 1094 int op = Opcode(); 1095 if( this->is_Store() ) { 1096 // Condition for back-to-back stores folding. 1097 return n->Opcode() == op && n->in(MemNode::Memory) == this; | 257 void DUIterator_Last::verify_step(uint num_edges) { 258 assert((int)num_edges > 0, "need non-zero edge count for loop progress"); 259 _outcnt -= num_edges; 260 _del_tick += num_edges; 261 // Make sure we are still in sync, possibly with no more out-edges: 262 const Node* node = _node; 263 verify(node, true); 264 assert(node->_last_del == _last, "must have deleted the edge just produced"); 265 } 266 267 #endif //OPTO_DU_ITERATOR_ASSERT 268 269 270 #endif //ASSERT 271 272 273 // This constant used to initialize _out may be any non-null value. 274 // The value NULL is reserved for the top node only. 275 #define NO_OUT_ARRAY ((Node**)-1) 276 277 // Out-of-line code from node constructors. 278 // Executed only when extra debug info. is being passed around. 279 static void init_node_notes(Compile* C, int idx, Node_Notes* nn) { 280 C->set_node_notes_at(idx, nn); 281 } 282 283 // Shared initialization code. 284 inline int Node::Init(int req) { 285 Compile* C = Compile::current(); 286 int idx = C->next_unique(); 287 288 // Allocate memory for the necessary number of edges. 289 if (req > 0) { 290 // Allocate space for _in array to have double alignment. 291 _in = (Node **) ((char *) (C->node_arena()->Amalloc_D(req * sizeof(void*)))); 292 #ifdef ASSERT 293 _in[req-1] = this; // magic cookie for assertion check 294 #endif 295 } 296 // If there are default notes floating around, capture them: 297 Node_Notes* nn = C->default_node_notes(); 298 if (nn != NULL) init_node_notes(C, idx, nn); 299 300 // Note: At this point, C is dead, 301 // and we begin to initialize the new Node. 302 303 _cnt = _max = req; 304 _outcnt = _outmax = 0; 305 _class_id = Class_Node; 306 _flags = 0; 307 _out = NO_OUT_ARRAY; 308 return idx; 309 } 310 311 //------------------------------Node------------------------------------------- 312 // Create a Node, with a given number of required edges. 313 Node::Node(uint req) 314 : _idx(Init(req)) 315 { 316 assert( req < (uint)(MaxNodeLimit - NodeLimitFudgeFactor), "Input limit exceeded" ); 317 debug_only( verify_construction() ); 318 NOT_PRODUCT(nodes_created++); 319 if (req == 0) { 320 assert( _in == (Node**)this, "Must not pass arg count to 'new'" ); 321 _in = NULL; 322 } else { 323 assert( _in[req-1] == this, "Must pass arg count to 'new'" ); 324 Node** to = _in; 325 for(uint i = 0; i < req; i++) { 326 to[i] = NULL; 327 } 328 } 329 } 330 331 //------------------------------Node------------------------------------------- 332 Node::Node(Node *n0) 333 : _idx(Init(1)) 334 { 335 debug_only( verify_construction() ); 336 NOT_PRODUCT(nodes_created++); 337 // Assert we allocated space for input array already 338 assert( _in[0] == this, "Must pass arg count to 'new'" ); 339 assert( is_not_dead(n0), "can not use dead node"); 340 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 341 } 342 343 //------------------------------Node------------------------------------------- 344 Node::Node(Node *n0, Node *n1) 345 : _idx(Init(2)) 346 { 347 debug_only( verify_construction() ); 348 NOT_PRODUCT(nodes_created++); 349 // Assert we allocated space for input array already 350 assert( _in[1] == this, "Must pass arg count to 'new'" ); 351 assert( is_not_dead(n0), "can not use dead node"); 352 assert( is_not_dead(n1), "can not use dead node"); 353 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 354 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 355 } 356 357 //------------------------------Node------------------------------------------- 358 Node::Node(Node *n0, Node *n1, Node *n2) 359 : _idx(Init(3)) 360 { 361 debug_only( verify_construction() ); 362 NOT_PRODUCT(nodes_created++); 363 // Assert we allocated space for input array already 364 assert( _in[2] == this, "Must pass arg count to 'new'" ); 365 assert( is_not_dead(n0), "can not use dead node"); 366 assert( is_not_dead(n1), "can not use dead node"); 367 assert( is_not_dead(n2), "can not use dead node"); 368 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 369 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 370 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); 371 } 372 373 //------------------------------Node------------------------------------------- 374 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3) 375 : _idx(Init(4)) 376 { 377 debug_only( verify_construction() ); 378 NOT_PRODUCT(nodes_created++); 379 // Assert we allocated space for input array already 380 assert( _in[3] == this, "Must pass arg count to 'new'" ); 381 assert( is_not_dead(n0), "can not use dead node"); 382 assert( is_not_dead(n1), "can not use dead node"); 383 assert( is_not_dead(n2), "can not use dead node"); 384 assert( is_not_dead(n3), "can not use dead node"); 385 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 386 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 387 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); 388 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); 389 } 390 391 //------------------------------Node------------------------------------------- 392 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, Node *n4) 393 : _idx(Init(5)) 394 { 395 debug_only( verify_construction() ); 396 NOT_PRODUCT(nodes_created++); 397 // Assert we allocated space for input array already 398 assert( _in[4] == this, "Must pass arg count to 'new'" ); 399 assert( is_not_dead(n0), "can not use dead node"); 400 assert( is_not_dead(n1), "can not use dead node"); 401 assert( is_not_dead(n2), "can not use dead node"); 402 assert( is_not_dead(n3), "can not use dead node"); 403 assert( is_not_dead(n4), "can not use dead node"); 404 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 405 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 406 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); 407 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); 408 _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); 409 } 410 411 //------------------------------Node------------------------------------------- 412 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, 413 Node *n4, Node *n5) 414 : _idx(Init(6)) 415 { 416 debug_only( verify_construction() ); 417 NOT_PRODUCT(nodes_created++); 418 // Assert we allocated space for input array already 419 assert( _in[5] == this, "Must pass arg count to 'new'" ); 420 assert( is_not_dead(n0), "can not use dead node"); 421 assert( is_not_dead(n1), "can not use dead node"); 422 assert( is_not_dead(n2), "can not use dead node"); 423 assert( is_not_dead(n3), "can not use dead node"); 424 assert( is_not_dead(n4), "can not use dead node"); 425 assert( is_not_dead(n5), "can not use dead node"); 426 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 427 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 428 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); 429 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); 430 _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); 431 _in[5] = n5; if (n5 != NULL) n5->add_out((Node *)this); 432 } 433 434 //------------------------------Node------------------------------------------- 435 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, 436 Node *n4, Node *n5, Node *n6) 437 : _idx(Init(7)) 438 { 439 debug_only( verify_construction() ); 440 NOT_PRODUCT(nodes_created++); 441 // Assert we allocated space for input array already 442 assert( _in[6] == this, "Must pass arg count to 'new'" ); 443 assert( is_not_dead(n0), "can not use dead node"); 444 assert( is_not_dead(n1), "can not use dead node"); 445 assert( is_not_dead(n2), "can not use dead node"); 446 assert( is_not_dead(n3), "can not use dead node"); 447 assert( is_not_dead(n4), "can not use dead node"); 448 assert( is_not_dead(n5), "can not use dead node"); 449 assert( is_not_dead(n6), "can not use dead node"); 450 _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); 451 _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); 452 _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); 453 _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); 454 _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); 455 _in[5] = n5; if (n5 != NULL) n5->add_out((Node *)this); 456 _in[6] = n6; if (n6 != NULL) n6->add_out((Node *)this); 457 } 1032 // Example: AddINode::Ideal must check for add of zero; in this case it 1033 // returns NULL instead of doing any graph reshaping. 1034 // 1035 // You cannot modify any old Nodes except for the 'this' pointer. Due to 1036 // sharing there may be other users of the old Nodes relying on their current 1037 // semantics. Modifying them will break the other users. 1038 // Example: when reshape "(X+3)+4" into "X+7" you must leave the Node for 1039 // "X+3" unchanged in case it is shared. 1040 // 1041 // If you modify the 'this' pointer's inputs, you should use 1042 // 'set_req'. If you are making a new Node (either as the new root or 1043 // some new internal piece) you may use 'init_req' to set the initial 1044 // value. You can make a new Node with either 'new' or 'clone'. In 1045 // either case, def-use info is correctly maintained. 1046 // 1047 // Example: reshape "(X+3)+4" into "X+7": 1048 // set_req(1, in(1)->in(1)); 1049 // set_req(2, phase->intcon(7)); 1050 // return this; 1051 // Example: reshape "X*4" into "X<<2" 1052 // return new LShiftINode(in(1), phase->intcon(2)); 1053 // 1054 // You must call 'phase->transform(X)' on any new Nodes X you make, except 1055 // for the returned root node. Example: reshape "X*31" with "(X<<5)-X". 1056 // Node *shift=phase->transform(new LShiftINode(in(1),phase->intcon(5))); 1057 // return new AddINode(shift, in(1)); 1058 // 1059 // When making a Node for a constant use 'phase->makecon' or 'phase->intcon'. 1060 // These forms are faster than 'phase->transform(new ConNode())' and Do 1061 // The Right Thing with def-use info. 1062 // 1063 // You cannot bury the 'this' Node inside of a graph reshape. If the reshaped 1064 // graph uses the 'this' Node it must be the root. If you want a Node with 1065 // the same Opcode as the 'this' pointer use 'clone'. 1066 // 1067 Node *Node::Ideal(PhaseGVN *phase, bool can_reshape) { 1068 return NULL; // Default to being Ideal already 1069 } 1070 1071 // Some nodes have specific Ideal subgraph transformations only if they are 1072 // unique users of specific nodes. Such nodes should be put on IGVN worklist 1073 // for the transformations to happen. 1074 bool Node::has_special_unique_user() const { 1075 assert(outcnt() == 1, "match only for unique out"); 1076 Node* n = unique_out(); 1077 int op = Opcode(); 1078 if( this->is_Store() ) { 1079 // Condition for back-to-back stores folding. 1080 return n->Opcode() == op && n->in(MemNode::Memory) == this; |