From c5aeca732d1ff6769b0659efebd1cfb5f60487e4 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Mon, 10 Jun 2024 09:14:14 +0100 Subject: Reapply#3 "[RemoveDIs] Load into new debug info format by default in LLVM (#89799)" Reapplies commit 91446e2, which was reverted due to a downstream error, discussed on the pull request. The error could not be reproduced upstream, and cannot be reproduced downstream as-of current main, so until the error can be confirmed to still exist this patch should return. This reverts commit 23f8fac745bdde70ed4f9c585d19c4913734f1b8. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 8519796deeb1..026595bdc634 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4355,7 +4355,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); -- cgit v1.2.3 From c4f8ae6f32dadf9383c94ed13152d91f68631255 Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov <6532716+alexander-shaposhnikov@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:53:22 -0700 Subject: [LLVM][IR][Sanitizers] Add sanitize_numerical_stability attribute (#95051) Add sanitize_numerical_stability attribute. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 026595bdc634..40852a6fd404 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2128,6 +2128,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: -- cgit v1.2.3 From 2dc2290860355dd2bac3b655eea895fe30fde257 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 11 Jun 2024 12:15:09 +0100 Subject: Revert new debug info format commits: "[Flang] Update test to not check for tail calls on debug intrinsics" & "Reapply#3 "[RemoveDIs] Load into new debug info format by default in LLVM (#89799)" Recent updates to flang have added debug info generation via MLIR, a path which currently does not support debug records. The patch that enables debug records by default (and a small followup patch) are thus being reverted until the MLIR path has been fixed. This reverts commits: 21396be865b4640abf6afa0b05de6708a1a996e0 c5aeca732d1ff6769b0659efebd1cfb5f60487e4 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 40852a6fd404..c667913005cd 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4357,7 +4357,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit, if (PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE) { TheModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat && - LoadBitcodeIntoNewDbgInfoFormat != cl::boolOrDefault::BOU_FALSE; + LoadBitcodeIntoNewDbgInfoFormat == cl::boolOrDefault::BOU_TRUE; } this->ValueTypeCallback = std::move(Callbacks.ValueType); -- cgit v1.2.3 From 294f3ce5dde916c358d8f672b4a1c706c0387154 Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Wed, 12 Jun 2024 12:52:28 -0700 Subject: =?UTF-8?q?Reapply=20"[llvm][IR]=20Extend=20BranchWeightMetadata?= =?UTF-8?q?=20to=20track=20provenance=20o=E2=80=A6=20(#95281)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …f weights" #95136 Reverts #95060, and relands #86609, with the unintended code generation changes addressed. This patch implements the changes to LLVM IR discussed in https://discourse.llvm.org/t/rfc-update-branch-weights-metadata-to-allow-tracking-branch-weight-origins/75032 In this patch, we add an optional field to MD_prof meatdata nodes for branch weights, which can be used to distinguish weights added from llvm.expect* intrinsics from those added via other methods, e.g. from profiles or inserted by the compiler. One of the major motivations, is for use with MisExpect diagnostics, which need to know if branch_weight metadata originates from an llvm.expect intrinsic. Without that information, we end up checking branch weights multiple times in the case if ThinLTO + SampleProfiling, leading to some inaccuracy in how we report MisExpect related diagnostics to users. Since we change the format of MD_prof metadata in a fundamental way, we need to update code handling branch weights in a number of places. We also update the lang ref for branch weights to reflect the change. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index c667913005cd..4ad3a2eaceea 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -57,6 +57,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" @@ -6951,8 +6952,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); } } -- cgit v1.2.3 From dc726c340392d4a0f3af9dde5f34c58d98198667 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Thu, 13 Jun 2024 17:21:24 +0100 Subject: Reapply#4 "[RemoveDIs] Load into new debug info format by default in LLVM (#89799)" Reapplies commit c5aeca73 (and its followup commit 21396be8), which were reverted due to missing functionality in MLIR and Flang regarding printing debug records. This has now been added in commit 08aa511, along with support for printing debug records in flang. This reverts commit 2dc2290860355dd2bac3b655eea895fe30fde257. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 4ad3a2eaceea..af5d6891805a 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4358,7 +4358,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); -- cgit v1.2.3 From 49ae2dcf369e0fd76e4bb18f1c84e6716ff0ec4b Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 20 Jun 2024 17:41:35 +0200 Subject: [PassManager] Remove some unnecessary includes (NFC) (#96175) SmallPtrSet.h and TimeProfiler.h are unused. CommandLine.h is only needed for the UseNewDbgInfoFormat declare, which can be moved to the places that need it. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index af5d6891805a..06d99366a8c3 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -109,6 +109,7 @@ cl::opt 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 UseNewDbgInfoFormat; extern cl::opt PreserveInputDbgFormat; extern bool WriteNewDbgInfoFormatToBitcode; extern cl::opt WriteNewDbgInfoFormat; -- cgit v1.2.3 From e1e5ed5893c50918dc9b6b56acfe6242f03354dc Mon Sep 17 00:00:00 2001 From: Jan Voung Date: Thu, 20 Jun 2024 21:04:14 -0400 Subject: Update ModuleSummaryIndexBitcodeReader::makeCallList reserve amount (#95461) Tighten the reserve() to `Record.size() / 2` instead of `Record.size()` in the HasProfile/HasRelBF cases. For the uncommon old profile format cases we leave it as is, but those should be rare and not worth optimizing. This reduces peak memory during ThinLTO indexing by ~3% in one example. Alternatively, we could make the branching for reserve more complex and try to cover every case. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 06d99366a8c3..6bcd0c17400d 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -7333,7 +7333,13 @@ ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef Record, bool IsOldProfileFormat, bool HasProfile, bool HasRelBF) { std::vector 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; -- cgit v1.2.3 From 5ece35df8586d0cb8c104a9f44eaae771de025f5 Mon Sep 17 00:00:00 2001 From: Haopeng Liu <153236845+haopliu@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:09:00 -0700 Subject: Add the 'initializes' attribute langref and support (#84803) We propose adding a new LLVM attribute, `initializes((Lo1,Hi1),(Lo2,Hi2),...)`, which expresses the notion of memory space (i.e., intervals, in bytes) that the argument pointing to is initialized in the function. Will commit the attribute inferring in the follow-up PRs. https://discourse.llvm.org/t/rfc-llvm-new-initialized-parameter-attribute-for-improved-interprocedural-dse/77337 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 49 +++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 6bcd0c17400d..6c6c5d56e134 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" @@ -838,10 +839,10 @@ private: } Expected readConstantRange(ArrayRef 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; @@ -861,6 +862,14 @@ private: } } + Expected + readBitWidthAndConstantRange(ArrayRef 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. @@ -2174,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; } } @@ -2352,12 +2363,39 @@ Error BitcodeReader::parseAttributeGroupBlock() { if (!Attribute::isConstantRangeAttrKind(Kind)) return error("Not a ConstantRange attribute"); - Expected MaybeCR = readConstantRange(Record, i); + Expected 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 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 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"); } @@ -3372,7 +3410,8 @@ Error BitcodeReader::parseConstants() { (void)InRangeIndex; } else if (BitCode == bitc::CST_CODE_CE_GEP_WITH_INRANGE) { Flags = Record[OpNum++]; - Expected MaybeInRange = readConstantRange(Record, OpNum); + Expected MaybeInRange = + readBitWidthAndConstantRange(Record, OpNum); if (!MaybeInRange) return MaybeInRange.takeError(); InRange = MaybeInRange.get(); -- cgit v1.2.3 From 6258b5f610d51d37a79456d660b12c2d8e98500b Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 24 Jun 2024 16:36:46 +0200 Subject: [BitcodeReader] Use poison instead of undef for invalid instructions --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 6c6c5d56e134..05c969712337 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3228,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; } @@ -3251,7 +3251,7 @@ Error BitcodeReader::parseConstants() { V = BitcodeConstant::create( Alloc, CurTy, BitcodeConstant::ConstantVectorOpcode, Elts); } else { - V = UndefValue::get(CurTy); + V = PoisonValue::get(CurTy); } break; } @@ -3332,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]); } @@ -3343,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) { @@ -3373,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); -- cgit v1.2.3