1 /* RTL reader for GCC. 2 Copyright (C) 1987-2017 Free Software Foundation, Inc. 3 4 This file is part of GCC. 5 6 GCC is free software; you can redistribute it and/or modify it under 7 the terms of the GNU General Public License as published by the Free 8 Software Foundation; either version 3, or (at your option) any later 9 version. 10 11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GCC; see the file COPYING3. If not see 18 <http://www.gnu.org/licenses/>. */ 19 20 /* This file is compiled twice: once for the generator programs 21 once for the compiler. */ 22 #ifdef GENERATOR_FILE 23 #include "bconfig.h" 24 #else 25 #include "config.h" 26 #endif 27 28 /* Disable rtl checking; it conflicts with the iterator handling. */ 29 #undef ENABLE_RTL_CHECKING 30 31 #include "system.h" 32 #include "coretypes.h" 33 #include "tm.h" 34 #include "rtl.h" 35 #include "obstack.h" 36 #include "read-md.h" 37 #include "gensupport.h" 38 39 #ifndef GENERATOR_FILE 40 #include "function.h" 41 #include "memmodel.h" 42 #include "emit-rtl.h" 43 #endif 44 45 /* One element in a singly-linked list of (integer, string) pairs. */ 46 struct map_value { 47 struct map_value *next; 48 int number; 49 const char *string; 50 }; 51 52 /* Maps an iterator or attribute name to a list of (integer, string) pairs. 53 The integers are iterator values; the strings are either C conditions 54 or attribute values. */ 55 struct mapping { 56 /* The name of the iterator or attribute. */ 57 const char *name; 58 59 /* The group (modes or codes) to which the iterator or attribute belongs. */ 60 struct iterator_group *group; 61 62 /* The list of (integer, string) pairs. */ 63 struct map_value *values; 64 65 /* For iterators, records the current value of the iterator. */ 66 struct map_value *current_value; 67 }; 68 69 /* A structure for abstracting the common parts of iterators. */ 70 struct iterator_group { 71 /* Tables of "mapping" structures, one for attributes and one for 72 iterators. */ 73 htab_t attrs, iterators; 74 75 /* Treat the given string as the name of a standard mode, etc., and 76 return its integer value. */ 77 int (*find_builtin) (const char *); 78 79 /* Make the given pointer use the given iterator value. */ 80 void (*apply_iterator) (void *, int); 81 }; 82 83 /* Records one use of an iterator. */ 84 struct iterator_use { 85 /* The iterator itself. */ 86 struct mapping *iterator; 87 88 /* The location of the use, as passed to the apply_iterator callback. */ 89 void *ptr; 90 }; 91 92 /* Records one use of an attribute (the "<[iterator:]attribute>" syntax) 93 in a non-string rtx field. */ 94 struct attribute_use { 95 /* The group that describes the use site. */ 96 struct iterator_group *group; 97 98 /* The name of the attribute, possibly with an "iterator:" prefix. */ 99 const char *value; 100 101 /* The location of the use, as passed to GROUP's apply_iterator callback. */ 102 void *ptr; 103 }; 104 105 /* This struct is used to link subst_attr named ATTR_NAME with 106 corresponding define_subst named ITER_NAME. */ 107 struct subst_attr_to_iter_mapping 108 { 109 char *attr_name; 110 char *iter_name; 111 }; 112 113 /* Hash-table to store links between subst-attributes and 114 define_substs. */ 115 htab_t subst_attr_to_iter_map = NULL; 116 /* This global stores name of subst-iterator which is currently being 117 processed. */ 118 const char *current_iterator_name; 119 120 static void validate_const_int (const char *); 121 static void one_time_initialization (void); 122 123 /* Global singleton. */ 124 rtx_reader *rtx_reader_ptr = NULL; 125 126 /* The mode and code iterator structures. */ 127 static struct iterator_group modes, codes, ints, substs; 128 129 /* All iterators used in the current rtx. */ 130 static vec<mapping *> current_iterators; 131 132 /* The list of all iterator uses in the current rtx. */ 133 static vec<iterator_use> iterator_uses; 134 135 /* The list of all attribute uses in the current rtx. */ 136 static vec<attribute_use> attribute_uses; 137 138 /* Implementations of the iterator_group callbacks for modes. */ 139 140 static int 141 find_mode (const char *name) 142 { 143 int i; 144 145 for (i = 0; i < NUM_MACHINE_MODES; i++) 146 if (strcmp (GET_MODE_NAME (i), name) == 0) 147 return i; 148 149 fatal_with_file_and_line ("unknown mode `%s'", name); 150 } 151 152 static void 153 apply_mode_iterator (void *loc, int mode) 154 { 155 PUT_MODE ((rtx) loc, (machine_mode) mode); 156 } 157 158 /* In compact dumps, the code of insns is prefixed with "c", giving "cinsn", 159 "cnote" etc, and CODE_LABEL is special-cased as "clabel". */ 160 161 struct compact_insn_name { 162 RTX_CODE code; 163 const char *name; 164 }; 165 166 static const compact_insn_name compact_insn_names[] = { 167 { DEBUG_INSN, "cdebug_insn" }, 168 { INSN, "cinsn" }, 169 { JUMP_INSN, "cjump_insn" }, 170 { CALL_INSN, "ccall_insn" }, 171 { JUMP_TABLE_DATA, "cjump_table_data" }, 172 { BARRIER, "cbarrier" }, 173 { CODE_LABEL, "clabel" }, 174 { NOTE, "cnote" } 175 }; 176 177 /* Implementations of the iterator_group callbacks for codes. */ 178 179 static int 180 find_code (const char *name) 181 { 182 int i; 183 184 for (i = 0; i < NUM_RTX_CODE; i++) 185 if (strcmp (GET_RTX_NAME (i), name) == 0) 186 return i; 187 188 for (i = 0; i < (signed)ARRAY_SIZE (compact_insn_names); i++) 189 if (strcmp (compact_insn_names[i].name, name) == 0) 190 return compact_insn_names[i].code; 191 192 fatal_with_file_and_line ("unknown rtx code `%s'", name); 193 } 194 195 static void 196 apply_code_iterator (void *loc, int code) 197 { 198 PUT_CODE ((rtx) loc, (enum rtx_code) code); 199 } 200 201 /* Implementations of the iterator_group callbacks for ints. */ 202 203 /* Since GCC does not construct a table of valid constants, 204 we have to accept any int as valid. No cross-checking can 205 be done. */ 206 207 static int 208 find_int (const char *name) 209 { 210 validate_const_int (name); 211 return atoi (name); 212 } 213 214 static void 215 apply_int_iterator (void *loc, int value) 216 { 217 *(int *)loc = value; 218 } 219 220 #ifdef GENERATOR_FILE 221 222 /* This routine adds attribute or does nothing depending on VALUE. When 223 VALUE is 1, it does nothing - the first duplicate of original 224 template is kept untouched when it's subjected to a define_subst. 225 When VALUE isn't 1, the routine modifies RTL-template LOC, adding 226 attribute, named exactly as define_subst, which later will be 227 applied. If such attribute has already been added, then no the 228 routine has no effect. */ 229 static void 230 apply_subst_iterator (void *loc, int value) 231 { 232 rtx rt = (rtx)loc; 233 rtx new_attr; 234 rtvec attrs_vec, new_attrs_vec; 235 int i; 236 if (value == 1) 237 return; 238 gcc_assert (GET_CODE (rt) == DEFINE_INSN 239 || GET_CODE (rt) == DEFINE_EXPAND); 240 241 attrs_vec = XVEC (rt, 4); 242 243 /* If we've already added attribute 'current_iterator_name', then we 244 have nothing to do now. */ 245 if (attrs_vec) 246 { 247 for (i = 0; i < GET_NUM_ELEM (attrs_vec); i++) 248 { 249 if (strcmp (XSTR (attrs_vec->elem[i], 0), current_iterator_name) == 0) 250 return; 251 } 252 } 253 254 /* Add attribute with subst name - it serves as a mark for 255 define_subst which later would be applied to this pattern. */ 256 new_attr = rtx_alloc (SET_ATTR); 257 PUT_CODE (new_attr, SET_ATTR); 258 XSTR (new_attr, 0) = xstrdup (current_iterator_name); 259 XSTR (new_attr, 1) = xstrdup ("yes"); 260 261 if (!attrs_vec) 262 { 263 new_attrs_vec = rtvec_alloc (1); 264 new_attrs_vec->elem[0] = new_attr; 265 } 266 else 267 { 268 new_attrs_vec = rtvec_alloc (GET_NUM_ELEM (attrs_vec) + 1); 269 memcpy (&new_attrs_vec->elem[0], &attrs_vec->elem[0], 270 GET_NUM_ELEM (attrs_vec) * sizeof (rtx)); 271 new_attrs_vec->elem[GET_NUM_ELEM (attrs_vec)] = new_attr; 272 } 273 XVEC (rt, 4) = new_attrs_vec; 274 } 275 276 /* Map subst-attribute ATTR to subst iterator ITER. */ 277 278 static void 279 bind_subst_iter_and_attr (const char *iter, const char *attr) 280 { 281 struct subst_attr_to_iter_mapping *value; 282 void **slot; 283 if (!subst_attr_to_iter_map) 284 subst_attr_to_iter_map = 285 htab_create (1, leading_string_hash, leading_string_eq_p, 0); 286 value = XNEW (struct subst_attr_to_iter_mapping); 287 value->attr_name = xstrdup (attr); 288 value->iter_name = xstrdup (iter); 289 slot = htab_find_slot (subst_attr_to_iter_map, value, INSERT); 290 *slot = value; 291 } 292 293 #endif /* #ifdef GENERATOR_FILE */ 294 295 /* Return name of a subst-iterator, corresponding to subst-attribute ATTR. */ 296 297 static char* 298 find_subst_iter_by_attr (const char *attr) 299 { 300 char *iter_name = NULL; 301 struct subst_attr_to_iter_mapping *value; 302 value = (struct subst_attr_to_iter_mapping*) 303 htab_find (subst_attr_to_iter_map, &attr); 304 if (value) 305 iter_name = value->iter_name; 306 return iter_name; 307 } 308 309 /* Map attribute string P to its current value. Return null if the attribute 310 isn't known. */ 311 312 static struct map_value * 313 map_attr_string (const char *p) 314 { 315 const char *attr; 316 struct mapping *iterator; 317 unsigned int i; 318 struct mapping *m; 319 struct map_value *v; 320 int iterator_name_len; 321 322 /* Peel off any "iterator:" prefix. Set ATTR to the start of the 323 attribute name. */ 324 attr = strchr (p, ':'); 325 if (attr == 0) 326 { 327 iterator_name_len = -1; 328 attr = p; 329 } 330 else 331 { 332 iterator_name_len = attr - p; 333 attr++; 334 } 335 336 FOR_EACH_VEC_ELT (current_iterators, i, iterator) 337 { 338 /* If an iterator name was specified, check that it matches. */ 339 if (iterator_name_len >= 0 340 && (strncmp (p, iterator->name, iterator_name_len) != 0 341 || iterator->name[iterator_name_len] != 0)) 342 continue; 343 344 /* Find the attribute specification. */ 345 m = (struct mapping *) htab_find (iterator->group->attrs, &attr); 346 if (m) 347 { 348 /* In contrast to code/mode/int iterators, attributes of subst 349 iterators are linked to one specific subst-iterator. So, if 350 we are dealing with subst-iterator, we should check if it's 351 the one which linked with the given attribute. */ 352 if (iterator->group == &substs) 353 { 354 char *iter_name = find_subst_iter_by_attr (attr); 355 if (strcmp (iter_name, iterator->name) != 0) 356 continue; 357 } 358 /* Find the attribute value associated with the current 359 iterator value. */ 360 for (v = m->values; v; v = v->next) 361 if (v->number == iterator->current_value->number) 362 return v; 363 } 364 } 365 return NULL; 366 } 367 368 /* Apply the current iterator values to STRING. Return the new string 369 if any changes were needed, otherwise return STRING itself. */ 370 371 const char * 372 md_reader::apply_iterator_to_string (const char *string) 373 { 374 char *base, *copy, *p, *start, *end; 375 struct map_value *v; 376 377 if (string == 0) 378 return string; 379 380 base = p = copy = ASTRDUP (string); 381 while ((start = strchr (p, '<')) && (end = strchr (start, '>'))) 382 { 383 p = start + 1; 384 385 *end = 0; 386 v = map_attr_string (p); 387 *end = '>'; 388 if (v == 0) 389 continue; 390 391 /* Add everything between the last copied byte and the '<', 392 then add in the attribute value. */ 393 obstack_grow (&m_string_obstack, base, start - base); 394 obstack_grow (&m_string_obstack, v->string, strlen (v->string)); 395 base = end + 1; 396 } 397 if (base != copy) 398 { 399 obstack_grow (&m_string_obstack, base, strlen (base) + 1); 400 copy = XOBFINISH (&m_string_obstack, char *); 401 copy_md_ptr_loc (copy, string); 402 return copy; 403 } 404 return string; 405 } 406 407 /* Return a deep copy of X, substituting the current iterator 408 values into any strings. */ 409 410 rtx 411 md_reader::copy_rtx_for_iterators (rtx original) 412 { 413 const char *format_ptr, *p; 414 int i, j; 415 rtx x; 416 417 if (original == 0) 418 return original; 419 420 /* Create a shallow copy of ORIGINAL. */ 421 x = rtx_alloc (GET_CODE (original)); 422 memcpy (x, original, RTX_CODE_SIZE (GET_CODE (original))); 423 424 /* Change each string and recursively change each rtx. */ 425 format_ptr = GET_RTX_FORMAT (GET_CODE (original)); 426 for (i = 0; format_ptr[i] != 0; i++) 427 switch (format_ptr[i]) 428 { 429 case 'T': 430 while (XTMPL (x, i) != (p = apply_iterator_to_string (XTMPL (x, i)))) 431 XTMPL (x, i) = p; 432 break; 433 434 case 'S': 435 case 's': 436 while (XSTR (x, i) != (p = apply_iterator_to_string (XSTR (x, i)))) 437 XSTR (x, i) = p; 438 break; 439 440 case 'e': 441 XEXP (x, i) = copy_rtx_for_iterators (XEXP (x, i)); 442 break; 443 444 case 'V': 445 case 'E': 446 if (XVEC (original, i)) 447 { 448 XVEC (x, i) = rtvec_alloc (XVECLEN (original, i)); 449 for (j = 0; j < XVECLEN (x, i); j++) 450 XVECEXP (x, i, j) 451 = copy_rtx_for_iterators (XVECEXP (original, i, j)); 452 } 453 break; 454 455 default: 456 break; 457 } 458 return x; 459 } 460 461 #ifdef GENERATOR_FILE 462 463 /* Return a condition that must satisfy both ORIGINAL and EXTRA. If ORIGINAL 464 has the form "&& ..." (as used in define_insn_and_splits), assume that 465 EXTRA is already satisfied. Empty strings are treated like "true". */ 466 467 static const char * 468 add_condition_to_string (const char *original, const char *extra) 469 { 470 if (original != 0 && original[0] == '&' && original[1] == '&') 471 return original; 472 return rtx_reader_ptr->join_c_conditions (original, extra); 473 } 474 475 /* Like add_condition, but applied to all conditions in rtx X. */ 476 477 static void 478 add_condition_to_rtx (rtx x, const char *extra) 479 { 480 switch (GET_CODE (x)) 481 { 482 case DEFINE_INSN: 483 case DEFINE_EXPAND: 484 case DEFINE_SUBST: 485 XSTR (x, 2) = add_condition_to_string (XSTR (x, 2), extra); 486 break; 487 488 case DEFINE_SPLIT: 489 case DEFINE_PEEPHOLE: 490 case DEFINE_PEEPHOLE2: 491 case DEFINE_COND_EXEC: 492 XSTR (x, 1) = add_condition_to_string (XSTR (x, 1), extra); 493 break; 494 495 case DEFINE_INSN_AND_SPLIT: 496 XSTR (x, 2) = add_condition_to_string (XSTR (x, 2), extra); 497 XSTR (x, 4) = add_condition_to_string (XSTR (x, 4), extra); 498 break; 499 500 default: 501 break; 502 } 503 } 504 505 /* Apply the current iterator values to all attribute_uses. */ 506 507 static void 508 apply_attribute_uses (void) 509 { 510 struct map_value *v; 511 attribute_use *ause; 512 unsigned int i; 513 514 FOR_EACH_VEC_ELT (attribute_uses, i, ause) 515 { 516 v = map_attr_string (ause->value); 517 if (!v) 518 fatal_with_file_and_line ("unknown iterator value `%s'", ause->value); 519 ause->group->apply_iterator (ause->ptr, 520 ause->group->find_builtin (v->string)); 521 } 522 } 523 524 /* A htab_traverse callback for iterators. Add all used iterators 525 to current_iterators. */ 526 527 static int 528 add_current_iterators (void **slot, void *data ATTRIBUTE_UNUSED) 529 { 530 struct mapping *iterator; 531 532 iterator = (struct mapping *) *slot; 533 if (iterator->current_value) 534 current_iterators.safe_push (iterator); 535 return 1; 536 } 537 538 /* Expand all iterators in the current rtx, which is given as ORIGINAL. 539 Build a list of expanded rtxes in the EXPR_LIST pointed to by QUEUE. */ 540 541 static void 542 apply_iterators (rtx original, vec<rtx> *queue) 543 { 544 unsigned int i; 545 const char *condition; 546 iterator_use *iuse; 547 struct mapping *iterator; 548 struct map_value *v; 549 rtx x; 550 551 if (iterator_uses.is_empty ()) 552 { 553 /* Raise an error if any attributes were used. */ 554 apply_attribute_uses (); 555 queue->safe_push (original); 556 return; 557 } 558 559 /* Clear out the iterators from the previous run. */ 560 FOR_EACH_VEC_ELT (current_iterators, i, iterator) 561 iterator->current_value = NULL; 562 current_iterators.truncate (0); 563 564 /* Mark the iterators that we need this time. */ 565 FOR_EACH_VEC_ELT (iterator_uses, i, iuse) 566 iuse->iterator->current_value = iuse->iterator->values; 567 568 /* Get the list of iterators that are in use, preserving the 569 definition order within each group. */ 570 htab_traverse (modes.iterators, add_current_iterators, NULL); 571 htab_traverse (codes.iterators, add_current_iterators, NULL); 572 htab_traverse (ints.iterators, add_current_iterators, NULL); 573 htab_traverse (substs.iterators, add_current_iterators, NULL); 574 gcc_assert (!current_iterators.is_empty ()); 575 576 for (;;) 577 { 578 /* Apply the current iterator values. Accumulate a condition to 579 say when the resulting rtx can be used. */ 580 condition = ""; 581 FOR_EACH_VEC_ELT (iterator_uses, i, iuse) 582 { 583 if (iuse->iterator->group == &substs) 584 continue; 585 v = iuse->iterator->current_value; 586 iuse->iterator->group->apply_iterator (iuse->ptr, v->number); 587 condition = rtx_reader_ptr->join_c_conditions (condition, v->string); 588 } 589 apply_attribute_uses (); 590 x = rtx_reader_ptr->copy_rtx_for_iterators (original); 591 add_condition_to_rtx (x, condition); 592 593 /* We apply subst iterator after RTL-template is copied, as during 594 subst-iterator processing, we could add an attribute to the 595 RTL-template, and we don't want to do it in the original one. */ 596 FOR_EACH_VEC_ELT (iterator_uses, i, iuse) 597 { 598 v = iuse->iterator->current_value; 599 if (iuse->iterator->group == &substs) 600 { 601 iuse->ptr = x; 602 current_iterator_name = iuse->iterator->name; 603 iuse->iterator->group->apply_iterator (iuse->ptr, v->number); 604 } 605 } 606 /* Add the new rtx to the end of the queue. */ 607 queue->safe_push (x); 608 609 /* Lexicographically increment the iterator value sequence. 610 That is, cycle through iterator values, starting from the right, 611 and stopping when one of them doesn't wrap around. */ 612 i = current_iterators.length (); 613 for (;;) 614 { 615 if (i == 0) 616 return; 617 i--; 618 iterator = current_iterators[i]; 619 iterator->current_value = iterator->current_value->next; 620 if (iterator->current_value) 621 break; 622 iterator->current_value = iterator->values; 623 } 624 } 625 } 626 #endif /* #ifdef GENERATOR_FILE */ 627 628 /* Add a new "mapping" structure to hashtable TABLE. NAME is the name 629 of the mapping and GROUP is the group to which it belongs. */ 630 631 static struct mapping * 632 add_mapping (struct iterator_group *group, htab_t table, const char *name) 633 { 634 struct mapping *m; 635 void **slot; 636 637 m = XNEW (struct mapping); 638 m->name = xstrdup (name); 639 m->group = group; 640 m->values = 0; 641 m->current_value = NULL; 642 643 slot = htab_find_slot (table, m, INSERT); 644 if (*slot != 0) 645 fatal_with_file_and_line ("`%s' already defined", name); 646 647 *slot = m; 648 return m; 649 } 650 651 /* Add the pair (NUMBER, STRING) to a list of map_value structures. 652 END_PTR points to the current null terminator for the list; return 653 a pointer the new null terminator. */ 654 655 static struct map_value ** 656 add_map_value (struct map_value **end_ptr, int number, const char *string) 657 { 658 struct map_value *value; 659 660 value = XNEW (struct map_value); 661 value->next = 0; 662 value->number = number; 663 value->string = string; 664 665 *end_ptr = value; 666 return &value->next; 667 } 668 669 /* Do one-time initialization of the mode and code attributes. */ 670 671 static void 672 initialize_iterators (void) 673 { 674 struct mapping *lower, *upper; 675 struct map_value **lower_ptr, **upper_ptr; 676 char *copy, *p; 677 int i; 678 679 modes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0); 680 modes.iterators = htab_create (13, leading_string_hash, 681 leading_string_eq_p, 0); 682 modes.find_builtin = find_mode; 683 modes.apply_iterator = apply_mode_iterator; 684 685 codes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0); 686 codes.iterators = htab_create (13, leading_string_hash, 687 leading_string_eq_p, 0); 688 codes.find_builtin = find_code; 689 codes.apply_iterator = apply_code_iterator; 690 691 ints.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0); 692 ints.iterators = htab_create (13, leading_string_hash, 693 leading_string_eq_p, 0); 694 ints.find_builtin = find_int; 695 ints.apply_iterator = apply_int_iterator; 696 697 substs.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0); 698 substs.iterators = htab_create (13, leading_string_hash, 699 leading_string_eq_p, 0); 700 substs.find_builtin = find_int; /* We don't use it, anyway. */ 701 #ifdef GENERATOR_FILE 702 substs.apply_iterator = apply_subst_iterator; 703 #endif 704 705 lower = add_mapping (&modes, modes.attrs, "mode"); 706 upper = add_mapping (&modes, modes.attrs, "MODE"); 707 lower_ptr = &lower->values; 708 upper_ptr = &upper->values; 709 for (i = 0; i < MAX_MACHINE_MODE; i++) 710 { 711 copy = xstrdup (GET_MODE_NAME (i)); 712 for (p = copy; *p != 0; p++) 713 *p = TOLOWER (*p); 714 715 upper_ptr = add_map_value (upper_ptr, i, GET_MODE_NAME (i)); 716 lower_ptr = add_map_value (lower_ptr, i, copy); 717 } 718 719 lower = add_mapping (&codes, codes.attrs, "code"); 720 upper = add_mapping (&codes, codes.attrs, "CODE"); 721 lower_ptr = &lower->values; 722 upper_ptr = &upper->values; 723 for (i = 0; i < NUM_RTX_CODE; i++) 724 { 725 copy = xstrdup (GET_RTX_NAME (i)); 726 for (p = copy; *p != 0; p++) 727 *p = TOUPPER (*p); 728 729 lower_ptr = add_map_value (lower_ptr, i, GET_RTX_NAME (i)); 730 upper_ptr = add_map_value (upper_ptr, i, copy); 731 } 732 } 733 734 /* Provide a version of a function to read a long long if the system does 735 not provide one. */ 736 #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !HAVE_DECL_ATOLL && !defined(HAVE_ATOQ) 737 HOST_WIDE_INT atoll (const char *); 738 739 HOST_WIDE_INT 740 atoll (const char *p) 741 { 742 int neg = 0; 743 HOST_WIDE_INT tmp_wide; 744 745 while (ISSPACE (*p)) 746 p++; 747 if (*p == '-') 748 neg = 1, p++; 749 else if (*p == '+') 750 p++; 751 752 tmp_wide = 0; 753 while (ISDIGIT (*p)) 754 { 755 HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0'); 756 if (new_wide < tmp_wide) 757 { 758 /* Return INT_MAX equiv on overflow. */ 759 tmp_wide = HOST_WIDE_INT_M1U >> 1; 760 break; 761 } 762 tmp_wide = new_wide; 763 p++; 764 } 765 766 if (neg) 767 tmp_wide = -tmp_wide; 768 return tmp_wide; 769 } 770 #endif 771 772 773 #ifdef GENERATOR_FILE 774 /* Process a define_conditions directive, starting with the optional 775 space after the "define_conditions". The directive looks like this: 776 777 (define_conditions [ 778 (number "string") 779 (number "string") 780 ... 781 ]) 782 783 It's not intended to appear in machine descriptions. It is 784 generated by (the program generated by) genconditions.c, and 785 slipped in at the beginning of the sequence of MD files read by 786 most of the other generators. */ 787 void 788 md_reader::read_conditions () 789 { 790 int c; 791 792 require_char_ws ('['); 793 794 while ( (c = read_skip_spaces ()) != ']') 795 { 796 struct md_name name; 797 char *expr; 798 int value; 799 800 if (c != '(') 801 fatal_expected_char ('(', c); 802 803 read_name (&name); 804 validate_const_int (name.string); 805 value = atoi (name.string); 806 807 require_char_ws ('"'); 808 expr = read_quoted_string (); 809 810 require_char_ws (')'); 811 812 add_c_test (expr, value); 813 } 814 } 815 #endif /* #ifdef GENERATOR_FILE */ 816 817 static void 818 validate_const_int (const char *string) 819 { 820 const char *cp; 821 int valid = 1; 822 823 cp = string; 824 while (*cp && ISSPACE (*cp)) 825 cp++; 826 if (*cp == '-' || *cp == '+') 827 cp++; 828 if (*cp == 0) 829 valid = 0; 830 for (; *cp; cp++) 831 if (! ISDIGIT (*cp)) 832 { 833 valid = 0; 834 break; 835 } 836 if (!valid) 837 fatal_with_file_and_line ("invalid decimal constant \"%s\"\n", string); 838 } 839 840 static void 841 validate_const_wide_int (const char *string) 842 { 843 const char *cp; 844 int valid = 1; 845 846 cp = string; 847 while (*cp && ISSPACE (*cp)) 848 cp++; 849 /* Skip the leading 0x. */ 850 if (cp[0] == '0' || cp[1] == 'x') 851 cp += 2; 852 else 853 valid = 0; 854 if (*cp == 0) 855 valid = 0; 856 for (; *cp; cp++) 857 if (! ISXDIGIT (*cp)) 858 valid = 0; 859 if (!valid) 860 fatal_with_file_and_line ("invalid hex constant \"%s\"\n", string); 861 } 862 863 /* Record that PTR uses iterator ITERATOR. */ 864 865 static void 866 record_iterator_use (struct mapping *iterator, void *ptr) 867 { 868 struct iterator_use iuse = {iterator, ptr}; 869 iterator_uses.safe_push (iuse); 870 } 871 872 /* Record that PTR uses attribute VALUE, which must match a built-in 873 value from group GROUP. */ 874 875 static void 876 record_attribute_use (struct iterator_group *group, void *ptr, 877 const char *value) 878 { 879 struct attribute_use ause = {group, value, ptr}; 880 attribute_uses.safe_push (ause); 881 } 882 883 /* Interpret NAME as either a built-in value, iterator or attribute 884 for group GROUP. PTR is the value to pass to GROUP's apply_iterator 885 callback. */ 886 887 void 888 md_reader::record_potential_iterator_use (struct iterator_group *group, 889 void *ptr, const char *name) 890 { 891 struct mapping *m; 892 size_t len; 893 894 len = strlen (name); 895 if (name[0] == '<' && name[len - 1] == '>') 896 { 897 /* Copy the attribute string into permanent storage, without the 898 angle brackets around it. */ 899 obstack_grow0 (&m_string_obstack, name + 1, len - 2); 900 record_attribute_use (group, ptr, XOBFINISH (&m_string_obstack, char *)); 901 } 902 else 903 { 904 m = (struct mapping *) htab_find (group->iterators, &name); 905 if (m != 0) 906 record_iterator_use (m, ptr); 907 else 908 group->apply_iterator (ptr, group->find_builtin (name)); 909 } 910 } 911 912 #ifdef GENERATOR_FILE 913 914 /* Finish reading a declaration of the form: 915 916 (define... <name> [<value1> ... <valuen>]) 917 918 from the MD file, where each <valuei> is either a bare symbol name or a 919 "(<name> <string>)" pair. The "(define..." part has already been read. 920 921 Represent the declaration as a "mapping" structure; add it to TABLE 922 (which belongs to GROUP) and return it. */ 923 924 struct mapping * 925 md_reader::read_mapping (struct iterator_group *group, htab_t table) 926 { 927 struct md_name name; 928 struct mapping *m; 929 struct map_value **end_ptr; 930 const char *string; 931 int number, c; 932 933 /* Read the mapping name and create a structure for it. */ 934 read_name (&name); 935 m = add_mapping (group, table, name.string); 936 937 require_char_ws ('['); 938 939 /* Read each value. */ 940 end_ptr = &m->values; 941 c = read_skip_spaces (); 942 do 943 { 944 if (c != '(') 945 { 946 /* A bare symbol name that is implicitly paired to an 947 empty string. */ 948 unread_char (c); 949 read_name (&name); 950 string = ""; 951 } 952 else 953 { 954 /* A "(name string)" pair. */ 955 read_name (&name); 956 string = read_string (false); 957 require_char_ws (')'); 958 } 959 number = group->find_builtin (name.string); 960 end_ptr = add_map_value (end_ptr, number, string); 961 c = read_skip_spaces (); 962 } 963 while (c != ']'); 964 965 return m; 966 } 967 968 /* For iterator with name ATTR_NAME generate define_attr with values 969 'yes' and 'no'. This attribute is used to mark templates to which 970 define_subst ATTR_NAME should be applied. This attribute is set and 971 defined implicitly and automatically. */ 972 static void 973 add_define_attr_for_define_subst (const char *attr_name, vec<rtx> *queue) 974 { 975 rtx const_str, return_rtx; 976 977 return_rtx = rtx_alloc (DEFINE_ATTR); 978 PUT_CODE (return_rtx, DEFINE_ATTR); 979 980 const_str = rtx_alloc (CONST_STRING); 981 PUT_CODE (const_str, CONST_STRING); 982 XSTR (const_str, 0) = xstrdup ("no"); 983 984 XSTR (return_rtx, 0) = xstrdup (attr_name); 985 XSTR (return_rtx, 1) = xstrdup ("no,yes"); 986 XEXP (return_rtx, 2) = const_str; 987 988 queue->safe_push (return_rtx); 989 } 990 991 /* This routine generates DEFINE_SUBST_ATTR expression with operands 992 ATTR_OPERANDS and places it to QUEUE. */ 993 static void 994 add_define_subst_attr (const char **attr_operands, vec<rtx> *queue) 995 { 996 rtx return_rtx; 997 int i; 998 999 return_rtx = rtx_alloc (DEFINE_SUBST_ATTR); 1000 PUT_CODE (return_rtx, DEFINE_SUBST_ATTR); 1001 1002 for (i = 0; i < 4; i++) 1003 XSTR (return_rtx, i) = xstrdup (attr_operands[i]); 1004 1005 queue->safe_push (return_rtx); 1006 } 1007 1008 /* Read define_subst_attribute construction. It has next form: 1009 (define_subst_attribute <attribute_name> <iterator_name> <value1> <value2>) 1010 Attribute is substituted with value1 when no subst is applied and with 1011 value2 in the opposite case. 1012 Attributes are added to SUBST_ATTRS_TABLE. 1013 In case the iterator is encountered for the first time, it's added to 1014 SUBST_ITERS_TABLE. Also, implicit define_attr is generated. */ 1015 1016 static void 1017 read_subst_mapping (htab_t subst_iters_table, htab_t subst_attrs_table, 1018 vec<rtx> *queue) 1019 { 1020 struct mapping *m; 1021 struct map_value **end_ptr; 1022 const char *attr_operands[4]; 1023 int i; 1024 1025 for (i = 0; i < 4; i++) 1026 attr_operands[i] = rtx_reader_ptr->read_string (false); 1027 1028 add_define_subst_attr (attr_operands, queue); 1029 1030 bind_subst_iter_and_attr (attr_operands[1], attr_operands[0]); 1031 1032 m = (struct mapping *) htab_find (substs.iterators, &attr_operands[1]); 1033 if (!m) 1034 { 1035 m = add_mapping (&substs, subst_iters_table, attr_operands[1]); 1036 end_ptr = &m->values; 1037 end_ptr = add_map_value (end_ptr, 1, ""); 1038 end_ptr = add_map_value (end_ptr, 2, ""); 1039 1040 add_define_attr_for_define_subst (attr_operands[1], queue); 1041 } 1042 1043 m = add_mapping (&substs, subst_attrs_table, attr_operands[0]); 1044 end_ptr = &m->values; 1045 end_ptr = add_map_value (end_ptr, 1, attr_operands[2]); 1046 end_ptr = add_map_value (end_ptr, 2, attr_operands[3]); 1047 } 1048 1049 /* Check newly-created code iterator ITERATOR to see whether every code has the 1050 same format. */ 1051 1052 static void 1053 check_code_iterator (struct mapping *iterator) 1054 { 1055 struct map_value *v; 1056 enum rtx_code bellwether; 1057 1058 bellwether = (enum rtx_code) iterator->values->number; 1059 for (v = iterator->values->next; v != 0; v = v->next) 1060 if (strcmp (GET_RTX_FORMAT (bellwether), GET_RTX_FORMAT (v->number)) != 0) 1061 fatal_with_file_and_line ("code iterator `%s' combines " 1062 "different rtx formats", iterator->name); 1063 } 1064 1065 /* Read an rtx-related declaration from the MD file, given that it 1066 starts with directive name RTX_NAME. Return true if it expands to 1067 one or more rtxes (as defined by rtx.def). When returning true, 1068 store the list of rtxes as an EXPR_LIST in *X. */ 1069 1070 bool 1071 rtx_reader::read_rtx (const char *rtx_name, vec<rtx> *rtxen) 1072 { 1073 /* Handle various rtx-related declarations that aren't themselves 1074 encoded as rtxes. */ 1075 if (strcmp (rtx_name, "define_conditions") == 0) 1076 { 1077 read_conditions (); 1078 return false; 1079 } 1080 if (strcmp (rtx_name, "define_mode_attr") == 0) 1081 { 1082 read_mapping (&modes, modes.attrs); 1083 return false; 1084 } 1085 if (strcmp (rtx_name, "define_mode_iterator") == 0) 1086 { 1087 read_mapping (&modes, modes.iterators); 1088 return false; 1089 } 1090 if (strcmp (rtx_name, "define_code_attr") == 0) 1091 { 1092 read_mapping (&codes, codes.attrs); 1093 return false; 1094 } 1095 if (strcmp (rtx_name, "define_code_iterator") == 0) 1096 { 1097 check_code_iterator (read_mapping (&codes, codes.iterators)); 1098 return false; 1099 } 1100 if (strcmp (rtx_name, "define_int_attr") == 0) 1101 { 1102 read_mapping (&ints, ints.attrs); 1103 return false; 1104 } 1105 if (strcmp (rtx_name, "define_int_iterator") == 0) 1106 { 1107 read_mapping (&ints, ints.iterators); 1108 return false; 1109 } 1110 if (strcmp (rtx_name, "define_subst_attr") == 0) 1111 { 1112 read_subst_mapping (substs.iterators, substs.attrs, rtxen); 1113 1114 /* READ_SUBST_MAPPING could generate a new DEFINE_ATTR. Return 1115 TRUE to process it. */ 1116 return true; 1117 } 1118 1119 apply_iterators (rtx_reader_ptr->read_rtx_code (rtx_name), rtxen); 1120 iterator_uses.truncate (0); 1121 attribute_uses.truncate (0); 1122 1123 return true; 1124 } 1125 1126 #endif /* #ifdef GENERATOR_FILE */ 1127 1128 /* Do one-time initialization. */ 1129 1130 static void 1131 one_time_initialization (void) 1132 { 1133 static bool initialized = false; 1134 1135 if (!initialized) 1136 { 1137 initialize_iterators (); 1138 initialized = true; 1139 } 1140 } 1141 1142 /* Consume characters until encountering a character in TERMINATOR_CHARS, 1143 consuming the terminator character if CONSUME_TERMINATOR is true. 1144 Return all characters before the terminator as an allocated buffer. */ 1145 1146 char * 1147 rtx_reader::read_until (const char *terminator_chars, bool consume_terminator) 1148 { 1149 int ch = read_skip_spaces (); 1150 unread_char (ch); 1151 auto_vec<char> buf; 1152 while (1) 1153 { 1154 ch = read_char (); 1155 if (strchr (terminator_chars, ch)) 1156 { 1157 if (!consume_terminator) 1158 unread_char (ch); 1159 break; 1160 } 1161 buf.safe_push (ch); 1162 } 1163 buf.safe_push ('\0'); 1164 return xstrdup (buf.address ()); 1165 } 1166 1167 /* Subroutine of read_rtx_code, for parsing zero or more flags. */ 1168 1169 static void 1170 read_flags (rtx return_rtx) 1171 { 1172 while (1) 1173 { 1174 int ch = read_char (); 1175 if (ch != '/') 1176 { 1177 unread_char (ch); 1178 break; 1179 } 1180 1181 int flag_char = read_char (); 1182 switch (flag_char) 1183 { 1184 case 's': 1185 RTX_FLAG (return_rtx, in_struct) = 1; 1186 break; 1187 case 'v': 1188 RTX_FLAG (return_rtx, volatil) = 1; 1189 break; 1190 case 'u': 1191 RTX_FLAG (return_rtx, unchanging) = 1; 1192 break; 1193 case 'f': 1194 RTX_FLAG (return_rtx, frame_related) = 1; 1195 break; 1196 case 'j': 1197 RTX_FLAG (return_rtx, jump) = 1; 1198 break; 1199 case 'c': 1200 RTX_FLAG (return_rtx, call) = 1; 1201 break; 1202 case 'i': 1203 RTX_FLAG (return_rtx, return_val) = 1; 1204 break; 1205 default: 1206 fatal_with_file_and_line ("unrecognized flag: `%c'", flag_char); 1207 } 1208 } 1209 } 1210 1211 /* Return the numeric value n for GET_REG_NOTE_NAME (n) for STRING, 1212 or fail if STRING isn't recognized. */ 1213 1214 static int 1215 parse_reg_note_name (const char *string) 1216 { 1217 for (int i = 0; i < REG_NOTE_MAX; i++) 1218 if (0 == strcmp (string, GET_REG_NOTE_NAME (i))) 1219 return i; 1220 fatal_with_file_and_line ("unrecognized REG_NOTE name: `%s'", string); 1221 } 1222 1223 /* Subroutine of read_rtx and read_nested_rtx. CODE_NAME is the name of 1224 either an rtx code or a code iterator. Parse the rest of the rtx and 1225 return it. */ 1226 1227 rtx 1228 rtx_reader::read_rtx_code (const char *code_name) 1229 { 1230 RTX_CODE code; 1231 struct mapping *iterator = NULL; 1232 const char *format_ptr; 1233 struct md_name name; 1234 rtx return_rtx; 1235 int c; 1236 long reuse_id = -1; 1237 1238 /* Linked list structure for making RTXs: */ 1239 struct rtx_list 1240 { 1241 struct rtx_list *next; 1242 rtx value; /* Value of this node. */ 1243 }; 1244 1245 /* Handle reuse_rtx ids e.g. "(0|scratch:DI)". */ 1246 if (ISDIGIT (code_name[0])) 1247 { 1248 reuse_id = atoi (code_name); 1249 while (char ch = *code_name++) 1250 if (ch == '|') 1251 break; 1252 } 1253 1254 /* Handle "reuse_rtx". */ 1255 if (strcmp (code_name, "reuse_rtx") == 0) 1256 { 1257 read_name (&name); 1258 unsigned idx = atoi (name.string); 1259 /* Look it up by ID. */ 1260 gcc_assert (idx < m_reuse_rtx_by_id.length ()); 1261 return_rtx = m_reuse_rtx_by_id[idx]; 1262 return return_rtx; 1263 } 1264 1265 /* If this code is an iterator, build the rtx using the iterator's 1266 first value. */ 1267 #ifdef GENERATOR_FILE 1268 iterator = (struct mapping *) htab_find (codes.iterators, &code_name); 1269 if (iterator != 0) 1270 code = (enum rtx_code) iterator->values->number; 1271 else 1272 code = (enum rtx_code) codes.find_builtin (code_name); 1273 #else 1274 code = (enum rtx_code) codes.find_builtin (code_name); 1275 #endif 1276 1277 /* If we end up with an insn expression then we free this space below. */ 1278 return_rtx = rtx_alloc (code); 1279 format_ptr = GET_RTX_FORMAT (code); 1280 memset (return_rtx, 0, RTX_CODE_SIZE (code)); 1281 PUT_CODE (return_rtx, code); 1282 1283 if (reuse_id != -1) 1284 { 1285 /* Store away for later reuse. */ 1286 m_reuse_rtx_by_id.safe_grow_cleared (reuse_id + 1); 1287 m_reuse_rtx_by_id[reuse_id] = return_rtx; 1288 } 1289 1290 if (iterator) 1291 record_iterator_use (iterator, return_rtx); 1292 1293 /* Check for flags. */ 1294 read_flags (return_rtx); 1295 1296 /* Read REG_NOTE names for EXPR_LIST and INSN_LIST. */ 1297 if ((GET_CODE (return_rtx) == EXPR_LIST 1298 || GET_CODE (return_rtx) == INSN_LIST 1299 || GET_CODE (return_rtx) == INT_LIST) 1300 && !m_in_call_function_usage) 1301 { 1302 char ch = read_char (); 1303 if (ch == ':') 1304 { 1305 read_name (&name); 1306 PUT_MODE_RAW (return_rtx, 1307 (machine_mode)parse_reg_note_name (name.string)); 1308 } 1309 else 1310 unread_char (ch); 1311 } 1312 1313 /* If what follows is `: mode ', read it and 1314 store the mode in the rtx. */ 1315 1316 c = read_skip_spaces (); 1317 if (c == ':') 1318 { 1319 read_name (&name); 1320 record_potential_iterator_use (&modes, return_rtx, name.string); 1321 } 1322 else 1323 unread_char (c); 1324 1325 if (INSN_CHAIN_CODE_P (code)) 1326 { 1327 read_name (&name); 1328 INSN_UID (return_rtx) = atoi (name.string); 1329 } 1330 1331 /* Use the format_ptr to parse the various operands of this rtx. */ 1332 for (int idx = 0; format_ptr[idx] != 0; idx++) 1333 return_rtx = read_rtx_operand (return_rtx, idx); 1334 1335 /* Handle any additional information that after the regular fields 1336 (e.g. when parsing function dumps). */ 1337 handle_any_trailing_information (return_rtx); 1338 1339 if (CONST_WIDE_INT_P (return_rtx)) 1340 { 1341 read_name (&name); 1342 validate_const_wide_int (name.string); 1343 { 1344 const char *s = name.string; 1345 int len; 1346 int index = 0; 1347 int gs = HOST_BITS_PER_WIDE_INT/4; 1348 int pos; 1349 char * buf = XALLOCAVEC (char, gs + 1); 1350 unsigned HOST_WIDE_INT wi; 1351 int wlen; 1352 1353 /* Skip the leading spaces. */ 1354 while (*s && ISSPACE (*s)) 1355 s++; 1356 1357 /* Skip the leading 0x. */ 1358 gcc_assert (s[0] == '0'); 1359 gcc_assert (s[1] == 'x'); 1360 s += 2; 1361 1362 len = strlen (s); 1363 pos = len - gs; 1364 wlen = (len + gs - 1) / gs; /* Number of words needed */ 1365 1366 return_rtx = const_wide_int_alloc (wlen); 1367 1368 while (pos > 0) 1369 { 1370 #if HOST_BITS_PER_WIDE_INT == 64 1371 sscanf (s + pos, "%16" HOST_WIDE_INT_PRINT "x", &wi); 1372 #else 1373 sscanf (s + pos, "%8" HOST_WIDE_INT_PRINT "x", &wi); 1374 #endif 1375 CWI_ELT (return_rtx, index++) = wi; 1376 pos -= gs; 1377 } 1378 strncpy (buf, s, gs - pos); 1379 buf [gs - pos] = 0; 1380 sscanf (buf, "%" HOST_WIDE_INT_PRINT "x", &wi); 1381 CWI_ELT (return_rtx, index++) = wi; 1382 /* TODO: After reading, do we want to canonicalize with: 1383 value = lookup_const_wide_int (value); ? */ 1384 } 1385 } 1386 1387 c = read_skip_spaces (); 1388 /* Syntactic sugar for AND and IOR, allowing Lisp-like 1389 arbitrary number of arguments for them. */ 1390 if (c == '(' 1391 && (GET_CODE (return_rtx) == AND 1392 || GET_CODE (return_rtx) == IOR)) 1393 return read_rtx_variadic (return_rtx); 1394 1395 unread_char (c); 1396 return return_rtx; 1397 } 1398 1399 /* Subroutine of read_rtx_code. Parse operand IDX within RETURN_RTX, 1400 based on the corresponding format character within GET_RTX_FORMAT 1401 for the GET_CODE (RETURN_RTX), and return RETURN_RTX. 1402 This is a virtual function, so that function_reader can override 1403 some parsing, and potentially return a different rtx. */ 1404 1405 rtx 1406 rtx_reader::read_rtx_operand (rtx return_rtx, int idx) 1407 { 1408 RTX_CODE code = GET_CODE (return_rtx); 1409 const char *format_ptr = GET_RTX_FORMAT (code); 1410 int c; 1411 struct md_name name; 1412 1413 switch (format_ptr[idx]) 1414 { 1415 /* 0 means a field for internal use only. 1416 Don't expect it to be present in the input. */ 1417 case '0': 1418 if (code == REG) 1419 ORIGINAL_REGNO (return_rtx) = REGNO (return_rtx); 1420 break; 1421 1422 case 'e': 1423 XEXP (return_rtx, idx) = read_nested_rtx (); 1424 break; 1425 1426 case 'u': 1427 XEXP (return_rtx, idx) = read_nested_rtx (); 1428 break; 1429 1430 case 'V': 1431 /* 'V' is an optional vector: if a closeparen follows, 1432 just store NULL for this element. */ 1433 c = read_skip_spaces (); 1434 unread_char (c); 1435 if (c == ')') 1436 { 1437 XVEC (return_rtx, idx) = 0; 1438 break; 1439 } 1440 /* Now process the vector. */ 1441 /* FALLTHRU */ 1442 1443 case 'E': 1444 { 1445 /* Obstack to store scratch vector in. */ 1446 struct obstack vector_stack; 1447 int list_counter = 0; 1448 rtvec return_vec = NULL_RTVEC; 1449 1450 require_char_ws ('['); 1451 1452 /* Add expressions to a list, while keeping a count. */ 1453 obstack_init (&vector_stack); 1454 while ((c = read_skip_spaces ()) && c != ']') 1455 { 1456 if (c == EOF) 1457 fatal_expected_char (']', c); 1458 unread_char (c); 1459 list_counter++; 1460 obstack_ptr_grow (&vector_stack, read_nested_rtx ()); 1461 } 1462 if (list_counter > 0) 1463 { 1464 return_vec = rtvec_alloc (list_counter); 1465 memcpy (&return_vec->elem[0], obstack_finish (&vector_stack), 1466 list_counter * sizeof (rtx)); 1467 } 1468 else if (format_ptr[idx] == 'E') 1469 fatal_with_file_and_line ("vector must have at least one element"); 1470 XVEC (return_rtx, idx) = return_vec; 1471 obstack_free (&vector_stack, NULL); 1472 /* close bracket gotten */ 1473 } 1474 break; 1475 1476 case 'S': 1477 case 'T': 1478 case 's': 1479 { 1480 char *stringbuf; 1481 int star_if_braced; 1482 1483 c = read_skip_spaces (); 1484 unread_char (c); 1485 if (c == ')') 1486 { 1487 /* 'S' fields are optional and should be NULL if no string 1488 was given. Also allow normal 's' and 'T' strings to be 1489 omitted, treating them in the same way as empty strings. */ 1490 XSTR (return_rtx, idx) = (format_ptr[idx] == 'S' ? NULL : ""); 1491 break; 1492 } 1493 1494 /* The output template slot of a DEFINE_INSN, 1495 DEFINE_INSN_AND_SPLIT, or DEFINE_PEEPHOLE automatically 1496 gets a star inserted as its first character, if it is 1497 written with a brace block instead of a string constant. */ 1498 star_if_braced = (format_ptr[idx] == 'T'); 1499 1500 stringbuf = read_string (star_if_braced); 1501 if (!stringbuf) 1502 break; 1503 1504 #ifdef GENERATOR_FILE 1505 /* For insn patterns, we want to provide a default name 1506 based on the file and line, like "*foo.md:12", if the 1507 given name is blank. These are only for define_insn and 1508 define_insn_and_split, to aid debugging. */ 1509 if (*stringbuf == '\0' 1510 && idx == 0 1511 && (GET_CODE (return_rtx) == DEFINE_INSN 1512 || GET_CODE (return_rtx) == DEFINE_INSN_AND_SPLIT)) 1513 { 1514 struct obstack *string_obstack = get_string_obstack (); 1515 char line_name[20]; 1516 const char *read_md_filename = get_filename (); 1517 const char *fn = (read_md_filename ? read_md_filename : "rtx"); 1518 const char *slash; 1519 for (slash = fn; *slash; slash ++) 1520 if (*slash == '/' || *slash == '\\' || *slash == ':') 1521 fn = slash + 1; 1522 obstack_1grow (string_obstack, '*'); 1523 obstack_grow (string_obstack, fn, strlen (fn)); 1524 sprintf (line_name, ":%d", get_lineno ()); 1525 obstack_grow (string_obstack, line_name, strlen (line_name)+1); 1526 stringbuf = XOBFINISH (string_obstack, char *); 1527 } 1528 1529 /* Find attr-names in the string. */ 1530 char *str; 1531 char *start, *end, *ptr; 1532 char tmpstr[256]; 1533 ptr = &tmpstr[0]; 1534 end = stringbuf; 1535 while ((start = strchr (end, '<')) && (end = strchr (start, '>'))) 1536 { 1537 if ((end - start - 1 > 0) 1538 && (end - start - 1 < (int)sizeof (tmpstr))) 1539 { 1540 strncpy (tmpstr, start+1, end-start-1); 1541 tmpstr[end-start-1] = 0; 1542 end++; 1543 } 1544 else 1545 break; 1546 struct mapping *m 1547 = (struct mapping *) htab_find (substs.attrs, &ptr); 1548 if (m != 0) 1549 { 1550 /* Here we should find linked subst-iter. */ 1551 str = find_subst_iter_by_attr (ptr); 1552 if (str) 1553 m = (struct mapping *) htab_find (substs.iterators, &str); 1554 else 1555 m = 0; 1556 } 1557 if (m != 0) 1558 record_iterator_use (m, return_rtx); 1559 } 1560 #endif /* #ifdef GENERATOR_FILE */ 1561 1562 const char *string_ptr = finalize_string (stringbuf); 1563 1564 if (star_if_braced) 1565 XTMPL (return_rtx, idx) = string_ptr; 1566 else 1567 XSTR (return_rtx, idx) = string_ptr; 1568 } 1569 break; 1570 1571 case 'w': 1572 { 1573 HOST_WIDE_INT tmp_wide; 1574 read_name (&name); 1575 validate_const_int (name.string); 1576 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT 1577 tmp_wide = atoi (name.string); 1578 #else 1579 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG 1580 tmp_wide = atol (name.string); 1581 #else 1582 /* Prefer atoll over atoq, since the former is in the ISO C99 standard. 1583 But prefer not to use our hand-rolled function above either. */ 1584 #if HAVE_DECL_ATOLL || !defined(HAVE_ATOQ) 1585 tmp_wide = atoll (name.string); 1586 #else 1587 tmp_wide = atoq (name.string); 1588 #endif 1589 #endif 1590 #endif 1591 XWINT (return_rtx, idx) = tmp_wide; 1592 } 1593 break; 1594 1595 case 'i': 1596 case 'n': 1597 /* Can be an iterator or an integer constant. */ 1598 read_name (&name); 1599 record_potential_iterator_use (&ints, &XINT (return_rtx, idx), 1600 name.string); 1601 break; 1602 1603 case 'r': 1604 read_name (&name); 1605 validate_const_int (name.string); 1606 set_regno_raw (return_rtx, atoi (name.string), 1); 1607 REG_ATTRS (return_rtx) = NULL; 1608 break; 1609 1610 default: 1611 gcc_unreachable (); 1612 } 1613 1614 return return_rtx; 1615 } 1616 1617 /* Read a nested rtx construct from the MD file and return it. */ 1618 1619 rtx 1620 rtx_reader::read_nested_rtx () 1621 { 1622 struct md_name name; 1623 rtx return_rtx; 1624 1625 /* In compact dumps, trailing "(nil)" values can be omitted. 1626 Handle such dumps. */ 1627 if (peek_char () == ')') 1628 return NULL_RTX; 1629 1630 require_char_ws ('('); 1631 1632 read_name (&name); 1633 if (strcmp (name.string, "nil") == 0) 1634 return_rtx = NULL; 1635 else 1636 return_rtx = read_rtx_code (name.string); 1637 1638 require_char_ws (')'); 1639 1640 return_rtx = postprocess (return_rtx); 1641 1642 return return_rtx; 1643 } 1644 1645 /* Mutually recursive subroutine of read_rtx which reads 1646 (thing x1 x2 x3 ...) and produces RTL as if 1647 (thing x1 (thing x2 (thing x3 ...))) had been written. 1648 When called, FORM is (thing x1 x2), and the file position 1649 is just past the leading parenthesis of x3. Only works 1650 for THINGs which are dyadic expressions, e.g. AND, IOR. */ 1651 rtx 1652 rtx_reader::read_rtx_variadic (rtx form) 1653 { 1654 char c = '('; 1655 rtx p = form, q; 1656 1657 do 1658 { 1659 unread_char (c); 1660 1661 q = rtx_alloc (GET_CODE (p)); 1662 PUT_MODE (q, GET_MODE (p)); 1663 1664 XEXP (q, 0) = XEXP (p, 1); 1665 XEXP (q, 1) = read_nested_rtx (); 1666 1667 XEXP (p, 1) = q; 1668 p = q; 1669 c = read_skip_spaces (); 1670 } 1671 while (c == '('); 1672 unread_char (c); 1673 return form; 1674 } 1675 1676 /* Constructor for class rtx_reader. */ 1677 1678 rtx_reader::rtx_reader (bool compact) 1679 : md_reader (compact), 1680 m_in_call_function_usage (false) 1681 { 1682 /* Set the global singleton pointer. */ 1683 rtx_reader_ptr = this; 1684 1685 one_time_initialization (); 1686 } 1687 1688 /* Destructor for class rtx_reader. */ 1689 1690 rtx_reader::~rtx_reader () 1691 { 1692 /* Clear the global singleton pointer. */ 1693 rtx_reader_ptr = NULL; 1694 } 1695