[IR] Add a target extension type to LLVM.

Target-extension types represent types that need to be preserved through
optimization, but otherwise are not introspectable by target-independent
optimizations. This patch doesn't add any uses of these types by an existing
backend, it only provides basic infrastructure such that these types would work
correctly.

Reviewed By: nikic, barannikov88

Differential Revision: https://reviews.llvm.org/D135202
This commit is contained in:
Joshua Cranmer
2022-12-20 11:02:11 -05:00
parent e43924a751
commit e6b02214c6
34 changed files with 717 additions and 7 deletions

View File

@@ -2486,6 +2486,35 @@ Error BitcodeReader::parseTypeTableBody() {
ResultTy = Res;
break;
}
case bitc::TYPE_CODE_TARGET_TYPE: { // TARGET_TYPE: [NumTy, Tys..., Ints...]
if (Record.size() < 1)
return error("Invalid target extension type record");
if (NumRecords >= TypeList.size())
return error("Invalid TYPE table");
if (Record[0] >= Record.size())
return error("Too many type parameters");
unsigned NumTys = Record[0];
SmallVector<Type *, 4> TypeParams;
SmallVector<unsigned, 8> IntParams;
for (unsigned i = 0; i < NumTys; i++) {
if (Type *T = getTypeByID(Record[i + 1]))
TypeParams.push_back(T);
else
return error("Invalid type");
}
for (unsigned i = NumTys + 1, e = Record.size(); i < e; i++) {
if (Record[i] > UINT_MAX)
return error("Integer parameter too large");
IntParams.push_back(Record[i]);
}
ResultTy = TargetExtType::get(Context, TypeName, TypeParams, IntParams);
TypeName.clear();
break;
}
case bitc::TYPE_CODE_ARRAY: // ARRAY: [numelts, eltty]
if (Record.size() < 2)
return error("Invalid array type record");
@@ -2989,6 +3018,9 @@ Error BitcodeReader::parseConstants() {
case bitc::CST_CODE_NULL: // NULL
if (CurTy->isVoidTy() || CurTy->isFunctionTy() || CurTy->isLabelTy())
return error("Invalid type for a constant null value");
if (auto *TETy = dyn_cast<TargetExtType>(CurTy))
if (!TETy->hasProperty(TargetExtType::HasZeroInit))
return error("Invalid type for a constant null value");
V = Constant::getNullValue(CurTy);
break;
case bitc::CST_CODE_INTEGER: // INTEGER: [intval]