SIL: add APIs to set and get the alignment of a pointer_to_address instruction.

Also add a getter for the `isInvariant` property.
This commit is contained in:
Erik Eckstein
2024-12-20 11:46:23 +01:00
parent 2d10da001a
commit 1856d4e94c
5 changed files with 45 additions and 4 deletions

View File

@@ -720,6 +720,9 @@ struct BridgedInstruction {
BRIDGED_INLINE IntrinsicID BuiltinInst_getIntrinsicID() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap BuiltinInst_getSubstitutionMap() const;
BRIDGED_INLINE bool PointerToAddressInst_isStrict() const;
BRIDGED_INLINE bool PointerToAddressInst_isInvariant() const;
BRIDGED_INLINE uint64_t PointerToAddressInst_getAlignment() const;
BRIDGED_INLINE void PointerToAddressInst_setAlignment(uint64_t alignment) const;
BRIDGED_INLINE bool AddressToPointerInst_needsStackProtection() const;
BRIDGED_INLINE bool IndexAddrInst_needsStackProtection() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedConformanceArray InitExistentialRefInst_getConformances() const;

View File

@@ -1140,6 +1140,23 @@ bool BridgedInstruction::PointerToAddressInst_isStrict() const {
return getAs<swift::PointerToAddressInst>()->isStrict();
}
bool BridgedInstruction::PointerToAddressInst_isInvariant() const {
return getAs<swift::PointerToAddressInst>()->isInvariant();
}
uint64_t BridgedInstruction::PointerToAddressInst_getAlignment() const {
auto maybeAlign = getAs<swift::PointerToAddressInst>()->alignment();
if (maybeAlign.has_value()) {
assert(maybeAlign->value() != 0);
return maybeAlign->value();
}
return 0;
}
void BridgedInstruction::PointerToAddressInst_setAlignment(uint64_t alignment) const {
getAs<swift::PointerToAddressInst>()->setAlignment(llvm::MaybeAlign(alignment));
}
bool BridgedInstruction::AddressToPointerInst_needsStackProtection() const {
return getAs<swift::AddressToPointerInst>()->needsStackProtection();
}

View File

@@ -6074,10 +6074,7 @@ class PointerToAddressInst
: UnaryInstructionBase(DebugLoc, Operand, Ty) {
sharedUInt8().PointerToAddressInst.isStrict = IsStrict;
sharedUInt8().PointerToAddressInst.isInvariant = IsInvariant;
unsigned encodedAlignment = llvm::encode(Alignment);
sharedUInt32().PointerToAddressInst.alignment = encodedAlignment;
assert(sharedUInt32().PointerToAddressInst.alignment == encodedAlignment
&& "pointer_to_address alignment overflow");
setAlignment(Alignment);
}
public:
@@ -6100,6 +6097,13 @@ public:
llvm::MaybeAlign alignment() const {
return llvm::decodeMaybeAlign(sharedUInt32().PointerToAddressInst.alignment);
}
void setAlignment(llvm::MaybeAlign Alignment) {
unsigned encodedAlignment = llvm::encode(Alignment);
sharedUInt32().PointerToAddressInst.alignment = encodedAlignment;
assert(sharedUInt32().PointerToAddressInst.alignment == encodedAlignment
&& "pointer_to_address alignment overflow");
}
};
/// Convert a heap object reference to a different type without any runtime