mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
Bytecode format for LLVM 1.2 no longer explicitly encodes zeros in primitive
type planes. This saves about 5k on 176.gcc, and is needed for a subsequent patch of mine I'm working on. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10908 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -66,10 +66,17 @@ const Type *BytecodeParser::getType(unsigned ID) {
|
|||||||
throw std::string("Illegal type reference!");
|
throw std::string("Illegal type reference!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool hasImplicitNull(unsigned TyID, bool EncodesPrimitiveZeros) {
|
||||||
|
if (!EncodesPrimitiveZeros)
|
||||||
|
return TyID != Type::LabelTyID && TyID != Type::TypeTyID &&
|
||||||
|
TyID != Type::VoidTyID;
|
||||||
|
return TyID >= Type::FirstDerivedTyID;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned BytecodeParser::insertValue(Value *Val, unsigned type,
|
unsigned BytecodeParser::insertValue(Value *Val, unsigned type,
|
||||||
ValueTable &ValueTab) {
|
ValueTable &ValueTab) {
|
||||||
assert((!isa<Constant>(Val) || Val->getType()->isPrimitiveType() ||
|
assert((!isa<Constant>(Val) || !cast<Constant>(Val)->isNullValue()) ||
|
||||||
!cast<Constant>(Val)->isNullValue()) &&
|
!hasImplicitNull(type, hasExplicitPrimitiveZeros) &&
|
||||||
"Cannot read null values from bytecode!");
|
"Cannot read null values from bytecode!");
|
||||||
assert(type != Type::TypeTyID && "Types should never be insertValue'd!");
|
assert(type != Type::TypeTyID && "Types should never be insertValue'd!");
|
||||||
|
|
||||||
@ -88,13 +95,12 @@ unsigned BytecodeParser::insertValue(Value *Val, unsigned type,
|
|||||||
return ValueTab[type]->size()-1 + HasOffset;
|
return ValueTab[type]->size()-1 + HasOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Value *BytecodeParser::getValue(unsigned type, unsigned oNum, bool Create) {
|
Value *BytecodeParser::getValue(unsigned type, unsigned oNum, bool Create) {
|
||||||
assert(type != Type::TypeTyID && "getValue() cannot get types!");
|
assert(type != Type::TypeTyID && "getValue() cannot get types!");
|
||||||
assert(type != Type::LabelTyID && "getValue() cannot get blocks!");
|
assert(type != Type::LabelTyID && "getValue() cannot get blocks!");
|
||||||
unsigned Num = oNum;
|
unsigned Num = oNum;
|
||||||
|
|
||||||
if (type >= FirstDerivedTyID) {
|
if (hasImplicitNull(type, hasExplicitPrimitiveZeros)) {
|
||||||
if (Num == 0)
|
if (Num == 0)
|
||||||
return Constant::getNullValue(getType(type));
|
return Constant::getNullValue(getType(type));
|
||||||
--Num;
|
--Num;
|
||||||
@ -536,6 +542,7 @@ void BytecodeParser::ParseVersionInfo(const unsigned char *&Buf,
|
|||||||
hasOldStyleVarargs = false;
|
hasOldStyleVarargs = false;
|
||||||
hasVarArgCallPadding = false;
|
hasVarArgCallPadding = false;
|
||||||
hasInconsistentModuleGlobalInfo = false;
|
hasInconsistentModuleGlobalInfo = false;
|
||||||
|
hasExplicitPrimitiveZeros = false;
|
||||||
FirstDerivedTyID = 14;
|
FirstDerivedTyID = 14;
|
||||||
|
|
||||||
switch (RevisionNum) {
|
switch (RevisionNum) {
|
||||||
@ -545,16 +552,15 @@ void BytecodeParser::ParseVersionInfo(const unsigned char *&Buf,
|
|||||||
hasExtendedLinkageSpecs = false;
|
hasExtendedLinkageSpecs = false;
|
||||||
hasOldStyleVarargs = true;
|
hasOldStyleVarargs = true;
|
||||||
hasVarArgCallPadding = true;
|
hasVarArgCallPadding = true;
|
||||||
hasInconsistentModuleGlobalInfo = true;
|
// FALL THROUGH
|
||||||
|
|
||||||
break;
|
|
||||||
case 0: // LLVM 1.0, 1.1 release version
|
case 0: // LLVM 1.0, 1.1 release version
|
||||||
// Compared to rev #2, we added support for weak linkage, a more dense
|
// Compared to rev #2, we added support for weak linkage, a more dense
|
||||||
// encoding, and better varargs support.
|
// encoding, and better varargs support.
|
||||||
|
|
||||||
// Base LLVM 1.0 bytecode format.
|
// Base LLVM 1.0 bytecode format.
|
||||||
hasInconsistentModuleGlobalInfo = true;
|
hasInconsistentModuleGlobalInfo = true;
|
||||||
break;
|
hasExplicitPrimitiveZeros = true;
|
||||||
|
// FALL THROUGH
|
||||||
case 1: // LLVM 1.2 release version
|
case 1: // LLVM 1.2 release version
|
||||||
// LLVM 1.2 added explicit support for emitting strings efficiently.
|
// LLVM 1.2 added explicit support for emitting strings efficiently.
|
||||||
|
|
||||||
|
@ -97,10 +97,16 @@ private:
|
|||||||
|
|
||||||
bool usesOldStyleVarargs; // Does this module USE old style varargs?
|
bool usesOldStyleVarargs; // Does this module USE old style varargs?
|
||||||
|
|
||||||
// LLVM 1.0 & 1.1 had an explicit alignment of data only for the
|
// Flags to distinguish LLVM 1.0 & 1.1 bytecode formats (revision #0)
|
||||||
// ModuleGlobalInfo block. This was fixed to be like all other blocks in 1.2
|
|
||||||
|
// Revision #0 had an explicit alignment of data only for the ModuleGlobalInfo
|
||||||
|
// block. This was fixed to be like all other blocks in 1.2
|
||||||
bool hasInconsistentModuleGlobalInfo;
|
bool hasInconsistentModuleGlobalInfo;
|
||||||
|
|
||||||
|
// Revision #0 also explicitly encoded zero values for primitive types like
|
||||||
|
// int/sbyte/etc.
|
||||||
|
bool hasExplicitPrimitiveZeros;
|
||||||
|
|
||||||
typedef std::vector<ValueList*> ValueTable;
|
typedef std::vector<ValueList*> ValueTable;
|
||||||
ValueTable Values;
|
ValueTable Values;
|
||||||
ValueTable ModuleValues;
|
ValueTable ModuleValues;
|
||||||
|
@ -406,6 +406,10 @@ int SlotCalculator::insertValue(const Value *D, bool dontIgnore) {
|
|||||||
return doInsertValue(D);
|
return doInsertValue(D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool hasNullValue(unsigned TyID) {
|
||||||
|
return TyID != Type::LabelTyID && TyID != Type::TypeTyID &&
|
||||||
|
TyID != Type::VoidTyID;
|
||||||
|
}
|
||||||
|
|
||||||
// doInsertValue - This is a small helper function to be called only
|
// doInsertValue - This is a small helper function to be called only
|
||||||
// be insertValue.
|
// be insertValue.
|
||||||
@ -435,7 +439,7 @@ int SlotCalculator::doInsertValue(const Value *D) {
|
|||||||
|
|
||||||
// If this is the first value to get inserted into the type plane, make sure
|
// If this is the first value to get inserted into the type plane, make sure
|
||||||
// to insert the implicit null value...
|
// to insert the implicit null value...
|
||||||
if (Table[Ty].empty() && Ty >= Type::FirstDerivedTyID && BuildBytecodeInfo) {
|
if (Table[Ty].empty() && BuildBytecodeInfo && hasNullValue(Ty)) {
|
||||||
Value *ZeroInitializer = Constant::getNullValue(Typ);
|
Value *ZeroInitializer = Constant::getNullValue(Typ);
|
||||||
|
|
||||||
// If we are pushing zeroinit, it will be handled below.
|
// If we are pushing zeroinit, it will be handled below.
|
||||||
|
@ -161,6 +161,11 @@ void BytecodeWriter::outputConstantsInPlane(const std::vector<const Value*>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool hasNullValue(unsigned TyID) {
|
||||||
|
return TyID != Type::LabelTyID && TyID != Type::TypeTyID &&
|
||||||
|
TyID != Type::VoidTyID;
|
||||||
|
}
|
||||||
|
|
||||||
void BytecodeWriter::outputConstants(bool isFunction) {
|
void BytecodeWriter::outputConstants(bool isFunction) {
|
||||||
ConstantTotalBytes -= Out.size();
|
ConstantTotalBytes -= Out.size();
|
||||||
if (isFunction) FunctionConstantTotalBytes -= Out.size();
|
if (isFunction) FunctionConstantTotalBytes -= Out.size();
|
||||||
@ -190,7 +195,7 @@ void BytecodeWriter::outputConstants(bool isFunction) {
|
|||||||
if (isFunction) // Don't re-emit module constants
|
if (isFunction) // Don't re-emit module constants
|
||||||
ValNo += Table.getModuleLevel(pno);
|
ValNo += Table.getModuleLevel(pno);
|
||||||
|
|
||||||
if (pno >= Type::FirstDerivedTyID) {
|
if (hasNullValue(pno)) {
|
||||||
// Skip zero initializer
|
// Skip zero initializer
|
||||||
if (ValNo == 0)
|
if (ValNo == 0)
|
||||||
ValNo = 1;
|
ValNo = 1;
|
||||||
|
@ -406,6 +406,10 @@ int SlotCalculator::insertValue(const Value *D, bool dontIgnore) {
|
|||||||
return doInsertValue(D);
|
return doInsertValue(D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool hasNullValue(unsigned TyID) {
|
||||||
|
return TyID != Type::LabelTyID && TyID != Type::TypeTyID &&
|
||||||
|
TyID != Type::VoidTyID;
|
||||||
|
}
|
||||||
|
|
||||||
// doInsertValue - This is a small helper function to be called only
|
// doInsertValue - This is a small helper function to be called only
|
||||||
// be insertValue.
|
// be insertValue.
|
||||||
@ -435,7 +439,7 @@ int SlotCalculator::doInsertValue(const Value *D) {
|
|||||||
|
|
||||||
// If this is the first value to get inserted into the type plane, make sure
|
// If this is the first value to get inserted into the type plane, make sure
|
||||||
// to insert the implicit null value...
|
// to insert the implicit null value...
|
||||||
if (Table[Ty].empty() && Ty >= Type::FirstDerivedTyID && BuildBytecodeInfo) {
|
if (Table[Ty].empty() && BuildBytecodeInfo && hasNullValue(Ty)) {
|
||||||
Value *ZeroInitializer = Constant::getNullValue(Typ);
|
Value *ZeroInitializer = Constant::getNullValue(Typ);
|
||||||
|
|
||||||
// If we are pushing zeroinit, it will be handled below.
|
// If we are pushing zeroinit, it will be handled below.
|
||||||
|
Reference in New Issue
Block a user