mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Replace the existing suite of checked cast instructions with: - unconditional_checked_cast, which performs an unconditional cast that aborts on failure (like the former downcast unconditional); and - checked_cast_br, which performs a conditional pass and branches on whether the cast succeeds, passing the result to the true branch as an argument. Both instructions take a CheckedCastKind that discriminates the different casting modes formerly discriminated by instruction type. This eliminates a source of null references in SIL and eliminates null SIL addresses completely. Swift SVN r8696
107 lines
2.8 KiB
C++
107 lines
2.8 KiB
C++
//===--- Address.h - Address Representation ---------------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// A structure for holding the address of an object.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_IRGEN_ADDRESS_H
|
|
#define SWIFT_IRGEN_ADDRESS_H
|
|
|
|
#include "IRGen.h"
|
|
#include "llvm/IR/Value.h"
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
namespace swift {
|
|
namespace irgen {
|
|
|
|
/// The address of an object in memory.
|
|
class Address {
|
|
llvm::Value *Addr;
|
|
Alignment Align;
|
|
|
|
public:
|
|
Address() : Addr(nullptr) {}
|
|
Address(llvm::Value *addr, Alignment align) : Addr(addr), Align(align) {
|
|
assert(addr != nullptr && "building an invalid address");
|
|
}
|
|
|
|
llvm::Value *operator->() const {
|
|
assert(isValid());
|
|
return getAddress();
|
|
}
|
|
|
|
bool isValid() const { return Addr != nullptr; }
|
|
|
|
llvm::Value *getAddress() const { return Addr; }
|
|
|
|
Alignment getAlignment() const {
|
|
return Align;
|
|
}
|
|
|
|
llvm::PointerType *getType() const {
|
|
return cast<llvm::PointerType>(Addr->getType());
|
|
}
|
|
};
|
|
|
|
/// An address in memory together with the (possibly null) heap
|
|
/// allocation which owns it.
|
|
class OwnedAddress {
|
|
Address Addr;
|
|
llvm::Value *Owner;
|
|
|
|
public:
|
|
OwnedAddress() : Owner(nullptr) {}
|
|
OwnedAddress(Address address, llvm::Value *owner)
|
|
: Addr(address), Owner(owner) {}
|
|
|
|
llvm::Value *getAddressPointer() const { return Addr.getAddress(); }
|
|
Alignment getAlignment() const { return Addr.getAlignment(); }
|
|
Address getAddress() const { return Addr; }
|
|
llvm::Value *getOwner() const { return Owner; }
|
|
|
|
Address getUnownedAddress() const {
|
|
assert(getOwner() == nullptr);
|
|
return getAddress();
|
|
}
|
|
|
|
operator Address() const { return getAddress(); }
|
|
|
|
bool isValid() const { return Addr.isValid(); }
|
|
};
|
|
|
|
/// An address in memory together with the local allocation which owns it.
|
|
class ContainedAddress {
|
|
/// The address of an object of type T.
|
|
Address Addr;
|
|
|
|
/// The address of an object of [local_storage] T.
|
|
Address Container;
|
|
|
|
public:
|
|
ContainedAddress() {}
|
|
ContainedAddress(Address container, Address address)
|
|
: Addr(address), Container(container) {}
|
|
|
|
llvm::Value *getAddressPointer() const { return Addr.getAddress(); }
|
|
Alignment getAlignment() const { return Addr.getAlignment(); }
|
|
Address getAddress() const { return Addr; }
|
|
Address getContainer() const { return Container; }
|
|
|
|
bool isValid() const { return Addr.isValid(); }
|
|
};
|
|
|
|
} // end namespace irgen
|
|
} // end namespace swift
|
|
|
|
#endif
|