Skip to content

Commit

Permalink
Merge branch 'AliveToolkit:master' into mutate
Browse files Browse the repository at this point in the history
  • Loading branch information
Hatsunespica authored Jun 25, 2024
2 parents 3188aa3 + f59964c commit 51da055
Show file tree
Hide file tree
Showing 31 changed files with 415 additions and 109 deletions.
28 changes: 19 additions & 9 deletions ir/attrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ ostream& operator<<(ostream &os, const ParamAttrs &attr) {
os << "allocptr ";
if (attr.has(ParamAttrs::AllocAlign))
os << "allocalign ";
if (attr.has(ParamAttrs::DeadOnUnwind))
os << "dead_on_unwind ";
if (attr.has(ParamAttrs::Writable))
os << "writable ";
return os;
}

Expand Down Expand Up @@ -293,8 +297,9 @@ bool ParamAttrs::refinedBy(const ParamAttrs &other) const {
unsigned attrs =
ByVal |
Dereferenceable |
DereferenceableOrNull |
NoUndef |
DereferenceableOrNull
Writable
;

auto other_params = (other.bits & attrs);
Expand All @@ -317,8 +322,11 @@ bool ParamAttrs::refinedBy(const ParamAttrs &other) const {
}

bool ParamAttrs::poisonImpliesUB() const {
return has(Dereferenceable) || has(NoUndef) || has(ByVal) ||
has(DereferenceableOrNull);
return has(ByVal) ||
has(Dereferenceable) ||
has(DereferenceableOrNull) ||
has(NoUndef) ||
has(Writable);
}

uint64_t ParamAttrs::getDerefBytes() const {
Expand All @@ -342,7 +350,8 @@ void ParamAttrs::merge(const ParamAttrs &other) {
static expr
encodePtrAttrs(State &s, const expr &ptrvalue, uint64_t derefBytes,
uint64_t derefOrNullBytes, uint64_t align, bool nonnull,
bool nocapture, const expr &allocsize, Value *allocalign) {
bool nocapture, bool writable, const expr &allocsize,
Value *allocalign) {
auto &m = s.getMemory();
Pointer p(m, ptrvalue);
expr non_poison(true);
Expand All @@ -356,15 +365,16 @@ encodePtrAttrs(State &s, const expr &ptrvalue, uint64_t derefBytes,
// dereferenceable, byval (ParamAttrs), dereferenceable_or_null
if (derefBytes)
s.addUB(merge(Pointer(m, ptrvalue)
.isDereferenceable(derefBytes, align, false, true)));
.isDereferenceable(derefBytes, align, writable, true)));
if (derefOrNullBytes)
s.addUB(p.isNull() ||
merge(Pointer(m, ptrvalue)
.isDereferenceable(derefOrNullBytes, align, false,true)));
.isDereferenceable(derefOrNullBytes, align, writable,
true)));
if (allocsize.isValid())
s.addUB(p.isNull() ||
merge(Pointer(m, ptrvalue)
.isDereferenceable(allocsize, align, false, true)));
.isDereferenceable(allocsize, align, writable, true)));
} else if (align != 1)
non_poison &= Pointer(m, ptrvalue).isAligned(align);

Expand All @@ -391,7 +401,7 @@ StateValue ParamAttrs::encode(State &s, StateValue &&val, const Type &ty) const{
if (ty.isPtrType())
val.non_poison &=
encodePtrAttrs(s, val.value, getDerefBytes(), derefOrNullBytes, align,
has(NonNull), has(NoCapture), {}, nullptr);
has(NonNull), has(NoCapture), has(Writable), {}, nullptr);

if (poisonImpliesUB()) {
s.addUB(std::move(val.non_poison));
Expand Down Expand Up @@ -494,7 +504,7 @@ StateValue FnAttrs::encode(State &s, StateValue &&val, const Type &ty,
if (ty.isPtrType())
val.non_poison &=
encodePtrAttrs(s, val.value, derefBytes, derefOrNullBytes, align,
has(NonNull), false, allocsize, allocalign);
has(NonNull), false, false, allocsize, allocalign);

if (poisonImpliesUB()) {
s.addUB(std::move(val.non_poison));
Expand Down
3 changes: 2 additions & 1 deletion ir/attrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class ParamAttrs final {
NoAlias = 1<<9, DereferenceableOrNull = 1<<10,
AllocPtr = 1<<11, AllocAlign = 1<<12,
ZeroExt = 1<<13, SignExt = 1<<14, InReg = 1<<15,
NoFPClass = 1<<16,
NoFPClass = 1<<16, DeadOnUnwind = 1<<17,
Writable = 1<<18,
IsArg = 1<<31 // used internally to make values as arguments
};

Expand Down
1 change: 1 addition & 0 deletions ir/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ unsigned bits_program_pointer = 64;
unsigned bits_size_t = 64;
unsigned bits_ptr_address = 64;
unsigned bits_byte = 8;
unsigned num_sub_byte_bits = 6;
unsigned strlen_unroll_cnt = 8;
unsigned memcmp_unroll_cnt = 8;
bool little_endian = true;
Expand Down
4 changes: 4 additions & 0 deletions ir/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ extern unsigned bits_ptr_address;
/// Number of bits for a byte.
extern unsigned bits_byte;

/// Required bits to store the size of sub-byte accesses
/// (e.g., store i5 -> we record 4, so 3 bits)
extern unsigned num_sub_byte_bits;

extern unsigned strlen_unroll_cnt;
extern unsigned memcmp_unroll_cnt;

Expand Down
15 changes: 13 additions & 2 deletions ir/instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,16 @@ vector<Value*> UnaryOp::operands() const {
}

bool UnaryOp::propagatesPoison() const {
return true;
switch (op) {
case Copy:
case BitReverse:
case BSwap:
case Ctpop:
case FFS:
return true;
case IsConstant: return false;
}
UNREACHABLE();
}

bool UnaryOp::hasSideEffects() const {
Expand Down Expand Up @@ -3503,11 +3512,13 @@ MemInstr::ByteAccessInfo::get(const Type &t, bool store, unsigned align) {
info.doesPtrStore = ptr_access && store;
info.doesPtrLoad = ptr_access && !store;
info.byteSize = gcd(align, getCommonAccessSize(t));
if (auto intTy = t.getAsIntType())
info.subByteAccess = intTy->maxSubBitAccess();
return info;
}

MemInstr::ByteAccessInfo MemInstr::ByteAccessInfo::full(unsigned byteSize) {
return { true, true, true, true, byteSize };
return { true, true, true, true, byteSize, 0 };
}


Expand Down
2 changes: 2 additions & 0 deletions ir/instr.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,8 @@ class MemInstr : public Instr {
// Otherwise, bytes of a memory can be widened to this size.
unsigned byteSize = 0;

unsigned subByteAccess = 0;

bool doesMemAccess() const { return byteSize; }

static ByteAccessInfo intOnly(unsigned byteSize);
Expand Down
Loading

0 comments on commit 51da055

Please sign in to comment.