50 #define DEBUG_NAME "compiler2/CodeGen"
60 Option<bool> CodeGenPass::print_code(
"PrintCodeSegment",
"compiler2: print code segment",
false,::
cacao::option::xx_root());
61 Option<bool> CodeGenPass::print_data(
"PrintDataSegment",
"compiler2: print data segment",
false,::
cacao::option::xx_root());
75 std::size_t bb_start = 0;
83 std::size_t start = CS.
size();
84 LOG2(
"MInst: " << MI <<
" emitted instruction:" <<
nl);
86 std::size_t end = CS.
size();
87 instruction_positions[MI] = start;
88 instruction_sizes[MI] = end - start;
89 #if defined(ENABLE_STATISTICS)
90 if (MI->
is_move() && start != end) {
99 while(start != end--) {
100 tmp.push_back(CS.
at(end));
102 #if defined(ENABLE_DISASSEMBLER)
103 disassemble(&tmp.front(), &tmp.front() + tmp.size());
110 std::size_t bb_end = CS.
size();
111 bbmap[MBB] = bb_end - bb_start;
117 bbmap[MBB] = CS.
size() - bb_start;
124 BasicBlockMap::const_iterator
i = bbmap.find(MBB);
125 if (i == bbmap.end())
132 #ifdef ENABLE_LOGGING
133 void print_hex(
OStream &
OS,
u1 *start,
u1 *end, uint32_t num_bytes_per_line = 8) {
135 for(
u1 *ptr = start, *
e = end; ptr <
e; ++ptr) {
136 if ( (ptr - start) % num_bytes_per_line == 0) {
137 OS <<
nl <<
"0x" <<
setz(16) << (
u8) ptr <<
": ";
139 OS <<
setz(2) << *ptr <<
' ';
145 template<
class OutputIt>
146 void find_all_replacement_points(MachineInstructionSchedule *MIS,
147 OutputIt outIterator) {
148 MachineBasicBlock *MBB = NULL;
149 for (MachineInstructionSchedule::const_iterator
i = MIS->begin(),
150 e = MIS->end() ;
i !=
e ; ++
i ) {
152 for (MachineBasicBlock::const_iterator
i = MBB->begin(),
153 e = MBB->end();
i !=
e ; ++
i) {
154 MachineInstruction *MI = *
i;
155 if (MI->to_MachineReplacementPointInst()) {
165 template<
class ForwardIt>
166 void CodeGenPass::resolve_replacement_points(ForwardIt first, ForwardIt last,
JITData &JD) {
171 code->rplpointcount = std::distance(first, last);
172 code->rplpoints =
MNEW(rplpoint, code->rplpointcount);
174 rplpoint *rp = code->rplpoints;
175 for (ForwardIt
i = first;
i != last;
i++) {
178 std::size_t offset = CS.
size() - instruction_positions[MI];
186 rp->regalloccount = MI->
op_size();
189 rp->patch_target_addr = NULL;
192 rp->flags |= rplpoint::FLAG_DEOPTIMIZE;
202 rp->patch_target_addr = code->
mcode + idx.idx;
207 rplalloc *
ra = rp->regalloc;
210 e = MI->
end();
i !=
e;
i++) {
221 ra->inmemory =
false;
244 LOG(
"resolved replacement point " << rp <<
nl);
279 codeinfo_ptr[
i] = (
reinterpret_cast<u1*
>(&code))[
i];
295 s4 alignedlen = alignedmcodelen + aligneddseglen;
320 for (CodeMemory::const_data_iterator
i = JD.
get_CodeMemory()->data_begin(),
322 u1* ptr = epoint - offset++;
325 <<
": " << hex << *
i <<
" " << *ptr <<
dec <<
nl);
326 assert(ptr >= code->
mcode);
334 for(
u8 *ptr = reinterpret_cast<u8*>(code->
mcode),
335 *e = reinterpret_cast<u8*>(code->
entrypoint); ptr < e; ++ptr) {
371 #if defined(HAS_ADDRESS_REGISTER_FILE)
372 code->savedadrcount = ADR_SAV_CNT - rd->savadrreguse;
375 #if defined(__AARCH64__) || defined(__X86_64__)
383 #if defined(__AARCH64__)
422 find_all_replacement_points(MIS, std::back_inserter(rplpoints));
423 resolve_replacement_points(rplpoints.begin(), rplpoints.end(), JD);
430 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP)
434 dseg_resolve_datareferences(jd);
442 #ifdef ENABLE_LOGGING
#define STATISTICS(x)
Wrapper for statistics only code.
MachineInstruction * get_call_inst() const
reverse_iterator rbegin()
returns an reverse_iterator to the beginning
std::reverse_iterator< const_iterator > const_reverse_iterator
reverse_iterator rend()
returns an reverse_iterator to the end
Linenumber table of a Java method.
virtual void emit(CodeMemory *CM) const
emit machine code
u4 get_frame_size() const
void link()
Link instructions.
A basic block of (scheduled) machine instructions.
u1 at(std::size_t i) const
get content
virtual Register * to_Register()
MachineInstructionSchedulingPass TODO: more info.
StackSlotManager * get_StackSlotManager()
void patcher_resolve(codeinfo *code)
Resolve all patchers in the current JIT run.
Represents a point in the program, where it is possible to recover the source state to perform on-sta...
static void code_unflag_leafmethod(codeinfo *code)
std::size_t size() const
get size
#define DEBUG_COND_N(VERBOSE)
virtual MachineReplacementPointCallSiteInst * to_MachineReplacementPointCallSiteInst()
jitdata * get_jitdata() const
void md_cacheflush(u1 *addr, s4 nbytes)
const CodeSegment & get_CodeSegment() const
get CodeSegment
void finalize()
Assigns each ManagedStackSlot a position in the virtual frame.
void(* functionptr)(void)
virtual MachineDeoptInst * to_MachineDeoptInst()
#define MCOPY(dest, src, type, num)
void reverse()
reverse content
std::vector< MachineInstruction * > MInstListTy
Instruction::InstID tmp[]
std::size_t op_size() const
void patcher_list_show(codeinfo *code)
Show the content of the whole patcher reference list for debugging purposes.
CodeMemory * get_CodeMemory()
std::vector< T, Allocator< T > > type
Stores the interdependencies of a pass.
Simple stream class for formatted output.
Container::const_reverse_iterator const_reverse_iterator
virtual MachineReplacementPointInst * to_MachineReplacementPointInst()
#define MEMORY_ALIGN(pos, size)
static void code_flag_using_frameptr(codeinfo *code)
void dseg_finish(jitdata *jd)
#define SIZE_OF_STACKSLOT
DataSegment::IdxTy get_idx() const
virtual MachineReplacementPointStaticSpecialInst * to_MachineReplacementPointStaticSpecialInst()
virtual void create_frame(CodeMemory *CM, StackSlotManager *SSM) const =0
#define LOG(STMT)
Analogous to DEBUG.
int convert_to_type(Type::TypeID type)
Convert a Type::TypeID to a Type.
virtual bool is_move() const
Proxy to encode explicit and implicit successors.
void exceptiontable_create(jitdata *jd)
operand_list::iterator operand_iterator
Type::TypeID get_type() const
int32_t synchronizedoffset
virtual MachineRegister * to_MachineRegister()
Operands that can be directly used by the machine (register, memory, stackslot)
LinenumberTable * linenumbertable
reverse_iterator rbegin()
returns an reverse_iterator to the beginning
void methodtree_insert(void *startpc, void *endpc)
void disassemble(u1 *start, u1 *end)
s4 get_javalocal_index(std::size_t i)
reverse_iterator rend()
returns an reverse_iterator to the end
u1 * get_start()
get start address
virtual IdentifyOffsetTy id_offset() const
virtual StackSlot * to_StackSlot()
static PassRegistry< BasicBlockSchedulingPass > X("BasicBlockSchedulingPass")
static SetZero setz(size_t w)
#define STAT_DECLARE_VAR(type, var, init)
Declare an external statistics variable.
virtual IdentifySizeTy id_size() const
Ref get_Ref(std::size_t t)
get a new reference to the segment
OStream & dbg()
The default destination for logging messages.
void add_requires()
PassName is required.
const DataSegment & get_DataSegment() const
get DataSegment