Skip to content

Commit 6e2207a

Browse files
committed
Revert "Make BitCodeAbbrev ownership explicit using shared_ptr rather than IntrusiveRefCntPtr"
Breaks Clang's use of bitcode. Reverting until I have a fix to go with it there. This reverts commit r291006. llvm-svn: 291007
1 parent daff78c commit 6e2207a

File tree

7 files changed

+127
-119
lines changed

7 files changed

+127
-119
lines changed

llvm/include/llvm/Bitcode/BitCodes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,11 @@ template <> struct isPodLike<BitCodeAbbrevOp> { static const bool value=true; };
166166
/// BitCodeAbbrev - This class represents an abbreviation record. An
167167
/// abbreviation allows a complex record that has redundancy to be stored in a
168168
/// specialized format instead of the fully-general, fully-vbr, format.
169-
class BitCodeAbbrev {
169+
class BitCodeAbbrev : public RefCountedBase<BitCodeAbbrev> {
170170
SmallVector<BitCodeAbbrevOp, 32> OperandList;
171+
// Only RefCountedBase is allowed to delete.
172+
~BitCodeAbbrev() = default;
173+
friend class RefCountedBase<BitCodeAbbrev>;
171174

172175
public:
173176
unsigned getNumOperandInfos() const {

llvm/include/llvm/Bitcode/BitstreamReader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class BitstreamBlockInfo {
4242
/// describe abbreviations that all blocks of the specified ID inherit.
4343
struct BlockInfo {
4444
unsigned BlockID;
45-
std::vector<std::shared_ptr<BitCodeAbbrev>> Abbrevs;
45+
std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> Abbrevs;
4646
std::string Name;
4747
std::vector<std::pair<unsigned, std::string> > RecordNames;
4848
};
@@ -316,11 +316,11 @@ class BitstreamCursor : SimpleBitstreamCursor {
316316
unsigned CurCodeSize = 2;
317317

318318
/// Abbrevs installed at in this block.
319-
std::vector<std::shared_ptr<BitCodeAbbrev>> CurAbbrevs;
319+
std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> CurAbbrevs;
320320

321321
struct Block {
322322
unsigned PrevCodeSize;
323-
std::vector<std::shared_ptr<BitCodeAbbrev>> PrevAbbrevs;
323+
std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> PrevAbbrevs;
324324

325325
explicit Block(unsigned PCS) : PrevCodeSize(PCS) {}
326326
};

llvm/include/llvm/Bitcode/BitstreamWriter.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ class BitstreamWriter {
4343
unsigned BlockInfoCurBID;
4444

4545
/// CurAbbrevs - Abbrevs installed at in this block.
46-
std::vector<std::shared_ptr<BitCodeAbbrev>> CurAbbrevs;
46+
std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> CurAbbrevs;
4747

4848
struct Block {
4949
unsigned PrevCodeSize;
5050
size_t StartSizeWord;
51-
std::vector<std::shared_ptr<BitCodeAbbrev>> PrevAbbrevs;
51+
std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> PrevAbbrevs;
5252
Block(unsigned PCS, size_t SSW) : PrevCodeSize(PCS), StartSizeWord(SSW) {}
5353
};
5454

@@ -59,7 +59,7 @@ class BitstreamWriter {
5959
/// These describe abbreviations that all blocks of the specified ID inherit.
6060
struct BlockInfo {
6161
unsigned BlockID;
62-
std::vector<std::shared_ptr<BitCodeAbbrev>> Abbrevs;
62+
std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> Abbrevs;
6363
};
6464
std::vector<BlockInfo> BlockInfoRecords;
6565

@@ -469,12 +469,12 @@ class BitstreamWriter {
469469

470470
private:
471471
// Emit the abbreviation as a DEFINE_ABBREV record.
472-
void EncodeAbbrev(const BitCodeAbbrev &Abbv) {
472+
void EncodeAbbrev(BitCodeAbbrev *Abbv) {
473473
EmitCode(bitc::DEFINE_ABBREV);
474-
EmitVBR(Abbv.getNumOperandInfos(), 5);
475-
for (unsigned i = 0, e = static_cast<unsigned>(Abbv.getNumOperandInfos());
474+
EmitVBR(Abbv->getNumOperandInfos(), 5);
475+
for (unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
476476
i != e; ++i) {
477-
const BitCodeAbbrevOp &Op = Abbv.getOperandInfo(i);
477+
const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
478478
Emit(Op.isLiteral(), 1);
479479
if (Op.isLiteral()) {
480480
EmitVBR64(Op.getLiteralValue(), 8);
@@ -489,10 +489,10 @@ class BitstreamWriter {
489489

490490
/// EmitAbbrev - This emits an abbreviation to the stream. Note that this
491491
/// method takes ownership of the specified abbrev.
492-
unsigned EmitAbbrev(std::shared_ptr<BitCodeAbbrev> Abbv) {
492+
unsigned EmitAbbrev(BitCodeAbbrev *Abbv) {
493493
// Emit the abbreviation as a record.
494-
EncodeAbbrev(*Abbv);
495-
CurAbbrevs.push_back(std::move(Abbv));
494+
EncodeAbbrev(Abbv);
495+
CurAbbrevs.push_back(Abbv);
496496
return static_cast<unsigned>(CurAbbrevs.size())-1 +
497497
bitc::FIRST_APPLICATION_ABBREV;
498498
}
@@ -532,13 +532,13 @@ class BitstreamWriter {
532532

533533
/// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified
534534
/// BlockID.
535-
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr<BitCodeAbbrev> Abbv) {
535+
unsigned EmitBlockInfoAbbrev(unsigned BlockID, BitCodeAbbrev *Abbv) {
536536
SwitchToBlockID(BlockID);
537-
EncodeAbbrev(*Abbv);
537+
EncodeAbbrev(Abbv);
538538

539539
// Add the abbrev to the specified block record.
540540
BlockInfo &Info = getOrCreateBlockInfo(BlockID);
541-
Info.Abbrevs.push_back(std::move(Abbv));
541+
Info.Abbrevs.push_back(Abbv);
542542

543543
return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV;
544544
}

llvm/include/llvm/Support/FileSystem.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,23 +829,28 @@ class directory_iterator {
829829
};
830830

831831
namespace detail {
832-
/// Keeps state for the recursive_directory_iterator.
833-
struct RecDirIterState {
832+
/// RecDirIterState - Keeps state for the recursive_directory_iterator. It is
833+
/// reference counted in order to preserve InputIterator semantics on copy.
834+
struct RecDirIterState : public RefCountedBase<RecDirIterState> {
835+
RecDirIterState()
836+
: Level(0)
837+
, HasNoPushRequest(false) {}
838+
834839
std::stack<directory_iterator, std::vector<directory_iterator>> Stack;
835-
uint16_t Level = 0;
836-
bool HasNoPushRequest = false;
840+
uint16_t Level;
841+
bool HasNoPushRequest;
837842
};
838843
} // end namespace detail
839844

840845
/// recursive_directory_iterator - Same as directory_iterator except for it
841846
/// recurses down into child directories.
842847
class recursive_directory_iterator {
843-
std::shared_ptr<detail::RecDirIterState> State;
848+
IntrusiveRefCntPtr<detail::RecDirIterState> State;
844849

845850
public:
846851
recursive_directory_iterator() = default;
847852
explicit recursive_directory_iterator(const Twine &path, std::error_code &ec)
848-
: State(std::make_shared<detail::RecDirIterState>()) {
853+
: State(new detail::RecDirIterState) {
849854
State->Stack.push(directory_iterator(path, ec));
850855
if (State->Stack.top() == directory_iterator())
851856
State.reset();

llvm/lib/Bitcode/Reader/BitstreamReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ unsigned BitstreamCursor::readRecord(unsigned AbbrevID,
273273
}
274274

275275
void BitstreamCursor::ReadAbbrevRecord() {
276-
auto Abbv = std::make_shared<BitCodeAbbrev>();
276+
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
277277
unsigned NumOpInfo = ReadVBR(5);
278278
for (unsigned i = 0; i != NumOpInfo; ++i) {
279279
bool IsLiteral = Read(1);
@@ -307,7 +307,7 @@ void BitstreamCursor::ReadAbbrevRecord() {
307307

308308
if (Abbv->getNumOperandInfos() == 0)
309309
report_fatal_error("Abbrev record with no operands");
310-
CurAbbrevs.push_back(std::move(Abbv));
310+
CurAbbrevs.push_back(Abbv);
311311
}
312312

313313
Optional<BitstreamBlockInfo>

0 commit comments

Comments
 (0)