aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorJoshua Cranmer <joshua.cranmer@intel.com>2022-12-20 11:02:11 -0500
committerJoshua Cranmer <joshua.cranmer@intel.com>2022-12-20 11:02:11 -0500
commite6b02214c68df2c9f826e02310c9352ac652e456 (patch)
tree81280c3f2a940610cd7f2e55393ac618a56c4025 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parente43924a75145d2f9e722f74b673145c3e62bfd07 (diff)
downloadllvm-e6b02214c68df2c9f826e02310c9352ac652e456.zip
llvm-e6b02214c68df2c9f826e02310c9352ac652e456.tar.gz
llvm-e6b02214c68df2c9f826e02310c9352ac652e456.tar.bz2
[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
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index a2de984..d8f6859 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -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]