aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Value.cpp
AgeCommit message (Collapse)AuthorFilesLines
12 days[NFC][LLVM][IR] Fix namespace usage in several files (#161756)Rahul Joshi1-1/+1
- Move standalone functions/variables out of anonymous namespace and make them static. - Use `using namespace llvm` instead of wrapping all the code in a file in `namespace llvm { }`. - Restrict anonymous namespace to just class/struct/enum declarations.
14 daysCleanup the LLVM exported symbols namespace (#161240)Nicolai Hähnle1-1/+1
There's a pattern throughout LLVM of cl::opts being exported. That in itself is probably a bit unfortunate, but what's especially bad about it is that a lot of those symbols are in the global namespace. Move them into the llvm namespace. While doing this, I noticed some other variables in the global namespace and moved them as well.
2025-09-30[IR] Don't create ptrtoint expression to determine alignment (NFCI) (#161364)Nikita Popov1-8/+6
We try to determine the alignment of a constant by creating a ptrtoint expression and seeing if it folds. I believe the only case this can actually handle is where the constant is an inttoptr expression. Handle that directly instead of going through another ptrtoint expression. I ran into this while trying to clean up our isEliminableCastPair() mess, which is going to disable ptrtoint(inttoptr) folding without DataLayout, breaking this code.
2025-09-02[IR] Allow nofree metadata to inttoptr (#153149)Ruiling, Song1-0/+3
Our GPU compiler usually construct pointers through inttoptr. The memory was pre-allocated before the shader function execution and remains valid through the execution of the shader function. This brings back the expected behavior of instruction hoisting for the test `hoist-speculatable-load.ll`, which was broken by #126117.
2025-08-08Revert "[IR] Optimize stripAndAccumulateConstantOffsets() for common case (NFC)"Nikita Popov1-26/+20
This reverts commit a7edc95c799c46665ecf4465a4dc7ff4bee3ced0. An issue has been reported at: https://github.com/llvm/llvm-project/commit/a7edc95c799c46665ecf4465a4dc7ff4bee3ced0#commitcomment-163691175
2025-07-23[IR] Optimize stripAndAccumulateConstantOffsets() for common case (NFC)Nikita Popov1-20/+26
For the common case where we don't have bit width changing address space casts, we can directly call accumulateConstantOffset() on the original Offset. Skip the bit width reconciliation logic in that case.
2025-07-21[DebugInfo] Remove intrinsic-flavours of findDbgUsers (#149816)Jeremy Morse1-7/+2
This is one of the final remaining debug-intrinsic specific codepaths out there, and pieces of cross-LLVM infrastructure to do with debug intrinsics.
2025-06-09Remove GlobalObject::getAlign/setAlignment (#143188)Eli Friedman1-22/+19
Currently, GlobalObject has an "alignment" property... but it's basically nonsense: alignment doesn't mean the same thing for variables and functions, and it's completely meaningless for ifuncs. This "removes" (actually marking protected) the methods from GlobalObject, adds the relevant methods to Function and GlobalVariable, and adjusts the code appropriately. This should make future alignment-related cleanups easier.
2025-05-08Reapply "IR: Remove reference counts from ConstantData (#137314)" (#138962)Matt Arsenault1-13/+17
This reverts commit 0274232b87177779e5c985eca06df22bf140f6cb.
2025-05-08Reapply "IR: Remove uselist for constantdata (#137313)" (#138961)Matt Arsenault1-8/+18
Reapply "IR: Remove uselist for constantdata (#137313)" This reverts commit 5936c02c8b9c6d1476f7830517781ce8b6e26e75. Fix checking uselists of constants in assume bundle queries
2025-05-07Revert "IR: Remove uselist for constantdata (#137313)"Kirill Stoimenov1-18/+8
Possibly breaks the build: https://lab.llvm.org/buildbot/#/builders/24/builds/8119 This reverts commit 87f312aad6ede636cd2de5d18f3058bf2caf5651.
2025-05-07Revert "IR: Remove reference counts from ConstantData (#137314)"Kirill Stoimenov1-17/+13
This reverts commit 51a3bd919d68a8fb1b026377d6e86b1523d37433. Possible breaks the build: https://lab.llvm.org/buildbot/#/builders/24/builds/8119/steps/9/logs/stdio
2025-05-06IR: Remove reference counts from ConstantData (#137314)Matt Arsenault1-13/+17
This is a follow up change to eliminating uselists for ConstantData. In the previous revision, ConstantData had a replacement reference count instead of a uselist. This reference count was misleading, and not useful in the same way as it would be for another value. The references may not have even been in the current module, since these are shared throughout the LLVMContext. This doesn't space leak any more than we previously did; nothing was attempting to garbage collect unused constants. Previously the use_empty, and hasNUses type of APIs were supported through the reference count. These now behave as if the uses are always empty. Ideally it would be illegal to inspect these, but this forces API complexity into quite a few places. It may be doable to make it illegal to check these counts, but I would like there to be a targeted fuzzing effort to make sure every transform properly deals with a constant in every operand position. All tests pass if I turn the hasNUses* and getNumUses queries into assertions, only hasOneUse in particular appears to hit in some set of contexts. I've added unit tests to ensure logical consistency between these cases
2025-05-06IR: Remove uselist for constantdata (#137313)Matt Arsenault1-8/+18
This is a resurrected version of the patch attached to this RFC: https://discourse.llvm.org/t/rfc-constantdata-should-not-have-use-lists/42606 In this adaptation, there are a few differences. In the original patch, the Use's use list was replaced with an unsigned* to the reference count in the value. This version leaves them as null and leaves the ref counting only in Value. Remove use-lists from instances of ConstantData (which are shared across modules and have no operands). To continue supporting most of the use-list API, store a ref-count in place of the use-list; this is for API like Value::use_empty and Value::hasNUses. Operations that actually need the use-list -- like Value::use_begin -- will assert. This change has three benefits: 1. The compiler output cannot in any way depend on the use-list order of instances of ConstantData. 2. There's no use-list traffic when adding and removing simple constants from operand lists (although there is ref-count traffic; YMMV). 3. It's cheaper to serialize use-lists (since we're no longer serializing the use-list order of things like i32 0). The downside is that you can't look at all the users of ConstantData, but traversals of users of i32 0 are already ill-advised. Possible follow-ups: - Track if an instance of a ConstantVector/ConstantArray/etc. is known to have all ConstantData arguments, and drop the use-lists to ref-counts in those cases. Callers need to check Value::hasUseList before iterating through the use-list. - Remove even the ref-counts. I'm not sure they have any benefit besides minimizing the scope of this commit, and maintaining the counts is not free. Fixes #58629 Co-authored-by: Duncan P. N. Exon Smith <dexonsmith@apple.com>
2025-04-23[llvm-extract] support unnamed bbs. (#135140)Allin Lee1-2/+0
Dear developer: I have recently working with LLVM IR and I want to isolate basic blocks using the command "llvm-extract". However, I found that the command option "llvm-extract --bb func_name:bb_name" will only function when dumping source code into IRs with options "-fno-discard-value-names". That is to say, the "llvm-extract" command cannot support unnamed basic blocks, which is a default output of the compiler. So, I made these changes and hope they will make LLVM better. Best regards, Co-authored-by: Yilin Li <allinleeme@gmail.com>
2025-04-19IR: Avoid repeating assert condition in Value destructor (#136340)Matt Arsenault1-1/+2
2025-04-07Value: Remove redundant removeFromList in dropDroppableUse (#134580)Matt Arsenault1-1/+0
2025-04-07IR: Use poison in dropDroppableUse (#134576)Matt Arsenault1-1/+1
2025-04-07IR: Fix typo in unreachable messageMatt Arsenault1-1/+1
2025-01-30[Value] Look through inttoptr (add ..) in accumulateConstantOffsets (#124981)Florian Hahn1-1/+20
Look through inttoptr (add (ptrtoint P), C) when accumulating offsets. Adds a missing fold after https://github.com/llvm/llvm-project/pull/123518 Alive2 for the tests with changes: https://alive2.llvm.org/ce/z/VvPrzv PR: https://github.com/llvm/llvm-project/pull/124981
2025-01-17[Loads] Respect UseDerefAtPointSemantics in isDerefAndAlignedPointer. (#123196)Florian Hahn1-1/+1
If a pointer gets freed, it may not be dereferenceable any longer, even though there is a dominating dereferenceable assumption. As first step, only consider assumptions if the pointer value cannot be freed if UseDerefAtPointSemantics is used. PR: https://github.com/llvm/llvm-project/pull/123196
2025-01-16[Options] Use UseDerefAtPointSemantics cl::opt<bool>. (#123192)Florian Hahn1-1/+1
It is used as boolean option, use cl::opt<bool> instead of vl::opt<unsigned>. PR: https://github.com/llvm/llvm-project/pull/123192
2024-07-04[IR] Don't strip through pointer to vector of pointer bitcastsNikita Popov1-2/+3
When using stripPointerCasts() and getUnderlyingObject(), don't strip through a bitcast from ptr to <1 x ptr>, which is not a no-op pointer cast. Calling code is generally not prepared to handle that situation, resulting in incorrect alias analysis results for example. Fixes https://github.com/llvm/llvm-project/issues/97600.
2024-03-20[RemoveDIs][NFC] Rename DPMarker->DbgMarker (#85931)Stephen Tozer1-1/+1
Another trivial rename patch, the last big one for now, which renamed DPMarkers to DbgMarkers. This required the field `DbgMarker` in `Instruction` to be renamed to `DebugMarker` to avoid a clash, but otherwise was a simple string substitution of `s/DPMarker/DbgMarker` and a manual renaming of `DPM` to `DM` in the few places where that acronym was used for debug markers.
2024-03-19[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)Stephen Tozer1-4/+4
This is the major rename patch that prior patches have built towards. The DPValue class is being renamed to DbgVariableRecord, which reflects the updated terminology for the "final" implementation of the RemoveDI feature. This is a pure string substitution + clang-format patch. The only manual component of this patch was determining where to perform these string substitutions: `DPValue` and `DPV` are almost exclusively used for DbgRecords, *except* for: - llvm/lib/target, where 'DP' is used to mean double-precision, and so appears as part of .td files and in variable names. NB: There is a single existing use of `DPValue` here that refers to debug info, which I've manually updated. - llvm/tools/gold, where 'LDPV' is used as a prefix for symbol visibility enums. Outside of these places, I've applied several basic string substitutions, with the intent that they only affect DbgRecord-related identifiers; I've checked them as I went through to verify this, with reasonable confidence that there are no unintended changes that slipped through the cracks. The substitutions applied are all case-sensitive, and are applied in the order shown: ``` DPValue -> DbgVariableRecord DPVal -> DbgVarRec DPV -> DVR ``` Following the previous rename patches, it should be the case that there are no instances of any of these strings that are meant to refer to the general case of DbgRecords, or anything other than the DPValue class. The idea behind this patch is therefore that pure string substitution is correct in all cases as long as these assumptions hold.
2024-01-12[IR] Reorder Value fields to put the SubclassID first (#53520)Reid Kleckner1-3/+3
Placing the class id at offset 0 should make `isa` and `dyn_cast` faster by eliminating the field offset (previously 0x10) from the memory operand, saving encoding space on x86, and, in theory, an add micro-op. You can see the load encodes one byte smaller here: https://godbolt.org/z/Whvz4can9 The compile time tracker shows some modestly positive results in the on the `cycle` metric and in the final clang binary size metric: https://llvm-compile-time-tracker.com/compare.php?from=33b54f01fe32030ff60d661a7a951e33360f82ee&to=2530347a57401744293c54f92f9781fbdae3d8c2&stat=cycles Clicking through to the per-library size breakdown shows that instcombine size reduces by 0.68%, which is meaningful, and I believe instcombine is known to be a hotspot. It is, however, potentially noise. I still think we should do this, because notionally, the class id really acts as the vptr of the Value, and conventionally the vptr is always at offset 0.
2024-01-04[IR] Fix GEP offset computations for vector GEPs (#75448)Jannik Silvanus1-1/+1
Vectors are always bit-packed and don't respect the elements' alignment requirements. This is different from arrays. This means offsets of vector GEPs need to be computed differently than offsets of array GEPs. This PR fixes many places that rely on an incorrect pattern that always relies on `DL.getTypeAllocSize(GTI.getIndexedType())`. We replace these by usages of `GTI.getSequentialElementStride(DL)`, which is a new helper function added in this PR. This changes behavior for GEPs into vectors with element types for which the (bit) size and alloc size is different. This includes two cases: * Types with a bit size that is not a multiple of a byte, e.g. i1. GEPs into such vectors are questionable to begin with, as some elements are not even addressable. * Overaligned types, e.g. i16 with 32-bit alignment. Existing tests are unaffected, but a miscompilation of a new test is fixed. --------- Co-authored-by: Nikita Popov <github@npopov.com>
2023-11-22[IR][TLI] Cache getLibFunc() result on Function (NFC) (#72867)Nikita Popov1-1/+1
Cache the result of the TLI libfunc lookup in the Function object. This only caches the actual lookup of the LibFunc in the TLI map, but not the prototype validation, as that might differ between different TLI instances. This uses the existing mechanism for invalidating the intrinsic ID when the function name changes. The libfunc will be invalidated in that case as well. I don't believe this increases the size of Function on 64bit (which currently has a trailing `bool` member), and I don't think we would particularly care if it did, as Functions are uncommon as Values go.
2023-11-18[DebugInfo][RemoveDIs] Support finding DPValues like dbg.values (#71952)Jeremy Morse1-1/+7
This patch extends findDbgValue and friends to optionally fill out a vector of DPValue pointers, containing DPValues that refer to the sought Value. This will allow us to incrementally add instrumentation to other optimisation passes one-at-a-time, while un-instrumented passes will not (yet) update DPValues. Unit tests to check this behaves in the same way as dbg.values.
2023-10-18[llvm] Use StringRef::contains (NFC)Kazu Hirata1-2/+1
2023-04-19[NFC] Rename isPointerOffset to getPointerOffsetFrom and move to Value.hOCHyams1-0/+73
Linking LLVMCore failed when building D148536 with shared libs enabled: https://lab.llvm.org/buildbot/#/builders/121/builds/29766 Make isPointerOffset a Value method and rename it to getPointerOffsetFrom. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D148698
2023-03-31[IR] Allow destruction of symbol table entries regardless of DiscardValueNamesYevgeny Rouban1-12/+14
Value::setNameImpl() is used both to set and reset name of the value. In destructor of Function all arguments get reset their names (see Function::clearArguments()). If the arguments had their names set (e.g. when the function was created with LLVMContex::DiscardValueNames == true) then their ValueName entries referred by the function's symbol table must be destructed. They are not destructed if LLVMContex::DiscardValueNames is set to false because of the fast path in Value::setNameImpl(). See the new test cases that demonstrate the problem. Without the fix they both crash in the function's destructor. In Value::setNameImpl() this patch narrows down the fast path return for DiscardValueNames == true to allow destruction of ValueName entries if any. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D143487
2023-02-19Use APInt::getSignificantBits instead of APInt::getMinSignedBits (NFC)Kazu Hirata1-1/+1
Note that getMinSignedBits has been soft-deprecated in favor of getSignificantBits.
2023-02-19Use APInt::count{l,r}_{zero,one} (NFC)Kazu Hirata1-1/+1
2023-01-11[NFC] Use TypeSize::geFixedValue() instead of TypeSize::getFixedSize()Guillaume Chatelet1-1/+1
This change is one of a series to implement the discussion from https://reviews.llvm.org/D141134.
2023-01-11[NFC] Use TypeSize::getKnownMinValue() instead of TypeSize::getKnownMinSize()Guillaume Chatelet1-2/+2
This change is one of a series to implement the discussion from https://reviews.llvm.org/D141134.
2022-12-25[NFC][ADT] Rename StringMapEntry *Create() into StringMapEntry *create.Alexey Lapshin1-1/+1
2022-12-02[AsmPrinter] .addrsig_sym: remove isTransitiveUsedByMetadataOnlyFangrui Song1-16/+0
With D135642 ignoring unregistered symbols, isTransitiveUsedByMetadataOnly added by D101512 is no longer needed (the operation is potentially slow). There is a `.addrsig_sym` directive for an only-used-by-metadata symbol but it does not emit an entry. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D138362
2022-10-27[IR] Allow typed pointers to be used in vector typesDmitry Sidorov1-1/+1
Reviewed By: nikic, jcranmer-intel Differential Revision: https://reviews.llvm.org/D136768
2022-08-08[llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-1/+1
With C++17 there is no Clang pedantic warning or MSVC C5051.
2022-08-04[IR] Move support for dxil::TypedPointerType to LLVM core IR.Joshua Cranmer1-0/+3
This allows the construct to be shared between different backends. However, it still remains illegal to use TypedPointerType in LLVM IR--the type is intended to remain an auxiliary type, not a real LLVM type. So no support is provided for LLVM-C, nor bitcode, nor LLVM assembly (besides the bare minimum needed to make Type->dump() work properly). Reviewed By: beanz, nikic, aeubanks Differential Revision: https://reviews.llvm.org/D130592
2022-06-30[IR] Fix typo in comment. NFCFraser Cormack1-1/+1
2022-04-11Value::isTransitiveUsedByMetadataOnly: Don't repeatedly add an element to ↵Fangrui Song1-7/+3
the worklist. NFC
2022-03-12Cleanup includes: DebugInfo & CodeGenserge-sans-paille1-1/+0
Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121332
2022-03-07[Attributor] Remove function pointer restriction for AAAlignNikita Popov1-0/+3
This check is not compatible with opaque pointers. We can avoid it by adjusting the getPointerAlignment() implementation to avoid creating unnecessary ptrtoint expressions for bitcasted pointers. The code already uses OnlyIfReduced to not create an expression if it does not simplify, and this makes sure that folding a bitcast and ptrtoint into a ptrtoint doesn't count as a simplification. Differential Revision: https://reviews.llvm.org/D120904
2022-02-13[NFC][IR] Value: assert this->takeName(this)Dmitry Vassiliev1-0/+1
Need to add an assert about this->takeName(this). This restriction is already documented, so this is just an NFC check. Without this assertion (as prescribed by original comments for this API), name deletion or down-stream assert failures may occur in other routines: e.g. at the beginning of replaceAllUsesWith() below. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D119636
2022-02-02Cleanup header dependencies in LLVMCoreserge-sans-paille1-3/+0
Based on the output of include-what-you-use. This is a big chunk of changes. It is very likely to break downstream code unless they took a lot of care in avoiding hidden ehader dependencies, something the LLVM codebase doesn't do that well :-/ I've tried to summarize the biggest change below: - llvm/include/llvm-c/Core.h: no longer includes llvm-c/ErrorHandling.h - llvm/IR/DIBuilder.h no longer includes llvm/IR/DebugInfo.h - llvm/IR/IRBuilder.h no longer includes llvm/IR/IntrinsicInst.h - llvm/IR/LLVMRemarkStreamer.h no longer includes llvm/Support/ToolOutputFile.h - llvm/IR/LegacyPassManager.h no longer include llvm/Pass.h - llvm/IR/Type.h no longer includes llvm/ADT/SmallPtrSet.h - llvm/IR/PassManager.h no longer includes llvm/Pass.h nor llvm/Support/Debug.h And the usual count of preprocessed lines: $ clang++ -E -Iinclude -I../llvm/include ../llvm/lib/IR/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 6400831 after: 6189948 200k lines less to process is no that bad ;-) Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D118652
2021-12-09[NFC] Replace some deprecated getAlignment() calls with getAlign()Arthur Eubanks1-1/+1
Reviewed By: gchatelet Differential Revision: https://reviews.llvm.org/D115370
2021-11-05[llvm] Use make_early_inc_range (NFC)Kazu Hirata1-3/+1
2021-10-25[InstSimplify] Refactor invariant.group load foldingNikita Popov1-0/+3
Currently strip.invariant/launder.invariant are handled by constructing constant expressions with the intrinsics skipped. This takes an alternative approach of accumulating the offset using stripAndAccumulateConstantOffsets(), with a flag to look through invariant.group intrinsics. Differential Revision: https://reviews.llvm.org/D112382