-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add the 'initializes' attribute langref and support #84803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 30 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
2554c82
Add 'initialized' attribute langref
haopliu a9256bf
Update the LangRef
haopliu 9150ece
Refactor the argument uses collecting to a function
haopliu 206b707
Add 'initialized' attribute support and undo the FunctionAttrs refact…
haopliu eaf5ca0
Update the LangRef (round 2)
haopliu 52cc649
Update FoldingSet.h
haopliu f7fddb0
Change the attribute type to ConstantRangeList
haopliu 3b5955a
Rename attr to initializes
haopliu 6a1df7a
Update CRL about accessing the range of an EmptySet/FullSet
haopliu fe2e0a5
Change CRL.insert to be ordered and no overlapping
haopliu f73df04
Optimize CRL::insert for common cases
haopliu 63c45f6
Update ConstantRangeList
haopliu dcc2b38
Add unit tests for BitcodeReader/Verifier/Assembler
haopliu 9723322
Add a space after commas
haopliu e70988d
Update CRL and unit tests
haopliu 9782c31
Update CRL to merge consecutive ranges
haopliu a924dd3
Handle a common case in CRL::insert and add CRL::dump
haopliu 45cdc34
Nit: change dbgs() to llvm::dbgs()
haopliu 4eeba08
Change the attr impl to TrailingObjects<ConstantRange>
haopliu 502e062
Update LLVMContextImpl.h
haopliu fac03b8
Merge branch 'llvm:main' into dse-commit
haopliu ea3e7c5
Rebase to the latest main
haopliu 7630510
Change getInitializes() to return ArrayRef<ConstantRange>
haopliu a604b4f
Remove llvm::
haopliu f941b24
Update LangRef and ConstantRangeList
haopliu e52fd9d
Update BitCodeReader/Writer
haopliu 8e64fa9
Encode bitwidth once for ConstantRangeList kind attr
haopliu 9ae0fca
Use SpecificBumpPtrAllocator to allocate mem and make sure to call de…
haopliu d4809ab
Refactor readConstantRange and update BitcodeReader
haopliu 99d36cc
Merge branch 'main' into dse-commit
haopliu 96191cd
Change the attr imple back to ConstantRangeList
haopliu 645f577
Add getConstantRangeList unittest
haopliu 2a8ea9a
Add Bitwidth in FoldingSetNodeId
haopliu 37edecd
Merge branch 'main' into dse-commit
haopliu 80306d7
Clean up a redundant check in BitcodeReader
haopliu 67445fe
Change attr impl to normal Alloc w/ a vector and call dtor for each a…
haopliu 68643a5
nit: use uninitialized_copy in the ConstantRangeListAttributeImpl ctor
haopliu 46e8d87
Remove redundant BitWidth in the attr Profile as APInt::Profile alrea…
haopliu 714d02f
Use ConstantRange::contains() in ConstantRangeList::insert()
haopliu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//===- ConstantRangeList.h - A list of constant ranges ----------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Represent a list of signed ConstantRange and do NOT support wrap around the | ||
// end of the numeric range. Ranges in the list are ordered and not overlapping. | ||
// Ranges should have the same bitwidth. Each range's lower should be less than | ||
// its upper. | ||
nikic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_IR_CONSTANTRANGELIST_H | ||
#define LLVM_IR_CONSTANTRANGELIST_H | ||
|
||
#include "llvm/ADT/APInt.h" | ||
#include "llvm/IR/ConstantRange.h" | ||
#include "llvm/Support/Debug.h" | ||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
namespace llvm { | ||
|
||
class raw_ostream; | ||
|
||
/// This class represents a list of constant ranges. | ||
class [[nodiscard]] ConstantRangeList { | ||
SmallVector<ConstantRange, 2> Ranges; | ||
|
||
public: | ||
ConstantRangeList() = default; | ||
ConstantRangeList(ArrayRef<ConstantRange> RangesRef) { | ||
for (const ConstantRange &R : RangesRef) { | ||
nikic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(R.getBitWidth() == getBitWidth()); | ||
Ranges.push_back(R); | ||
} | ||
} | ||
ArrayRef<ConstantRange> rangesRef() const { return Ranges; } | ||
SmallVectorImpl<ConstantRange>::iterator begin() { return Ranges.begin(); } | ||
aeubanks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SmallVectorImpl<ConstantRange>::iterator end() { return Ranges.end(); } | ||
SmallVectorImpl<ConstantRange>::const_iterator begin() const { | ||
return Ranges.begin(); | ||
} | ||
SmallVectorImpl<ConstantRange>::const_iterator end() const { | ||
return Ranges.end(); | ||
} | ||
ConstantRange getRange(unsigned i) const { return Ranges[i]; } | ||
|
||
/// Return true if this list contains no members. | ||
bool empty() const { return Ranges.empty(); } | ||
|
||
/// Get the bit width of this ConstantRangeList. | ||
uint32_t getBitWidth() const { return 64; } | ||
nikic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Return the number of ranges in this ConstantRangeList. | ||
size_t size() const { return Ranges.size(); } | ||
aeubanks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Insert a new range to Ranges and keep the list ordered. | ||
void insert(const ConstantRange &NewRange); | ||
void insert(int64_t Lower, int64_t Upper) { | ||
insert(ConstantRange(APInt(64, Lower, /*isSigned=*/true), | ||
APInt(64, Upper, /*isSigned=*/true))); | ||
} | ||
|
||
/// Return true if this range list is equal to another range list. | ||
bool operator==(const ConstantRangeList &CRL) const { | ||
return Ranges == CRL.Ranges; | ||
} | ||
bool operator!=(const ConstantRangeList &CRL) const { | ||
return !operator==(CRL); | ||
} | ||
|
||
/// Print out the ranges to a stream. | ||
void print(raw_ostream &OS) const; | ||
|
||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||
void dump() const; | ||
nikic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#endif | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_IR_CONSTANTRANGELIST_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -835,10 +836,10 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer { | |
} | ||
|
||
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; | ||
|
@@ -858,6 +859,14 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer { | |
} | ||
} | ||
|
||
Expected<ConstantRange> | ||
readBitWidthAndConstantRange(ArrayRef<uint64_t> Record, unsigned &OpNum) { | ||
if (Record.size() - OpNum < 3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
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. | ||
|
@@ -2159,6 +2168,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; | ||
} | ||
} | ||
|
||
|
@@ -2337,12 +2348,35 @@ 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; | ||
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; | ||
unsigned RangeSize = Record[++i]; | ||
unsigned BitWidth = Record[++i]; | ||
nikic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (i + 2 * RangeSize >= e) | ||
return error("Incomplete constant range list"); | ||
for (unsigned Idx = 0; Idx < RangeSize; ++Idx) { | ||
i++; | ||
nikic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Expected<ConstantRange> MaybeCR = | ||
readConstantRange(Record, i, BitWidth); | ||
if (!MaybeCR) | ||
return MaybeCR.takeError(); | ||
i--; | ||
Val.push_back(MaybeCR.get()); | ||
} | ||
B.addConstantRangeListAttr(Kind, Val); | ||
} else { | ||
return error("Invalid attribute group entry"); | ||
} | ||
|
@@ -3357,7 +3391,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(); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.