-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathCallInfo.hpp
502 lines (423 loc) · 20.8 KB
/
CallInfo.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
/*******************************************************************************
* Copyright IBM Corp. and others 2000
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
///////////////////////////////////////////////////////////////////////////
// CallGraph.hpp contains the class definitions for:
// TR_CallSite --> represents a callsite (ex, a virtual call)
// TR_CallTarget --> represents a concrete implementation (ex a specific method)
///////////////////////////////////////////////////////////////////////////
#ifndef CALLGRAPH_INCL
#define CALLGRAPH_INCL
#include <stddef.h>
#include <stdint.h>
#include "compile/Compilation.hpp"
#include "env/TRMemory.hpp"
#include "env/jittypes.h"
#include "il/AnyConst.hpp"
#include "il/MethodSymbol.hpp"
#include "il/Node.hpp"
#include "infra/Assert.hpp"
#include "infra/deque.hpp"
#include "infra/Link.hpp"
#include "infra/List.hpp"
#include "infra/map.hpp"
#include "infra/TRlist.hpp"
#include "infra/Uncopyable.hpp"
#include "optimizer/DeferredOSRAssumption.hpp"
#include "optimizer/InlinerFailureReason.hpp"
namespace TR { class CompilationFilters;}
class TR_FrontEnd;
class TR_InlineBlocks;
class TR_InlinerBase;
class TR_InlinerTracer;
class TR_InnerPreexistenceInfo;
class TR_PrexArgInfo;
class TR_ResolvedMethod;
namespace TR { class AutomaticSymbol; }
namespace TR { class Block; }
namespace TR { class CFG; }
namespace TR { class Method; }
namespace TR { class ResolvedMethodSymbol; }
namespace TR { class SymbolReference; }
namespace TR { class TreeTop; }
class TR_CallSite;
struct TR_VirtualGuardSelection;
namespace TR { struct RequiredConst; }
class TR_CallStack : public TR_Link<TR_CallStack>
{
public:
TR_CallStack(TR::Compilation *, TR::ResolvedMethodSymbol *, TR_ResolvedMethod *, TR_CallStack *, int32_t, bool safeToAddSymRefs = false);
~TR_CallStack();
void commit();
TR::Compilation * comp() { return _comp; }
TR_Memory * trMemory() { return _trMemory; }
TR_StackMemory trStackMemory() { return _trMemory; }
TR_HeapMemory trHeapMemory() { return _trMemory; }
TR_PersistentMemory * trPersistentMemory(){ return _trMemory->trPersistentMemory(); }
void initializeControlFlowInfo(TR::ResolvedMethodSymbol *);
TR_CallStack * isCurrentlyOnTheStack(TR_ResolvedMethod *, int32_t);
bool isAnywhereOnTheStack (TR_ResolvedMethod *, int32_t); // Even searches calls already inlined by previous opts
void updateState(TR::Block *);
void addAutomatic(TR::AutomaticSymbol * a);
void addTemp(TR::SymbolReference *);
void addInjectedBasicBlockTemp(TR::SymbolReference *);
void makeTempsAvailable(List<TR::SymbolReference> &);
void makeTempsAvailable(List<TR::SymbolReference> &, List<TR::SymbolReference> &);
void makeBasicBlockTempsAvailable(List<TR::SymbolReference> &);
struct BlockInfo
{
TR_ALLOC(TR_Memory::Inliner);
BlockInfo() : _alwaysReached(false) { }
bool _inALoop;
bool _alwaysReached;
};
BlockInfo & blockInfo(int32_t);
class SetCurrentCallNode
{
TR_CallStack &_cs;
TR::Node *_originalValue;
public:
SetCurrentCallNode(TR_CallStack &cs, TR::Node *callNode)
:_cs(cs),_originalValue(cs._currentCallNode)
{ _cs._currentCallNode = callNode; }
~SetCurrentCallNode()
{ _cs._currentCallNode = _originalValue; }
};
TR::Compilation * _comp;
TR_Memory * _trMemory;
TR::ResolvedMethodSymbol * _methodSymbol;
TR_ResolvedMethod * _method;
TR::Node * _currentCallNode;
BlockInfo * _blockInfo;
List<TR::AutomaticSymbol> _autos;
List<TR::SymbolReference> _temps;
List<TR::SymbolReference> _injectedBasicBlockTemps;
TR_InnerPreexistenceInfo *_innerPrexInfo;
TR::CompilationFilters * _inlineFilters;
int32_t _maxCallSize;
bool _inALoop;
bool _alwaysCalled;
bool _safeToAddSymRefs;
};
namespace TR {
/**
* \brief A constant value that was observed during call target selection.
*
* When IL is generated for a call target, it's necessary in general to repeat
* any constant folding that occurred while selecting targets recursively
* within it so that the IL is guaranteed to match what the inliner saw.
*
* This repeated folding is important whenever a value might be allowed to be
* folded despite the possibility of a later change. It also allows constants
* to be speculative by specifying the assumptions that are necessary in order
* for the folding to be correct, and by informing the IL generator of the
* locations where such assumptions have been made (though the locations are
* tracked externally to this class).
*/
struct RequiredConst
{
TR::AnyConst _value; ///< The value.
/// The assumptions required to guarantee the value is constant, if any.
TR::list<TR::DeferredOSRAssumption*, TR::Region&> _assumptions;
RequiredConst(const TR::AnyConst &value, TR::Region ®ion)
: _value(value), _assumptions(region) {}
};
} // namespace TR
struct TR_CallTarget : public TR_Link<TR_CallTarget>
{
TR_ALLOC(TR_Memory::Inliner);
friend class TR_InlinerTracer;
TR_CallTarget(TR::Region &memRegion,
TR_CallSite *callsite,
TR::ResolvedMethodSymbol *calleeSymbol,
TR_ResolvedMethod *calleeMethod,
TR_VirtualGuardSelection *guard,
TR_OpaqueClassBlock *receiverClass,
TR_PrexArgInfo *ecsPrexArgInfo,
float freqAdj=1.0);
const char* signature(TR_Memory *trMemory);
TR_CallSite * _myCallSite;
// Target Specific
TR::ResolvedMethodSymbol * _calleeSymbol; //must have this by the time we actually do the inlinining
TR_ResolvedMethod * _calleeMethod;
TR::MethodSymbol::Kinds _calleeMethodKind;
TR_VirtualGuardSelection * _guard;
int32_t _size;
int32_t _weight;
float _callGraphAdjustedWeight;
TR_OpaqueClassBlock* _receiverClass;
float _frequencyAdjustment; // may need this for multiple call targets.
bool _alreadyInlined; // so we don't keep trying to inline the same method repeatedly
void setComp(TR::Compilation *comp){ _comp = comp; }
TR::Compilation *comp() { return _comp; }
TR::ResolvedMethodSymbol *getSymbol() { return _calleeSymbol; }
void setNumber(int32_t num) { _nodeNumber = num; }
int32_t getNumber() { return _nodeNumber;}
void addCallee(TR_CallSite *cs)
{
_myCallees.add(cs);
_numCallees++;
}
void removeCallee(TR_CallSite *cs)
{
_myCallees.remove(cs);
_numCallees--;
_deletedCallees.add(cs);
_numDeletedCallees++;
}
TR_InlineBlocks *_partialInline;
TR_LinkHead<TR_CallSite> _myCallees;
int32_t _numCallees;
int32_t _partialSize;
int32_t _fullSize;
bool _isPartialInliningCandidate;
TR::Block *_originatingBlock;
TR::CFG *_cfg;
TR_PrexArgInfo *_prexArgInfo; // used by computePrexInfo to calculate prex on generatedIL and transform IL
TR_PrexArgInfo *_ecsPrexArgInfo; // used by ECS and findInlineTargets to assist in choosing correct inline targets
/**
* \brief Constant values that were observed during call target selection
* within this particular call target, keyed on bytecode index.
*/
TR::map<int32_t, TR::RequiredConst> _requiredConsts;
void addDeadCallee(TR_CallSite *cs)
{
_deletedCallees.add(cs);
_numDeletedCallees++;
}
TR_InlinerFailureReason getCallTargetFailureReason() { return _failureReason; }
TR_LinkHead<TR_CallSite> _deletedCallees;
int32_t _numDeletedCallees;
int32_t _nodeNumber;
TR_InlinerFailureReason _failureReason;
TR::Compilation *_comp;
};
#define TR_CALLSITE_DEFAULT_ALLOC \
TR_ALLOC(TR_Memory::Inliner);
#define TR_CALLSITE_INHERIT_CONSTRUCTOR_COMMON(EXTENDED,BASE) \
EXTENDED (TR_ResolvedMethod *callerResolvedMethod, \
TR::TreeTop *callNodeTreeTop, \
TR::Node *parent, \
TR::Node *callNode, \
TR::Method * interfaceMethod, \
TR_OpaqueClassBlock *receiverClass, \
int32_t vftSlot, \
int32_t cpIndex, \
TR_ResolvedMethod *initialCalleeMethod, \
TR::ResolvedMethodSymbol * initialCalleeSymbol, \
bool isIndirectCall, \
bool isInterface, \
TR_ByteCodeInfo & bcInfo, \
TR::Compilation *comp, \
int32_t depth, \
bool allConsts) : \
BASE (callerResolvedMethod, \
callNodeTreeTop, \
parent, \
callNode, \
interfaceMethod, \
receiverClass, \
vftSlot, \
cpIndex, \
initialCalleeMethod, \
initialCalleeSymbol, \
isIndirectCall, \
isInterface, \
bcInfo, \
comp, \
depth, \
allConsts)
#define TR_CALLSITE_EMPTY_CONSTRUCTOR_BODY { };
/*
* \def TR_CALLSITE_TR_ALLOC_AND_INHERIT_EMPTY_CONSTRUCTOR (EXTENDED,BASE)
* Declare the allocation and a constructor with an empty method body.
* Used by call sites constructors that initialize given fields and do nothing else.
*/
#define TR_CALLSITE_TR_ALLOC_AND_INHERIT_EMPTY_CONSTRUCTOR(EXTENDED,BASE) \
TR_CALLSITE_DEFAULT_ALLOC \
TR_CALLSITE_INHERIT_CONSTRUCTOR_COMMON (EXTENDED,BASE) \
TR_CALLSITE_EMPTY_CONSTRUCTOR_BODY
/*
* \def TR_CALLSITE_TR_ALLOC_AND_INHERIT_CONSTRUCTOR(EXTENDED,BASE)
* Declare the allocation and a constructor WITHOUT a method body.
* Used by call sites constructors that do more complicated things other than just initializing given field.
*/
#define TR_CALLSITE_TR_ALLOC_AND_INHERIT_CONSTRUCTOR(EXTENDED,BASE) \
TR_CALLSITE_DEFAULT_ALLOC \
TR_CALLSITE_INHERIT_CONSTRUCTOR_COMMON (EXTENDED,BASE)
class TR_CallSite : public TR_Link<TR_CallSite>, private TR::Uncopyable
{
public:
TR_ALLOC(TR_Memory::Inliner);
friend class TR_InlinerTracer;
TR_CallSite(TR_ResolvedMethod *callerResolvedMethod,
TR::TreeTop *callNodeTreeTop,
TR::Node *parent,
TR::Node *callNode,
TR::Method * interfaceMethod,
TR_OpaqueClassBlock *receiverClass,
int32_t vftSlot,
int32_t cpIndex,
TR_ResolvedMethod *initialCalleeMethod,
TR::ResolvedMethodSymbol * initialCalleeSymbol,
bool isIndirectCall,
bool isInterface,
TR_ByteCodeInfo & bcInfo,
TR::Compilation *comp,
int32_t depth,
bool allConsts);
TR_InlinerFailureReason getCallSiteFailureReason() { return _failureReason; }
//Call Site Specific
bool isBackEdge() { return _isBackEdge; }
void setIsBackEdge() { _isBackEdge = true; }
bool isIndirectCall() { return _isIndirectCall; }
bool isInterface() { return _isInterface; }
int32_t numTargets() { return static_cast<int32_t>(_mytargets.size()); }
int32_t numRemovedTargets() { return static_cast<int32_t>(_myRemovedTargets.size()); }
bool isForceInline() { return _forceInline; }
void tagcalltarget(int32_t index, TR_InlinerTracer *tracer, TR_InlinerFailureReason reason );
void tagcalltarget(TR_CallTarget *ct, TR_InlinerTracer *tracer, TR_InlinerFailureReason reason);
void removecalltarget(int32_t index, TR_InlinerTracer *tracer, TR_InlinerFailureReason reason );
void removecalltarget(TR_CallTarget *ct, TR_InlinerTracer *tracer, TR_InlinerFailureReason reason);
void removeAllTargets(TR_InlinerTracer *tracer, TR_InlinerFailureReason reason);
void removeTargets(TR_InlinerTracer *tracer, int index, TR_InlinerFailureReason reason);
TR_CallTarget * getTarget(int32_t i)
{
TR_ASSERT(i>=0 && i<_mytargets.size(), "indexing a target out of range.");
return _mytargets[i];
}
void setTarget(int32_t i, TR_CallTarget * ct)
{
TR_ASSERT(i>=0 && i<_mytargets.size(), "indexing a target out of range.");
_mytargets[i] = ct;
}
TR_CallTarget * addTarget(TR_Memory* , TR_InlinerBase*, TR_VirtualGuardSelection *, TR_ResolvedMethod *, TR_OpaqueClassBlock *,TR_AllocationKind allocKind=stackAlloc,float ratio=1.0);
bool addTarget0(TR_Memory*, TR_InlinerTracer *, TR_VirtualGuardSelection *, TR_ResolvedMethod *, TR_OpaqueClassBlock *,TR_AllocationKind allocKind=stackAlloc,float ratio=1.0);
void addTarget(TR_CallTarget *target)
{
_mytargets.push_back(target);
}
void addTargetToFront(TR_CallTarget *target)
{
_mytargets.push_front(target);
}
TR_CallTarget * getRemovedTarget(int32_t i)
{
TR_ASSERT( i >= 0 && i<_myRemovedTargets.size(), "indexing a target out of range.");
return _myRemovedTargets[i];
}
const char* signature(TR_Memory *trMemory);
TR_OpaqueClassBlock *calleeClass();
TR::Compilation * _comp;
TR_ResolvedMethod * _callerResolvedMethod;
TR::TreeTop * _callNodeTreeTop;
TR::TreeTop * _cursorTreeTop;
TR::Node * _parent; /* tree top node of the call site callNode */
TR::Node * _callNode;
// Initial Information We Need to Calculate a CallTarget
TR::Method * _interfaceMethod; // If we have an interface, we'll only have a TR::Method until we determine others
TR_OpaqueClassBlock * _receiverClass; // for interface calls, we might know this?
int32_t _vftSlot; //
int32_t _cpIndex; //
TR_ResolvedMethod * _initialCalleeMethod; // alot of times we might already know the resolved method.
TR::ResolvedMethodSymbol * _initialCalleeSymbol; // and in those cases, we should also know the methodsymbol..
TR_ByteCodeInfo _bcInfo;
int32_t _stmtNo;
// except we don't always have a call node! (ie when we come from ECS)
int32_t _byteCodeIndex;
bool _isIndirectCall;
bool _isInterface;
bool _forceInline;
bool _isBackEdge;
TR::Block * _callerBlock;
vcount_t _visitCount; // a woefully bad choice of name. The number of times we have visited this callsite during inlining. In theory, when you have multiple targets for a callsite, you will have multiple visits to a callsite.
List<TR::SymbolReference> _unavailableTemps;
List<TR::SymbolReference> _unavailableBlockTemps;
TR_InlinerFailureReason _failureReason; //used for inliner report!
// we propagate from calltarget to callee callsite when appropriate in ecs
TR_PrexArgInfo *_ecsPrexArgInfo; // used by ECS and findInlineTargets to assist in choosing correct inline targets
//new findInlineTargets API
virtual bool findCallSiteTarget (TR_CallStack *callStack, TR_InlinerBase* inliner);
virtual const char* name () { return "TR_CallSite"; }
static TR_CallSite*
create(TR::TreeTop* callNodeTreeTop,
TR::Node *parent,
TR::Node* callNode,
TR_OpaqueClassBlock *receiverClass,
TR::SymbolReference *symRef,
TR_ResolvedMethod *resolvedMethod,
TR::Compilation* comp,
TR_Memory* trMemory,
TR_AllocationKind kind,
TR_ResolvedMethod* caller = NULL,
int32_t depth=-1,
bool allConsts = false);
protected:
TR::Compilation* comp() {return _comp; }
TR_FrontEnd* fe() {return _comp->fe(); }
private:
TR::deque<TR_CallTarget *> _mytargets;
TR::deque<TR_CallTarget *> _myRemovedTargets;
//Partial Inlining Stuff
public:
void setDepth(int32_t d) { _depth = d; }
int32_t getDepth() { return _depth; }
bool _allConsts;
private:
int32_t _depth;
};
class TR_DirectCallSite : public TR_CallSite
{
public:
TR_CALLSITE_TR_ALLOC_AND_INHERIT_EMPTY_CONSTRUCTOR(TR_DirectCallSite, TR_CallSite)
virtual bool findCallSiteTarget (TR_CallStack *callStack, TR_InlinerBase* inliner);
virtual const char* name () { return "TR_DirectCallSite"; }
};
class TR_IndirectCallSite : public TR_CallSite
{
public:
TR_CALLSITE_TR_ALLOC_AND_INHERIT_EMPTY_CONSTRUCTOR(TR_IndirectCallSite, TR_CallSite)
virtual bool findCallSiteTarget (TR_CallStack *callStack, TR_InlinerBase* inliner);
virtual const char* name () { return "TR_IndirectCallSite"; }
virtual TR_ResolvedMethod* findSingleJittedImplementer (TR_InlinerBase* inliner);
protected:
bool hasFixedTypeArgInfo();
bool hasResolvedTypeArgInfo();
TR_OpaqueClassBlock* getClassFromArgInfo();
bool tryToRefineReceiverClassBasedOnResolvedTypeArgInfo(TR_InlinerBase* inliner);
virtual bool findCallTargetUsingArgumentPreexistence(TR_InlinerBase* inliner);
virtual TR_ResolvedMethod* getResolvedMethod (TR_OpaqueClassBlock* klass);
TR_OpaqueClassBlock * extractAndLogClassArgument(TR_InlinerBase* inliner);
//capabilities
bool addTargetIfMethodIsNotOverriden (TR_InlinerBase* inliner);
bool addTargetIfMethodIsNotOverridenInReceiversHierarchy (TR_InlinerBase* inliner);
bool addTargetIfThereIsSingleImplementer(TR_InlinerBase* inliner);
virtual TR_OpaqueClassBlock* getClassFromMethod ()
{
TR_ASSERT(0, "TR_CallSite::getClassFromMethod is not implemented");
return NULL;
}
};
class TR_FunctionPointerCallSite : public TR_IndirectCallSite
{
protected :
TR_CALLSITE_TR_ALLOC_AND_INHERIT_EMPTY_CONSTRUCTOR(TR_FunctionPointerCallSite, TR_IndirectCallSite)
};
#endif