PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/javac_compiler/HotspotSource/JavaHotSpotSrc/src/vm/adlc/output_h.cpp

http://jvmnotebook.googlecode.com/
C++ | 1450 lines | 1105 code | 110 blank | 235 comment | 321 complexity | 4f1381224612b83af400c247fe9ba814 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0, CPL-1.0, AGPL-1.0, JSON, LGPL-2.1, GPL-2.0, BSD-3-Clause, BSD-3-Clause-No-Nuclear-License-2014, Unlicense, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  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…

Large files files are truncated, but you can click here to view the full file