PageRenderTime 30ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/hotspot/src/share/vm/adlc/output_h.cpp

https://bitbucket.org/xiaoqiangnk/openjdk-mips
C++ | 2199 lines | 1636 code | 191 blank | 372 comment | 487 complexity | 0562a893774d56d325a64be34295167c MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, BSD-3-Clause, LGPL-3.0
  1. /*
  2. * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation.
  8. *
  9. * This code is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * version 2 for more details (a copy is included in the LICENSE file that
  13. * accompanied this code).
  14. *
  15. * You should have received a copy of the GNU General Public License version
  16. * 2 along with this work; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20. * or visit www.oracle.com if you need additional information or have any
  21. * questions.
  22. *
  23. */
  24. // output_h.cpp - Class HPP file output routines for architecture definition
  25. #include "adlc.hpp"
  26. // Generate the #define that describes the number of registers.
  27. static void defineRegCount(FILE *fp, RegisterForm *registers) {
  28. if (registers) {
  29. int regCount = AdlcVMDeps::Physical + registers->_rdefs.count();
  30. fprintf(fp,"\n");
  31. fprintf(fp,"// the number of reserved registers + machine registers.\n");
  32. fprintf(fp,"#define REG_COUNT %d\n", regCount);
  33. }
  34. }
  35. // Output enumeration of machine register numbers
  36. // (1)
  37. // // Enumerate machine registers starting after reserved regs.
  38. // // in the order of occurrence in the register block.
  39. // enum MachRegisterNumbers {
  40. // EAX_num = 0,
  41. // ...
  42. // _last_Mach_Reg
  43. // }
  44. void ArchDesc::buildMachRegisterNumbers(FILE *fp_hpp) {
  45. if (_register) {
  46. RegDef *reg_def = NULL;
  47. // Output a #define for the number of machine registers
  48. defineRegCount(fp_hpp, _register);
  49. // Count all the Save_On_Entry and Always_Save registers
  50. int saved_on_entry = 0;
  51. int c_saved_on_entry = 0;
  52. _register->reset_RegDefs();
  53. while( (reg_def = _register->iter_RegDefs()) != NULL ) {
  54. if( strcmp(reg_def->_callconv,"SOE") == 0 ||
  55. strcmp(reg_def->_callconv,"AS") == 0 ) ++saved_on_entry;
  56. if( strcmp(reg_def->_c_conv,"SOE") == 0 ||
  57. strcmp(reg_def->_c_conv,"AS") == 0 ) ++c_saved_on_entry;
  58. }
  59. fprintf(fp_hpp, "\n");
  60. fprintf(fp_hpp, "// the number of save_on_entry + always_saved registers.\n");
  61. fprintf(fp_hpp, "#define MAX_SAVED_ON_ENTRY_REG_COUNT %d\n", max(saved_on_entry,c_saved_on_entry));
  62. fprintf(fp_hpp, "#define SAVED_ON_ENTRY_REG_COUNT %d\n", saved_on_entry);
  63. fprintf(fp_hpp, "#define C_SAVED_ON_ENTRY_REG_COUNT %d\n", c_saved_on_entry);
  64. // (1)
  65. // Build definition for enumeration of register numbers
  66. fprintf(fp_hpp, "\n");
  67. fprintf(fp_hpp, "// Enumerate machine register numbers starting after reserved regs.\n");
  68. fprintf(fp_hpp, "// in the order of occurrence in the register block.\n");
  69. fprintf(fp_hpp, "enum MachRegisterNumbers {\n");
  70. // Output the register number for each register in the allocation classes
  71. _register->reset_RegDefs();
  72. int i = 0;
  73. while( (reg_def = _register->iter_RegDefs()) != NULL ) {
  74. fprintf(fp_hpp," %s_num,\t\t// %d\n", reg_def->_regname, i++);
  75. }
  76. // Finish defining enumeration
  77. fprintf(fp_hpp, " _last_Mach_Reg\t// %d\n", i);
  78. fprintf(fp_hpp, "};\n");
  79. }
  80. fprintf(fp_hpp, "\n// Size of register-mask in ints\n");
  81. fprintf(fp_hpp, "#define RM_SIZE %d\n",RegisterForm::RegMask_Size());
  82. fprintf(fp_hpp, "// Unroll factor for loops over the data in a RegMask\n");
  83. fprintf(fp_hpp, "#define FORALL_BODY ");
  84. int len = RegisterForm::RegMask_Size();
  85. for( int i = 0; i < len; i++ )
  86. fprintf(fp_hpp, "BODY(%d) ",i);
  87. fprintf(fp_hpp, "\n\n");
  88. fprintf(fp_hpp,"class RegMask;\n");
  89. // All RegMasks are declared "extern const ..." in ad_<arch>.hpp
  90. // fprintf(fp_hpp,"extern RegMask STACK_OR_STACK_SLOTS_mask;\n\n");
  91. }
  92. // Output enumeration of machine register encodings
  93. // (2)
  94. // // Enumerate machine registers starting after reserved regs.
  95. // // in the order of occurrence in the alloc_class(es).
  96. // enum MachRegisterEncodes {
  97. // EAX_enc = 0x00,
  98. // ...
  99. // }
  100. void ArchDesc::buildMachRegisterEncodes(FILE *fp_hpp) {
  101. if (_register) {
  102. RegDef *reg_def = NULL;
  103. RegDef *reg_def_next = NULL;
  104. // (2)
  105. // Build definition for enumeration of encode values
  106. fprintf(fp_hpp, "\n");
  107. fprintf(fp_hpp, "// Enumerate machine registers starting after reserved regs.\n");
  108. fprintf(fp_hpp, "// in the order of occurrence in the alloc_class(es).\n");
  109. fprintf(fp_hpp, "enum MachRegisterEncodes {\n");
  110. // Output the register encoding for each register in the allocation classes
  111. _register->reset_RegDefs();
  112. reg_def_next = _register->iter_RegDefs();
  113. while( (reg_def = reg_def_next) != NULL ) {
  114. reg_def_next = _register->iter_RegDefs();
  115. fprintf(fp_hpp," %s_enc = %s%s\n",
  116. reg_def->_regname, reg_def->register_encode(), reg_def_next == NULL? "" : "," );
  117. }
  118. // Finish defining enumeration
  119. fprintf(fp_hpp, "};\n");
  120. } // Done with register form
  121. }
  122. // Declare an array containing the machine register names, strings.
  123. static void declareRegNames(FILE *fp, RegisterForm *registers) {
  124. if (registers) {
  125. // fprintf(fp,"\n");
  126. // fprintf(fp,"// An array of character pointers to machine register names.\n");
  127. // fprintf(fp,"extern const char *regName[];\n");
  128. }
  129. }
  130. // Declare an array containing the machine register sizes in 32-bit words.
  131. void ArchDesc::declareRegSizes(FILE *fp) {
  132. // regSize[] is not used
  133. }
  134. // Declare an array containing the machine register encoding values
  135. static void declareRegEncodes(FILE *fp, RegisterForm *registers) {
  136. if (registers) {
  137. // // //
  138. // fprintf(fp,"\n");
  139. // fprintf(fp,"// An array containing the machine register encode values\n");
  140. // fprintf(fp,"extern const char regEncode[];\n");
  141. }
  142. }
  143. // ---------------------------------------------------------------------------
  144. //------------------------------Utilities to build Instruction Classes--------
  145. // ---------------------------------------------------------------------------
  146. static void out_RegMask(FILE *fp) {
  147. fprintf(fp," virtual const RegMask &out_RegMask() const;\n");
  148. }
  149. // ---------------------------------------------------------------------------
  150. //--------Utilities to build MachOper and MachNode derived Classes------------
  151. // ---------------------------------------------------------------------------
  152. //------------------------------Utilities to build Operand Classes------------
  153. static void in_RegMask(FILE *fp) {
  154. fprintf(fp," virtual const RegMask *in_RegMask(int index) const;\n");
  155. }
  156. static void declare_hash(FILE *fp) {
  157. fprintf(fp," virtual uint hash() const;\n");
  158. }
  159. static void declare_cmp(FILE *fp) {
  160. fprintf(fp," virtual uint cmp( const MachOper &oper ) const;\n");
  161. }
  162. static void declareConstStorage(FILE *fp, FormDict &globals, OperandForm *oper) {
  163. int i = 0;
  164. Component *comp;
  165. if (oper->num_consts(globals) == 0) return;
  166. // Iterate over the component list looking for constants
  167. oper->_components.reset();
  168. if ((comp = oper->_components.iter()) == NULL) {
  169. assert(oper->num_consts(globals) == 1, "Bad component list detected.\n");
  170. const char *type = oper->ideal_type(globals);
  171. if (!strcmp(type, "ConI")) {
  172. if (i > 0) fprintf(fp,", ");
  173. fprintf(fp," int32 _c%d;\n", i);
  174. }
  175. else if (!strcmp(type, "ConP")) {
  176. if (i > 0) fprintf(fp,", ");
  177. fprintf(fp," const TypePtr *_c%d;\n", i);
  178. }
  179. else if (!strcmp(type, "ConN")) {
  180. if (i > 0) fprintf(fp,", ");
  181. fprintf(fp," const TypeNarrowOop *_c%d;\n", i);
  182. }
  183. else if (!strcmp(type, "ConL")) {
  184. if (i > 0) fprintf(fp,", ");
  185. fprintf(fp," jlong _c%d;\n", i);
  186. }
  187. else if (!strcmp(type, "ConF")) {
  188. if (i > 0) fprintf(fp,", ");
  189. fprintf(fp," jfloat _c%d;\n", i);
  190. }
  191. else if (!strcmp(type, "ConD")) {
  192. if (i > 0) fprintf(fp,", ");
  193. fprintf(fp," jdouble _c%d;\n", i);
  194. }
  195. else if (!strcmp(type, "Bool")) {
  196. fprintf(fp,"private:\n");
  197. fprintf(fp," BoolTest::mask _c%d;\n", i);
  198. fprintf(fp,"public:\n");
  199. }
  200. else {
  201. assert(0, "Non-constant operand lacks component list.");
  202. }
  203. } // end if NULL
  204. else {
  205. oper->_components.reset();
  206. while ((comp = oper->_components.iter()) != NULL) {
  207. if (!strcmp(comp->base_type(globals), "ConI")) {
  208. fprintf(fp," jint _c%d;\n", i);
  209. i++;
  210. }
  211. else if (!strcmp(comp->base_type(globals), "ConP")) {
  212. fprintf(fp," const TypePtr *_c%d;\n", i);
  213. i++;
  214. }
  215. else if (!strcmp(comp->base_type(globals), "ConN")) {
  216. fprintf(fp," const TypePtr *_c%d;\n", i);
  217. i++;
  218. }
  219. else if (!strcmp(comp->base_type(globals), "ConL")) {
  220. fprintf(fp," jlong _c%d;\n", i);
  221. i++;
  222. }
  223. else if (!strcmp(comp->base_type(globals), "ConF")) {
  224. fprintf(fp," jfloat _c%d;\n", i);
  225. i++;
  226. }
  227. else if (!strcmp(comp->base_type(globals), "ConD")) {
  228. fprintf(fp," jdouble _c%d;\n", i);
  229. i++;
  230. }
  231. }
  232. }
  233. }
  234. // Declare constructor.
  235. // Parameters start with condition code, then all other constants
  236. //
  237. // (0) public:
  238. // (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn)
  239. // (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { }
  240. //
  241. static void defineConstructor(FILE *fp, const char *name, uint num_consts,
  242. ComponentList &lst, bool is_ideal_bool,
  243. Form::DataType constant_type, FormDict &globals) {
  244. fprintf(fp,"public:\n");
  245. // generate line (1)
  246. fprintf(fp," %sOper(", name);
  247. if( num_consts == 0 ) {
  248. fprintf(fp,") {}\n");
  249. return;
  250. }
  251. // generate parameters for constants
  252. uint i = 0;
  253. Component *comp;
  254. lst.reset();
  255. if ((comp = lst.iter()) == NULL) {
  256. assert(num_consts == 1, "Bad component list detected.\n");
  257. switch( constant_type ) {
  258. case Form::idealI : {
  259. fprintf(fp,is_ideal_bool ? "BoolTest::mask c%d" : "int32 c%d", i);
  260. break;
  261. }
  262. case Form::idealN : { fprintf(fp,"const TypeNarrowOop *c%d", i); break; }
  263. case Form::idealP : { fprintf(fp,"const TypePtr *c%d", i); break; }
  264. case Form::idealL : { fprintf(fp,"jlong c%d", i); break; }
  265. case Form::idealF : { fprintf(fp,"jfloat c%d", i); break; }
  266. case Form::idealD : { fprintf(fp,"jdouble c%d", i); break; }
  267. default:
  268. assert(!is_ideal_bool, "Non-constant operand lacks component list.");
  269. break;
  270. }
  271. } // end if NULL
  272. else {
  273. lst.reset();
  274. while((comp = lst.iter()) != NULL) {
  275. if (!strcmp(comp->base_type(globals), "ConI")) {
  276. if (i > 0) fprintf(fp,", ");
  277. fprintf(fp,"int32 c%d", i);
  278. i++;
  279. }
  280. else if (!strcmp(comp->base_type(globals), "ConP")) {
  281. if (i > 0) fprintf(fp,", ");
  282. fprintf(fp,"const TypePtr *c%d", i);
  283. i++;
  284. }
  285. else if (!strcmp(comp->base_type(globals), "ConN")) {
  286. if (i > 0) fprintf(fp,", ");
  287. fprintf(fp,"const TypePtr *c%d", i);
  288. i++;
  289. }
  290. else if (!strcmp(comp->base_type(globals), "ConL")) {
  291. if (i > 0) fprintf(fp,", ");
  292. fprintf(fp,"jlong c%d", i);
  293. i++;
  294. }
  295. else if (!strcmp(comp->base_type(globals), "ConF")) {
  296. if (i > 0) fprintf(fp,", ");
  297. fprintf(fp,"jfloat c%d", i);
  298. i++;
  299. }
  300. else if (!strcmp(comp->base_type(globals), "ConD")) {
  301. if (i > 0) fprintf(fp,", ");
  302. fprintf(fp,"jdouble c%d", i);
  303. i++;
  304. }
  305. else if (!strcmp(comp->base_type(globals), "Bool")) {
  306. if (i > 0) fprintf(fp,", ");
  307. fprintf(fp,"BoolTest::mask c%d", i);
  308. i++;
  309. }
  310. }
  311. }
  312. // finish line (1) and start line (2)
  313. fprintf(fp,") : ");
  314. // generate initializers for constants
  315. i = 0;
  316. fprintf(fp,"_c%d(c%d)", i, i);
  317. for( i = 1; i < num_consts; ++i) {
  318. fprintf(fp,", _c%d(c%d)", i, i);
  319. }
  320. // The body for the constructor is empty
  321. fprintf(fp," {}\n");
  322. }
  323. // ---------------------------------------------------------------------------
  324. // Utilities to generate format rules for machine operands and instructions
  325. // ---------------------------------------------------------------------------
  326. // Generate the format rule for condition codes
  327. static void defineCCodeDump(OperandForm* oper, FILE *fp, int i) {
  328. assert(oper != NULL, "what");
  329. CondInterface* cond = oper->_interface->is_CondInterface();
  330. fprintf(fp, " if( _c%d == BoolTest::eq ) st->print(\"%s\");\n",i,cond->_equal_format);
  331. fprintf(fp, " else if( _c%d == BoolTest::ne ) st->print(\"%s\");\n",i,cond->_not_equal_format);
  332. fprintf(fp, " else if( _c%d == BoolTest::le ) st->print(\"%s\");\n",i,cond->_less_equal_format);
  333. fprintf(fp, " else if( _c%d == BoolTest::ge ) st->print(\"%s\");\n",i,cond->_greater_equal_format);
  334. fprintf(fp, " else if( _c%d == BoolTest::lt ) st->print(\"%s\");\n",i,cond->_less_format);
  335. fprintf(fp, " else if( _c%d == BoolTest::gt ) st->print(\"%s\");\n",i,cond->_greater_format);
  336. }
  337. // Output code that dumps constant values, increment "i" if type is constant
  338. static uint dump_spec_constant(FILE *fp, const char *ideal_type, uint i, OperandForm* oper) {
  339. if (!strcmp(ideal_type, "ConI")) {
  340. fprintf(fp," st->print(\"#%%d\", _c%d);\n", i);
  341. ++i;
  342. }
  343. else if (!strcmp(ideal_type, "ConP")) {
  344. fprintf(fp," _c%d->dump_on(st);\n", i);
  345. ++i;
  346. }
  347. else if (!strcmp(ideal_type, "ConN")) {
  348. fprintf(fp," _c%d->dump_on(st);\n", i);
  349. ++i;
  350. }
  351. else if (!strcmp(ideal_type, "ConL")) {
  352. fprintf(fp," st->print(\"#\" INT64_FORMAT, _c%d);\n", i);
  353. ++i;
  354. }
  355. else if (!strcmp(ideal_type, "ConF")) {
  356. fprintf(fp," st->print(\"#%%f\", _c%d);\n", i);
  357. ++i;
  358. }
  359. else if (!strcmp(ideal_type, "ConD")) {
  360. fprintf(fp," st->print(\"#%%f\", _c%d);\n", i);
  361. ++i;
  362. }
  363. else if (!strcmp(ideal_type, "Bool")) {
  364. defineCCodeDump(oper, fp,i);
  365. ++i;
  366. }
  367. return i;
  368. }
  369. // Generate the format rule for an operand
  370. void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file = false) {
  371. if (!for_c_file) {
  372. // invoked after output #ifndef PRODUCT to ad_<arch>.hpp
  373. // compile the bodies separately, to cut down on recompilations
  374. fprintf(fp," virtual void int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const;\n");
  375. fprintf(fp," virtual void ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const;\n");
  376. return;
  377. }
  378. // Local pointer indicates remaining part of format rule
  379. uint idx = 0; // position of operand in match rule
  380. // Generate internal format function, used when stored locally
  381. fprintf(fp, "\n#ifndef PRODUCT\n");
  382. fprintf(fp,"void %sOper::int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const {\n", oper._ident);
  383. // Generate the user-defined portion of the format
  384. if (oper._format) {
  385. if ( oper._format->_strings.count() != 0 ) {
  386. // No initialization code for int_format
  387. // Build the format from the entries in strings and rep_vars
  388. const char *string = NULL;
  389. oper._format->_rep_vars.reset();
  390. oper._format->_strings.reset();
  391. while ( (string = oper._format->_strings.iter()) != NULL ) {
  392. fprintf(fp," ");
  393. // Check if this is a standard string or a replacement variable
  394. if ( string != NameList::_signal ) {
  395. // Normal string
  396. // Pass through to st->print
  397. fprintf(fp,"st->print(\"%s\");\n", string);
  398. } else {
  399. // Replacement variable
  400. const char *rep_var = oper._format->_rep_vars.iter();
  401. // Check that it is a local name, and an operand
  402. const Form* form = oper._localNames[rep_var];
  403. if (form == NULL) {
  404. globalAD->syntax_err(oper._linenum,
  405. "\'%s\' not found in format for %s\n", rep_var, oper._ident);
  406. assert(form, "replacement variable was not found in local names");
  407. }
  408. OperandForm *op = form->is_operand();
  409. // Get index if register or constant
  410. if ( op->_matrule && op->_matrule->is_base_register(globals) ) {
  411. idx = oper.register_position( globals, rep_var);
  412. }
  413. else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
  414. idx = oper.constant_position( globals, rep_var);
  415. } else {
  416. idx = 0;
  417. }
  418. // output invocation of "$..."s format function
  419. if ( op != NULL ) op->int_format(fp, globals, idx);
  420. if ( idx == -1 ) {
  421. fprintf(stderr,
  422. "Using a name, %s, that isn't in match rule\n", rep_var);
  423. assert( strcmp(op->_ident,"label")==0, "Unimplemented");
  424. }
  425. } // Done with a replacement variable
  426. } // Done with all format strings
  427. } else {
  428. // Default formats for base operands (RegI, RegP, ConI, ConP, ...)
  429. oper.int_format(fp, globals, 0);
  430. }
  431. } else { // oper._format == NULL
  432. // Provide a few special case formats where the AD writer cannot.
  433. if ( strcmp(oper._ident,"Universe")==0 ) {
  434. fprintf(fp, " st->print(\"$$univ\");\n");
  435. }
  436. // labelOper::int_format is defined in ad_<...>.cpp
  437. }
  438. // ALWAYS! Provide a special case output for condition codes.
  439. if( oper.is_ideal_bool() ) {
  440. defineCCodeDump(&oper, fp,0);
  441. }
  442. fprintf(fp,"}\n");
  443. // Generate external format function, when data is stored externally
  444. fprintf(fp,"void %sOper::ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const {\n", oper._ident);
  445. // Generate the user-defined portion of the format
  446. if (oper._format) {
  447. if ( oper._format->_strings.count() != 0 ) {
  448. // Check for a replacement string "$..."
  449. if ( oper._format->_rep_vars.count() != 0 ) {
  450. // Initialization code for ext_format
  451. }
  452. // Build the format from the entries in strings and rep_vars
  453. const char *string = NULL;
  454. oper._format->_rep_vars.reset();
  455. oper._format->_strings.reset();
  456. while ( (string = oper._format->_strings.iter()) != NULL ) {
  457. fprintf(fp," ");
  458. // Check if this is a standard string or a replacement variable
  459. if ( string != NameList::_signal ) {
  460. // Normal string
  461. // Pass through to st->print
  462. fprintf(fp,"st->print(\"%s\");\n", string);
  463. } else {
  464. // Replacement variable
  465. const char *rep_var = oper._format->_rep_vars.iter();
  466. // Check that it is a local name, and an operand
  467. const Form* form = oper._localNames[rep_var];
  468. if (form == NULL) {
  469. globalAD->syntax_err(oper._linenum,
  470. "\'%s\' not found in format for %s\n", rep_var, oper._ident);
  471. assert(form, "replacement variable was not found in local names");
  472. }
  473. OperandForm *op = form->is_operand();
  474. // Get index if register or constant
  475. if ( op->_matrule && op->_matrule->is_base_register(globals) ) {
  476. idx = oper.register_position( globals, rep_var);
  477. }
  478. else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
  479. idx = oper.constant_position( globals, rep_var);
  480. } else {
  481. idx = 0;
  482. }
  483. // output invocation of "$..."s format function
  484. if ( op != NULL ) op->ext_format(fp, globals, idx);
  485. // Lookup the index position of the replacement variable
  486. idx = oper._components.operand_position_format(rep_var);
  487. if ( idx == -1 ) {
  488. fprintf(stderr,
  489. "Using a name, %s, that isn't in match rule\n", rep_var);
  490. assert( strcmp(op->_ident,"label")==0, "Unimplemented");
  491. }
  492. } // Done with a replacement variable
  493. } // Done with all format strings
  494. } else {
  495. // Default formats for base operands (RegI, RegP, ConI, ConP, ...)
  496. oper.ext_format(fp, globals, 0);
  497. }
  498. } else { // oper._format == NULL
  499. // Provide a few special case formats where the AD writer cannot.
  500. if ( strcmp(oper._ident,"Universe")==0 ) {
  501. fprintf(fp, " st->print(\"$$univ\");\n");
  502. }
  503. // labelOper::ext_format is defined in ad_<...>.cpp
  504. }
  505. // ALWAYS! Provide a special case output for condition codes.
  506. if( oper.is_ideal_bool() ) {
  507. defineCCodeDump(&oper, fp,0);
  508. }
  509. fprintf(fp, "}\n");
  510. fprintf(fp, "#endif\n");
  511. }
  512. // Generate the format rule for an instruction
  513. void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &inst, bool for_c_file = false) {
  514. if (!for_c_file) {
  515. // compile the bodies separately, to cut down on recompilations
  516. // #ifndef PRODUCT region generated by caller
  517. fprintf(fp," virtual void format(PhaseRegAlloc *ra, outputStream *st) const;\n");
  518. return;
  519. }
  520. // Define the format function
  521. fprintf(fp, "#ifndef PRODUCT\n");
  522. fprintf(fp, "void %sNode::format(PhaseRegAlloc *ra, outputStream *st) const {\n", inst._ident);
  523. // Generate the user-defined portion of the format
  524. if( inst._format ) {
  525. // If there are replacement variables,
  526. // Generate index values needed for determining the operand position
  527. if( inst._format->_rep_vars.count() )
  528. inst.index_temps(fp, globals);
  529. // Build the format from the entries in strings and rep_vars
  530. const char *string = NULL;
  531. inst._format->_rep_vars.reset();
  532. inst._format->_strings.reset();
  533. while( (string = inst._format->_strings.iter()) != NULL ) {
  534. fprintf(fp," ");
  535. // Check if this is a standard string or a replacement variable
  536. if( string == NameList::_signal ) { // Replacement variable
  537. const char* rep_var = inst._format->_rep_vars.iter();
  538. inst.rep_var_format( fp, rep_var);
  539. } else if( string == NameList::_signal3 ) { // Replacement variable in raw text
  540. const char* rep_var = inst._format->_rep_vars.iter();
  541. const Form *form = inst._localNames[rep_var];
  542. if (form == NULL) {
  543. fprintf(stderr, "unknown replacement variable in format statement: '%s'\n", rep_var);
  544. assert(false, "ShouldNotReachHere()");
  545. }
  546. OpClassForm *opc = form->is_opclass();
  547. assert( opc, "replacement variable was not found in local names");
  548. // Lookup the index position of the replacement variable
  549. int idx = inst.operand_position_format(rep_var);
  550. if ( idx == -1 ) {
  551. assert( strcmp(opc->_ident,"label")==0, "Unimplemented");
  552. assert( false, "ShouldNotReachHere()");
  553. }
  554. if (inst.is_noninput_operand(idx)) {
  555. assert( false, "ShouldNotReachHere()");
  556. } else {
  557. // Output the format call for this operand
  558. fprintf(fp,"opnd_array(%d)",idx);
  559. }
  560. rep_var = inst._format->_rep_vars.iter();
  561. inst._format->_strings.iter();
  562. if ( strcmp(rep_var,"$constant") == 0 && opc->is_operand()) {
  563. Form::DataType constant_type = form->is_operand()->is_base_constant(globals);
  564. if ( constant_type == Form::idealD ) {
  565. fprintf(fp,"->constantD()");
  566. } else if ( constant_type == Form::idealF ) {
  567. fprintf(fp,"->constantF()");
  568. } else if ( constant_type == Form::idealL ) {
  569. fprintf(fp,"->constantL()");
  570. } else {
  571. fprintf(fp,"->constant()");
  572. }
  573. } else if ( strcmp(rep_var,"$cmpcode") == 0) {
  574. fprintf(fp,"->ccode()");
  575. } else {
  576. assert( false, "ShouldNotReachHere()");
  577. }
  578. } else if( string == NameList::_signal2 ) // Raw program text
  579. fputs(inst._format->_strings.iter(), fp);
  580. else
  581. fprintf(fp,"st->print(\"%s\");\n", string);
  582. } // Done with all format strings
  583. } // Done generating the user-defined portion of the format
  584. // Add call debug info automatically
  585. Form::CallType call_type = inst.is_ideal_call();
  586. if( call_type != Form::invalid_type ) {
  587. switch( call_type ) {
  588. case Form::JAVA_DYNAMIC:
  589. fprintf(fp," _method->print_short_name();\n");
  590. break;
  591. case Form::JAVA_STATIC:
  592. fprintf(fp," if( _method ) _method->print_short_name(st); else st->print(\" wrapper for: %%s\", _name);\n");
  593. fprintf(fp," if( !_method ) dump_trap_args(st);\n");
  594. break;
  595. case Form::JAVA_COMPILED:
  596. case Form::JAVA_INTERP:
  597. break;
  598. case Form::JAVA_RUNTIME:
  599. case Form::JAVA_LEAF:
  600. case Form::JAVA_NATIVE:
  601. fprintf(fp," st->print(\" %%s\", _name);");
  602. break;
  603. default:
  604. assert(0,"ShouldNotReacHere");
  605. }
  606. fprintf(fp, " st->print_cr(\"\");\n" );
  607. fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" );
  608. fprintf(fp, " st->print(\" # \");\n" );
  609. fprintf(fp, " if( _jvms ) _oop_map->print_on(st);\n");
  610. }
  611. else if(inst.is_ideal_safepoint()) {
  612. fprintf(fp, " st->print(\"\");\n" );
  613. fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" );
  614. fprintf(fp, " st->print(\" # \");\n" );
  615. fprintf(fp, " if( _jvms ) _oop_map->print_on(st);\n");
  616. }
  617. else if( inst.is_ideal_if() ) {
  618. fprintf(fp, " st->print(\" P=%%f C=%%f\",_prob,_fcnt);\n" );
  619. }
  620. else if( inst.is_ideal_mem() ) {
  621. // Print out the field name if available to improve readability
  622. fprintf(fp, " if (ra->C->alias_type(adr_type())->field() != NULL) {\n");
  623. fprintf(fp, " st->print(\" ! Field \");\n");
  624. fprintf(fp, " if( ra->C->alias_type(adr_type())->is_volatile() )\n");
  625. fprintf(fp, " st->print(\" Volatile\");\n");
  626. fprintf(fp, " ra->C->alias_type(adr_type())->field()->holder()->name()->print_symbol_on(st);\n");
  627. fprintf(fp, " st->print(\".\");\n");
  628. fprintf(fp, " ra->C->alias_type(adr_type())->field()->name()->print_symbol_on(st);\n");
  629. fprintf(fp, " } else\n");
  630. // Make sure 'Volatile' gets printed out
  631. fprintf(fp, " if( ra->C->alias_type(adr_type())->is_volatile() )\n");
  632. fprintf(fp, " st->print(\" Volatile!\");\n");
  633. }
  634. // Complete the definition of the format function
  635. fprintf(fp, " }\n#endif\n");
  636. }
  637. static bool is_non_constant(char* x) {
  638. // Tells whether the string (part of an operator interface) is non-constant.
  639. // Simply detect whether there is an occurrence of a formal parameter,
  640. // which will always begin with '$'.
  641. return strchr(x, '$') == 0;
  642. }
  643. void ArchDesc::declare_pipe_classes(FILE *fp_hpp) {
  644. if (!_pipeline)
  645. return;
  646. fprintf(fp_hpp, "\n");
  647. fprintf(fp_hpp, "// Pipeline_Use_Cycle_Mask Class\n");
  648. fprintf(fp_hpp, "class Pipeline_Use_Cycle_Mask {\n");
  649. if (_pipeline->_maxcycleused <=
  650. #ifdef SPARC
  651. 64
  652. #else
  653. 32
  654. #endif
  655. ) {
  656. fprintf(fp_hpp, "protected:\n");
  657. fprintf(fp_hpp, " %s _mask;\n\n", _pipeline->_maxcycleused <= 32 ? "uint" : "uint64_t" );
  658. fprintf(fp_hpp, "public:\n");
  659. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : _mask(0) {}\n\n");
  660. if (_pipeline->_maxcycleused <= 32)
  661. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask) : _mask(mask) {}\n\n");
  662. else {
  663. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint mask1, uint mask2) : _mask((((uint64_t)mask1) << 32) | mask2) {}\n\n");
  664. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(uint64_t mask) : _mask(mask) {}\n\n");
  665. }
  666. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n");
  667. fprintf(fp_hpp, " _mask = in._mask;\n");
  668. fprintf(fp_hpp, " return *this;\n");
  669. fprintf(fp_hpp, " }\n\n");
  670. fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");
  671. fprintf(fp_hpp, " return ((_mask & in2._mask) != 0);\n");
  672. fprintf(fp_hpp, " }\n\n");
  673. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n");
  674. fprintf(fp_hpp, " _mask <<= n;\n");
  675. fprintf(fp_hpp, " return *this;\n");
  676. fprintf(fp_hpp, " }\n\n");
  677. fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &in2) {\n");
  678. fprintf(fp_hpp, " _mask |= in2._mask;\n");
  679. fprintf(fp_hpp, " }\n\n");
  680. fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n");
  681. fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n");
  682. }
  683. else {
  684. fprintf(fp_hpp, "protected:\n");
  685. uint masklen = (_pipeline->_maxcycleused + 31) >> 5;
  686. uint l;
  687. fprintf(fp_hpp, " uint ");
  688. for (l = 1; l <= masklen; l++)
  689. fprintf(fp_hpp, "_mask%d%s", l, l < masklen ? ", " : ";\n\n");
  690. fprintf(fp_hpp, "public:\n");
  691. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask() : ");
  692. for (l = 1; l <= masklen; l++)
  693. fprintf(fp_hpp, "_mask%d(0)%s", l, l < masklen ? ", " : " {}\n\n");
  694. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask(");
  695. for (l = 1; l <= masklen; l++)
  696. fprintf(fp_hpp, "uint mask%d%s", l, l < masklen ? ", " : ") : ");
  697. for (l = 1; l <= masklen; l++)
  698. fprintf(fp_hpp, "_mask%d(mask%d)%s", l, l, l < masklen ? ", " : " {}\n\n");
  699. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator=(const Pipeline_Use_Cycle_Mask &in) {\n");
  700. for (l = 1; l <= masklen; l++)
  701. fprintf(fp_hpp, " _mask%d = in._mask%d;\n", l, l);
  702. fprintf(fp_hpp, " return *this;\n");
  703. fprintf(fp_hpp, " }\n\n");
  704. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask intersect(const Pipeline_Use_Cycle_Mask &in2) {\n");
  705. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask out;\n");
  706. for (l = 1; l <= masklen; l++)
  707. fprintf(fp_hpp, " out._mask%d = _mask%d & in2._mask%d;\n", l, l, l);
  708. fprintf(fp_hpp, " return out;\n");
  709. fprintf(fp_hpp, " }\n\n");
  710. fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Cycle_Mask &in2) const {\n");
  711. fprintf(fp_hpp, " return (");
  712. for (l = 1; l <= masklen; l++)
  713. fprintf(fp_hpp, "((_mask%d & in2._mask%d) != 0)%s", l, l, l < masklen ? " || " : "");
  714. fprintf(fp_hpp, ") ? true : false;\n");
  715. fprintf(fp_hpp, " }\n\n");
  716. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask& operator<<=(int n) {\n");
  717. fprintf(fp_hpp, " if (n >= 32)\n");
  718. fprintf(fp_hpp, " do {\n ");
  719. for (l = masklen; l > 1; l--)
  720. fprintf(fp_hpp, " _mask%d = _mask%d;", l, l-1);
  721. fprintf(fp_hpp, " _mask%d = 0;\n", 1);
  722. fprintf(fp_hpp, " } while ((n -= 32) >= 32);\n\n");
  723. fprintf(fp_hpp, " if (n > 0) {\n");
  724. fprintf(fp_hpp, " uint m = 32 - n;\n");
  725. fprintf(fp_hpp, " uint mask = (1 << n) - 1;\n");
  726. fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n;\n", 2, 1, 1);
  727. for (l = 2; l < masklen; l++) {
  728. fprintf(fp_hpp, " uint temp%d = mask & (_mask%d >> m); _mask%d <<= n; _mask%d |= temp%d;\n", l+1, l, l, l, l);
  729. }
  730. fprintf(fp_hpp, " _mask%d <<= n; _mask%d |= temp%d;\n", masklen, masklen, masklen);
  731. fprintf(fp_hpp, " }\n");
  732. fprintf(fp_hpp, " return *this;\n");
  733. fprintf(fp_hpp, " }\n\n");
  734. fprintf(fp_hpp, " void Or(const Pipeline_Use_Cycle_Mask &);\n\n");
  735. fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n");
  736. fprintf(fp_hpp, " friend Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &, const Pipeline_Use_Cycle_Mask &);\n\n");
  737. }
  738. fprintf(fp_hpp, " friend class Pipeline_Use;\n\n");
  739. fprintf(fp_hpp, " friend class Pipeline_Use_Element;\n\n");
  740. fprintf(fp_hpp, "};\n\n");
  741. uint rescount = 0;
  742. const char *resource;
  743. for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {
  744. int mask = _pipeline->_resdict[resource]->is_resource()->mask();
  745. if ((mask & (mask-1)) == 0)
  746. rescount++;
  747. }
  748. fprintf(fp_hpp, "// Pipeline_Use_Element Class\n");
  749. fprintf(fp_hpp, "class Pipeline_Use_Element {\n");
  750. fprintf(fp_hpp, "protected:\n");
  751. fprintf(fp_hpp, " // Mask of used functional units\n");
  752. fprintf(fp_hpp, " uint _used;\n\n");
  753. fprintf(fp_hpp, " // Lower and upper bound of functional unit number range\n");
  754. fprintf(fp_hpp, " uint _lb, _ub;\n\n");
  755. fprintf(fp_hpp, " // Indicates multiple functionals units available\n");
  756. fprintf(fp_hpp, " bool _multiple;\n\n");
  757. fprintf(fp_hpp, " // Mask of specific used cycles\n");
  758. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask _mask;\n\n");
  759. fprintf(fp_hpp, "public:\n");
  760. fprintf(fp_hpp, " Pipeline_Use_Element() {}\n\n");
  761. fprintf(fp_hpp, " Pipeline_Use_Element(uint used, uint lb, uint ub, bool multiple, Pipeline_Use_Cycle_Mask mask)\n");
  762. fprintf(fp_hpp, " : _used(used), _lb(lb), _ub(ub), _multiple(multiple), _mask(mask) {}\n\n");
  763. fprintf(fp_hpp, " uint used() const { return _used; }\n\n");
  764. fprintf(fp_hpp, " uint lowerBound() const { return _lb; }\n\n");
  765. fprintf(fp_hpp, " uint upperBound() const { return _ub; }\n\n");
  766. fprintf(fp_hpp, " bool multiple() const { return _multiple; }\n\n");
  767. fprintf(fp_hpp, " Pipeline_Use_Cycle_Mask mask() const { return _mask; }\n\n");
  768. fprintf(fp_hpp, " bool overlaps(const Pipeline_Use_Element &in2) const {\n");
  769. fprintf(fp_hpp, " return ((_used & in2._used) != 0 && _mask.overlaps(in2._mask));\n");
  770. fprintf(fp_hpp, " }\n\n");
  771. fprintf(fp_hpp, " void step(uint cycles) {\n");
  772. fprintf(fp_hpp, " _used = 0;\n");
  773. fprintf(fp_hpp, " _mask <<= cycles;\n");
  774. fprintf(fp_hpp, " }\n\n");
  775. fprintf(fp_hpp, " friend class Pipeline_Use;\n");
  776. fprintf(fp_hpp, "};\n\n");
  777. fprintf(fp_hpp, "// Pipeline_Use Class\n");
  778. fprintf(fp_hpp, "class Pipeline_Use {\n");
  779. fprintf(fp_hpp, "protected:\n");
  780. fprintf(fp_hpp, " // These resources can be used\n");
  781. fprintf(fp_hpp, " uint _resources_used;\n\n");
  782. fprintf(fp_hpp, " // These resources are used; excludes multiple choice functional units\n");
  783. fprintf(fp_hpp, " uint _resources_used_exclusively;\n\n");
  784. fprintf(fp_hpp, " // Number of elements\n");
  785. fprintf(fp_hpp, " uint _count;\n\n");
  786. fprintf(fp_hpp, " // This is the array of Pipeline_Use_Elements\n");
  787. fprintf(fp_hpp, " Pipeline_Use_Element * _elements;\n\n");
  788. fprintf(fp_hpp, "public:\n");
  789. fprintf(fp_hpp, " Pipeline_Use(uint resources_used, uint resources_used_exclusively, uint count, Pipeline_Use_Element *elements)\n");
  790. fprintf(fp_hpp, " : _resources_used(resources_used)\n");
  791. fprintf(fp_hpp, " , _resources_used_exclusively(resources_used_exclusively)\n");
  792. fprintf(fp_hpp, " , _count(count)\n");
  793. fprintf(fp_hpp, " , _elements(elements)\n");
  794. fprintf(fp_hpp, " {}\n\n");
  795. fprintf(fp_hpp, " uint resourcesUsed() const { return _resources_used; }\n\n");
  796. fprintf(fp_hpp, " uint resourcesUsedExclusively() const { return _resources_used_exclusively; }\n\n");
  797. fprintf(fp_hpp, " uint count() const { return _count; }\n\n");
  798. fprintf(fp_hpp, " Pipeline_Use_Element * element(uint i) const { return &_elements[i]; }\n\n");
  799. fprintf(fp_hpp, " uint full_latency(uint delay, const Pipeline_Use &pred) const;\n\n");
  800. fprintf(fp_hpp, " void add_usage(const Pipeline_Use &pred);\n\n");
  801. fprintf(fp_hpp, " void reset() {\n");
  802. fprintf(fp_hpp, " _resources_used = _resources_used_exclusively = 0;\n");
  803. fprintf(fp_hpp, " };\n\n");
  804. fprintf(fp_hpp, " void step(uint cycles) {\n");
  805. fprintf(fp_hpp, " reset();\n");
  806. fprintf(fp_hpp, " for (uint i = 0; i < %d; i++)\n",
  807. rescount);
  808. fprintf(fp_hpp, " (&_elements[i])->step(cycles);\n");
  809. fprintf(fp_hpp, " };\n\n");
  810. fprintf(fp_hpp, " static const Pipeline_Use elaborated_use;\n");
  811. fprintf(fp_hpp, " static const Pipeline_Use_Element elaborated_elements[%d];\n\n",
  812. rescount);
  813. fprintf(fp_hpp, " friend class Pipeline;\n");
  814. fprintf(fp_hpp, "};\n\n");
  815. fprintf(fp_hpp, "// Pipeline Class\n");
  816. fprintf(fp_hpp, "class Pipeline {\n");
  817. fprintf(fp_hpp, "public:\n");
  818. fprintf(fp_hpp, " static bool enabled() { return %s; }\n\n",
  819. _pipeline ? "true" : "false" );
  820. assert( _pipeline->_maxInstrsPerBundle &&
  821. ( _pipeline->_instrUnitSize || _pipeline->_bundleUnitSize) &&
  822. _pipeline->_instrFetchUnitSize &&
  823. _pipeline->_instrFetchUnits,
  824. "unspecified pipeline architecture units");
  825. uint unitSize = _pipeline->_instrUnitSize ? _pipeline->_instrUnitSize : _pipeline->_bundleUnitSize;
  826. fprintf(fp_hpp, " enum {\n");
  827. fprintf(fp_hpp, " _variable_size_instructions = %d,\n",
  828. _pipeline->_variableSizeInstrs ? 1 : 0);
  829. fprintf(fp_hpp, " _fixed_size_instructions = %d,\n",
  830. _pipeline->_variableSizeInstrs ? 0 : 1);
  831. fprintf(fp_hpp, " _branch_has_delay_slot = %d,\n",
  832. _pipeline->_branchHasDelaySlot ? 1 : 0);
  833. fprintf(fp_hpp, " _max_instrs_per_bundle = %d,\n",
  834. _pipeline->_maxInstrsPerBundle);
  835. fprintf(fp_hpp, " _max_bundles_per_cycle = %d,\n",
  836. _pipeline->_maxBundlesPerCycle);
  837. fprintf(fp_hpp, " _max_instrs_per_cycle = %d\n",
  838. _pipeline->_maxBundlesPerCycle * _pipeline->_maxInstrsPerBundle);
  839. fprintf(fp_hpp, " };\n\n");
  840. fprintf(fp_hpp, " static bool instr_has_unit_size() { return %s; }\n\n",
  841. _pipeline->_instrUnitSize != 0 ? "true" : "false" );
  842. if( _pipeline->_bundleUnitSize != 0 )
  843. if( _pipeline->_instrUnitSize != 0 )
  844. fprintf(fp_hpp, "// Individual Instructions may be bundled together by the hardware\n\n");
  845. else
  846. fprintf(fp_hpp, "// Instructions exist only in bundles\n\n");
  847. else
  848. fprintf(fp_hpp, "// Bundling is not supported\n\n");
  849. if( _pipeline->_instrUnitSize != 0 )
  850. fprintf(fp_hpp, " // Size of an instruction\n");
  851. else
  852. fprintf(fp_hpp, " // Size of an individual instruction does not exist - unsupported\n");
  853. fprintf(fp_hpp, " static uint instr_unit_size() {");
  854. if( _pipeline->_instrUnitSize == 0 )
  855. fprintf(fp_hpp, " assert( false, \"Instructions are only in bundles\" );");
  856. fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_instrUnitSize);
  857. if( _pipeline->_bundleUnitSize != 0 )
  858. fprintf(fp_hpp, " // Size of a bundle\n");
  859. else
  860. fprintf(fp_hpp, " // Bundles do not exist - unsupported\n");
  861. fprintf(fp_hpp, " static uint bundle_unit_size() {");
  862. if( _pipeline->_bundleUnitSize == 0 )
  863. fprintf(fp_hpp, " assert( false, \"Bundles are not supported\" );");
  864. fprintf(fp_hpp, " return %d; };\n\n", _pipeline->_bundleUnitSize);
  865. fprintf(fp_hpp, " static bool requires_bundling() { return %s; }\n\n",
  866. _pipeline->_bundleUnitSize != 0 && _pipeline->_instrUnitSize == 0 ? "true" : "false" );
  867. fprintf(fp_hpp, "private:\n");
  868. fprintf(fp_hpp, " Pipeline(); // Not a legal constructor\n");
  869. fprintf(fp_hpp, "\n");
  870. fprintf(fp_hpp, " const unsigned char _read_stage_count;\n");
  871. fprintf(fp_hpp, " const unsigned char _write_stage;\n");
  872. fprintf(fp_hpp, " const unsigned char _fixed_latency;\n");
  873. fprintf(fp_hpp, " const unsigned char _instruction_count;\n");
  874. fprintf(fp_hpp, " const bool _has_fixed_latency;\n");
  875. fprintf(fp_hpp, " const bool _has_branch_delay;\n");
  876. fprintf(fp_hpp, " const bool _has_multiple_bundles;\n");
  877. fprintf(fp_hpp, " const bool _force_serialization;\n");
  878. fprintf(fp_hpp, " const bool _may_have_no_code;\n");
  879. fprintf(fp_hpp, " const enum machPipelineStages * const _read_stages;\n");
  880. fprintf(fp_hpp, " const enum machPipelineStages * const _resource_stage;\n");
  881. fprintf(fp_hpp, " const uint * const _resource_cycles;\n");
  882. fprintf(fp_hpp, " const Pipeline_Use _resource_use;\n");
  883. fprintf(fp_hpp, "\n");
  884. fprintf(fp_hpp, "public:\n");
  885. fprintf(fp_hpp, " Pipeline(uint write_stage,\n");
  886. fprintf(fp_hpp, " uint count,\n");
  887. fprintf(fp_hpp, " bool has_fixed_latency,\n");
  888. fprintf(fp_hpp, " uint fixed_latency,\n");
  889. fprintf(fp_hpp, " uint instruction_count,\n");
  890. fprintf(fp_hpp, " bool has_branch_delay,\n");
  891. fprintf(fp_hpp, " bool has_multiple_bundles,\n");
  892. fprintf(fp_hpp, " bool force_serialization,\n");
  893. fprintf(fp_hpp, " bool may_have_no_code,\n");
  894. fprintf(fp_hpp, " enum machPipelineStages * const dst,\n");
  895. fprintf(fp_hpp, " enum machPipelineStages * const stage,\n");
  896. fprintf(fp_hpp, " uint * const cycles,\n");
  897. fprintf(fp_hpp, " Pipeline_Use resource_use)\n");
  898. fprintf(fp_hpp, " : _write_stage(write_stage)\n");
  899. fprintf(fp_hpp, " , _read_stage_count(count)\n");
  900. fprintf(fp_hpp, " , _has_fixed_latency(has_fixed_latency)\n");
  901. fprintf(fp_hpp, " , _fixed_latency(fixed_latency)\n");
  902. fprintf(fp_hpp, " , _read_stages(dst)\n");
  903. fprintf(fp_hpp, " , _resource_stage(stage)\n");
  904. fprintf(fp_hpp, " , _resource_cycles(cycles)\n");
  905. fprintf(fp_hpp, " , _resource_use(resource_use)\n");
  906. fprintf(fp_hpp, " , _instruction_count(instruction_count)\n");
  907. fprintf(fp_hpp, " , _has_branch_delay(has_branch_delay)\n");
  908. fprintf(fp_hpp, " , _has_multiple_bundles(has_multiple_bundles)\n");
  909. fprintf(fp_hpp, " , _force_serialization(force_serialization)\n");
  910. fprintf(fp_hpp, " , _may_have_no_code(may_have_no_code)\n");
  911. fprintf(fp_hpp, " {};\n");
  912. fprintf(fp_hpp, "\n");
  913. fprintf(fp_hpp, " uint writeStage() const {\n");
  914. fprintf(fp_hpp, " return (_write_stage);\n");
  915. fprintf(fp_hpp, " }\n");
  916. fprintf(fp_hpp, "\n");
  917. fprintf(fp_hpp, " enum machPipelineStages readStage(int ndx) const {\n");
  918. fprintf(fp_hpp, " return (ndx < _read_stage_count ? _read_stages[ndx] : stage_undefined);");
  919. fprintf(fp_hpp, " }\n\n");
  920. fprintf(fp_hpp, " uint resourcesUsed() const {\n");
  921. fprintf(fp_hpp, " return _resource_use.resourcesUsed();\n }\n\n");
  922. fprintf(fp_hpp, " uint resourcesUsedExclusively() const {\n");
  923. fprintf(fp_hpp, " return _resource_use.resourcesUsedExclusively();\n }\n\n");
  924. fprintf(fp_hpp, " bool hasFixedLatency() const {\n");
  925. fprintf(fp_hpp, " return (_has_fixed_latency);\n }\n\n");
  926. fprintf(fp_hpp, " uint fixedLatency() const {\n");
  927. fprintf(fp_hpp, " return (_fixed_latency);\n }\n\n");
  928. fprintf(fp_hpp, " uint functional_unit_latency(uint start, const Pipeline *pred) const;\n\n");
  929. fprintf(fp_hpp, " uint operand_latency(uint opnd, const Pipeline *pred) const;\n\n");
  930. fprintf(fp_hpp, " const Pipeline_Use& resourceUse() const {\n");
  931. fprintf(fp_hpp, " return (_resource_use); }\n\n");
  932. fprintf(fp_hpp, " const Pipeline_Use_Element * resourceUseElement(uint i) const {\n");
  933. fprintf(fp_hpp, " return (&_resource_use._elements[i]); }\n\n");
  934. fprintf(fp_hpp, " uint resourceUseCount() const {\n");
  935. fprintf(fp_hpp, " return (_resource_use._count); }\n\n");
  936. fprintf(fp_hpp, " uint instructionCount() const {\n");
  937. fprintf(fp_hpp, " return (_instruction_count); }\n\n");
  938. fprintf(fp_hpp, " bool hasBranchDelay() const {\n");
  939. fprintf(fp_hpp, " return (_has_branch_delay); }\n\n");
  940. fprintf(fp_hpp, " bool hasMultipleBundles() const {\n");
  941. fprintf(fp_hpp, " return (_has_multiple_bundles); }\n\n");
  942. fprintf(fp_hpp, " bool forceSerialization() const {\n");
  943. fprintf(fp_hpp, " return (_force_serialization); }\n\n");
  944. fprintf(fp_hpp, " bool mayHaveNoCode() const {\n");
  945. fprintf(fp_hpp, " return (_may_have_no_code); }\n\n");
  946. fprintf(fp_hpp, "//const Pipeline_Use_Cycle_Mask& resourceUseMask(int resource) const {\n");
  947. fprintf(fp_hpp, "// return (_resource_use_masks[resource]); }\n\n");
  948. fprintf(fp_hpp, "\n#ifndef PRODUCT\n");
  949. fprintf(fp_hpp, " static const char * stageName(uint i);\n");
  950. fprintf(fp_hpp, "#endif\n");
  951. fprintf(fp_hpp, "};\n\n");
  952. fprintf(fp_hpp, "// Bundle class\n");
  953. fprintf(fp_hpp, "class Bundle {\n");
  954. uint mshift = 0;
  955. for (uint msize = _pipeline->_maxInstrsPerBundle * _pipeline->_maxBundlesPerCycle; msize != 0; msize >>= 1)
  956. mshift++;
  957. uint rshift = rescount;
  958. fprintf(fp_hpp, "protected:\n");
  959. fprintf(fp_hpp, " enum {\n");
  960. fprintf(fp_hpp, " _unused_delay = 0x%x,\n", 0);
  961. fprintf(fp_hpp, " _use_nop_delay = 0x%x,\n", 1);
  962. fprintf(fp_hpp, " _use_unconditional_delay = 0x%x,\n", 2);
  963. fprintf(fp_hpp, " _use_conditional_delay = 0x%x,\n", 3);
  964. fprintf(fp_hpp, " _used_in_conditional_delay = 0x%x,\n", 4);
  965. fprintf(fp_hpp, " _used_in_unconditional_delay = 0x%x,\n", 5);
  966. fprintf(fp_hpp, " _used_in_all_conditional_delays = 0x%x,\n", 6);
  967. fprintf(fp_hpp, "\n");
  968. fprintf(fp_hpp, " _use_delay = 0x%x,\n", 3);
  969. fprintf(fp_hpp, " _used_in_delay = 0x%x\n", 4);
  970. fprintf(fp_hpp, " };\n\n");
  971. fprintf(fp_hpp, " uint _flags : 3,\n");
  972. fprintf(fp_hpp, " _starts_bundle : 1,\n");
  973. fprintf(fp_hpp, " _instr_count : %d,\n", mshift);
  974. fprintf(fp_hpp, " _resources_used : %d;\n", rshift);
  975. fprintf(fp_hpp, "public:\n");
  976. fprintf(fp_hpp, " Bundle() : _flags(_unused_delay), _starts_bundle(0), _instr_count(0), _resources_used(0) {}\n\n");
  977. fprintf(fp_hpp, " void set_instr_count(uint i) { _instr_count = i; }\n");
  978. fprintf(fp_hpp, " void set_resources_used(uint i) { _resources_used = i; }\n");
  979. fprintf(fp_hpp, " void clear_usage() { _flags = _unused_delay; }\n");
  980. fprintf(fp_hpp, " void set_starts_bundle() { _starts_bundle = true; }\n");
  981. fprintf(fp_hpp, " uint flags() const { return (_flags); }\n");
  982. fprintf(fp_hpp, " uint instr_count() const { return (_instr_count); }\n");
  983. fprintf(fp_hpp, " uint resources_used() const { return (_resources_used); }\n");
  984. fprintf(fp_hpp, " bool starts_bundle() const { return (_starts_bundle != 0); }\n");
  985. fprintf(fp_hpp, " void set_use_nop_delay() { _flags = _use_nop_delay; }\n");
  986. fprintf(fp_hpp, " void set_use_unconditional_delay() { _flags = _use_unconditional_delay; }\n");
  987. fprintf(fp_hpp, " void set_use_conditional_delay() { _flags = _use_conditional_delay; }\n");
  988. fprintf(fp_hpp, " void set_used_in_unconditional_delay() { _flags = _used_in_unconditional_delay; }\n");
  989. fprintf(fp_hpp, " void set_used_in_conditional_delay() { _flags = _used_in_conditional_delay; }\n");
  990. fprintf(fp_hpp, " void set_used_in_all_conditional_delays() { _flags = _used_in_all_conditional_delays; }\n");
  991. fprintf(fp_hpp, " bool use_nop_delay() { return (_flags == _use_nop_delay); }\n");
  992. fprintf(fp_hpp, " bool use_unconditional_delay() { return (_flags == _use_unconditional_delay); }\n");
  993. fprintf(fp_hpp, " bool use_conditional_delay() { return (_flags == _use_conditional_delay); }\n");
  994. fprintf(fp_hpp, " bool used_in_unconditional_delay() { return (_flags == _used_in_unconditional_delay); }\n");
  995. fprintf(fp_hpp, " bool used_in_conditional_delay() { return (_flags == _used_in_conditional_delay); }\n");
  996. fprintf(fp_hpp, " bool used_in_all_conditional_delays() { return (_flags == _used_in_all_conditional_delays); }\n");
  997. fprintf(fp_hpp, " bool use_delay() { return ((_flags & _use_delay) != 0); }\n");
  998. fprintf(fp_hpp, " bool used_in_delay() { return ((_flags & _used_in_delay) != 0); }\n\n");
  999. fprintf(fp_hpp, " enum {\n");
  1000. fprintf(fp_hpp, " _nop_count = %d\n",
  1001. _pipeline->_nopcnt);
  1002. fprintf(fp_hpp, " };\n\n");
  1003. fprintf(fp_hpp, " static void initialize_nops(MachNode *nop_list[%d], Compile* C);\n\n",
  1004. _pipeline->_nopcnt);
  1005. fprintf(fp_hpp, "#ifndef PRODUCT\n");
  1006. fprintf(fp_hpp, " void dump() const;\n");
  1007. fprintf(fp_hpp, "#endif\n");
  1008. fprintf(fp_hpp, "};\n\n");
  1009. // const char *classname;
  1010. // for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) {
  1011. // PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass();
  1012. // fprintf(fp_hpp, "// Pipeline Class Instance for \"%s\"\n", classname);
  1013. // }
  1014. }
  1015. //------------------------------declareClasses---------------------------------
  1016. // Construct the class hierarchy of MachNode classes from the instruction &
  1017. // operand lists
  1018. void ArchDesc::declareClasses(FILE *fp) {
  1019. // Declare an array containing the machine register names, strings.
  1020. declareRegNames(fp, _register);
  1021. // Declare an array containing the machine register encoding values
  1022. declareRegEncodes(fp, _register);
  1023. // Generate declarations for the total number of operands
  1024. fprintf(fp,"\n");
  1025. fprintf(fp,"// Total number of operands defined in architecture definition\n");
  1026. int num_operands = 0;
  1027. OperandForm *op;
  1028. for (_operands.reset(); (op = (OperandForm*)_operands.iter()) != NULL; ) {
  1029. // Ensure this is a machine-world instruction
  1030. if (op->ideal_only()) continue;
  1031. ++num_operands;
  1032. }
  1033. int first_operand_class = num_operands;
  1034. OpClassForm *opc;
  1035. for (_opclass.reset(); (opc = (OpClassForm*)_opclass.iter()) != NULL; ) {
  1036. // Ensure this is a machine-world instruction
  1037. if (opc->ideal_only()) continue;
  1038. ++num_operands;
  1039. }
  1040. fprintf(fp,"#define FIRST_OPERAND_CLASS %d\n", first_operand_class);
  1041. fprintf(fp,"#define NUM_OPERANDS %d\n", num_operands);
  1042. fprintf(fp,"\n");
  1043. // Generate declarations for the total number of instructions
  1044. fprintf(fp,"// Total number of instructions defined in architecture definition\n");
  1045. fprintf(fp,"#define NUM_INSTRUCTIONS %d\n",instructFormCount());
  1046. // Generate Machine Classes for each operand defined in AD file
  1047. fprintf(fp,"\n");
  1048. fprintf(fp,"//----------------------------Declare classes derived from MachOper----------\n");
  1049. // Iterate through all operands
  1050. _operands.reset();
  1051. OperandForm *oper;
  1052. for( ; (oper = (OperandForm*)_operands.iter()) != NULL;) {
  1053. // Ensure this is a machine-world instruction
  1054. if (oper->ideal_only() ) continue;
  1055. // The declaration of labelOper is in machine-independent file: machnode
  1056. if ( strcmp(oper->_ident,"label") == 0 ) continue;
  1057. // The declaration of methodOper is in machine-independent file: machnode
  1058. if ( strcmp(oper->_ident,"method") == 0 ) continue;
  1059. // Build class definition for this operand
  1060. fprintf(fp,"\n");
  1061. fprintf(fp,"class %sOper : public MachOper { \n",oper->_ident);
  1062. fprintf(fp,"private:\n");
  1063. // Operand definitions that depend upon number of input edges
  1064. {
  1065. uint num_edges = oper->num_edges(_globalNames);
  1066. if( num_edges != 1 ) { // Use MachOper::num_edges() {return 1;}
  1067. fprintf(fp," virtual uint num_edges() const { return %d; }\n",
  1068. num_edges );
  1069. }
  1070. if( num_edges > 0 ) {
  1071. in_RegMask(fp);
  1072. }
  1073. }
  1074. // Support storing constants inside the MachOper
  1075. declareConstStorage(fp,_globalNames,oper);
  1076. // Support storage of the condition codes
  1077. if( oper->is_ideal_bool() ) {
  1078. fprintf(fp," virtual int ccode() const { \n");
  1079. fprintf(fp," switch (_c0) {\n");
  1080. fprintf(fp," case BoolTest::eq : return equal();\n");
  1081. fprintf(fp," case BoolTest::gt : return greater();\n");
  1082. fprintf(fp," case BoolTest::lt : return less();\n");
  1083. fprintf(fp," case BoolTest::ne : return not_equal();\n");
  1084. fprintf(fp," case BoolTest::le : return less_equal();\n");
  1085. fprintf(fp," case BoolTest::ge : return greater_equal();\n");
  1086. fprintf(fp," default : ShouldNotReachHere(); return 0;\n");
  1087. fprintf(fp," }\n");
  1088. fprintf(fp," };\n");
  1089. }
  1090. // Support storage of the condition codes
  1091. if( oper->is_ideal_bool() ) {
  1092. fprintf(fp," virtual void negate() { \n");
  1093. fprintf(fp," _c0 = (BoolTest::mask)((int)_c0^0x4); \n");
  1094. fprintf(fp," };\n");
  1095. }
  1096. // Declare constructor.
  1097. // Parameters start with condition code, then all other constants
  1098. //
  1099. // (1) MachXOper(int32 ccode, int32 c0, int32 c1, ..., int32 cn)
  1100. // (2) : _ccode(ccode), _c0(c0), _c1(c1), ..., _cn(cn) { }
  1101. //
  1102. Form::DataType constant_type = oper->simple_type(_globalNames);
  1103. defineConstructor(fp, oper->_ident, oper->num_consts(_globalNames),
  1104. oper->_components, oper->is_ideal_bool(),
  1105. constant_type, _globalNames);
  1106. // Clone function
  1107. fprintf(fp," virtual MachOper *clone(Compile* C) const;\n");
  1108. // Support setting a spill offset into a constant operand.
  1109. // We only support setting an 'int' offset, while in the
  1110. // LP64 build spill offsets are added with an AddP which
  1111. // requires a long constant. Thus we don't support spilling
  1112. // in frames larger than 4Gig.
  1113. if( oper->has_conI(_globalNames) ||
  1114. oper->has_conL(_globalNames) )
  1115. fprintf(fp, " virtual void set_con( jint c0 ) { _c0 = c0; }\n");
  1116. // virtual functions for encoding and format
  1117. // fprintf(fp," virtual void encode() const {\n %s }\n",
  1118. // (oper->_encrule)?(oper->_encrule->_encrule):"");
  1119. // Check the interface type, and generate the correct query functions
  1120. // encoding queries based upon MEMORY_INTER, REG_INTER, CONST_INTER.
  1121. fprintf(fp," virtual uint opcode() const { return %s; }\n",
  1122. machOperEnum(oper->_ident));
  1123. // virtual function to look up ideal return type of machine instruction
  1124. //
  1125. // (1) virtual const Type *type() const { return .....; }
  1126. //
  1127. if ((oper->_matrule) && (oper->_matrule->_lChild == NULL) &&
  1128. (oper->_matrule->_rChild == NULL)) {
  1129. unsigned int position = 0;
  1130. const char *opret, *opname, *optype;
  1131. oper->_matrule->base_operand(position,_globalNames,opret,opname,optype);
  1132. fprintf(fp," virtual const Type *type() const {");
  1133. const char *type = getIdealType(optype);
  1134. if( type != NULL ) {
  1135. Form::DataType data_type = oper->is_base_constant(_globalNames);
  1136. // Check if we are an ideal pointer type
  1137. if( data_type == Form::idealP || data_type == Form::idealN ) {
  1138. // Return the ideal type we already have: <TypePtr *>
  1139. fprintf(fp," return _c0;");
  1140. } else {
  1141. // Return the appropriate bottom type
  1142. fprintf(fp," return %s;", getIdealType(optype));
  1143. }
  1144. } else {
  1145. fprintf(fp," ShouldNotCallThis(); return Type::BOTTOM;");
  1146. }
  1147. fprintf(fp," }\n");
  1148. } else {
  1149. // Check for user-defined stack slots, based upon sRegX
  1150. Form::DataType data_type = oper->is_user_name_for_sReg();
  1151. if( data_type != Form::none ){
  1152. const char *type = NULL;
  1153. switch( data_type ) {
  1154. case Form::idealI: type = "TypeInt::INT"; break;
  1155. case Form::idealP: type = "TypePtr::BOTTOM";break;
  1156. case Form::idealF: type = "Type::FLOAT"; break;
  1157. case Form::idealD: type = "Type::DOUBLE"; break;
  1158. case Form::idealL: type = "TypeLong::LONG"; break;
  1159. case Form::none: // fall through
  1160. default:
  1161. assert( false, "No support for this type of stackSlot");
  1162. }
  1163. fprintf(fp," virtual const Type *type() const { return %s; } // stackSlotX\n", type);
  1164. }
  1165. }
  1166. //
  1167. // virtual functions for defining the encoding interface.
  1168. //
  1169. // Access the linearized ideal register mask,
  1170. // map to physical register encoding
  1171. if ( oper->_matrule && oper->_matrule->is_base_register(_globalNames) ) {
  1172. // Just use the default virtual 'reg' call
  1173. } else if ( oper->ideal_to_sReg_type(oper->_ident) != Form::none ) {
  1174. // Special handling for operand 'sReg', a Stack Slot Register.
  1175. // Map linearized ideal register mask to stack slot number
  1176. fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node) const {\n");
  1177. fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node));/* sReg */\n");
  1178. fprintf(fp," }\n");
  1179. fprintf(fp," virtual int reg(PhaseRegAlloc *ra_, const Node *node, int idx) const {\n");
  1180. fprintf(fp," return (int)OptoReg::reg2stack(ra_->get_reg_first(node->in(idx)));/* sReg */\n");
  1181. fprintf(fp," }\n");
  1182. }
  1183. // Output the operand specific access functions used by an enc_class
  1184. // These are only defined when we want to override the default virtual func
  1185. if (oper->_interface != NULL) {
  1186. fprintf(fp,"\n");
  1187. // Check if it is a Memory Interface
  1188. if ( oper->_interface->is_MemInterface() != NULL ) {
  1189. MemInterface *mem_interface = oper->_interface->is_MemInterface();
  1190. const char *base = mem_interface->_base;
  1191. if( base != NULL ) {
  1192. define_oper_interface(fp, *oper, _globalNames, "base", base);
  1193. }
  1194. char *index = mem_interface->_index;
  1195. if( index != NULL ) {
  1196. define_oper_interface(fp, *oper, _globalNames, "index", index);
  1197. }
  1198. const char *scale = mem_interface->_scale;
  1199. if( scale != NULL ) {
  1200. define_oper_interface(fp, *oper, _globalNames, "scale", scale);
  1201. }
  1202. const char *disp = mem_interface->_disp;
  1203. if( disp != NULL ) {
  1204. define_oper_interface(fp, *oper, _globalNames, "disp", disp);
  1205. oper->disp_is_oop(fp, _globalNames);
  1206. }
  1207. if( oper->stack_slots_only(_globalNames) ) {
  1208. // should not call this:
  1209. fprintf(fp," virtual int constant_disp() const { return Type::OffsetBot; }");
  1210. } else if ( disp != NULL ) {
  1211. define_oper_interface(fp, *oper, _globalNames, "constant_disp", disp);
  1212. }
  1213. } // end Memory Interface
  1214. // Check if it is a Conditional Interface
  1215. else if (oper->_interface->is_CondInterface() != NULL) {
  1216. CondInterface *cInterface = oper->_interface->is_CondInterface();
  1217. const char *equal = cInterface->_equal;
  1218. if( equal != NULL ) {
  1219. define_oper_interface(fp, *oper, _globalNames, "equal", equal);
  1220. }
  1221. const char *not_equal = cInterface->_not_equal;
  1222. if( not_equal != NULL ) {
  1223. define_oper_interface(fp, *oper, _globalNames, "not_equal", not_equal);
  1224. }
  1225. const char *less = cInterface->_less;
  1226. if( less != NULL ) {
  1227. define_oper_interface(fp, *oper, _globalNames, "less", less);
  1228. }
  1229. const char *greater_equal = cInterface->_greater_equal;
  1230. if( greater_equal != NULL ) {
  1231. define_oper_interface(fp, *oper, _globalNames, "greater_equal", greater_equal);
  1232. }
  1233. const char *less_equal = cInterface->_less_equal;
  1234. if( less_equal != NULL ) {
  1235. define_oper_interface(fp, *oper, _globalNames, "less_equal", less_equal);
  1236. }
  1237. const char *greater = cInterface->_greater;
  1238. if( greater != NULL ) {
  1239. define_oper_interface(fp, *oper, _globalNames, "greater", greater);
  1240. }
  1241. } // end Conditional Interface
  1242. // Check if it is a Constant Interface
  1243. else if (oper->_interface->is_ConstInterface() != NULL ) {
  1244. assert( oper->num_consts(_globalNames) == 1,
  1245. "Must have one constant when using CONST_INTER encoding");
  1246. if (!strcmp(oper->ideal_type(_globalNames), "ConI")) {
  1247. // Access the locally stored constant
  1248. fprintf(fp," virtual intptr_t constant() const {");
  1249. fprintf(fp, " return (intptr_t)_c0;");
  1250. fprintf(fp," }\n");
  1251. }
  1252. else if (!strcmp(oper->ideal_type(_globalNames), "ConP")) {
  1253. // Access the locally stored constant
  1254. fprintf(fp," virtual intptr_t constant() const {");
  1255. fprintf(fp, " return _c0->get_con();");
  1256. fprintf(fp, " }\n");
  1257. // Generate query to determine if this pointer is an oop
  1258. fprintf(fp," virtual bool constant_is_oop() const {");
  1259. fprintf(fp, " return _c0->isa_oop_ptr();");
  1260. fprintf(fp, " }\n");
  1261. }
  1262. else if (!strcmp(oper->ideal_type(_globalNames), "ConN")) {
  1263. // Access the locally stored constant
  1264. fprintf(fp," virtual intptr_t constant() const {");
  1265. fprintf(fp, " return _c0->get_ptrtype()->get_con();");
  1266. fprintf(fp, " }\n");
  1267. // Generate query to determine if this pointer is an oop
  1268. fprintf(fp," virtual bool constant_is_oop() const {");
  1269. fprintf(fp, " return _c0->get_ptrtype()->isa_oop_ptr();");
  1270. fprintf(fp, " }\n");
  1271. }
  1272. else if (!strcmp(oper->ideal_type(_globalNames), "ConL")) {
  1273. fprintf(fp," virtual intptr_t constant() const {");
  1274. // We don't support addressing modes with > 4Gig offsets.
  1275. // Truncate to int.
  1276. fprintf(fp, " return (intptr_t)_c0;");
  1277. fprintf(fp, " }\n");
  1278. fprintf(fp," virtual jlong constantL() const {");
  1279. fprintf(fp, " return _c0;");
  1280. fprintf(fp, " }\n");
  1281. }
  1282. else if (!strcmp(oper->ideal_type(_globalNames), "ConF")) {
  1283. fprintf(fp," virtual intptr_t constant() const {");
  1284. fprintf(fp, " ShouldNotReachHere(); return 0; ");
  1285. fprintf(fp, " }\n");
  1286. fprintf(fp," virtual jfloat constantF() const {");
  1287. fprintf(fp, " return (jfloat)_c0;");
  1288. fprintf(fp, " }\n");
  1289. }
  1290. else if (!strcmp(oper->ideal_type(_globalNames), "ConD")) {
  1291. fprintf(fp," virtual intptr_t constant() const {");
  1292. fprintf(fp, " ShouldNotReachHere(); return 0; ");
  1293. fprintf(fp, " }\n");
  1294. fprintf(fp," virtual jdouble constantD() const {");
  1295. fprintf(fp, " return _c0;");
  1296. fprintf(fp, " }\n");
  1297. }
  1298. }
  1299. else if (oper->_interface->is_RegInterface() != NULL) {
  1300. // make sure that a fixed format string isn't used for an
  1301. // operand which might be assiged to multiple registers.
  1302. // Otherwise the opto assembly output could be misleading.
  1303. if (oper->_format->_strings.count() != 0 && !oper->is_bound_register()) {
  1304. syntax_err(oper->_linenum,
  1305. "Only bound registers can have fixed formats: %s\n",
  1306. oper->_ident);
  1307. }
  1308. }
  1309. else {
  1310. assert( false, "ShouldNotReachHere();");
  1311. }
  1312. }
  1313. fprintf(fp,"\n");
  1314. // // Currently all XXXOper::hash() methods are identical (990820)
  1315. // declare_hash(fp);
  1316. // // Currently all XXXOper::Cmp() methods are identical (990820)
  1317. // declare_cmp(fp);
  1318. // Do not place dump_spec() and Name() into PRODUCT code
  1319. // int_format and ext_format are not needed in PRODUCT code either
  1320. fprintf(fp, "#ifndef PRODUCT\n");
  1321. // Declare int_format() and ext_format()
  1322. gen_oper_format(fp, _globalNames, *oper);
  1323. // Machine independent print functionality for debugging
  1324. // IF we have constants, create a dump_spec function for the derived class
  1325. //
  1326. // (1) virtual void dump_spec() const {
  1327. // (2) st->print("#%d", _c#); // Constant != ConP
  1328. // OR _c#->dump_on(st); // Type ConP
  1329. // ...
  1330. // (3) }
  1331. uint num_consts = oper->num_consts(_globalNames);
  1332. if( num_consts > 0 ) {
  1333. // line (1)
  1334. fprintf(fp, " virtual void dump_spec(outputStream *st) const {\n");
  1335. // generate format string for st->print
  1336. // Iterate over the component list & spit out the right thing
  1337. uint i = 0;
  1338. const char *type = oper->ideal_type(_globalNames);
  1339. Component *comp;
  1340. oper->_components.reset();
  1341. if ((comp = oper->_components.iter()) == NULL) {
  1342. assert(num_consts == 1, "Bad component list detected.\n");
  1343. i = dump_spec_constant( fp, type, i, oper );
  1344. // Check that type actually matched
  1345. assert( i != 0, "Non-constant operand lacks component list.");
  1346. } // end if NULL
  1347. else {
  1348. // line (2)
  1349. // dump all components
  1350. oper->_components.reset();
  1351. while((comp = oper->_components.iter()) != NULL) {
  1352. type = comp->base_type(_globalNames);
  1353. i = dump_spec_constant( fp, type, i, NULL );
  1354. }
  1355. }
  1356. // finish line (3)
  1357. fprintf(fp," }\n");
  1358. }
  1359. fprintf(fp," virtual const char *Name() const { return \"%s\";}\n",
  1360. oper->_ident);
  1361. fprintf(fp,"#endif\n");
  1362. // Close definition of this XxxMachOper
  1363. fprintf(fp,"};\n");
  1364. }
  1365. // Generate Machine Classes for each instruction defined in AD file
  1366. fprintf(fp,"\n");
  1367. fprintf(fp,"//----------------------------Declare classes for Pipelines-----------------\n");
  1368. declare_pipe_classes(fp);
  1369. // Generate Machine Classes for each instruction defined in AD file
  1370. fprintf(fp,"\n");
  1371. fprintf(fp,"//----------------------------Declare classes derived from MachNode----------\n");
  1372. _instructions.reset();
  1373. InstructForm *instr;
  1374. for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
  1375. // Ensure this is a machine-world instruction
  1376. if ( instr->ideal_only() ) continue;
  1377. // Build class definition for this instruction
  1378. fprintf(fp,"\n");
  1379. fprintf(fp,"class %sNode : public %s { \n",
  1380. instr->_ident, instr->mach_base_class() );
  1381. fprintf(fp,"private:\n");
  1382. fprintf(fp," MachOper *_opnd_array[%d];\n", instr->num_opnds() );
  1383. if ( instr->is_ideal_jump() ) {
  1384. fprintf(fp, " GrowableArray<Label*> _index2label;\n");
  1385. }
  1386. fprintf(fp,"public:\n");
  1387. fprintf(fp," MachOper *opnd_array(uint operand_index) const { assert(operand_index < _num_opnds, \"invalid _opnd_array index\"); return _opnd_array[operand_index]; }\n");
  1388. fprintf(fp," void set_opnd_array(uint operand_index, MachOper *operand) { assert(operand_index < _num_opnds, \"invalid _opnd_array index\"); _opnd_array[operand_index] = operand; }\n");
  1389. fprintf(fp,"private:\n");
  1390. if ( instr->is_ideal_jump() ) {
  1391. fprintf(fp," virtual void add_case_label(int index_num, Label* blockLabel) {\n");
  1392. fprintf(fp," _index2label.at_put_grow(index_num, blockLabel);}\n");
  1393. }
  1394. if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {
  1395. fprintf(fp," const RegMask *_cisc_RegMask;\n");
  1396. }
  1397. out_RegMask(fp); // output register mask
  1398. fprintf(fp," virtual uint rule() const { return %s_rule; }\n",
  1399. instr->_ident);
  1400. // If this instruction contains a labelOper
  1401. // Declare Node::methods that set operand Label's contents
  1402. int label_position = instr->label_position();
  1403. if( label_position != -1 ) {
  1404. // Set the label, stored in labelOper::_branch_label
  1405. fprintf(fp," virtual void label_set( Label& label, uint block_num );\n");
  1406. }
  1407. // If this instruction contains a methodOper
  1408. // Declare Node::methods that set operand method's contents
  1409. int method_position = instr->method_position();
  1410. if( method_position != -1 ) {
  1411. // Set the address method, stored in methodOper::_method
  1412. fprintf(fp," virtual void method_set( intptr_t method );\n");
  1413. }
  1414. // virtual functions for attributes
  1415. //
  1416. // Each instruction attribute results in a virtual call of same name.
  1417. // The ins_cost is not handled here.
  1418. Attribute *attr = instr->_attribs;
  1419. bool is_pc_relative = false;
  1420. while (attr != NULL) {
  1421. if (strcmp(attr->_ident,"ins_cost") &&
  1422. strcmp(attr->_ident,"ins_pc_relative")) {
  1423. fprintf(fp," int %s() const { return %s; }\n",
  1424. attr->_ident, attr->_val);
  1425. }
  1426. // Check value for ins_pc_relative, and if it is true (1), set the flag
  1427. if (!strcmp(attr->_ident,"ins_pc_relative") && attr->int_val(*this) != 0)
  1428. is_pc_relative = true;
  1429. attr = (Attribute *)attr->_next;
  1430. }
  1431. // virtual functions for encode and format
  1432. //
  1433. // Output the opcode function and the encode function here using the
  1434. // encoding class information in the _insencode slot.
  1435. if ( instr->_insencode ) {
  1436. fprintf(fp," virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const;\n");
  1437. }
  1438. // virtual function for getting the size of an instruction
  1439. if ( instr->_size ) {
  1440. fprintf(fp," virtual uint size(PhaseRegAlloc *ra_) const;\n");
  1441. }
  1442. // Return the top-level ideal opcode.
  1443. // Use MachNode::ideal_Opcode() for nodes based on MachNode class
  1444. // if the ideal_Opcode == Op_Node.
  1445. if ( strcmp("Node", instr->ideal_Opcode(_globalNames)) != 0 ||
  1446. strcmp("MachNode", instr->mach_base_class()) != 0 ) {
  1447. fprintf(fp," virtual int ideal_Opcode() const { return Op_%s; }\n",
  1448. instr->ideal_Opcode(_globalNames) );
  1449. }
  1450. // Allow machine-independent optimization, invert the sense of the IF test
  1451. if( instr->is_ideal_if() ) {
  1452. fprintf(fp," virtual void negate() { \n");
  1453. // Identify which operand contains the negate(able) ideal condition code
  1454. int idx = 0;
  1455. instr->_components.reset();
  1456. for( Component *comp; (comp = instr->_components.iter()) != NULL; ) {
  1457. // Check that component is an operand
  1458. Form *form = (Form*)_globalNames[comp->_type];
  1459. OperandForm *opForm = form ? form->is_operand() : NULL;
  1460. if( opForm == NULL ) continue;
  1461. // Lookup the position of the operand in the instruction.
  1462. if( opForm->is_ideal_bool() ) {
  1463. idx = instr->operand_position(comp->_name, comp->_usedef);
  1464. assert( idx != NameList::Not_in_list, "Did not find component in list that contained it.");
  1465. break;
  1466. }
  1467. }
  1468. fprintf(fp," opnd_array(%d)->negate();\n", idx);
  1469. fprintf(fp," _prob = 1.0f - _prob;\n");
  1470. fprintf(fp," };\n");
  1471. }
  1472. // Identify which input register matches the input register.
  1473. uint matching_input = instr->two_address(_globalNames);
  1474. // Generate the method if it returns != 0 otherwise use MachNode::two_adr()
  1475. if( matching_input != 0 ) {
  1476. fprintf(fp," virtual uint two_adr() const ");
  1477. fprintf(fp,"{ return oper_input_base()");
  1478. for( uint i = 2; i <= matching_input; i++ )
  1479. fprintf(fp," + opnd_array(%d)->num_edges()",i-1);
  1480. fprintf(fp,"; }\n");
  1481. }
  1482. // Declare cisc_version, if applicable
  1483. // MachNode *cisc_version( int offset /* ,... */ );
  1484. instr->declare_cisc_version(*this, fp);
  1485. // If there is an explicit peephole rule, build it
  1486. if ( instr->peepholes() != NULL ) {
  1487. fprintf(fp," virtual MachNode *peephole(Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted, Compile *C);\n");
  1488. }
  1489. // Output the declaration for number of relocation entries
  1490. if ( instr->reloc(_globalNames) != 0 ) {
  1491. fprintf(fp," virtual int reloc() const;\n");
  1492. }
  1493. if (instr->alignment() != 1) {
  1494. fprintf(fp," virtual int alignment_required() const { return %d; }\n", instr->alignment());
  1495. fprintf(fp," virtual int compute_padding(int current_offset) const;\n");
  1496. }
  1497. // Starting point for inputs matcher wants.
  1498. // Use MachNode::oper_input_base() for nodes based on MachNode class
  1499. // if the base == 1.
  1500. if ( instr->oper_input_base(_globalNames) != 1 ||
  1501. strcmp("MachNode", instr->mach_base_class()) != 0 ) {
  1502. fprintf(fp," virtual uint oper_input_base() const { return %d; }\n",
  1503. instr->oper_input_base(_globalNames));
  1504. }
  1505. // Make the constructor and following methods 'public:'
  1506. fprintf(fp,"public:\n");
  1507. // Constructor
  1508. if ( instr->is_ideal_jump() ) {
  1509. fprintf(fp," %sNode() : _index2label(MinJumpTableSize*2) { ", instr->_ident);
  1510. } else {
  1511. fprintf(fp," %sNode() { ", instr->_ident);
  1512. if( can_cisc_spill() && (instr->cisc_spill_alternate() != NULL) ) {
  1513. fprintf(fp,"_cisc_RegMask = NULL; ");
  1514. }
  1515. }
  1516. fprintf(fp," _num_opnds = %d; _opnds = _opnd_array; ", instr->num_opnds());
  1517. bool node_flags_set = false;
  1518. // flag: if this instruction matches an ideal 'Goto' node
  1519. if ( instr->is_ideal_goto() ) {
  1520. fprintf(fp,"init_flags(Flag_is_Goto");
  1521. node_flags_set = true;
  1522. }
  1523. // flag: if this instruction matches an ideal 'Copy*' node
  1524. if ( instr->is_ideal_copy() != 0 ) {
  1525. if ( node_flags_set ) {
  1526. fprintf(fp," | Flag_is_Copy");
  1527. } else {
  1528. fprintf(fp,"init_flags(Flag_is_Copy");
  1529. node_flags_set = true;
  1530. }
  1531. }
  1532. // Is an instruction is a constant? If so, get its type
  1533. Form::DataType data_type;
  1534. const char *opType = NULL;
  1535. const char *result = NULL;
  1536. data_type = instr->is_chain_of_constant(_globalNames, opType, result);
  1537. // Check if this instruction is a constant
  1538. if ( data_type != Form::none ) {
  1539. if ( node_flags_set ) {
  1540. fprintf(fp," | Flag_is_Con");
  1541. } else {
  1542. fprintf(fp,"init_flags(Flag_is_Con");
  1543. node_flags_set = true;
  1544. }
  1545. }
  1546. // flag: if instruction matches 'If' | 'Goto' | 'CountedLoopEnd | 'Jump'
  1547. if ( instr->is_ideal_branch() ) {
  1548. if ( node_flags_set ) {
  1549. fprintf(fp," | Flag_is_Branch");
  1550. } else {
  1551. fprintf(fp,"init_flags(Flag_is_Branch");
  1552. node_flags_set = true;
  1553. }
  1554. }
  1555. // flag: if this instruction is cisc alternate
  1556. if ( can_cisc_spill() && instr->is_cisc_alternate() ) {
  1557. if ( node_flags_set ) {
  1558. fprintf(fp," | Flag_is_cisc_alternate");
  1559. } else {
  1560. fprintf(fp,"init_flags(Flag_is_cisc_alternate");
  1561. node_flags_set = true;
  1562. }
  1563. }
  1564. // flag: if this instruction is pc relative
  1565. if ( is_pc_relative ) {
  1566. if ( node_flags_set ) {
  1567. fprintf(fp," | Flag_is_pc_relative");
  1568. } else {
  1569. fprintf(fp,"init_flags(Flag_is_pc_relative");
  1570. node_flags_set = true;
  1571. }
  1572. }
  1573. // flag: if this instruction has short branch form
  1574. if ( instr->has_short_branch_form() ) {
  1575. if ( node_flags_set ) {
  1576. fprintf(fp," | Flag_may_be_short_branch");
  1577. } else {
  1578. fprintf(fp,"init_flags(Flag_may_be_short_branch");
  1579. node_flags_set = true;
  1580. }
  1581. }
  1582. // Check if machine instructions that USE memory, but do not DEF memory,
  1583. // depend upon a node that defines memory in machine-independent graph.
  1584. if ( instr->needs_anti_dependence_check(_globalNames) ) {
  1585. if ( node_flags_set ) {
  1586. fprintf(fp," | Flag_needs_anti_dependence_check");
  1587. } else {
  1588. fprintf(fp,"init_flags(Flag_needs_anti_dependence_check");
  1589. node_flags_set = true;
  1590. }
  1591. }
  1592. if ( node_flags_set ) {
  1593. fprintf(fp,"); ");
  1594. }
  1595. if (instr->is_ideal_unlock() || instr->is_ideal_call_leaf()) {
  1596. fprintf(fp,"clear_flag(Flag_is_safepoint_node); ");
  1597. }
  1598. fprintf(fp,"}\n");
  1599. // size_of, used by base class's clone to obtain the correct size.
  1600. fprintf(fp," virtual uint size_of() const {");
  1601. fprintf(fp, " return sizeof(%sNode);", instr->_ident);
  1602. fprintf(fp, " }\n");
  1603. // Virtual methods which are only generated to override base class
  1604. if( instr->expands() || instr->needs_projections() ||
  1605. instr->has_temps() ||
  1606. instr->_matrule != NULL &&
  1607. instr->num_opnds() != instr->num_unique_opnds() ) {
  1608. fprintf(fp," virtual MachNode *Expand(State *state, Node_List &proj_list, Node* mem);\n");
  1609. }
  1610. if (instr->is_pinned(_globalNames)) {
  1611. fprintf(fp," virtual bool pinned() const { return ");
  1612. if (instr->is_parm(_globalNames)) {
  1613. fprintf(fp,"_in[0]->pinned();");
  1614. } else {
  1615. fprintf(fp,"true;");
  1616. }
  1617. fprintf(fp," }\n");
  1618. }
  1619. if (instr->is_projection(_globalNames)) {
  1620. fprintf(fp," virtual const Node *is_block_proj() const { return this; }\n");
  1621. }
  1622. if ( instr->num_post_match_opnds() != 0
  1623. || instr->is_chain_of_constant(_globalNames) ) {
  1624. fprintf(fp," friend MachNode *State::MachNodeGenerator(int opcode, Compile* C);\n");
  1625. }
  1626. if ( instr->rematerialize(_globalNames, get_registers()) ) {
  1627. fprintf(fp," // Rematerialize %s\n", instr->_ident);
  1628. }
  1629. // Declare short branch methods, if applicable
  1630. instr->declare_short_branch_methods(fp);
  1631. // Instructions containing a constant that will be entered into the
  1632. // float/double table redefine the base virtual function
  1633. #ifdef SPARC
  1634. // Sparc doubles entries in the constant table require more space for
  1635. // alignment. (expires 9/98)
  1636. int table_entries = (3 * instr->num_consts( _globalNames, Form::idealD ))
  1637. + instr->num_consts( _globalNames, Form::idealF );
  1638. #else
  1639. int table_entries = instr->num_consts( _globalNames, Form::idealD )
  1640. + instr->num_consts( _globalNames, Form::idealF );
  1641. #endif
  1642. if( table_entries != 0 ) {
  1643. fprintf(fp," virtual int const_size() const {");
  1644. fprintf(fp, " return %d;", table_entries);
  1645. fprintf(fp, " }\n");
  1646. }
  1647. // See if there is an "ins_pipe" declaration for this instruction
  1648. if (instr->_ins_pipe) {
  1649. fprintf(fp," static const Pipeline *pipeline_class();\n");
  1650. fprintf(fp," virtual const Pipeline *pipeline() const;\n");
  1651. }
  1652. // Generate virtual function for MachNodeX::bottom_type when necessary
  1653. //
  1654. // Note on accuracy: Pointer-types of machine nodes need to be accurate,
  1655. // or else alias analysis on the matched graph may produce bad code.
  1656. // Moreover, the aliasing decisions made on machine-node graph must be
  1657. // no less accurate than those made on the ideal graph, or else the graph
  1658. // may fail to schedule. (Reason: Memory ops which are reordered in
  1659. // the ideal graph might look interdependent in the machine graph,
  1660. // thereby removing degrees of scheduling freedom that the optimizer
  1661. // assumed would be available.)
  1662. //
  1663. // %%% We should handle many of these cases with an explicit ADL clause:
  1664. // instruct foo() %{ ... bottom_type(TypeRawPtr::BOTTOM); ... %}
  1665. if( data_type != Form::none ) {
  1666. // A constant's bottom_type returns a Type containing its constant value
  1667. // !!!!!
  1668. // Convert all ints, floats, ... to machine-independent TypeXs
  1669. // as is done for pointers
  1670. //
  1671. // Construct appropriate constant type containing the constant value.
  1672. fprintf(fp," virtual const class Type *bottom_type() const{\n");
  1673. switch( data_type ) {
  1674. case Form::idealI:
  1675. fprintf(fp," return TypeInt::make(opnd_array(1)->constant());\n");
  1676. break;
  1677. case Form::idealP:
  1678. case Form::idealN:
  1679. fprintf(fp," return opnd_array(1)->type();\n");
  1680. break;
  1681. case Form::idealD:
  1682. fprintf(fp," return TypeD::make(opnd_array(1)->constantD());\n");
  1683. break;
  1684. case Form::idealF:
  1685. fprintf(fp," return TypeF::make(opnd_array(1)->constantF());\n");
  1686. break;
  1687. case Form::idealL:
  1688. fprintf(fp," return TypeLong::make(opnd_array(1)->constantL());\n");
  1689. break;
  1690. default:
  1691. assert( false, "Unimplemented()" );
  1692. break;
  1693. }
  1694. fprintf(fp," };\n");
  1695. }
  1696. /* else if ( instr->_matrule && instr->_matrule->_rChild &&
  1697. ( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0
  1698. || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {
  1699. // !!!!! !!!!!
  1700. // Provide explicit bottom type for conversions to int
  1701. // On Intel the result operand is a stackSlot, untyped.
  1702. fprintf(fp," virtual const class Type *bottom_type() const{");
  1703. fprintf(fp, " return TypeInt::INT;");
  1704. fprintf(fp, " };\n");
  1705. }*/
  1706. else if( instr->is_ideal_copy() &&
  1707. !strcmp(instr->_matrule->_lChild->_opType,"stackSlotP") ) {
  1708. // !!!!!
  1709. // Special hack for ideal Copy of pointer. Bottom type is oop or not depending on input.
  1710. fprintf(fp," const Type *bottom_type() const { return in(1)->bottom_type(); } // Copy?\n");
  1711. }
  1712. else if( instr->is_ideal_loadPC() ) {
  1713. // LoadPCNode provides the return address of a call to native code.
  1714. // Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM
  1715. // since it is a pointer to an internal VM location and must have a zero offset.
  1716. // Allocation detects derived pointers, in part, by their non-zero offsets.
  1717. fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // LoadPC?\n");
  1718. }
  1719. else if( instr->is_ideal_box() ) {
  1720. // BoxNode provides the address of a stack slot.
  1721. // Define its bottom type to be TypeRawPtr::BOTTOM instead of TypePtr::BOTTOM
  1722. // This prevent s insert_anti_dependencies from complaining. It will
  1723. // complain if it see that the pointer base is TypePtr::BOTTOM since
  1724. // it doesn't understand what that might alias.
  1725. fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // Box?\n");
  1726. }
  1727. else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveP") ) {
  1728. int offset = 1;
  1729. // Special special hack to see if the Cmp? has been incorporated in the conditional move
  1730. MatchNode *rl = instr->_matrule->_rChild->_lChild;
  1731. if( rl && !strcmp(rl->_opType, "Binary") ) {
  1732. MatchNode *rlr = rl->_rChild;
  1733. if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)
  1734. offset = 2;
  1735. }
  1736. // Special hack for ideal CMoveP; ideal type depends on inputs
  1737. fprintf(fp," const Type *bottom_type() const { const Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // CMoveP\n",
  1738. offset, offset+1, offset+1);
  1739. }
  1740. else if( instr->_matrule && instr->_matrule->_rChild && !strcmp(instr->_matrule->_rChild->_opType,"CMoveN") ) {
  1741. int offset = 1;
  1742. // Special special hack to see if the Cmp? has been incorporated in the conditional move
  1743. MatchNode *rl = instr->_matrule->_rChild->_lChild;
  1744. if( rl && !strcmp(rl->_opType, "Binary") ) {
  1745. MatchNode *rlr = rl->_rChild;
  1746. if (rlr && strncmp(rlr->_opType, "Cmp", 3) == 0)
  1747. offset = 2;
  1748. }
  1749. // Special hack for ideal CMoveN; ideal type depends on inputs
  1750. fprintf(fp," const Type *bottom_type() const { const Type *t = in(oper_input_base()+%d)->bottom_type(); return (req() <= oper_input_base()+%d) ? t : t->meet(in(oper_input_base()+%d)->bottom_type()); } // CMoveN\n",
  1751. offset, offset+1, offset+1);
  1752. }
  1753. else if( instr->needs_base_oop_edge(_globalNames) ) {
  1754. // Special hack for ideal AddP. Bottom type is an oop IFF it has a
  1755. // legal base-pointer input. Otherwise it is NOT an oop.
  1756. fprintf(fp," const Type *bottom_type() const { return AddPNode::mach_bottom_type(this); } // AddP\n");
  1757. }
  1758. else if (instr->is_tls_instruction()) {
  1759. // Special hack for tlsLoadP
  1760. fprintf(fp," const Type *bottom_type() const { return TypeRawPtr::BOTTOM; } // tlsLoadP\n");
  1761. }
  1762. else if ( instr->is_ideal_if() ) {
  1763. fprintf(fp," const Type *bottom_type() const { return TypeTuple::IFBOTH; } // matched IfNode\n");
  1764. }
  1765. else if ( instr->is_ideal_membar() ) {
  1766. fprintf(fp," const Type *bottom_type() const { return TypeTuple::MEMBAR; } // matched MemBar\n");
  1767. }
  1768. // Check where 'ideal_type' must be customized
  1769. /*
  1770. if ( instr->_matrule && instr->_matrule->_rChild &&
  1771. ( strcmp("ConvF2I",instr->_matrule->_rChild->_opType)==0
  1772. || strcmp("ConvD2I",instr->_matrule->_rChild->_opType)==0 ) ) {
  1773. fprintf(fp," virtual uint ideal_reg() const { return Compile::current()->matcher()->base2reg[Type::Int]; }\n");
  1774. }*/
  1775. // Analyze machine instructions that either USE or DEF memory.
  1776. int memory_operand = instr->memory_operand(_globalNames);
  1777. // Some guys kill all of memory
  1778. if ( instr->is_wide_memory_kill(_globalNames) ) {
  1779. memory_operand = InstructForm::MANY_MEMORY_OPERANDS;
  1780. }
  1781. if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) {
  1782. if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) {
  1783. fprintf(fp," virtual const TypePtr *adr_type() const;\n");
  1784. }
  1785. fprintf(fp," virtual const MachOper *memory_operand() const;\n");
  1786. }
  1787. fprintf(fp, "#ifndef PRODUCT\n");
  1788. // virtual function for generating the user's assembler output
  1789. gen_inst_format(fp, _globalNames,*instr);
  1790. // Machine independent print functionality for debugging
  1791. fprintf(fp," virtual const char *Name() const { return \"%s\";}\n",
  1792. instr->_ident);
  1793. fprintf(fp, "#endif\n");
  1794. // Close definition of this XxxMachNode
  1795. fprintf(fp,"};\n");
  1796. };
  1797. }
  1798. void ArchDesc::defineStateClass(FILE *fp) {
  1799. static const char *state__valid = "_valid[((uint)index) >> 5] & (0x1 << (((uint)index) & 0x0001F))";
  1800. static const char *state__set_valid= "_valid[((uint)index) >> 5] |= (0x1 << (((uint)index) & 0x0001F))";
  1801. fprintf(fp,"\n");
  1802. fprintf(fp,"// MACROS to inline and constant fold State::valid(index)...\n");
  1803. fprintf(fp,"// when given a constant 'index' in dfa_<arch>.cpp\n");
  1804. fprintf(fp,"// uint word = index >> 5; // Shift out bit position\n");
  1805. fprintf(fp,"// uint bitpos = index & 0x0001F; // Mask off word bits\n");
  1806. fprintf(fp,"#define STATE__VALID(index) ");
  1807. fprintf(fp," (%s)\n", state__valid);
  1808. fprintf(fp,"\n");
  1809. fprintf(fp,"#define STATE__NOT_YET_VALID(index) ");
  1810. fprintf(fp," ( (%s) == 0 )\n", state__valid);
  1811. fprintf(fp,"\n");
  1812. fprintf(fp,"#define STATE__VALID_CHILD(state,index) ");
  1813. fprintf(fp," ( state && (state->%s) )\n", state__valid);
  1814. fprintf(fp,"\n");
  1815. fprintf(fp,"#define STATE__SET_VALID(index) ");
  1816. fprintf(fp," (%s)\n", state__set_valid);
  1817. fprintf(fp,"\n");
  1818. fprintf(fp,
  1819. "//---------------------------State-------------------------------------------\n");
  1820. fprintf(fp,"// State contains an integral cost vector, indexed by machine operand opcodes,\n");
  1821. fprintf(fp,"// a rule vector consisting of machine operand/instruction opcodes, and also\n");
  1822. fprintf(fp,"// indexed by machine operand opcodes, pointers to the children in the label\n");
  1823. fprintf(fp,"// tree generated by the Label routines in ideal nodes (currently limited to\n");
  1824. fprintf(fp,"// two for convenience, but this could change).\n");
  1825. fprintf(fp,"class State : public ResourceObj {\n");
  1826. fprintf(fp,"public:\n");
  1827. fprintf(fp," int _id; // State identifier\n");
  1828. fprintf(fp," Node *_leaf; // Ideal (non-machine-node) leaf of match tree\n");
  1829. fprintf(fp," State *_kids[2]; // Children of state node in label tree\n");
  1830. fprintf(fp," unsigned int _cost[_LAST_MACH_OPER]; // Cost vector, indexed by operand opcodes\n");
  1831. fprintf(fp," unsigned int _rule[_LAST_MACH_OPER]; // Rule vector, indexed by operand opcodes\n");
  1832. fprintf(fp," unsigned int _valid[(_LAST_MACH_OPER/32)+1]; // Bit Map of valid Cost/Rule entries\n");
  1833. fprintf(fp,"\n");
  1834. fprintf(fp," State(void); // Constructor\n");
  1835. fprintf(fp," DEBUG_ONLY( ~State(void); ) // Destructor\n");
  1836. fprintf(fp,"\n");
  1837. fprintf(fp," // Methods created by ADLC and invoked by Reduce\n");
  1838. fprintf(fp," MachOper *MachOperGenerator( int opcode, Compile* C );\n");
  1839. fprintf(fp," MachNode *MachNodeGenerator( int opcode, Compile* C );\n");
  1840. fprintf(fp,"\n");
  1841. fprintf(fp," // Assign a state to a node, definition of method produced by ADLC\n");
  1842. fprintf(fp," bool DFA( int opcode, const Node *ideal );\n");
  1843. fprintf(fp,"\n");
  1844. fprintf(fp," // Access function for _valid bit vector\n");
  1845. fprintf(fp," bool valid(uint index) {\n");
  1846. fprintf(fp," return( STATE__VALID(index) != 0 );\n");
  1847. fprintf(fp," }\n");
  1848. fprintf(fp,"\n");
  1849. fprintf(fp," // Set function for _valid bit vector\n");
  1850. fprintf(fp," void set_valid(uint index) {\n");
  1851. fprintf(fp," STATE__SET_VALID(index);\n");
  1852. fprintf(fp," }\n");
  1853. fprintf(fp,"\n");
  1854. fprintf(fp,"#ifndef PRODUCT\n");
  1855. fprintf(fp," void dump(); // Debugging prints\n");
  1856. fprintf(fp," void dump(int depth);\n");
  1857. fprintf(fp,"#endif\n");
  1858. if (_dfa_small) {
  1859. // Generate the routine name we'll need
  1860. for (int i = 1; i < _last_opcode; i++) {
  1861. if (_mlistab[i] == NULL) continue;
  1862. fprintf(fp, " void _sub_Op_%s(const Node *n);\n", NodeClassNames[i]);
  1863. }
  1864. }
  1865. fprintf(fp,"};\n");
  1866. fprintf(fp,"\n");
  1867. fprintf(fp,"\n");
  1868. }
  1869. //---------------------------buildMachOperEnum---------------------------------
  1870. // Build enumeration for densely packed operands.
  1871. // This enumeration is used to index into the arrays in the State objects
  1872. // that indicate cost and a successfull rule match.
  1873. // Information needed to generate the ReduceOp mapping for the DFA
  1874. class OutputMachOperands : public OutputMap {
  1875. public:
  1876. OutputMachOperands(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
  1877. : OutputMap(hpp, cpp, globals, AD) {};
  1878. void declaration() { }
  1879. void definition() { fprintf(_cpp, "enum MachOperands {\n"); }
  1880. void closing() { fprintf(_cpp, " _LAST_MACH_OPER\n");
  1881. OutputMap::closing();
  1882. }
  1883. void map(OpClassForm &opc) { fprintf(_cpp, " %s", _AD.machOperEnum(opc._ident) ); }
  1884. void map(OperandForm &oper) { fprintf(_cpp, " %s", _AD.machOperEnum(oper._ident) ); }
  1885. void map(char *name) { fprintf(_cpp, " %s", _AD.machOperEnum(name)); }
  1886. bool do_instructions() { return false; }
  1887. void map(InstructForm &inst){ assert( false, "ShouldNotCallThis()"); }
  1888. };
  1889. void ArchDesc::buildMachOperEnum(FILE *fp_hpp) {
  1890. // Construct the table for MachOpcodes
  1891. OutputMachOperands output_mach_operands(fp_hpp, fp_hpp, _globalNames, *this);
  1892. build_map(output_mach_operands);
  1893. }
  1894. //---------------------------buildMachEnum----------------------------------
  1895. // Build enumeration for all MachOpers and all MachNodes
  1896. // Information needed to generate the ReduceOp mapping for the DFA
  1897. class OutputMachOpcodes : public OutputMap {
  1898. int begin_inst_chain_rule;
  1899. int end_inst_chain_rule;
  1900. int begin_rematerialize;
  1901. int end_rematerialize;
  1902. int end_instructions;
  1903. public:
  1904. OutputMachOpcodes(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
  1905. : OutputMap(hpp, cpp, globals, AD),
  1906. begin_inst_chain_rule(-1), end_inst_chain_rule(-1), end_instructions(-1)
  1907. {};
  1908. void declaration() { }
  1909. void definition() { fprintf(_cpp, "enum MachOpcodes {\n"); }
  1910. void closing() {
  1911. if( begin_inst_chain_rule != -1 )
  1912. fprintf(_cpp, " _BEGIN_INST_CHAIN_RULE = %d,\n", begin_inst_chain_rule);
  1913. if( end_inst_chain_rule != -1 )
  1914. fprintf(_cpp, " _END_INST_CHAIN_RULE = %d,\n", end_inst_chain_rule);
  1915. if( begin_rematerialize != -1 )
  1916. fprintf(_cpp, " _BEGIN_REMATERIALIZE = %d,\n", begin_rematerialize);
  1917. if( end_rematerialize != -1 )
  1918. fprintf(_cpp, " _END_REMATERIALIZE = %d,\n", end_rematerialize);
  1919. // always execute since do_instructions() is true, and avoids trailing comma
  1920. fprintf(_cpp, " _last_Mach_Node = %d \n", end_instructions);
  1921. OutputMap::closing();
  1922. }
  1923. void map(OpClassForm &opc) { fprintf(_cpp, " %s_rule", opc._ident ); }
  1924. void map(OperandForm &oper) { fprintf(_cpp, " %s_rule", oper._ident ); }
  1925. void map(char *name) { if (name) fprintf(_cpp, " %s_rule", name);
  1926. else fprintf(_cpp, " 0"); }
  1927. void map(InstructForm &inst) {fprintf(_cpp, " %s_rule", inst._ident ); }
  1928. void record_position(OutputMap::position place, int idx ) {
  1929. switch(place) {
  1930. case OutputMap::BEGIN_INST_CHAIN_RULES :
  1931. begin_inst_chain_rule = idx;
  1932. break;
  1933. case OutputMap::END_INST_CHAIN_RULES :
  1934. end_inst_chain_rule = idx;
  1935. break;
  1936. case OutputMap::BEGIN_REMATERIALIZE :
  1937. begin_rematerialize = idx;
  1938. break;
  1939. case OutputMap::END_REMATERIALIZE :
  1940. end_rematerialize = idx;
  1941. break;
  1942. case OutputMap::END_INSTRUCTIONS :
  1943. end_instructions = idx;
  1944. break;
  1945. default:
  1946. break;
  1947. }
  1948. }
  1949. };
  1950. void ArchDesc::buildMachOpcodesEnum(FILE *fp_hpp) {
  1951. // Construct the table for MachOpcodes
  1952. OutputMachOpcodes output_mach_opcodes(fp_hpp, fp_hpp, _globalNames, *this);
  1953. build_map(output_mach_opcodes);
  1954. }
  1955. // Generate an enumeration of the pipeline states, and both
  1956. // the functional units (resources) and the masks for
  1957. // specifying resources
  1958. void ArchDesc::build_pipeline_enums(FILE *fp_hpp) {
  1959. int stagelen = (int)strlen("undefined");
  1960. int stagenum = 0;
  1961. if (_pipeline) { // Find max enum string length
  1962. const char *stage;
  1963. for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; ) {
  1964. int len = (int)strlen(stage);
  1965. if (stagelen < len) stagelen = len;
  1966. }
  1967. }
  1968. // Generate a list of stages
  1969. fprintf(fp_hpp, "\n");
  1970. fprintf(fp_hpp, "// Pipeline Stages\n");
  1971. fprintf(fp_hpp, "enum machPipelineStages {\n");
  1972. fprintf(fp_hpp, " stage_%-*s = 0,\n", stagelen, "undefined");
  1973. if( _pipeline ) {
  1974. const char *stage;
  1975. for ( _pipeline->_stages.reset(); (stage = _pipeline->_stages.iter()) != NULL; )
  1976. fprintf(fp_hpp, " stage_%-*s = %d,\n", stagelen, stage, ++stagenum);
  1977. }
  1978. fprintf(fp_hpp, " stage_%-*s = %d\n", stagelen, "count", stagenum);
  1979. fprintf(fp_hpp, "};\n");
  1980. fprintf(fp_hpp, "\n");
  1981. fprintf(fp_hpp, "// Pipeline Resources\n");
  1982. fprintf(fp_hpp, "enum machPipelineResources {\n");
  1983. int rescount = 0;
  1984. if( _pipeline ) {
  1985. const char *resource;
  1986. int reslen = 0;
  1987. // Generate a list of resources, and masks
  1988. for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {
  1989. int len = (int)strlen(resource);
  1990. if (reslen < len)
  1991. reslen = len;
  1992. }
  1993. for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {
  1994. const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource();
  1995. int mask = resform->mask();
  1996. if ((mask & (mask-1)) == 0)
  1997. fprintf(fp_hpp, " resource_%-*s = %d,\n", reslen, resource, rescount++);
  1998. }
  1999. fprintf(fp_hpp, "\n");
  2000. for ( _pipeline->_reslist.reset(); (resource = _pipeline->_reslist.iter()) != NULL; ) {
  2001. const ResourceForm *resform = _pipeline->_resdict[resource]->is_resource();
  2002. fprintf(fp_hpp, " res_mask_%-*s = 0x%08x,\n", reslen, resource, resform->mask());
  2003. }
  2004. fprintf(fp_hpp, "\n");
  2005. }
  2006. fprintf(fp_hpp, " resource_count = %d\n", rescount);
  2007. fprintf(fp_hpp, "};\n");
  2008. }