[llvm][Bitcode] Add bitcode reader/writer for DSOLocalEquivalent

This is necessary for compilation with [thin]lto.

Differential Revision: https://reviews.llvm.org/D96170
This commit is contained in:
Leonard Chan
2021-02-10 10:48:22 -08:00
parent 95d13c01ec
commit 1c932baeaa
5 changed files with 108 additions and 2 deletions

View File

@@ -218,6 +218,7 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
STRINGIFY_CODE(CST_CODE, INLINEASM)
STRINGIFY_CODE(CST_CODE, CE_SHUFVEC_EX)
STRINGIFY_CODE(CST_CODE, CE_UNOP)
STRINGIFY_CODE(CST_CODE, DSO_LOCAL_EQUIVALENT)
case bitc::CST_CODE_BLOCKADDRESS:
return "CST_CODE_BLOCKADDRESS";
STRINGIFY_CODE(CST_CODE, DATA)

View File

@@ -2888,6 +2888,20 @@ Error BitcodeReader::parseConstants() {
V = BlockAddress::get(Fn, BB);
break;
}
case bitc::CST_CODE_DSO_LOCAL_EQUIVALENT: {
if (Record.size() < 2)
return error("Invalid record");
Type *GVTy = getTypeByID(Record[0]);
if (!GVTy)
return error("Invalid record");
GlobalValue *GV = dyn_cast_or_null<GlobalValue>(
ValueList.getConstantFwdRef(Record[1], GVTy));
if (!GV)
return error("Invalid record");
V = DSOLocalEquivalent::get(GV);
break;
}
}
assert(V->getType() == flattenPointerTypes(CurFullTy) &&

View File

@@ -2609,6 +2609,10 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
Record.push_back(VE.getTypeID(BA->getFunction()->getType()));
Record.push_back(VE.getValueID(BA->getFunction()));
Record.push_back(VE.getGlobalBasicBlockID(BA->getBasicBlock()));
} else if (const auto *Equiv = dyn_cast<DSOLocalEquivalent>(C)) {
Code = bitc::CST_CODE_DSO_LOCAL_EQUIVALENT;
Record.push_back(VE.getTypeID(Equiv->getGlobalValue()->getType()));
Record.push_back(VE.getValueID(Equiv->getGlobalValue()));
} else {
#ifndef NDEBUG
C->dump();