forked from OSchip/llvm-project
[opaque pointer type] encode the pointee type of global variables
Use a few extra bits in the const field (after widening it from a fixed single bit) to stash the address space which is no longer provided by the type (and an extra bit in there to specify that we're using that new encoding). llvm-svn: 235911
This commit is contained in:
parent
fe723b9a6d
commit
1a848da518
|
@ -2876,12 +2876,18 @@ std::error_code BitcodeReader::ParseModule(bool Resume,
|
||||||
Type *Ty = getTypeByID(Record[0]);
|
Type *Ty = getTypeByID(Record[0]);
|
||||||
if (!Ty)
|
if (!Ty)
|
||||||
return Error("Invalid record");
|
return Error("Invalid record");
|
||||||
|
bool isConstant = Record[1] & 1;
|
||||||
|
bool explicitType = Record[1] & 2;
|
||||||
|
unsigned AddressSpace;
|
||||||
|
if (explicitType) {
|
||||||
|
AddressSpace = Record[1] >> 2;
|
||||||
|
} else {
|
||||||
if (!Ty->isPointerTy())
|
if (!Ty->isPointerTy())
|
||||||
return Error("Invalid type for value");
|
return Error("Invalid type for value");
|
||||||
unsigned AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
|
AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
|
||||||
Ty = cast<PointerType>(Ty)->getElementType();
|
Ty = cast<PointerType>(Ty)->getElementType();
|
||||||
|
}
|
||||||
|
|
||||||
bool isConstant = Record[1];
|
|
||||||
uint64_t RawLinkage = Record[3];
|
uint64_t RawLinkage = Record[3];
|
||||||
GlobalValue::LinkageTypes Linkage = getDecodedLinkage(RawLinkage);
|
GlobalValue::LinkageTypes Linkage = getDecodedLinkage(RawLinkage);
|
||||||
unsigned Alignment;
|
unsigned Alignment;
|
||||||
|
|
|
@ -590,7 +590,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
||||||
unsigned MaxGlobalType = 0;
|
unsigned MaxGlobalType = 0;
|
||||||
for (const GlobalValue &GV : M->globals()) {
|
for (const GlobalValue &GV : M->globals()) {
|
||||||
MaxAlignment = std::max(MaxAlignment, GV.getAlignment());
|
MaxAlignment = std::max(MaxAlignment, GV.getAlignment());
|
||||||
MaxGlobalType = std::max(MaxGlobalType, VE.getTypeID(GV.getType()));
|
MaxGlobalType = std::max(MaxGlobalType, VE.getTypeID(GV.getValueType()));
|
||||||
if (GV.hasSection()) {
|
if (GV.hasSection()) {
|
||||||
// Give section names unique ID's.
|
// Give section names unique ID's.
|
||||||
unsigned &Entry = SectionMap[GV.getSection()];
|
unsigned &Entry = SectionMap[GV.getSection()];
|
||||||
|
@ -631,7 +631,9 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
||||||
Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_GLOBALVAR));
|
Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_GLOBALVAR));
|
||||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
|
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
|
||||||
Log2_32_Ceil(MaxGlobalType+1)));
|
Log2_32_Ceil(MaxGlobalType+1)));
|
||||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constant.
|
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddrSpace << 2
|
||||||
|
//| explicitType << 1
|
||||||
|
//| constant
|
||||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Initializer.
|
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Initializer.
|
||||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // Linkage.
|
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // Linkage.
|
||||||
if (MaxAlignment == 0) // Alignment.
|
if (MaxAlignment == 0) // Alignment.
|
||||||
|
@ -659,8 +661,8 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
|
||||||
// linkage, alignment, section, visibility, threadlocal,
|
// linkage, alignment, section, visibility, threadlocal,
|
||||||
// unnamed_addr, externally_initialized, dllstorageclass,
|
// unnamed_addr, externally_initialized, dllstorageclass,
|
||||||
// comdat]
|
// comdat]
|
||||||
Vals.push_back(VE.getTypeID(GV.getType()));
|
Vals.push_back(VE.getTypeID(GV.getValueType()));
|
||||||
Vals.push_back(GV.isConstant());
|
Vals.push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
|
||||||
Vals.push_back(GV.isDeclaration() ? 0 :
|
Vals.push_back(GV.isDeclaration() ? 0 :
|
||||||
(VE.getValueID(GV.getInitializer()) + 1));
|
(VE.getValueID(GV.getInitializer()) + 1));
|
||||||
Vals.push_back(getEncodedLinkage(GV));
|
Vals.push_back(getEncodedLinkage(GV));
|
||||||
|
|
Loading…
Reference in New Issue