mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-18 13:04:36 +03:00
Minor changes.
This commit is contained in:
@@ -379,17 +379,17 @@ _OnVisit:
|
||||
VarData* vd = va->getVd();
|
||||
|
||||
uint32_t flags = va->getFlags();
|
||||
uint32_t ctxId = vd->getLocalId();
|
||||
uint32_t localId = vd->getLocalId();
|
||||
|
||||
if ((flags & kVarAttrWAll) && !(flags & kVarAttrRAll)) {
|
||||
// Write-Only.
|
||||
bTmp->setBit(ctxId);
|
||||
bCur->delBit(ctxId);
|
||||
bTmp->setBit(localId);
|
||||
bCur->delBit(localId);
|
||||
}
|
||||
else {
|
||||
// Read-Only or Read/Write.
|
||||
bTmp->setBit(ctxId);
|
||||
bCur->setBit(ctxId);
|
||||
bTmp->setBit(localId);
|
||||
bCur->setBit(localId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -516,6 +516,64 @@ _NoMemory:
|
||||
return setLastError(kErrorNoHeapMemory);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// [asmjit::Context - Annotate]
|
||||
// ============================================================================
|
||||
|
||||
Error Context::formatInlineComment(StringBuilder& dst, HLNode* node) {
|
||||
#if !defined(ASMJIT_DISABLE_LOGGER)
|
||||
if (node->getComment())
|
||||
dst.appendString(node->getComment());
|
||||
|
||||
if (node->hasLiveness()) {
|
||||
if (dst.getLength() < _annotationLength)
|
||||
dst.appendChars(' ', _annotationLength - dst.getLength());
|
||||
|
||||
uint32_t vdCount = static_cast<uint32_t>(_contextVd.getLength());
|
||||
size_t offset = dst.getLength() + 1;
|
||||
|
||||
dst.appendChar('[');
|
||||
dst.appendChars(' ', vdCount);
|
||||
dst.appendChar(']');
|
||||
|
||||
BitArray* liveness = node->getLiveness();
|
||||
VarMap* map = node->getMap();
|
||||
|
||||
uint32_t i;
|
||||
for (i = 0; i < vdCount; i++) {
|
||||
if (liveness->getBit(i))
|
||||
dst.getData()[offset + i] = '.';
|
||||
}
|
||||
|
||||
if (map != nullptr) {
|
||||
uint32_t vaCount = map->getVaCount();
|
||||
VarAttr* vaList = reinterpret_cast<VarAttr*>(((uint8_t*)map) + _varMapToVaListOffset);
|
||||
|
||||
for (i = 0; i < vaCount; i++) {
|
||||
VarAttr* va = &vaList[i];
|
||||
VarData* vd = va->getVd();
|
||||
|
||||
uint32_t flags = va->getFlags();
|
||||
char c = 'u';
|
||||
|
||||
if ( (flags & kVarAttrRAll) && !(flags & kVarAttrWAll)) c = 'r';
|
||||
if (!(flags & kVarAttrRAll) && (flags & kVarAttrWAll)) c = 'w';
|
||||
if ( (flags & kVarAttrRAll) && (flags & kVarAttrWAll)) c = 'x';
|
||||
|
||||
// Uppercase if unused.
|
||||
if ((flags & kVarAttrUnuse))
|
||||
c -= 'a' - 'A';
|
||||
|
||||
ASMJIT_ASSERT(offset + vd->getLocalId() < dst.getLength());
|
||||
dst._data[offset + vd->getLocalId()] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ASMJIT_DISABLE_LOGGER
|
||||
|
||||
return kErrorOk;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// [asmjit::Context - Schedule]
|
||||
// ============================================================================
|
||||
|
||||
@@ -792,6 +792,7 @@ struct Context {
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
virtual Error annotate() = 0;
|
||||
virtual Error formatInlineComment(StringBuilder& dst, HLNode* node);
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// [Translate]
|
||||
|
||||
@@ -66,9 +66,11 @@ ASMJIT_ENUM(LoggerStyle) {
|
||||
#if defined(ASMJIT_EXPORTS)
|
||||
struct LogUtil {
|
||||
enum {
|
||||
kMaxCommentLength = 80,
|
||||
kMaxInstLength = 36,
|
||||
kMaxBinaryLength = 22
|
||||
// Has to be big to be able to hold all metadata compiler can assign to a
|
||||
// single instruction.
|
||||
kMaxCommentLength = 512,
|
||||
kMaxInstLength = 40,
|
||||
kMaxBinaryLength = 26
|
||||
};
|
||||
|
||||
static bool formatLine(StringBuilder& sb, const uint8_t* binData, size_t binLen, size_t dispLen, size_t imLen, const char* comment);
|
||||
|
||||
@@ -2509,13 +2509,7 @@ _NextGroup:
|
||||
if (extendedInfo.isZeroIfMem() && opList[1].isMem())
|
||||
movSize = 16;
|
||||
|
||||
if (movSize >= varSize) {
|
||||
// If move size is greater than or equal to the size of
|
||||
// the variable there is nothing to do, because the move
|
||||
// will overwrite the variable in all cases.
|
||||
combinedFlags = outFlags;
|
||||
}
|
||||
else if (static_cast<const X86Var*>(op)->isGp()) {
|
||||
if (static_cast<const X86Var*>(op)->isGp()) {
|
||||
uint32_t opSize = static_cast<const X86Var*>(op)->getSize();
|
||||
|
||||
// Move size is zero in case that it should be determined
|
||||
@@ -2530,6 +2524,12 @@ _NextGroup:
|
||||
if (movSize >= 4 || movSize >= varSize)
|
||||
combinedFlags = outFlags;
|
||||
}
|
||||
else if (movSize >= varSize) {
|
||||
// If move size is greater than or equal to the size of
|
||||
// the variable there is nothing to do, because the move
|
||||
// will overwrite the variable in all cases.
|
||||
combinedFlags = outFlags;
|
||||
}
|
||||
}
|
||||
// Comparison/Test instructions don't modify any operand.
|
||||
else if (extendedInfo.isTest()) {
|
||||
@@ -3760,7 +3760,7 @@ ASMJIT_INLINE uint32_t X86VarAlloc::guessAlloc(VarData* vd, uint32_t allocableRe
|
||||
uint32_t counter = 0;
|
||||
uint32_t maxInst = _compiler->getMaxLookAhead();
|
||||
|
||||
uint32_t cId = vd->getLocalId();
|
||||
uint32_t localId = vd->getLocalId();
|
||||
uint32_t localToken = _compiler->_generateUniqueToken();
|
||||
|
||||
uint32_t gfIndex = 0;
|
||||
@@ -3790,7 +3790,7 @@ ASMJIT_INLINE uint32_t X86VarAlloc::guessAlloc(VarData* vd, uint32_t allocableRe
|
||||
counter++;
|
||||
|
||||
// Terminate if the variable is dead here.
|
||||
if (node->hasLiveness() && !node->getLiveness()->getBit(cId)) {
|
||||
if (node->hasLiveness() && !node->getLiveness()->getBit(localId)) {
|
||||
ASMJIT_TLOG("[RA-GUESS] %s (Terminating, Not alive here)\n", vd->getName());
|
||||
break;
|
||||
}
|
||||
@@ -3956,7 +3956,7 @@ ASMJIT_INLINE uint32_t X86VarAlloc::guessAlloc(VarData* vd, uint32_t allocableRe
|
||||
if (Utils::isPowerOf2(allocableRegs))
|
||||
return allocableRegs;
|
||||
|
||||
uint32_t cId = vd->getLocalId();
|
||||
uint32_t localId = vd->getLocalId();
|
||||
uint32_t safeRegs = allocableRegs;
|
||||
|
||||
uint32_t i;
|
||||
@@ -3968,7 +3968,7 @@ ASMJIT_INLINE uint32_t X86VarAlloc::guessAlloc(VarData* vd, uint32_t allocableRe
|
||||
BitArray* liveness = node->getLiveness();
|
||||
|
||||
// If the variable becomes dead it doesn't make sense to continue.
|
||||
if (liveness != nullptr && !liveness->getBit(cId))
|
||||
if (liveness != nullptr && !liveness->getBit(localId))
|
||||
break;
|
||||
|
||||
// Stop on `HLSentinel` and `HLRet`.
|
||||
@@ -5761,73 +5761,20 @@ _Done:
|
||||
// [asmjit::X86Context - Serialize]
|
||||
// ============================================================================
|
||||
|
||||
template<int LoggingEnabled>
|
||||
static ASMJIT_INLINE Error X86Context_serialize(X86Context* self, X86Assembler* assembler, HLNode* start, HLNode* stop) {
|
||||
Error X86Context::serialize(Assembler* assembler_, HLNode* start, HLNode* stop) {
|
||||
X86Assembler* assembler = static_cast<X86Assembler*>(assembler_);
|
||||
HLNode* node_ = start;
|
||||
StringBuilder& sb = self->_stringBuilder;
|
||||
|
||||
#if !defined(ASMJIT_DISABLE_LOGGER)
|
||||
uint32_t vdCount;
|
||||
uint32_t annotationLength;
|
||||
|
||||
Logger* logger;
|
||||
|
||||
if (LoggingEnabled) {
|
||||
logger = assembler->getLogger();
|
||||
|
||||
vdCount = static_cast<uint32_t>(self->_contextVd.getLength());
|
||||
annotationLength = self->_annotationLength;
|
||||
}
|
||||
Logger* logger = assembler->getLogger();
|
||||
#endif // !ASMJIT_DISABLE_LOGGER
|
||||
|
||||
do {
|
||||
#if !defined(ASMJIT_DISABLE_LOGGER)
|
||||
if (LoggingEnabled) {
|
||||
sb.clear();
|
||||
|
||||
if (node_->getComment()) {
|
||||
sb.appendString(node_->getComment());
|
||||
}
|
||||
|
||||
if (sb.getLength() < annotationLength)
|
||||
sb.appendChars(' ', annotationLength - sb.getLength());
|
||||
|
||||
size_t offset = sb.getLength();
|
||||
sb.appendChars(' ', vdCount);
|
||||
|
||||
if (node_->hasLiveness()) {
|
||||
BitArray* liveness = node_->getLiveness();
|
||||
X86VarMap* map = static_cast<X86VarMap*>(node_->getMap());
|
||||
|
||||
uint32_t i;
|
||||
for (i = 0; i < vdCount; i++) {
|
||||
if (liveness->getBit(i))
|
||||
sb.getData()[offset + i] = '.';
|
||||
}
|
||||
|
||||
if (map != nullptr) {
|
||||
uint32_t vaCount = map->getVaCount();
|
||||
|
||||
for (i = 0; i < vaCount; i++) {
|
||||
VarAttr* va = map->getVa(i);
|
||||
VarData* vd = va->getVd();
|
||||
|
||||
uint32_t flags = va->getFlags();
|
||||
char c = 'u';
|
||||
|
||||
if ( (flags & kVarAttrRAll) && !(flags & kVarAttrWAll)) c = 'r';
|
||||
if (!(flags & kVarAttrRAll) && (flags & kVarAttrWAll)) c = 'w';
|
||||
if ( (flags & kVarAttrRAll) && (flags & kVarAttrWAll)) c = 'x';
|
||||
|
||||
if ((flags & kVarAttrUnuse))
|
||||
c -= 'a' - 'A';
|
||||
|
||||
sb.getData()[offset + vd->getLocalId()] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assembler->_comment = sb.getData();
|
||||
if (logger) {
|
||||
_stringBuilder.clear();
|
||||
formatInlineComment(_stringBuilder, node_);
|
||||
assembler->_comment = _stringBuilder.getData();
|
||||
}
|
||||
#endif // !ASMJIT_DISABLE_LOGGER
|
||||
|
||||
@@ -5847,7 +5794,7 @@ static ASMJIT_INLINE Error X86Context_serialize(X86Context* self, X86Assembler*
|
||||
case kHLNodeTypeComment: {
|
||||
#if !defined(ASMJIT_DISABLE_LOGGER)
|
||||
HLComment* node = static_cast<HLComment*>(node_);
|
||||
if (LoggingEnabled)
|
||||
if (logger)
|
||||
logger->logFormat(kLoggerStyleComment,
|
||||
"%s; %s\n", logger->getIndentation(), node->getComment());
|
||||
#endif // !ASMJIT_DISABLE_LOGGER
|
||||
@@ -6047,15 +5994,6 @@ static ASMJIT_INLINE Error X86Context_serialize(X86Context* self, X86Assembler*
|
||||
return kErrorOk;
|
||||
}
|
||||
|
||||
Error X86Context::serialize(Assembler* assembler, HLNode* start, HLNode* stop) {
|
||||
#if !defined(ASMJIT_DISABLE_LOGGER)
|
||||
if (assembler->hasLogger())
|
||||
return X86Context_serialize<1>(this, static_cast<X86Assembler*>(assembler), start, stop);
|
||||
#endif // !ASMJIT_DISABLE_LOGGER
|
||||
|
||||
return X86Context_serialize<0>(this, static_cast<X86Assembler*>(assembler), start, stop);
|
||||
}
|
||||
|
||||
} // asmjit namespace
|
||||
|
||||
// [Api-End]
|
||||
|
||||
Reference in New Issue
Block a user