diff options
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
| -rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 77 |
1 files changed, 64 insertions, 13 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 8519796deeb1..05c969712337 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -30,6 +30,7 @@ #include "llvm/IR/CallingConv.h" #include "llvm/IR/Comdat.h" #include "llvm/IR/Constant.h" +#include "llvm/IR/ConstantRangeList.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DebugInfo.h" @@ -57,6 +58,7 @@ #include "llvm/IR/Module.h" #include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/ProfDataUtils.h" #include "llvm/IR/Type.h" #include "llvm/IR/Value.h" #include "llvm/IR/Verifier.h" @@ -108,6 +110,7 @@ cl::opt<cl::boolOrDefault> LoadBitcodeIntoNewDbgInfoFormat( "load-bitcode-into-experimental-debuginfo-iterators", cl::Hidden, cl::desc("Load bitcode directly into the new debug info format (regardless " "of input format)")); +extern cl::opt<bool> UseNewDbgInfoFormat; extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat; extern bool WriteNewDbgInfoFormatToBitcode; extern cl::opt<bool> WriteNewDbgInfoFormat; @@ -836,10 +839,10 @@ private: } Expected<ConstantRange> readConstantRange(ArrayRef<uint64_t> Record, - unsigned &OpNum) { - if (Record.size() - OpNum < 3) + unsigned &OpNum, + unsigned BitWidth) { + if (Record.size() - OpNum < 2) return error("Too few records for range"); - unsigned BitWidth = Record[OpNum++]; if (BitWidth > 64) { unsigned LowerActiveWords = Record[OpNum]; unsigned UpperActiveWords = Record[OpNum++] >> 32; @@ -859,6 +862,14 @@ private: } } + Expected<ConstantRange> + readBitWidthAndConstantRange(ArrayRef<uint64_t> Record, unsigned &OpNum) { + if (Record.size() - OpNum < 1) + return error("Too few records for range"); + unsigned BitWidth = Record[OpNum++]; + return readConstantRange(Record, OpNum, BitWidth); + } + /// Upgrades old-style typeless byval/sret/inalloca attributes by adding the /// corresponding argument's pointee type. Also upgrades intrinsics that now /// require an elementtype attribute. @@ -2128,6 +2139,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) { return Attribute::SanitizeThread; case bitc::ATTR_KIND_SANITIZE_MEMORY: return Attribute::SanitizeMemory; + case bitc::ATTR_KIND_SANITIZE_NUMERICAL_STABILITY: + return Attribute::SanitizeNumericalStability; case bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING: return Attribute::SpeculativeLoadHardening; case bitc::ATTR_KIND_SWIFT_ERROR: @@ -2170,6 +2183,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) { return Attribute::DeadOnUnwind; case bitc::ATTR_KIND_RANGE: return Attribute::Range; + case bitc::ATTR_KIND_INITIALIZES: + return Attribute::Initializes; } } @@ -2348,12 +2363,39 @@ Error BitcodeReader::parseAttributeGroupBlock() { if (!Attribute::isConstantRangeAttrKind(Kind)) return error("Not a ConstantRange attribute"); - Expected<ConstantRange> MaybeCR = readConstantRange(Record, i); + Expected<ConstantRange> MaybeCR = + readBitWidthAndConstantRange(Record, i); if (!MaybeCR) return MaybeCR.takeError(); i--; B.addConstantRangeAttr(Kind, MaybeCR.get()); + } else if (Record[i] == 8) { + Attribute::AttrKind Kind; + + i++; + if (Error Err = parseAttrKind(Record[i++], &Kind)) + return Err; + if (!Attribute::isConstantRangeListAttrKind(Kind)) + return error("Not a constant range list attribute"); + + SmallVector<ConstantRange, 2> Val; + if (i + 2 > e) + return error("Too few records for constant range list"); + unsigned RangeSize = Record[i++]; + unsigned BitWidth = Record[i++]; + for (unsigned Idx = 0; Idx < RangeSize; ++Idx) { + Expected<ConstantRange> MaybeCR = + readConstantRange(Record, i, BitWidth); + if (!MaybeCR) + return MaybeCR.takeError(); + Val.push_back(MaybeCR.get()); + } + i--; + + if (!ConstantRangeList::isOrderedRanges(Val)) + return error("Invalid (unordered or overlapping) range list"); + B.addConstantRangeListAttr(Kind, Val); } else { return error("Invalid attribute group entry"); } @@ -3186,7 +3228,7 @@ Error BitcodeReader::parseConstants() { V = ConstantFP::get( CurTy, APFloat(APFloat::PPCDoubleDouble(), APInt(128, Record))); else - V = UndefValue::get(CurTy); + V = PoisonValue::get(CurTy); break; } @@ -3209,7 +3251,7 @@ Error BitcodeReader::parseConstants() { V = BitcodeConstant::create( Alloc, CurTy, BitcodeConstant::ConstantVectorOpcode, Elts); } else { - V = UndefValue::get(CurTy); + V = PoisonValue::get(CurTy); } break; } @@ -3290,7 +3332,7 @@ Error BitcodeReader::parseConstants() { return error("Invalid unary op constexpr record"); int Opc = getDecodedUnaryOpcode(Record[0], CurTy); if (Opc < 0) { - V = UndefValue::get(CurTy); // Unknown unop. + V = PoisonValue::get(CurTy); // Unknown unop. } else { V = BitcodeConstant::create(Alloc, CurTy, Opc, (unsigned)Record[1]); } @@ -3301,7 +3343,7 @@ Error BitcodeReader::parseConstants() { return error("Invalid binary op constexpr record"); int Opc = getDecodedBinaryOpcode(Record[0], CurTy); if (Opc < 0) { - V = UndefValue::get(CurTy); // Unknown binop. + V = PoisonValue::get(CurTy); // Unknown binop. } else { uint8_t Flags = 0; if (Record.size() >= 4) { @@ -3331,7 +3373,7 @@ Error BitcodeReader::parseConstants() { return error("Invalid cast constexpr record"); int Opc = getDecodedCastOpcode(Record[0]); if (Opc < 0) { - V = UndefValue::get(CurTy); // Unknown cast. + V = PoisonValue::get(CurTy); // Unknown cast. } else { unsigned OpTyID = Record[1]; Type *OpTy = getTypeByID(OpTyID); @@ -3368,7 +3410,8 @@ Error BitcodeReader::parseConstants() { (void)InRangeIndex; } else if (BitCode == bitc::CST_CODE_CE_GEP_WITH_INRANGE) { Flags = Record[OpNum++]; - Expected<ConstantRange> MaybeInRange = readConstantRange(Record, OpNum); + Expected<ConstantRange> MaybeInRange = + readBitWidthAndConstantRange(Record, OpNum); if (!MaybeInRange) return MaybeInRange.takeError(); InRange = MaybeInRange.get(); @@ -4355,7 +4398,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit, if (PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE) { TheModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat && - LoadBitcodeIntoNewDbgInfoFormat == cl::boolOrDefault::BOU_TRUE; + LoadBitcodeIntoNewDbgInfoFormat != cl::boolOrDefault::BOU_FALSE; } this->ValueTypeCallback = std::move(Callbacks.ValueType); @@ -6949,8 +6992,10 @@ Error BitcodeReader::materialize(GlobalValue *GV) { else continue; // ignore and continue. + unsigned Offset = getBranchWeightOffset(MD); + // If branch weight doesn't match, just strip branch weight. - if (MD->getNumOperands() != 1 + ExpectedNumOperands) + if (MD->getNumOperands() != Offset + ExpectedNumOperands) I.setMetadata(LLVMContext::MD_prof, nullptr); } } @@ -7327,7 +7372,13 @@ ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef<uint64_t> Record, bool IsOldProfileFormat, bool HasProfile, bool HasRelBF) { std::vector<FunctionSummary::EdgeTy> Ret; - Ret.reserve(Record.size()); + // In the case of new profile formats, there are two Record entries per + // Edge. Otherwise, conservatively reserve up to Record.size. + if (!IsOldProfileFormat && (HasProfile || HasRelBF)) + Ret.reserve(Record.size() / 2); + else + Ret.reserve(Record.size()); + for (unsigned I = 0, E = Record.size(); I != E; ++I) { CalleeInfo::HotnessType Hotness = CalleeInfo::HotnessType::Unknown; bool HasTailCall = false; |
