1 /* src/vm/jit/codegen-common.cpp - architecture independent code generator stuff
3 Copyright (C) 1996-2005, 2006, 2007, 2008, 2009
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 Copyright (C) 2009 Theobroma Systems Ltd.
7 This file is part of CACAO.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 All functions assume the following code area / data area layout:
28 | code area | code area grows to higher addresses
30 +-----------+ <-- start of procedure
32 | data area | data area grows to lower addresses
36 The functions first write into a temporary code/data area allocated by
37 "codegen_init". "codegen_finish" copies the code and data area into permanent
38 memory. All functions writing values into the data area return the offset
39 relative the begin of the code area (start of procedure).
55 #include "mm/memory.hpp"
57 #include "toolbox/avl.h"
58 #include "toolbox/list.hpp"
59 #include "toolbox/logging.hpp"
61 #include "native/llni.h"
62 #include "native/localref.hpp"
63 #include "native/native.hpp"
65 #include "threads/thread.hpp"
67 #include "vm/jit/builtin.hpp"
68 #include "vm/exceptions.hpp"
69 #include "vm/method.hpp"
70 #include "vm/options.h"
71 #include "vm/statistics.h"
72 #include "vm/string.hpp"
74 #include "vm/jit/abi.h"
75 #include "vm/jit/asmpart.h"
76 #include "vm/jit/code.hpp"
77 #include "vm/jit/codegen-common.hpp"
79 #if defined(ENABLE_DISASSEMBLER)
80 # include "vm/jit/disass.h"
83 #include "vm/jit/dseg.h"
84 #include "vm/jit/emit-common.hpp"
85 #include "vm/jit/jit.hpp"
86 #include "vm/jit/linenumbertable.hpp"
87 #include "vm/jit/methodheader.h"
88 #include "vm/jit/methodtree.h"
89 #include "vm/jit/patcher-common.hpp"
90 #include "vm/jit/replace.hpp"
91 #include "vm/jit/show.hpp"
92 #include "vm/jit/stacktrace.hpp"
93 #include "vm/jit/trace.hpp"
95 #include "vm/jit/optimizing/profile.h"
97 #if defined(ENABLE_SSA)
98 # include "vm/jit/optimizing/lsra.h"
99 # include "vm/jit/optimizing/ssa.h"
100 #elif defined(ENABLE_LSRA)
101 # include "vm/jit/allocator/lsra.h"
104 #if defined(ENABLE_INTRP)
105 #include "vm/jit/intrp/intrp.h"
108 #if defined(ENABLE_VMLOG)
109 #include <vmlog_cacao.h>
113 /* codegen_init ****************************************************************
117 *******************************************************************************/
119 void codegen_init(void)
124 /* codegen_setup ***************************************************************
126 Allocates and initialises code area, data area and references.
128 *******************************************************************************/
130 void codegen_setup(jitdata *jd)
135 /* get required compiler data */
140 /* initialize members */
142 // Set flags as requested.
143 if (opt_AlwaysEmitLongBranches) {
144 cd->flags = CODEGENDATA_FLAG_LONGBRANCHES;
150 cd->mcodebase = (u1*) DumpMemory::allocate(MCODEINITSIZE);
151 cd->mcodeend = cd->mcodebase + MCODEINITSIZE;
152 cd->mcodesize = MCODEINITSIZE;
154 /* initialize mcode variables */
156 cd->mcodeptr = cd->mcodebase;
157 cd->lastmcodeptr = cd->mcodebase;
159 #if defined(ENABLE_INTRP)
160 /* native dynamic superinstructions variables */
163 cd->ncodebase = (u1*) DumpMemory::allocate(NCODEINITSIZE);
164 cd->ncodesize = NCODEINITSIZE;
166 /* initialize ncode variables */
168 cd->ncodeptr = cd->ncodebase;
170 cd->lastinstwithoutdispatch = ~0; /* no inst without dispatch */
171 cd->superstarts = NULL;
178 cd->jumpreferences = NULL;
180 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP)
181 cd->datareferences = NULL;
184 cd->brancheslabel = new DumpList<branch_label_ref_t*>();
185 cd->linenumbers = new DumpList<Linenumber>();
189 /* codegen_reset ***************************************************************
191 Resets the codegen data structure so we can recompile the method.
193 *******************************************************************************/
195 static void codegen_reset(jitdata *jd)
201 /* get required compiler data */
206 /* reset error flag */
208 cd->flags &= ~CODEGENDATA_FLAG_ERROR;
210 /* reset some members, we reuse the code memory already allocated
211 as this should have almost the correct size */
213 cd->mcodeptr = cd->mcodebase;
214 cd->lastmcodeptr = cd->mcodebase;
219 cd->jumpreferences = NULL;
221 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP)
222 cd->datareferences = NULL;
225 cd->brancheslabel = new DumpList<branch_label_ref_t*>();
226 cd->linenumbers = new DumpList<Linenumber>();
228 /* We need to clear the mpc and the branch references from all
229 basic blocks as they will definitely change. */
231 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
233 bptr->branchrefs = NULL;
236 /* We need to clear all the patcher references from the codeinfo
237 since they all will be regenerated */
239 patcher_list_reset(code);
241 #if defined(ENABLE_REPLACEMENT)
242 code->rplpoints = NULL;
243 code->rplpointcount = 0;
244 code->regalloc = NULL;
245 code->regalloccount = 0;
246 code->globalcount = 0;
251 /* codegen_generate ************************************************************
253 Generates the code for the currently compiled method.
255 *******************************************************************************/
257 bool codegen_generate(jitdata *jd)
261 /* get required compiler data */
265 /* call the machine-dependent code generation function */
267 if (!codegen_emit(jd))
270 /* check for an error */
272 if (CODEGENDATA_HAS_FLAG_ERROR(cd)) {
273 /* check for long-branches flag, if it is set we recompile the
278 log_message_method("Re-generating code: ", jd->m);
281 /* XXX maybe we should tag long-branches-methods for recompilation */
283 if (CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
284 /* we have to reset the codegendata structure first */
288 /* and restart the compiler run */
290 if (!codegen_emit(jd))
294 os::abort("codegen_generate: unknown error occurred during codegen_emit: flags=%x\n", cd->flags);
299 log_message_method("Re-generating code done: ", jd->m);
303 /* reallocate the memory and finish the code generation */
307 /* everything's ok */
313 /* codegen_close ***************************************************************
317 *******************************************************************************/
319 void codegen_close(void)
321 /* TODO: release avl tree on i386 and x86_64 */
325 /* codegen_increase ************************************************************
329 *******************************************************************************/
331 void codegen_increase(codegendata *cd)
335 /* save old mcodebase pointer */
337 oldmcodebase = cd->mcodebase;
339 /* reallocate to new, doubled memory */
341 cd->mcodebase = (u1*) DumpMemory::reallocate(cd->mcodebase,
345 cd->mcodeend = cd->mcodebase + cd->mcodesize;
347 /* set new mcodeptr */
349 cd->mcodeptr = cd->mcodebase + (cd->mcodeptr - oldmcodebase);
351 #if defined(__I386__) || defined(__MIPS__) || defined(__X86_64__) || defined(__M68K__) || defined(ENABLE_INTRP) \
352 || defined(__SPARC_64__)
353 /* adjust the pointer to the last patcher position */
355 if (cd->lastmcodeptr != NULL)
356 cd->lastmcodeptr = cd->mcodebase + (cd->lastmcodeptr - oldmcodebase);
361 /* codegen_ncode_increase ******************************************************
365 *******************************************************************************/
367 #if defined(ENABLE_INTRP)
368 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr)
372 /* save old ncodebase pointer */
374 oldncodebase = cd->ncodebase;
376 /* reallocate to new, doubled memory */
378 cd->ncodebase = DMREALLOC(cd->ncodebase,
384 /* return the new ncodeptr */
386 return (cd->ncodebase + (ncodeptr - oldncodebase));
391 /* codegen_add_branch_ref ******************************************************
393 Prepends an branch to the list.
395 *******************************************************************************/
397 void codegen_add_branch_ref(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 options)
402 STATISTICS(count_branches_unresolved++);
404 /* calculate the mpc of the branch instruction */
406 branchmpc = cd->mcodeptr - cd->mcodebase;
408 br = (branchref*) DumpMemory::allocate(sizeof(branchref));
410 br->branchmpc = branchmpc;
411 br->condition = condition;
413 br->options = options;
414 br->next = target->branchrefs;
416 target->branchrefs = br;
420 /* codegen_resolve_branchrefs **************************************************
422 Resolves and patches the branch references of a given basic block.
424 *******************************************************************************/
426 void codegen_resolve_branchrefs(codegendata *cd, basicblock *bptr)
431 /* Save the mcodeptr because in the branch emitting functions
432 we generate code somewhere inside already generated code,
433 but we're still in the actual code generation phase. */
435 mcodeptr = cd->mcodeptr;
437 /* just to make sure */
439 assert(bptr->mpc >= 0);
441 for (br = bptr->branchrefs; br != NULL; br = br->next) {
442 /* temporary set the mcodeptr */
444 cd->mcodeptr = cd->mcodebase + br->branchmpc;
446 /* emit_bccz and emit_branch emit the correct code, even if we
447 pass condition == BRANCH_UNCONDITIONAL or reg == -1. */
449 emit_bccz(cd, bptr, br->condition, br->reg, br->options);
452 /* restore mcodeptr */
454 cd->mcodeptr = mcodeptr;
458 /* codegen_branch_label_add ****************************************************
460 Append an branch to the label-branch list.
462 *******************************************************************************/
464 void codegen_branch_label_add(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options)
466 // Calculate the current mpc.
467 int32_t mpc = cd->mcodeptr - cd->mcodebase;
469 branch_label_ref_t* br = (branch_label_ref_t*) DumpMemory::allocate(sizeof(branch_label_ref_t));
473 br->condition = condition;
475 br->options = options;
477 // Add the branch to the list.
478 cd->brancheslabel->push_back(br);
482 /* codegen_set_replacement_point_notrap ****************************************
484 Record the position of a non-trappable replacement point.
486 *******************************************************************************/
488 #if defined(ENABLE_REPLACEMENT)
490 void codegen_set_replacement_point_notrap(codegendata *cd, s4 type)
492 void codegen_set_replacement_point_notrap(codegendata *cd)
495 assert(cd->replacementpoint);
496 assert(cd->replacementpoint->type == type);
497 assert(cd->replacementpoint->flags & RPLPOINT_FLAG_NOTRAP);
499 cd->replacementpoint->pc = (u1*) (ptrint) (cd->mcodeptr - cd->mcodebase);
501 cd->replacementpoint++;
503 #endif /* defined(ENABLE_REPLACEMENT) */
506 /* codegen_set_replacement_point ***********************************************
508 Record the position of a trappable replacement point.
510 *******************************************************************************/
512 #if defined(ENABLE_REPLACEMENT)
514 void codegen_set_replacement_point(codegendata *cd, s4 type)
516 void codegen_set_replacement_point(codegendata *cd)
519 assert(cd->replacementpoint);
520 assert(cd->replacementpoint->type == type);
521 assert(!(cd->replacementpoint->flags & RPLPOINT_FLAG_NOTRAP));
523 cd->replacementpoint->pc = (u1*) (ptrint) (cd->mcodeptr - cd->mcodebase);
525 cd->replacementpoint++;
528 /* XXX actually we should use an own REPLACEMENT_NOPS here! */
529 if (opt_TestReplacement)
533 /* XXX assert(cd->lastmcodeptr <= cd->mcodeptr); */
535 cd->lastmcodeptr = cd->mcodeptr + PATCHER_CALL_SIZE;
537 #endif /* defined(ENABLE_REPLACEMENT) */
540 /* codegen_finish **************************************************************
542 Finishes the code generation. A new memory, large enough for both
543 data and code, is allocated and data and code are copied together
544 to their final layout, unresolved jumps are resolved, ...
546 *******************************************************************************/
548 void codegen_finish(jitdata *jd)
551 #if defined(ENABLE_INTRP)
559 /* Get required compiler data. */
561 codeinfo* code = jd->code;
562 codegendata* cd = jd->cd;
563 registerdata* rd = jd->rd;
565 /* prevent compiler warning */
567 #if defined(ENABLE_INTRP)
571 /* calculate the code length */
573 mcodelen = (s4) (cd->mcodeptr - cd->mcodebase);
575 #if defined(ENABLE_STATISTICS)
577 count_code_len += mcodelen;
578 count_data_len += cd->dseglen;
582 alignedmcodelen = MEMORY_ALIGN(mcodelen, MAX_ALIGN);
584 #if defined(ENABLE_INTRP)
586 ncodelen = cd->ncodeptr - cd->ncodebase;
588 ncodelen = 0; /* avoid compiler warning */
592 cd->dseglen = MEMORY_ALIGN(cd->dseglen, MAX_ALIGN);
593 alignedlen = alignedmcodelen + cd->dseglen;
595 #if defined(ENABLE_INTRP)
597 alignedlen += ncodelen;
601 /* allocate new memory */
603 code->mcodelength = mcodelen + cd->dseglen;
604 code->mcode = CNEW(u1, alignedlen);
606 /* set the entrypoint of the method */
608 assert(code->entrypoint == NULL);
609 code->entrypoint = epoint = (code->mcode + cd->dseglen);
611 /* fill the data segment (code->entrypoint must already be set!) */
615 /* copy code to the new location */
617 MCOPY((void *) code->entrypoint, cd->mcodebase, u1, mcodelen);
619 #if defined(ENABLE_INTRP)
620 /* relocate native dynamic superinstruction code (if any) */
623 cd->mcodebase = code->entrypoint;
626 u1 *ncodebase = code->mcode + cd->dseglen + alignedmcodelen;
628 MCOPY((void *) ncodebase, cd->ncodebase, u1, ncodelen);
630 /* flush the instruction and data caches */
632 md_cacheflush(ncodebase, ncodelen);
634 /* set some cd variables for dynamic_super_rerwite */
636 cd->ncodebase = ncodebase;
639 cd->ncodebase = NULL;
642 dynamic_super_rewrite(cd);
646 /* Fill runtime information about generated code. */
648 code->stackframesize = cd->stackframesize;
649 code->synchronizedoffset = rd->memuse * 8;
650 code->savedintcount = INT_SAV_CNT - rd->savintreguse;
651 code->savedfltcount = FLT_SAV_CNT - rd->savfltreguse;
652 #if defined(HAS_ADDRESS_REGISTER_FILE)
653 code->savedadrcount = ADR_SAV_CNT - rd->savadrreguse;
656 /* Create the exception table. */
658 exceptiontable_create(jd);
660 /* Create the linenumber table. */
662 code->linenumbertable = new LinenumberTable(jd);
664 /* jump table resolving */
666 for (jr = cd->jumpreferences; jr != NULL; jr = jr->next)
667 *((functionptr *) ((ptrint) epoint + jr->tablepos)) =
668 (functionptr) ((ptrint) epoint + (ptrint) jr->target->mpc);
670 /* patcher resolving */
674 #if defined(ENABLE_REPLACEMENT)
675 /* replacement point resolving */
680 rp = code->rplpoints;
681 for (i=0; i<code->rplpointcount; ++i, ++rp) {
682 rp->pc = (u1*) ((ptrint) epoint + (ptrint) rp->pc);
685 #endif /* defined(ENABLE_REPLACEMENT) */
687 /* Insert method into methodtree to find the entrypoint. */
689 methodtree_insert(code->entrypoint, code->entrypoint + mcodelen);
691 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP)
692 /* resolve data segment references */
694 dseg_resolve_datareferences(jd);
697 /* flush the instruction and data caches */
699 md_cacheflush(code->mcode, code->mcodelength);
703 /* codegen_start_native_call ***************************************************
705 Prepares the stuff required for a native (JNI) function call:
707 - adds a stackframe info structure to the chain, for stacktraces
708 - prepares the local references table on the stack
710 The layout of the native stub stackframe should look like this:
712 +---------------------------+ <- java SP (of parent Java function)
714 +---------------------------+ <- data SP
716 | stackframe info structure |
718 +---------------------------+
720 | local references table |
722 +---------------------------+
724 | saved registers (if any) |
726 +---------------------------+
728 | arguments (if any) |
730 +---------------------------+ <- current SP (native stub)
732 *******************************************************************************/
734 java_handle_t *codegen_start_native_call(u1 *sp, u1 *pv)
736 stackframeinfo_t *sfi;
747 STATISTICS(count_calls_java_to_native++);
749 // Get information from method header.
750 code = code_get_codeinfo_for_pv(pv);
751 assert(code != NULL);
753 framesize = md_stacktrace_get_framesize(code);
754 assert(framesize >= (int32_t) (sizeof(stackframeinfo_t) + sizeof(localref_table)));
756 // Get the methodinfo.
757 m = code_get_methodinfo_for_pv(pv);
760 /* calculate needed values */
762 #if defined(__ALPHA__) || defined(__ARM__)
763 datasp = sp + framesize - SIZEOF_VOID_P;
764 javasp = sp + framesize;
765 arg_regs = (uint64_t *) sp;
766 arg_stack = (uint64_t *) javasp;
767 #elif defined(__MIPS__)
768 /* MIPS always uses 8 bytes to store the RA */
769 datasp = sp + framesize - 8;
770 javasp = sp + framesize;
771 # if SIZEOF_VOID_P == 8
772 arg_regs = (uint64_t *) sp;
774 arg_regs = (uint64_t *) (sp + 5 * 8);
776 arg_stack = (uint64_t *) javasp;
777 #elif defined(__S390__)
778 datasp = sp + framesize - 8;
779 javasp = sp + framesize;
780 arg_regs = (uint64_t *) (sp + 96);
781 arg_stack = (uint64_t *) javasp;
782 #elif defined(__I386__) || defined(__M68K__) || defined(__X86_64__)
783 datasp = sp + framesize;
784 javasp = sp + framesize + SIZEOF_VOID_P;
785 arg_regs = (uint64_t *) sp;
786 arg_stack = (uint64_t *) javasp;
787 #elif defined(__POWERPC__)
788 datasp = sp + framesize;
789 javasp = sp + framesize;
790 arg_regs = (uint64_t *) (sp + LA_SIZE + 4 * SIZEOF_VOID_P);
791 arg_stack = (uint64_t *) javasp;
792 #elif defined(__POWERPC64__)
793 datasp = sp + framesize;
794 javasp = sp + framesize;
795 arg_regs = (uint64_t *) (sp + PA_SIZE + LA_SIZE + 4 * SIZEOF_VOID_P);
796 arg_stack = (uint64_t *) javasp;
798 /* XXX is was unable to do this port for SPARC64, sorry. (-michi) */
799 /* XXX maybe we need to pass the RA as argument there */
800 os::abort("codegen_start_native_call: unsupported architecture");
803 /* get data structures from stack */
805 sfi = (stackframeinfo_t *) (datasp - sizeof(stackframeinfo_t));
806 lrt = (localref_table *) (datasp - sizeof(stackframeinfo_t) -
807 sizeof(localref_table));
809 #if defined(ENABLE_JNI)
810 /* add current JNI local references table to this thread */
812 localref_table_add(lrt);
816 # if defined(__ALPHA__) || defined(__I386__) || defined(__M68K__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__S390__) || defined(__X86_64__)
817 /* print the call-trace if necesarry */
818 /* BEFORE: filling the local reference table */
820 if (opt_TraceJavaCalls || opt_TraceBuiltinCalls)
821 trace_java_call_enter(m, arg_regs, arg_stack);
825 #if defined(ENABLE_HANDLES)
826 /* place all references into the local reference table */
827 /* BEFORE: creating stackframeinfo */
829 localref_native_enter(m, arg_regs, arg_stack);
832 /* Add a stackframeinfo for this native method. We don't have RA
833 and XPC here. These are determined in
834 stacktrace_stackframeinfo_add. */
836 stacktrace_stackframeinfo_add(sfi, pv, sp, NULL, NULL);
838 /* Return a wrapped classinfo for static methods. */
840 if (m->flags & ACC_STATIC)
841 return (java_handle_t *) LLNI_classinfo_wrap(m->clazz);
847 /* codegen_finish_native_call **************************************************
849 Removes the stuff required for a native (JNI) function call.
850 Additionally it checks for an exceptions and in case, get the
851 exception object and clear the pointer.
853 *******************************************************************************/
855 java_object_t *codegen_finish_native_call(u1 *sp, u1 *pv)
857 stackframeinfo_t *sfi;
867 // Get information from method header.
868 code = code_get_codeinfo_for_pv(pv);
869 assert(code != NULL);
871 framesize = md_stacktrace_get_framesize(code);
873 // Get the methodinfo.
877 /* calculate needed values */
879 #if defined(__ALPHA__) || defined(__ARM__)
880 datasp = sp + framesize - SIZEOF_VOID_P;
881 ret_regs = (uint64_t *) sp;
882 #elif defined(__MIPS__)
883 /* MIPS always uses 8 bytes to store the RA */
884 datasp = sp + framesize - 8;
885 # if SIZEOF_VOID_P == 8
886 ret_regs = (uint64_t *) sp;
888 ret_regs = (uint64_t *) (sp + 1 * 8);
890 #elif defined(__S390__)
891 datasp = sp + framesize - 8;
892 ret_regs = (uint64_t *) (sp + 96);
893 #elif defined(__I386__)
894 datasp = sp + framesize;
895 ret_regs = (uint64_t *) (sp + 2 * SIZEOF_VOID_P);
896 #elif defined(__M68K__)
897 datasp = sp + framesize;
898 ret_regs = (uint64_t *) (sp + 2 * 8);
899 #elif defined(__X86_64__)
900 datasp = sp + framesize;
901 ret_regs = (uint64_t *) sp;
902 #elif defined(__POWERPC__)
903 datasp = sp + framesize;
904 ret_regs = (uint64_t *) (sp + LA_SIZE + 2 * SIZEOF_VOID_P);
905 #elif defined(__POWERPC64__)
906 datasp = sp + framesize;
907 ret_regs = (uint64_t *) (sp + PA_SIZE + LA_SIZE + 2 * SIZEOF_VOID_P);
909 os::abort("codegen_finish_native_call: unsupported architecture");
912 /* get data structures from stack */
914 sfi = (stackframeinfo_t *) (datasp - sizeof(stackframeinfo_t));
916 /* Remove current stackframeinfo from chain. */
918 stacktrace_stackframeinfo_remove(sfi);
920 #if defined(ENABLE_HANDLES)
921 /* unwrap the return value from the local reference table */
922 /* AFTER: removing the stackframeinfo */
923 /* BEFORE: releasing the local reference table */
925 localref_native_exit(m, ret_regs);
928 /* get and unwrap the exception */
929 /* AFTER: removing the stackframe info */
930 /* BEFORE: releasing the local reference table */
932 e = exceptions_get_and_clear_exception();
935 #if defined(ENABLE_JNI)
936 /* release JNI local references table for this thread */
938 localref_frame_pop_all();
939 localref_table_remove();
943 # if defined(__ALPHA__) || defined(__I386__) || defined(__M68K__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__S390__) || defined(__X86_64__)
944 /* print the call-trace if necesarry */
945 /* AFTER: unwrapping the return value */
947 if (opt_TraceJavaCalls || opt_TraceBuiltinCalls)
948 trace_java_call_exit(m, ret_regs);
956 /* codegen_reg_of_var **********************************************************
958 This function determines a register, to which the result of an
959 operation should go, when it is ultimatively intended to store the
960 result in pseudoregister v. If v is assigned to an actual
961 register, this register will be returned. Otherwise (when v is
962 spilled) this function returns tempregnum. If not already done,
963 regoff and flags are set in the stack location.
965 *******************************************************************************/
967 s4 codegen_reg_of_var(u2 opcode, varinfo *v, s4 tempregnum)
969 if (!(v->flags & INMEMORY))
976 /* codegen_reg_of_dst **********************************************************
978 This function determines a register, to which the result of an
979 operation should go, when it is ultimatively intended to store the
980 result in iptr->dst.var. If dst.var is assigned to an actual
981 register, this register will be returned. Otherwise (when it is
982 spilled) this function returns tempregnum. If not already done,
983 regoff and flags are set in the stack location.
985 *******************************************************************************/
987 s4 codegen_reg_of_dst(jitdata *jd, instruction *iptr, s4 tempregnum)
989 return codegen_reg_of_var(iptr->opc, VAROP(iptr->dst), tempregnum);
994 * Generates machine code.
996 bool codegen_emit(jitdata *jd)
999 builtintable_entry* bte;
1001 int32_t s1, s2, /*s3,*/ d;
1006 // Get required compiler data.
1007 //methodinfo* m = jd->m;
1008 codeinfo* code = jd->code;
1009 codegendata* cd = jd->cd;
1010 registerdata* rd = jd->rd;
1011 #if defined(ENABLE_SSA)
1012 lsradata* ls = jd->ls;
1013 bool last_cmd_was_goto = false;
1016 // Space to save used callee saved registers.
1017 int32_t savedregs_num = 0;
1018 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
1019 savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);
1020 #ifdef HAS_ADDRESS_REGISTER_FILE
1021 savedregs_num += (ADR_SAV_CNT - rd->savadrreguse);
1024 // Calculate size of stackframe.
1025 cd->stackframesize = rd->memuse + savedregs_num;
1027 // Space to save the return address.
1028 #if STACKFRAME_RA_TOP_OF_FRAME
1029 # if STACKFRAME_LEAFMETHODS_RA_REGISTER
1030 if (!code_is_leafmethod(code))
1032 cd->stackframesize += 1;
1035 // Space to save argument of monitor_enter.
1036 #if defined(ENABLE_THREADS)
1037 if (checksync && code_is_synchronized(code))
1038 # if STACKFRAME_SYNC_NEEDS_TWO_SLOTS
1039 /* On some architectures the stack position for the argument can
1040 not be shared with place to save the return register values to
1041 survive monitor_exit since both values reside in the same register. */
1042 cd->stackframesize += 2;
1044 cd->stackframesize += 1;
1048 // Keep stack of non-leaf functions 16-byte aligned for calls into
1050 if (!code_is_leafmethod(code) || JITDATA_HAS_FLAG_VERBOSECALL(jd))
1051 #if STACKFRMAE_RA_BETWEEN_FRAMES
1052 ALIGN_ODD(cd->stackframesize);
1054 ALIGN_EVEN(cd->stackframesize);
1057 #if defined(SPECIALMEMUSE)
1058 // On architectures having a linkage area, we can get rid of the whole
1059 // stackframe in leaf functions without saved registers.
1060 if (code_is_leafmethod(code) && (cd->stackframesize == LA_SIZE_IN_POINTERS))
1061 cd->stackframesize = 0;
1065 * SECTION 1: Method header generation.
1068 // The method header was reduced to the bare minimum of one pointer
1069 // to the codeinfo structure, which in turn contains all runtime
1070 // information. However this section together with the methodheader.h
1071 // file will be kept alive for historical reasons. It might come in
1072 // handy at some point.
1074 (void) dseg_add_unique_address(cd, code); ///< CodeinfoPointer
1076 // XXX, REMOVEME: We still need it for exception handling in assembler.
1077 // XXX ARM, M68K: (void) dseg_add_unique_s4(cd, cd->stackframesize);
1078 #if defined(__I386__)
1079 int align_off = (cd->stackframesize != 0) ? 4 : 0;
1080 (void) dseg_add_unique_s4(cd, cd->stackframesize * 8 + align_off); /* FrameSize */
1082 (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize */
1084 // XXX M68K: We use the IntSave as a split field for the adr now
1085 // (void) dseg_add_unique_s4(cd, (ADR_SAV_CNT - rd->savadrreguse) << 16 | (INT_SAV_CNT - rd->savintreguse)); /* IntSave */
1086 (void) dseg_add_unique_s4(cd, code_is_leafmethod(code) ? 1 : 0);
1087 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
1088 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
1091 * SECTION 2: Method prolog generation.
1094 #if defined(ENABLE_PROFILING)
1095 // Generate method profiling code.
1096 if (JITDATA_HAS_FLAG_INSTRUMENT(jd)) {
1098 // Count method frequency.
1099 emit_profile_method(cd, code);
1101 # if defined(__X86_64__)
1102 // Start CPU cycle counting.
1103 emit_profile_cycle_start();
1108 // Emit code for the method prolog.
1109 codegen_emit_prolog(jd);
1111 #if defined(ENABLE_THREADS)
1112 // Emit code to call monitorenter function.
1113 if (checksync && code_is_synchronized(code))
1114 emit_monitor_enter(jd, rd->memuse * 8);
1117 #if !defined(NDEBUG)
1118 // Call trace function.
1119 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
1120 emit_verbosecall_enter(jd);
1123 #if defined(ENABLE_SSA)
1124 // With SSA the header is basicblock 0, insert phi moves if necessary.
1126 codegen_emit_phi_moves(jd, ls->basicblocks[0]);
1129 // Create replacement points.
1130 REPLACEMENT_POINTS_INIT(cd, jd);
1133 * SECTION 3: ICMD code generation.
1136 // Walk through all basic blocks.
1137 for (basicblock* bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
1139 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
1141 // Is this basic block reached?
1142 if (bptr->flags < BBREACHED)
1145 // Branch resolving.
1146 codegen_resolve_branchrefs(cd, bptr);
1148 // Handle replacement points.
1149 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
1151 #if defined(ENABLE_REPLACEMENT) && defined(__I386__)
1152 // Generate countdown trap code.
1153 methodinfo* m = jd->m;
1154 if (bptr->bitflags & BBFLAG_REPLACEMENT) {
1155 if (cd->replacementpoint[-1].flags & RPLPOINT_FLAG_COUNTDOWN) {
1157 emit_trap_countdown(cd, &(m->hitcountdown));
1162 #if defined(ENABLE_PROFILING)
1163 // Generate basicblock profiling code.
1164 if (JITDATA_HAS_FLAG_INSTRUMENT(jd)) {
1166 // Count basicblock frequency.
1167 emit_profile_basicblock(cd, code, bptr);
1169 # if defined(__X86_64__)
1170 // If this is an exception handler, start profiling again.
1171 if (bptr->type == BBTYPE_EXH)
1172 emit_profile_cycle_start();
1177 // Copy interface registers to their destination.
1178 int32_t indepth = bptr->indepth;
1179 // XXX Check if this is true for all archs.
1180 MCODECHECK(64+indepth); // All
1181 MCODECHECK(128+indepth); // PPC64
1182 MCODECHECK(512); // I386, X86_64, S390
1183 #if defined(ENABLE_SSA)
1184 // XXX Check if this is correct and add a propper comment!
1186 last_cmd_was_goto = false;
1188 #elif defined(ENABLE_LSRA)
1190 while (indepth > 0) {
1192 var = VAR(bptr->invars[indepth]);
1193 if ((indepth == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
1194 if (!IS_INMEMORY(src->flags))
1198 // XXX M68K: Actually this is M_ADRMOVE(REG_ATMP1_XPTR, d);
1199 // XXX Sparc64: Here we use REG_ITMP2_XPTR, fix this!
1200 // XXX S390: Here we use REG_ITMP3_XPTR, fix this!
1201 emit_imove(cd, REG_ITMP1_XPTR, d);
1202 emit_store(jd, NULL, var, d);
1207 while (indepth > 0) {
1209 var = VAR(bptr->invars[indepth]);
1210 if ((indepth == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
1211 d = codegen_reg_of_var(0, var, REG_ITMP1_XPTR);
1212 // XXX M68K: Actually this is M_ADRMOVE(REG_ATMP1_XPTR, d);
1213 // XXX Sparc64: Here we use REG_ITMP2_XPTR, fix this!
1214 // XXX S390: Here we use REG_ITMP3_XPTR, fix this!
1215 emit_imove(cd, REG_ITMP1_XPTR, d);
1216 emit_store(jd, NULL, var, d);
1219 assert((var->flags & INOUT));
1222 #if defined(ENABLE_SSA) || defined(ENABLE_LSRA)
1226 // Walk through all instructions.
1227 int32_t len = bptr->icount;
1228 uint16_t currentline = 0;
1229 for (instruction* iptr = bptr->iinstr; len > 0; len--, iptr++) {
1232 if (iptr->line != currentline) {
1233 linenumbertable_list_entry_add(cd, iptr->line);
1234 currentline = iptr->line;
1237 // An instruction usually needs < 64 words.
1238 // XXX Check if this is true for all archs.
1239 MCODECHECK(64); // All
1240 MCODECHECK(128); // PPC64
1241 MCODECHECK(1024); // I386, X86_64, M68K, S390 /* 1kB should be enough */
1244 switch (iptr->opc) {
1246 case ICMD_NOP: /* ... ==> ... */
1247 case ICMD_POP: /* ..., value ==> ... */
1248 case ICMD_POP2: /* ..., value, value ==> ... */
1251 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
1253 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1254 emit_nullpointer_check(cd, iptr, s1);
1257 #if defined(ENABLE_SSA)
1258 case ICMD_GETEXCEPTION:
1260 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1261 emit_imove(cd, REG_ITMP1, d);
1262 emit_store_dst(jd, iptr, d);
1266 /* inline operations **********************************************/
1268 case ICMD_INLINE_START:
1270 REPLACEMENT_POINT_INLINE_START(cd, iptr);
1273 case ICMD_INLINE_BODY:
1275 REPLACEMENT_POINT_INLINE_BODY(cd, iptr);
1276 linenumbertable_list_entry_add_inline_start(cd, iptr);
1277 linenumbertable_list_entry_add(cd, iptr->line);
1280 case ICMD_INLINE_END:
1282 linenumbertable_list_entry_add_inline_end(cd, iptr);
1283 linenumbertable_list_entry_add(cd, iptr->line);
1287 /* constant operations ********************************************/
1289 case ICMD_ICONST: /* ... ==> ..., constant */
1291 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1292 ICONST(d, iptr->sx.val.i);
1293 emit_store_dst(jd, iptr, d);
1296 case ICMD_LCONST: /* ... ==> ..., constant */
1298 d = codegen_reg_of_dst(jd, iptr, REG_LTMP12);
1299 LCONST(d, iptr->sx.val.l);
1300 emit_store_dst(jd, iptr, d);
1304 /* load/store/copy/move operations ********************************/
1308 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
1309 case ICMD_LLOAD: /* s1 = local variable */
1313 case ICMD_ISTORE: /* ..., value ==> ... */
1318 emit_copy(jd, iptr);
1323 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
1324 emit_copy(jd, iptr);
1328 /* integer operations *********************************************/
1330 case ICMD_FCONST: /* ... ==> ..., constant */
1331 case ICMD_DCONST: /* ... ==> ..., constant */
1332 case ICMD_ACONST: /* ... ==> ..., constant */
1333 case ICMD_INEG: /* ..., value ==> ..., - value */
1334 case ICMD_LNEG: /* ..., value ==> ..., - value */
1335 case ICMD_I2L: /* ..., value ==> ..., value */
1336 case ICMD_L2I: /* ..., value ==> ..., value */
1337 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
1338 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
1339 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
1340 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1342 case ICMD_IADDCONST: /* ..., value ==> ..., value + constant */
1343 /* sx.val.i = constant */
1344 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1345 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
1346 /* sx.val.l = constant */
1347 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1348 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
1349 /* sx.val.i = constant */
1350 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1351 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
1352 /* sx.val.l = constant */
1353 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1354 case ICMD_IMULCONST: /* ..., value ==> ..., value * constant */
1355 /* sx.val.i = constant */
1356 case ICMD_LMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1357 case ICMD_LMULCONST: /* ..., value ==> ..., value * constant */
1358 /* sx.val.l = constant */
1359 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1360 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1361 case ICMD_IDIVPOW2: /* ..., value ==> ..., value >> constant */
1362 /* sx.val.i = constant */
1363 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
1364 /* sx.val.i = constant */
1365 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1366 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1367 case ICMD_LDIVPOW2: /* ..., value ==> ..., value >> constant */
1368 /* sx.val.i = constant */
1369 case ICMD_LREMPOW2: /* ..., value ==> ..., value % constant */
1370 /* sx.val.l = constant */
1371 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
1372 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
1373 /* sx.val.i = constant */
1374 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
1375 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
1376 /* sx.val.i = constant */
1377 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
1378 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
1379 /* sx.val.i = constant */
1380 case ICMD_LSHL: /* ..., val1, val2 ==> ..., val1 << val2 */
1381 case ICMD_LSHLCONST: /* ..., value ==> ..., value << constant */
1382 /* sx.val.i = constant */
1383 case ICMD_LSHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
1384 case ICMD_LSHRCONST: /* ..., value ==> ..., value >> constant */
1385 /* sx.val.i = constant */
1386 case ICMD_LUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
1387 case ICMD_LUSHRCONST: /* ..., value ==> ..., value >>> constant */
1388 /* sx.val.l = constant */
1389 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
1390 case ICMD_IANDCONST: /* ..., value ==> ..., value & constant */
1391 /* sx.val.i = constant */
1392 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
1393 case ICMD_LANDCONST: /* ..., value ==> ..., value & constant */
1394 /* sx.val.l = constant */
1395 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
1396 case ICMD_IORCONST: /* ..., value ==> ..., value | constant */
1397 /* sx.val.i = constant */
1398 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
1399 case ICMD_LORCONST: /* ..., value ==> ..., value | constant */
1400 /* sx.val.l = constant */
1401 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
1402 case ICMD_IXORCONST: /* ..., value ==> ..., value ^ constant */
1403 /* sx.val.i = constant */
1404 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
1405 case ICMD_LXORCONST: /* ..., value ==> ..., value ^ constant */
1406 /* sx.val.l = constant */
1408 // Generate architecture specific instructions.
1409 codegen_emit_instruction(jd, iptr);
1413 /* floating operations ********************************************/
1415 #if !defined(ENABLE_SOFTFLOAT)
1416 case ICMD_FNEG: /* ..., value ==> ..., - value */
1418 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1420 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1422 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1424 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1426 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1428 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1429 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1430 case ICMD_L2F: /* ..., value ==> ..., (float) value */
1431 case ICMD_L2D: /* ..., value ==> ..., (double) value */
1432 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1434 case ICMD_F2L: /* ..., value ==> ..., (long) value */
1436 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1437 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1438 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1439 case ICMD_DCMPL: /* == => 0, < => 1, > => -1 */
1440 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1441 case ICMD_DCMPG: /* == => 0, < => 1, > => -1 */
1443 // Generate architecture specific instructions.
1444 codegen_emit_instruction(jd, iptr);
1446 #endif /* !defined(ENABLE_SOFTFLOAT) */
1449 /* memory operations **********************************************/
1451 case ICMD_ARRAYLENGTH:/* ..., arrayref ==> ..., length */
1453 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1454 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1455 /* implicit null-pointer check */
1456 // XXX PPC64: Here we had an explicit null-pointer check
1457 // which I think was obsolete, please confirm. Otherwise:
1458 // emit_nullpointer_check(cd, iptr, s1);
1459 M_ILD(d, s1, OFFSET(java_array_t, size));
1460 emit_store_dst(jd, iptr, d);
1463 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1464 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1465 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1466 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1467 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1468 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1469 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1470 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1471 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1472 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1473 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1474 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1475 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1476 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1477 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1478 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1479 case ICMD_BASTORECONST: /* ..., arrayref, index ==> ... */
1480 case ICMD_CASTORECONST: /* ..., arrayref, index ==> ... */
1481 case ICMD_SASTORECONST: /* ..., arrayref, index ==> ... */
1482 case ICMD_IASTORECONST: /* ..., arrayref, index ==> ... */
1483 case ICMD_LASTORECONST: /* ..., arrayref, index ==> ... */
1484 case ICMD_FASTORECONST: /* ..., arrayref, index ==> ... */
1485 case ICMD_DASTORECONST: /* ..., arrayref, index ==> ... */
1486 case ICMD_AASTORECONST: /* ..., arrayref, index ==> ... */
1487 case ICMD_GETFIELD: /* ... ==> ..., value */
1488 case ICMD_PUTFIELD: /* ..., value ==> ... */
1489 case ICMD_PUTFIELDCONST: /* ..., objectref ==> ... */
1490 /* val = value (in current instruction) */
1491 case ICMD_PUTSTATICCONST: /* ... ==> ... */
1492 /* val = value (in current instruction) */
1494 // Generate architecture specific instructions.
1495 codegen_emit_instruction(jd, iptr);
1498 case ICMD_GETSTATIC: /* ... ==> ..., value */
1500 #if defined(__I386__)
1501 // Generate architecture specific instructions.
1502 codegen_emit_instruction(jd, iptr);
1504 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1505 unresolved_field* uf = iptr->sx.s23.s3.uf;
1506 fieldtype = uf->fieldref->parseddesc.fd->type;
1507 disp = dseg_add_unique_address(cd, 0);
1509 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1512 fieldinfo* fi = iptr->sx.s23.s3.fmiref->p.field;
1513 fieldtype = fi->type;
1514 disp = dseg_add_address(cd, fi->value);
1516 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
1518 patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz, 0);
1519 PROFILE_CYCLE_START;
1523 // XXX X86_64: Here We had this:
1524 /* This approach is much faster than moving the field
1525 address inline into a register. */
1527 // XXX ARM: M_DSEG_LOAD(REG_ITMP3, disp);
1528 M_ALD_DSEG(REG_ITMP1, disp);
1530 switch (fieldtype) {
1532 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1533 M_ALD(d, REG_ITMP1, 0);
1536 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1537 M_ILD(d, REG_ITMP1, 0);
1540 d = codegen_reg_of_dst(jd, iptr, REG_LTMP23);
1541 M_LLD(d, REG_ITMP1, 0);
1544 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1545 M_FLD(d, REG_ITMP1, 0);
1548 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1549 M_DLD(d, REG_ITMP1, 0);
1552 emit_store_dst(jd, iptr, d);
1556 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1558 #if defined(__I386__)
1559 // Generate architecture specific instructions.
1560 codegen_emit_instruction(jd, iptr);
1562 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1563 unresolved_field* uf = iptr->sx.s23.s3.uf;
1564 fieldtype = uf->fieldref->parseddesc.fd->type;
1565 disp = dseg_add_unique_address(cd, 0);
1567 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1570 fieldinfo* fi = iptr->sx.s23.s3.fmiref->p.field;
1571 fieldtype = fi->type;
1572 disp = dseg_add_address(cd, fi->value);
1574 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
1576 patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz, 0);
1577 PROFILE_CYCLE_START;
1581 // XXX X86_64: Here We had this:
1582 /* This approach is much faster than moving the field
1583 address inline into a register. */
1585 // XXX ARM: M_DSEG_LOAD(REG_ITMP3, disp);
1586 M_ALD_DSEG(REG_ITMP1, disp);
1588 switch (fieldtype) {
1590 s1 = emit_load_s1(jd, iptr, REG_ITMP2);
1591 M_AST(s1, REG_ITMP1, 0);
1594 s1 = emit_load_s1(jd, iptr, REG_ITMP2);
1595 M_IST(s1, REG_ITMP1, 0);
1598 s1 = emit_load_s1(jd, iptr, REG_LTMP23);
1599 M_LST(s1, REG_ITMP1, 0);
1602 s1 = emit_load_s1(jd, iptr, REG_FTMP2);
1603 M_FST(s1, REG_ITMP1, 0);
1606 s1 = emit_load_s1(jd, iptr, REG_FTMP2);
1607 M_DST(s1, REG_ITMP1, 0);
1613 /* branch operations **********************************************/
1615 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1617 // We might leave this method, stop profiling.
1620 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1621 // XXX M68K: Actually this is M_ADRMOVE(s1, REG_ATMP1_XPTR);
1622 // XXX Sparc64: We use REG_ITMP2_XPTR here, fix me!
1623 emit_imove(cd, s1, REG_ITMP1_XPTR);
1625 #ifdef ENABLE_VERIFIER
1626 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1627 unresolved_class *uc = iptr->sx.s23.s2.uc;
1628 patcher_add_patch_ref(jd, PATCHER_resolve_class, uc, 0);
1630 #endif /* ENABLE_VERIFIER */
1632 // Generate architecture specific instructions.
1633 codegen_emit_instruction(jd, iptr);
1637 case ICMD_GOTO: /* ... ==> ... */
1638 case ICMD_RET: /* ... ==> ... */
1640 #if defined(ENABLE_SSA)
1641 // In case of a goto, phimoves have to be inserted
1644 last_cmd_was_goto = true;
1645 codegen_emit_phi_moves(jd, bptr);
1648 emit_br(cd, iptr->dst.block);
1652 case ICMD_JSR: /* ... ==> ... */
1654 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1658 case ICMD_IFNULL: /* ..., value ==> ... */
1659 case ICMD_IFNONNULL:
1661 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1662 #if SUPPORT_BRANCH_CONDITIONAL_ONE_INTEGER_REGISTER
1663 emit_bccz(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, s1, BRANCH_OPT_NONE);
1664 #elif SUPPORT_BRANCH_CONDITIONAL_CONDITION_REGISTER
1666 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1668 # error Unable to generate code for this configuration!
1672 case ICMD_IFEQ: /* ..., value ==> ... */
1679 // XXX Sparc64: int compares must not branch on the
1680 // register directly. Reason is, that register content is
1681 // not 32-bit clean. Fix this!
1683 #if SUPPORT_BRANCH_CONDITIONAL_ONE_INTEGER_REGISTER
1684 if (iptr->sx.val.i == 0) {
1685 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1686 emit_bccz(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, s1, BRANCH_OPT_NONE);
1688 // Generate architecture specific instructions.
1689 codegen_emit_instruction(jd, iptr);
1691 #elif SUPPORT_BRANCH_CONDITIONAL_CONDITION_REGISTER
1692 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1693 emit_icmp_imm(cd, s1, iptr->sx.val.i);
1694 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1696 # error Unable to generate code for this configuration!
1700 case ICMD_IF_LEQ: /* ..., value ==> ... */
1707 // Generate architecture specific instructions.
1708 codegen_emit_instruction(jd, iptr);
1711 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1712 case ICMD_IF_ACMPNE: /* op1 = target JavaVM pc */
1714 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1715 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1716 #if SUPPORT_BRANCH_CONDITIONAL_TWO_INTEGER_REGISTERS
1717 switch (iptr->opc) {
1718 case ICMD_IF_ACMPEQ:
1719 emit_beq(cd, iptr->dst.block, s1, s2);
1721 case ICMD_IF_ACMPNE:
1722 emit_bne(cd, iptr->dst.block, s1, s2);
1725 #elif SUPPORT_BRANCH_CONDITIONAL_CONDITION_REGISTER
1727 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1728 #elif SUPPORT_BRANCH_CONDITIONAL_ONE_INTEGER_REGISTER
1729 M_CMPEQ(s1, s2, REG_ITMP1);
1730 switch (iptr->opc) {
1731 case ICMD_IF_ACMPEQ:
1732 emit_bnez(cd, iptr->dst.block, REG_ITMP1);
1734 case ICMD_IF_ACMPNE:
1735 emit_beqz(cd, iptr->dst.block, REG_ITMP1);
1739 # error Unable to generate code for this configuration!
1743 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1744 case ICMD_IF_ICMPNE: /* op1 = target JavaVM pc */
1746 #if SUPPORT_BRANCH_CONDITIONAL_TWO_INTEGER_REGISTERS
1747 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1748 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1749 switch (iptr->opc) {
1750 case ICMD_IF_ICMPEQ:
1751 emit_beq(cd, iptr->dst.block, s1, s2);
1753 case ICMD_IF_ICMPNE:
1754 emit_bne(cd, iptr->dst.block, s1, s2);
1762 case ICMD_IF_ICMPLT: /* ..., value, value ==> ... */
1763 case ICMD_IF_ICMPGT: /* op1 = target JavaVM pc */
1764 case ICMD_IF_ICMPLE:
1765 case ICMD_IF_ICMPGE:
1767 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1768 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1769 #if SUPPORT_BRANCH_CONDITIONAL_CONDITION_REGISTER
1770 # if defined(__I386__) || defined(__M68K__) || defined(__X86_64__)
1771 // XXX Fix this soon!!!
1776 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1777 #elif SUPPORT_BRANCH_CONDITIONAL_ONE_INTEGER_REGISTER
1778 // Generate architecture specific instructions.
1779 codegen_emit_instruction(jd, iptr);
1781 # error Unable to generate code for this configuration!
1785 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1786 case ICMD_IF_LCMPNE: /* op1 = target JavaVM pc */
1787 case ICMD_IF_LCMPLT:
1788 case ICMD_IF_LCMPGT:
1789 case ICMD_IF_LCMPLE:
1790 case ICMD_IF_LCMPGE:
1792 // Generate architecture specific instructions.
1793 codegen_emit_instruction(jd, iptr);
1796 case ICMD_RETURN: /* ... ==> ... */
1798 REPLACEMENT_POINT_RETURN(cd, iptr);
1799 goto nowperformreturn;
1801 case ICMD_ARETURN: /* ..., retvalue ==> ... */
1803 REPLACEMENT_POINT_RETURN(cd, iptr);
1804 s1 = emit_load_s1(jd, iptr, REG_RESULT);
1805 // XXX M68K: This should actually be M_ADR2INTMOVE(s1, REG_RESULT);
1806 // XXX Sparc64: Here this should be REG_RESULT_CALLEE!
1807 emit_imove(cd, s1, REG_RESULT);
1809 #ifdef ENABLE_VERIFIER
1810 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1812 unresolved_class *uc = iptr->sx.s23.s2.uc;
1813 patcher_add_patch_ref(jd, PATCHER_resolve_class, uc, 0);
1814 PROFILE_CYCLE_START;
1816 #endif /* ENABLE_VERIFIER */
1817 goto nowperformreturn;
1819 case ICMD_IRETURN: /* ..., retvalue ==> ... */
1821 REPLACEMENT_POINT_RETURN(cd, iptr);
1822 s1 = emit_load_s1(jd, iptr, REG_RESULT);
1823 // XXX Sparc64: Here this should be REG_RESULT_CALLEE!
1824 emit_imove(cd, s1, REG_RESULT);
1825 goto nowperformreturn;
1827 case ICMD_LRETURN: /* ..., retvalue ==> ... */
1829 REPLACEMENT_POINT_RETURN(cd, iptr);
1830 s1 = emit_load_s1(jd, iptr, REG_LRESULT);
1831 // XXX Sparc64: Here this should be REG_RESULT_CALLEE!
1832 emit_lmove(cd, s1, REG_LRESULT);
1833 goto nowperformreturn;
1835 case ICMD_FRETURN: /* ..., retvalue ==> ... */
1837 REPLACEMENT_POINT_RETURN(cd, iptr);
1838 s1 = emit_load_s1(jd, iptr, REG_FRESULT);
1839 // XXX ARM: Here this was M_CAST_F2I(s1, REG_RESULT);
1840 emit_fmove(cd, s1, REG_FRESULT);
1841 goto nowperformreturn;
1843 case ICMD_DRETURN: /* ..., retvalue ==> ... */
1845 REPLACEMENT_POINT_RETURN(cd, iptr);
1846 s1 = emit_load_s1(jd, iptr, REG_FRESULT);
1847 // XXX ARM: Here this was M_CAST_D2L(s1, REG_RESULT_PACKED);
1848 emit_dmove(cd, s1, REG_FRESULT);
1849 goto nowperformreturn;
1852 #if !defined(NDEBUG)
1853 // Call trace function.
1854 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
1855 emit_verbosecall_exit(jd);
1858 #if defined(ENABLE_THREADS)
1859 // Emit code to call monitorexit function.
1860 if (checksync && code_is_synchronized(code)) {
1861 emit_monitor_exit(jd, rd->memuse * 8);
1865 // Generate method profiling code.
1868 // Emit code for the method epilog.
1869 codegen_emit_epilog(jd);
1873 case ICMD_BUILTIN: /* ..., [arg1, [arg2 ...]] ==> ... */
1875 REPLACEMENT_POINT_FORGC_BUILTIN(cd, iptr);
1877 bte = iptr->sx.s23.s3.bte;
1880 #if defined(ENABLE_ESCAPE_REASON) && defined(__I386__)
1881 if (bte->fp == BUILTIN_escape_reason_new) {
1882 void set_escape_reasons(void *);
1883 M_ASUB_IMM(8, REG_SP);
1884 M_MOV_IMM(iptr->escape_reasons, REG_ITMP1);
1885 M_AST(EDX, REG_SP, 4);
1886 M_AST(REG_ITMP1, REG_SP, 0);
1887 M_MOV_IMM(set_escape_reasons, REG_ITMP1);
1889 M_ALD(EDX, REG_SP, 4);
1890 M_AADD_IMM(8, REG_SP);
1896 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
1897 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
1898 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
1899 case ICMD_INVOKEINTERFACE:
1901 REPLACEMENT_POINT_INVOKE(cd, iptr);
1903 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1904 unresolved_method* um = iptr->sx.s23.s3.um;
1905 md = um->methodref->parseddesc.md;
1908 methodinfo* lm = iptr->sx.s23.s3.fmiref->p.method;
1909 md = lm->parseddesc;
1915 // XXX Check this again!
1916 MCODECHECK((i << 1) + 64); // PPC
1918 // Copy arguments to registers or stack location.
1919 for (i = i - 1; i >= 0; i--) {
1920 var = VAR(iptr->sx.s23.s2.args[i]);
1921 d = md->params[i].regoff;
1923 // Already pre-allocated?
1924 if (var->flags & PREALLOC)
1927 if (!md->params[i].inmemory) {
1928 assert(ARG_CNT > 0);
1929 s1 = emit_load(jd, iptr, var, d);
1931 switch (var->type) {
1934 assert(INT_ARG_CNT > 0);
1935 emit_imove(cd, s1, d);
1938 #if 0 //XXX For ARM:
1939 if (!md->params[s3].inmemory) {
1940 s1 = emit_load(jd, iptr, var, REG_FTMP1);
1941 if (IS_2_WORD_TYPE(var->type))
1946 #endif //XXX End of ARM!
1949 emit_lmove(cd, s1, d);
1953 emit_fmove(cd, s1, d);
1957 emit_dmove(cd, s1, d);
1962 switch (var->type) {
1964 s1 = emit_load(jd, iptr, var, REG_ITMP1);
1965 // XXX M68K: This should actually be like this:
1966 // s1 = emit_load(jd, iptr, var, REG_ATMP1);
1967 // XXX Sparc64: Here this actually was:
1968 // M_STX(s1, REG_SP, JITSTACK + d);
1969 M_AST(s1, REG_SP, d);
1973 #if SIZEOF_VOID_P == 4
1974 s1 = emit_load(jd, iptr, var, REG_ITMP1);
1975 M_IST(s1, REG_SP, d);
1982 s1 = emit_load(jd, iptr, var, REG_LTMP12);
1983 // XXX Sparc64: Here this actually was:
1984 // M_STX(s1, REG_SP, JITSTACK + d);
1985 M_LST(s1, REG_SP, d);
1989 #if SIZEOF_VOID_P == 4
1990 s1 = emit_load(jd, iptr, var, REG_FTMP1);
1991 M_FST(s1, REG_SP, d);
1998 s1 = emit_load(jd, iptr, var, REG_FTMP1);
1999 // XXX Sparc64: Here this actually was:
2000 // M_DST(s1, REG_SP, JITSTACK + d);
2001 M_DST(s1, REG_SP, d);
2007 // Generate method profiling code.
2010 // Generate architecture specific instructions.
2011 codegen_emit_instruction(jd, iptr);
2013 // Generate method profiling code.
2014 PROFILE_CYCLE_START;
2016 // Store size of call code in replacement point.
2017 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2018 REPLACEMENT_POINT_FORGC_BUILTIN_RETURN(cd, iptr);
2020 // Recompute the procedure vector (PV).
2021 emit_recompute_pv(cd);
2023 // Store return value.
2024 #if defined(ENABLE_SSA)
2025 if ((ls == NULL) /* || (!IS_TEMPVAR_INDEX(iptr->dst.varindex)) */ ||
2026 (ls->lifetime[iptr->dst.varindex].type != UNUSED))
2027 /* a "living" stackslot */
2029 switch (md->returntype.type) {
2032 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2033 // XXX Sparc64: This should actually be REG_RESULT_CALLER, fix this!
2034 emit_imove(cd, REG_RESULT, s1);
2035 emit_store_dst(jd, iptr, s1);
2039 s1 = codegen_reg_of_dst(jd, iptr, REG_LRESULT);
2040 // XXX Sparc64: This should actually be REG_RESULT_CALLER, fix this!
2041 emit_lmove(cd, REG_LRESULT, s1);
2042 emit_store_dst(jd, iptr, s1);
2045 #if 0 //XXX For ARM!!!
2046 #if !defined(ENABLE_SOFTFLOAT)
2048 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2049 if (IS_2_WORD_TYPE(d))
2050 M_CAST_L2D(REG_RESULT_PACKED, s1);
2052 M_CAST_I2F(REG_RESULT, s1);
2054 #endif /* !defined(ENABLE_SOFTFLOAT) */
2055 #endif //XXX End of ARM
2058 s1 = codegen_reg_of_dst(jd, iptr, REG_FRESULT);
2059 emit_fmove(cd, REG_FRESULT, s1);
2060 emit_store_dst(jd, iptr, s1);
2064 s1 = codegen_reg_of_dst(jd, iptr, REG_FRESULT);
2065 emit_dmove(cd, REG_FRESULT, s1);
2066 emit_store_dst(jd, iptr, s1);
2075 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2077 // Generate architecture specific instructions.
2078 codegen_emit_instruction(jd, iptr);
2081 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2083 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2084 i = iptr->sx.s23.s2.lookupcount;
2086 // XXX Again we need to check this
2087 MCODECHECK((i<<2)+8); // Alpha, ARM, i386, MIPS, M68K, Sparc64
2088 MCODECHECK((i<<3)+8); // PPC64
2089 MCODECHECK(8 + ((7 + 6) * i) + 5); // X86_64, S390
2092 for (lookup_target_t* lookup = iptr->dst.lookup; i > 0; ++lookup, --i) {
2093 #if SUPPORT_BRANCH_CONDITIONAL_CONDITION_REGISTER
2094 emit_icmp_imm(cd, s1, lookup->value);
2095 emit_beq(cd, lookup->target.block);
2096 #elif SUPPORT_BRANCH_CONDITIONAL_TWO_INTEGER_REGISTERS
2097 ICONST(REG_ITMP2, lookup->value);
2098 emit_beq(cd, lookup->target.block, s1, REG_ITMP2);
2099 #elif SUPPORT_BRANCH_CONDITIONAL_ONE_INTEGER_REGISTER
2100 emit_icmpeq_imm(cd, s1, lookup->value, REG_ITMP2);
2101 emit_bnez(cd, lookup->target.block, REG_ITMP2);
2103 # error Unable to generate code for this configuration!
2108 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2112 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2113 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2114 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2116 // Generate architecture specific instructions.
2117 codegen_emit_instruction(jd, iptr);
2121 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2127 } // for all instructions
2129 #if defined(ENABLE_SSA)
2130 // By edge splitting, in blocks with phi moves there can only
2131 // be a goto as last command, no other jump/branch command.
2133 if (!last_cmd_was_goto)
2134 codegen_emit_phi_moves(jd, bptr);
2138 #if defined(__I386__) || defined(__M68K__) || defined(__MIPS__) || defined(__S390__) || defined(__SPARC_64__) || defined(__X86_64__)
2140 /* XXX require a lower number? */
2141 MCODECHECK(64); // I386, MIPS, Sparc64
2142 MCODECHECK(512); // S390, X86_64
2144 /* XXX We can remove that when we don't use UD2 anymore on i386
2147 /* At the end of a basic block we may have to append some nops,
2148 because the patcher stub calling code might be longer than the
2149 actual instruction. So codepatching does not change the
2150 following block unintentionally. */
2152 if (cd->mcodeptr < cd->lastmcodeptr) {
2153 while (cd->mcodeptr < cd->lastmcodeptr) {
2159 } // for all basic blocks
2162 emit_patcher_traps(jd);
2169 /* codegen_emit_phi_moves ****************************************************
2171 Emits phi moves at the end of the basicblock.
2173 *******************************************************************************/
2175 #if defined(ENABLE_SSA)
2176 void codegen_emit_phi_moves(jitdata *jd, basicblock *bptr)
2189 /* Moves from phi functions with highest indices have to be */
2190 /* inserted first, since this is the order as is used for */
2191 /* conflict resolution */
2193 for(i = ls->num_phi_moves[bptr->nr] - 1; i >= 0 ; i--) {
2194 lt_d = ls->phi_moves[bptr->nr][i][0];
2195 lt_s = ls->phi_moves[bptr->nr][i][1];
2196 #if defined(SSA_DEBUG_VERBOSE)
2198 printf("BB %3i Move %3i <- %3i ", bptr->nr, lt_d, lt_s);
2200 if (lt_s == UNUSED) {
2201 #if defined(SSA_DEBUG_VERBOSE)
2203 printf(" ... not processed \n");
2208 d = VAR(ls->lifetime[lt_d].v_index);
2209 s = VAR(ls->lifetime[lt_s].v_index);
2212 if (d->type == -1) {
2213 #if defined(SSA_DEBUG_VERBOSE)
2215 printf("...returning - phi lifetimes where joined\n");
2220 if (s->type == -1) {
2221 #if defined(SSA_DEBUG_VERBOSE)
2223 printf("...returning - phi lifetimes where joined\n");
2229 tmp_i.s1.varindex = ls->lifetime[lt_s].v_index;
2230 tmp_i.dst.varindex = ls->lifetime[lt_d].v_index;
2231 emit_copy(jd, &tmp_i);
2233 #if defined(SSA_DEBUG_VERBOSE)
2234 if (compileverbose) {
2235 if (IS_INMEMORY(d->flags) && IS_INMEMORY(s->flags)) {
2237 printf("M%3i <- M%3i",d->vv.regoff,s->vv.regoff);
2239 else if (IS_INMEMORY(s->flags)) {
2241 printf("R%3i <- M%3i",d->vv.regoff,s->vv.regoff);
2243 else if (IS_INMEMORY(d->flags)) {
2245 printf("M%3i <- R%3i",d->vv.regoff,s->vv.regoff);
2249 printf("R%3i <- R%3i",d->vv.regoff,s->vv.regoff);
2253 #endif /* defined(SSA_DEBUG_VERBOSE) */
2256 #endif /* defined(ENABLE_SSA) */
2259 /* REMOVEME When we have exception handling in C. */
2261 void *md_asm_codegen_get_pv_from_pc(void *ra)
2263 return md_codegen_get_pv_from_pc(ra);
2268 * These are local overrides for various environment variables in Emacs.
2269 * Please do not remove this and leave it at the end of the file, where
2270 * Emacs will automagically detect them.
2271 * ---------------------------------------------------------------------
2274 * indent-tabs-mode: t
2278 * vim:noexpandtab:sw=4:ts=4: