Skip to content

Commit 3793ff8

Browse files
address review feedback
Created using spr 1.3.7
2 parents fdc13b3 + 6dcdf27 commit 3793ff8

File tree

5 files changed

+67
-72
lines changed

5 files changed

+67
-72
lines changed

llvm/include/llvm/CAS/OnDiskGraphDB.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
namespace llvm::cas::ondisk {
2424

25-
/// Standard 8B reference inside OnDiskGraphDB.
25+
/// Standard 8 byte reference inside OnDiskGraphDB.
2626
class InternalRef {
2727
public:
2828
FileOffset getFileOffset() const { return FileOffset(Data); }
@@ -43,7 +43,7 @@ class InternalRef {
4343
uint64_t Data;
4444
};
4545

46-
/// Compact 4B reference inside OnDiskGraphDB for smaller references.
46+
/// Compact 4 byte reference inside OnDiskGraphDB for smaller references.
4747
class InternalRef4B {
4848
public:
4949
FileOffset getFileOffset() const { return FileOffset(Data); }
@@ -199,9 +199,8 @@ class ObjectHandle {
199199
public:
200200
uint64_t getOpaqueData() const { return Opaque; }
201201

202-
static ObjectHandle fromOpaqueData(uint64_t Opaque) {
203-
return ObjectHandle(Opaque);
204-
}
202+
static ObjectHandle fromFileOffset(FileOffset Offset);
203+
static ObjectHandle fromMemory(uintptr_t Ptr);
205204

206205
friend bool operator==(const ObjectHandle &LHS, const ObjectHandle &RHS) {
207206
return LHS.Opaque == RHS.Opaque;
@@ -401,8 +400,8 @@ class OnDiskGraphDB {
401400
/// Create a standalone leaf file.
402401
Error createStandaloneLeaf(IndexProxy &I, ArrayRef<char> Data);
403402

404-
/// @name Helper functions for internal data structures.
405-
/// @{
403+
/// \name Helper functions for internal data structures.
404+
/// \{
406405
static InternalRef getInternalRef(ObjectID Ref) {
407406
return InternalRef::getFromRawData(Ref.getOpaqueData());
408407
}
@@ -425,7 +424,7 @@ class OnDiskGraphDB {
425424
getIndexProxyFromPointer(OnDiskTrieRawHashMap::ConstOnDiskPtr P) const;
426425

427426
InternalRefArrayRef getInternalRefs(ObjectHandle Node) const;
428-
/// @}
427+
/// \}
429428

430429
/// Get the atomic variable that keeps track of the standalone data storage
431430
/// size.
@@ -453,7 +452,7 @@ class OnDiskGraphDB {
453452
OnDiskDataAllocator DataPool;
454453

455454
/// A StandaloneDataMap.
456-
void *StandaloneData;
455+
void *StandaloneData = nullptr;
457456

458457
/// Path to the root directory.
459458
std::string RootPath;

llvm/lib/CAS/OnDiskGraphDB.cpp

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
///
1414
/// OnDiskGraphDB defines:
1515
///
16-
/// - How the data are stored inside database, either as a standalone file, or
16+
/// - How the data is stored inside database, either as a standalone file, or
1717
/// allocated inside a datapool.
1818
/// - How references to other objects inside the same database is stored. They
1919
/// are stored as internal references, instead of full hash value to save
@@ -90,7 +90,7 @@ static Error createCorruptObjectError(Expected<ArrayRef<uint8_t>> ID) {
9090

9191
namespace {
9292

93-
/// Trie record data: 8B, atomic<uint64_t>
93+
/// Trie record data: 8 bytes, atomic<uint64_t>
9494
/// - 1-byte: StorageKind
9595
/// - 7-bytes: DataStoreOffset (offset into referenced file)
9696
class TrieRecord {
@@ -129,7 +129,7 @@ class TrieRecord {
129129
}
130130

131131
enum Limits : int64_t {
132-
// Saves files bigger than 64KB standalone instead of embedding them.
132+
/// Saves files bigger than 64KB standalone instead of embedding them.
133133
MaxEmbeddedSize = 64LL * 1024LL - 1,
134134
};
135135

@@ -138,6 +138,7 @@ class TrieRecord {
138138
FileOffset Offset;
139139
};
140140

141+
/// Pack StorageKind and Offset from Data into 8 byte TrieRecord.
141142
static uint64_t pack(Data D) {
142143
assert(D.Offset.get() < (int64_t)(1ULL << 56));
143144
uint64_t Packed = uint64_t(D.SK) << 56 | D.Offset.get();
@@ -150,6 +151,7 @@ class TrieRecord {
150151
return Packed;
151152
}
152153

154+
// Unpack TrieRecord into Data.
153155
static Data unpack(uint64_t Packed) {
154156
Data D;
155157
if (!Packed)
@@ -221,7 +223,7 @@ struct DataRecordHandle {
221223
0,
222224
"Not enough bits");
223225

224-
// layout of the DataRecordHandle and how to decode it.
226+
/// Layout of the DataRecordHandle and how to decode it.
225227
struct LayoutFlags {
226228
NumRefsFlags NumRefs;
227229
DataSizeFlags DataSize;
@@ -287,10 +289,12 @@ struct DataRecordHandle {
287289
return getDataRelOffset() + getDataSize() + 1;
288290
}
289291

292+
/// Describe the layout of data stored and how to decode from
293+
/// DataRecordHandle.
290294
struct Layout {
291295
explicit Layout(const Input &I);
292296

293-
LayoutFlags Flags{};
297+
LayoutFlags Flags;
294298
uint64_t DataSize = 0;
295299
uint32_t NumRefs = 0;
296300
int64_t RefsRelOffset = 0;
@@ -349,7 +353,7 @@ struct OnDiskContent {
349353
std::optional<ArrayRef<char>> Bytes;
350354
};
351355

352-
// Data loaded inside the memory from standalone file.
356+
/// Data loaded inside the memory from standalone file.
353357
class StandaloneDataInMemory {
354358
public:
355359
OnDiskContent getContent() const;
@@ -382,9 +386,8 @@ template <size_t NumShards> class StandaloneDataMap {
382386
static_assert(isPowerOf2_64(NumShards), "Expected power of 2");
383387

384388
public:
385-
const StandaloneDataInMemory &
386-
insert(ArrayRef<uint8_t> Hash, TrieRecord::StorageKind SK,
387-
std::unique_ptr<sys::fs::mapped_file_region> Region);
389+
uintptr_t insert(ArrayRef<uint8_t> Hash, TrieRecord::StorageKind SK,
390+
std::unique_ptr<sys::fs::mapped_file_region> Region);
388391

389392
const StandaloneDataInMemory *lookup(ArrayRef<uint8_t> Hash) const;
390393
bool count(ArrayRef<uint8_t> Hash) const { return bool(lookup(Hash)); }
@@ -409,27 +412,7 @@ template <size_t NumShards> class StandaloneDataMap {
409412

410413
using StandaloneDataMapTy = StandaloneDataMap<16>;
411414

412-
struct InternalHandle {
413-
FileOffset getAsFileOffset() const { return *DataOffset; }
414-
415-
uint64_t getRawData() const {
416-
if (DataOffset) {
417-
uint64_t Raw = DataOffset->get();
418-
assert(!(Raw & 0x1));
419-
return Raw;
420-
}
421-
uint64_t Raw = reinterpret_cast<uintptr_t>(SDIM);
422-
assert(!(Raw & 0x1));
423-
return Raw | 1;
424-
}
425-
426-
explicit InternalHandle(FileOffset DataOffset) : DataOffset(DataOffset) {}
427-
explicit InternalHandle(uint64_t DataOffset) : DataOffset(DataOffset) {}
428-
explicit InternalHandle(const StandaloneDataInMemory &SDIM) : SDIM(&SDIM) {}
429-
std::optional<FileOffset> DataOffset;
430-
const StandaloneDataInMemory *SDIM = nullptr;
431-
};
432-
415+
/// A vector of internal node references.
433416
class InternalRefVector {
434417
public:
435418
void push_back(InternalRef Ref) {
@@ -476,6 +459,18 @@ DataRecordHandle::create(function_ref<char *(size_t Size)> Alloc,
476459
return constructImpl(Alloc(L.getTotalSize()), I, L);
477460
}
478461

462+
ObjectHandle ObjectHandle::fromFileOffset(FileOffset Offset) {
463+
// Store the file offset as it is.
464+
assert(!(Offset.get() & 0x1));
465+
return ObjectHandle(Offset.get());
466+
}
467+
468+
ObjectHandle ObjectHandle::fromMemory(uintptr_t Ptr) {
469+
// Store the pointer from memory with lowest bit set.
470+
assert(!(Ptr & 0x1));
471+
return ObjectHandle(Ptr | 1);
472+
}
473+
479474
/// Proxy for an on-disk index record.
480475
struct OnDiskGraphDB::IndexProxy {
481476
FileOffset Offset;
@@ -484,15 +479,15 @@ struct OnDiskGraphDB::IndexProxy {
484479
};
485480

486481
template <size_t N>
487-
const StandaloneDataInMemory &StandaloneDataMap<N>::insert(
482+
uintptr_t StandaloneDataMap<N>::insert(
488483
ArrayRef<uint8_t> Hash, TrieRecord::StorageKind SK,
489484
std::unique_ptr<sys::fs::mapped_file_region> Region) {
490485
auto &S = getShard(Hash);
491486
std::lock_guard<std::mutex> Lock(S.Mutex);
492487
auto &V = S.Map[Hash.data()];
493488
if (!V)
494489
V = std::make_unique<StandaloneDataInMemory>(std::move(Region), SK);
495-
return *V;
490+
return reinterpret_cast<uintptr_t>(V.get());
496491
}
497492

498493
template <size_t N>
@@ -1168,20 +1163,16 @@ ArrayRef<uint8_t> OnDiskGraphDB::getDigest(const IndexProxy &I) const {
11681163

11691164
static OnDiskContent getContentFromHandle(const OnDiskDataAllocator &DataPool,
11701165
ObjectHandle OH) {
1171-
auto getInternalHandle = [](ObjectHandle Handle) -> InternalHandle {
1172-
uint64_t Data = Handle.getOpaqueData();
1173-
if (Data & 1)
1174-
return InternalHandle(*reinterpret_cast<const StandaloneDataInMemory *>(
1175-
Data & (-1ULL << 1)));
1176-
return InternalHandle(Data);
1177-
};
1178-
1179-
InternalHandle Handle = getInternalHandle(OH);
1180-
if (Handle.SDIM)
1181-
return Handle.SDIM->getContent();
1166+
// Decode ObjectHandle to locate the stored content.
1167+
uint64_t Data = OH.getOpaqueData();
1168+
if (Data & 1) {
1169+
const auto *SDIM =
1170+
reinterpret_cast<const StandaloneDataInMemory *>(Data & (-1ULL << 1));
1171+
return SDIM->getContent();
1172+
}
11821173

1183-
auto DataHandle = cantFail(
1184-
DataRecordHandle::getFromDataPool(DataPool, Handle.getAsFileOffset()));
1174+
auto DataHandle =
1175+
cantFail(DataRecordHandle::getFromDataPool(DataPool, FileOffset(Data)));
11851176
assert(DataHandle.getData().end()[0] == 0 && "Null termination");
11861177
return OnDiskContent{DataHandle, std::nullopt};
11871178
}
@@ -1215,12 +1206,8 @@ OnDiskGraphDB::load(ObjectID ExternalRef) {
12151206
return faultInFromUpstream(ExternalRef);
12161207
}
12171208

1218-
auto toObjectHandle = [](InternalHandle H) -> ObjectHandle {
1219-
return ObjectHandle::fromOpaqueData(H.getRawData());
1220-
};
1221-
12221209
if (Object.SK == TrieRecord::StorageKind::DataPool)
1223-
return toObjectHandle(InternalHandle(Object.Offset));
1210+
return ObjectHandle::fromFileOffset(Object.Offset);
12241211

12251212
// Only TrieRecord::StorageKind::Standalone (and variants) need to be
12261213
// explicitly loaded.
@@ -1263,9 +1250,9 @@ OnDiskGraphDB::load(ObjectID ExternalRef) {
12631250
if (EC)
12641251
return createCorruptObjectError(getDigest(*I));
12651252

1266-
return toObjectHandle(
1267-
InternalHandle(static_cast<StandaloneDataMapTy *>(StandaloneData)
1268-
->insert(I->Hash, Object.SK, std::move(Region))));
1253+
return ObjectHandle::fromMemory(
1254+
static_cast<StandaloneDataMapTy *>(StandaloneData)
1255+
->insert(I->Hash, Object.SK, std::move(Region)));
12691256
}
12701257

12711258
Expected<bool> OnDiskGraphDB::isMaterialized(ObjectID Ref) {

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,10 +2979,14 @@ Instruction *InstCombinerImpl::foldAndOrOfSelectUsingImpliedCond(Value *Op,
29792979
"Op must be either i1 or vector of i1.");
29802980
if (SI.getCondition()->getType() != Op->getType())
29812981
return nullptr;
2982-
if (Value *V = simplifyNestedSelectsUsingImpliedCond(SI, Op, IsAnd, DL))
2983-
return SelectInst::Create(Op,
2984-
IsAnd ? V : ConstantInt::getTrue(Op->getType()),
2985-
IsAnd ? ConstantInt::getFalse(Op->getType()) : V);
2982+
if (Value *V = simplifyNestedSelectsUsingImpliedCond(SI, Op, IsAnd, DL)) {
2983+
Instruction *MDFrom = nullptr;
2984+
if (!ProfcheckDisableMetadataFixes)
2985+
MDFrom = &SI;
2986+
return SelectInst::Create(
2987+
Op, IsAnd ? V : ConstantInt::getTrue(Op->getType()),
2988+
IsAnd ? ConstantInt::getFalse(Op->getType()) : V, "", nullptr, MDFrom);
2989+
}
29862990
return nullptr;
29872991
}
29882992

llvm/test/Transforms/InstCombine/select-safe-impliedcond-transforms.ll

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
22
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
33

44
define i1 @a_true_implies_b_true(i8 %z, i1 %X, i1 %Y) {
@@ -34,15 +34,15 @@ define <2 x i1> @a_true_implies_b_true_vec(i8 %z0, <2 x i1> %X, <2 x i1> %Y) {
3434
ret <2 x i1> %res
3535
}
3636

37-
define i1 @a_true_implies_b_true2(i8 %z, i1 %X, i1 %Y) {
37+
define i1 @a_true_implies_b_true2(i8 %z, i1 %X, i1 %Y) !prof !0 {
3838
; CHECK-LABEL: @a_true_implies_b_true2(
3939
; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 20
40-
; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[X:%.*]], i1 false
40+
; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[X:%.*]], i1 false, !prof [[PROF1:![0-9]+]]
4141
; CHECK-NEXT: ret i1 [[RES]]
4242
;
4343
%a = icmp ugt i8 %z, 20
4444
%b = icmp ugt i8 %z, 10
45-
%sel = select i1 %b, i1 %X, i1 %Y
45+
%sel = select i1 %b, i1 %X, i1 %Y, !prof !1
4646
%res = and i1 %a, %sel
4747
ret i1 %res
4848
}
@@ -258,3 +258,10 @@ define i1 @neg_icmp_eq_implies_trunc(i8 %x, i1 %c) {
258258
%sel2 = select i1 %cmp, i1 true, i1 %sel1
259259
ret i1 %sel2
260260
}
261+
262+
!0 = !{!"function_entry_count", i64 1000}
263+
!1 = !{!"branch_weights", i32 2, i32 3}
264+
;.
265+
; CHECK: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
266+
; CHECK: [[PROF1]] = !{!"branch_weights", i32 2, i32 3}
267+
;.

llvm/utils/profcheck-xfail.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,6 @@ Transforms/InstCombine/select_frexp.ll
906906
Transforms/InstCombine/select.ll
907907
Transforms/InstCombine/select-min-max.ll
908908
Transforms/InstCombine/select-of-symmetric-selects.ll
909-
Transforms/InstCombine/select-safe-impliedcond-transforms.ll
910909
Transforms/InstCombine/select-safe-transforms.ll
911910
Transforms/InstCombine/select-select.ll
912911
Transforms/InstCombine/select-with-extreme-eq-cond.ll
@@ -1237,7 +1236,6 @@ Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll
12371236
Transforms/PGOProfile/chr-dead-pred.ll
12381237
Transforms/PGOProfile/chr-dup-threshold.ll
12391238
Transforms/PGOProfile/chr-lifetimes.ll
1240-
Transforms/PGOProfile/chr.ll
12411239
Transforms/PGOProfile/chr-poison.ll
12421240
Transforms/PGOProfile/comdat.ll
12431241
Transforms/PGOProfile/memop_profile_funclet_wasm.ll

0 commit comments

Comments
 (0)