mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 19:08:21 +08:00
[clang][bytecode][NFC] Add Block::getBlockDesc<T>() (#172218)
Which returns the block-level descriptor. This way we don't have to do the reinterpret_cast dance everywhere.
This commit is contained in:
@@ -4798,8 +4798,7 @@ VarCreationState Compiler<Emitter>::visitDecl(const VarDecl *VD,
|
||||
if (!R && Context::shouldBeGloballyIndexed(VD)) {
|
||||
if (auto GlobalIndex = P.getGlobal(VD)) {
|
||||
Block *GlobalBlock = P.getGlobal(*GlobalIndex);
|
||||
GlobalInlineDescriptor &GD =
|
||||
*reinterpret_cast<GlobalInlineDescriptor *>(GlobalBlock->rawData());
|
||||
auto &GD = GlobalBlock->getBlockDesc<GlobalInlineDescriptor>();
|
||||
|
||||
GD.InitState = GlobalInitState::InitializerFailed;
|
||||
GlobalBlock->invokeDtor();
|
||||
@@ -4860,8 +4859,7 @@ bool Compiler<Emitter>::visitDeclAndReturn(const VarDecl *VD, const Expr *Init,
|
||||
auto GlobalIndex = P.getGlobal(VD);
|
||||
assert(GlobalIndex);
|
||||
Block *GlobalBlock = P.getGlobal(*GlobalIndex);
|
||||
GlobalInlineDescriptor &GD =
|
||||
*reinterpret_cast<GlobalInlineDescriptor *>(GlobalBlock->rawData());
|
||||
auto &GD = GlobalBlock->getBlockDesc<GlobalInlineDescriptor>();
|
||||
|
||||
GD.InitState = GlobalInitState::InitializerFailed;
|
||||
GlobalBlock->invokeDtor();
|
||||
|
||||
@@ -110,7 +110,7 @@ Scope::Local EvalEmitter::createLocal(Descriptor *D) {
|
||||
B->invokeCtor();
|
||||
|
||||
// Initialize local variable inline descriptor.
|
||||
InlineDescriptor &Desc = *reinterpret_cast<InlineDescriptor *>(B->rawData());
|
||||
auto &Desc = B->getBlockDesc<InlineDescriptor>();
|
||||
Desc.Desc = D;
|
||||
Desc.Offset = sizeof(InlineDescriptor);
|
||||
Desc.IsActive = false;
|
||||
@@ -304,7 +304,7 @@ bool EvalEmitter::emitSetLocal(uint32_t I, SourceInfo Info) {
|
||||
|
||||
Block *B = getLocal(I);
|
||||
*reinterpret_cast<T *>(B->data()) = S.Stk.pop<T>();
|
||||
InlineDescriptor &Desc = *reinterpret_cast<InlineDescriptor *>(B->rawData());
|
||||
auto &Desc = B->getBlockDesc<InlineDescriptor>();
|
||||
Desc.IsInitialized = true;
|
||||
|
||||
return true;
|
||||
@@ -327,8 +327,7 @@ bool EvalEmitter::emitGetLocalEnabled(uint32_t I, SourceInfo Info) {
|
||||
return true;
|
||||
|
||||
Block *B = getLocal(I);
|
||||
const InlineDescriptor &Desc =
|
||||
*reinterpret_cast<InlineDescriptor *>(B->rawData());
|
||||
const auto &Desc = B->getBlockDesc<InlineDescriptor>();
|
||||
|
||||
S.Stk.push<bool>(Desc.IsActive);
|
||||
return true;
|
||||
@@ -344,7 +343,7 @@ bool EvalEmitter::emitEnableLocal(uint32_t I, SourceInfo Info) {
|
||||
// probably use a different struct than InlineDescriptor for the block-level
|
||||
// inline descriptor of local varaibles.
|
||||
Block *B = getLocal(I);
|
||||
InlineDescriptor &Desc = *reinterpret_cast<InlineDescriptor *>(B->rawData());
|
||||
auto &Desc = B->getBlockDesc<InlineDescriptor>();
|
||||
Desc.IsActive = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -736,8 +736,7 @@ static bool CheckWeak(InterpState &S, CodePtr OpPC, const Block *B) {
|
||||
// For example, since those can't be members of structs, they also can't
|
||||
// be mutable.
|
||||
bool CheckGlobalLoad(InterpState &S, CodePtr OpPC, const Block *B) {
|
||||
const auto &Desc =
|
||||
*reinterpret_cast<const GlobalInlineDescriptor *>(B->rawData());
|
||||
const auto &Desc = B->getBlockDesc<GlobalInlineDescriptor>();
|
||||
if (!B->isAccessible()) {
|
||||
if (!CheckExtern(S, OpPC, Pointer(const_cast<Block *>(B))))
|
||||
return false;
|
||||
|
||||
@@ -1455,8 +1455,7 @@ bool GetGlobal(InterpState &S, CodePtr OpPC, uint32_t I) {
|
||||
template <PrimType Name, class T = typename PrimConv<Name>::T>
|
||||
bool GetGlobalUnchecked(InterpState &S, CodePtr OpPC, uint32_t I) {
|
||||
const Block *B = S.P.getGlobal(I);
|
||||
const auto &Desc =
|
||||
*reinterpret_cast<const GlobalInlineDescriptor *>(B->rawData());
|
||||
const auto &Desc = B->getBlockDesc<GlobalInlineDescriptor>();
|
||||
if (Desc.InitState != GlobalInitState::Initialized)
|
||||
return DiagnoseUninitialized(S, OpPC, B->isExtern(), B->getDescriptor(),
|
||||
AK_Read);
|
||||
|
||||
@@ -122,6 +122,14 @@ public:
|
||||
}
|
||||
template <typename T> T &deref() { return *reinterpret_cast<T *>(data()); }
|
||||
|
||||
template <typename T> T &getBlockDesc() {
|
||||
assert(sizeof(T) == getDescriptor()->getMetadataSize());
|
||||
return *reinterpret_cast<T *>(rawData());
|
||||
}
|
||||
template <typename T> const T &getBlockDesc() const {
|
||||
return const_cast<Block *>(this)->getBlockDesc<T>();
|
||||
}
|
||||
|
||||
/// Invokes the constructor.
|
||||
void invokeCtor() {
|
||||
assert(!IsInitialized);
|
||||
|
||||
@@ -444,8 +444,7 @@ bool Pointer::isInitialized() const {
|
||||
|
||||
if (isRoot() && BS.Base == sizeof(GlobalInlineDescriptor) &&
|
||||
Offset == BS.Base) {
|
||||
const GlobalInlineDescriptor &GD =
|
||||
*reinterpret_cast<const GlobalInlineDescriptor *>(block()->rawData());
|
||||
const auto &GD = block()->getBlockDesc<GlobalInlineDescriptor>();
|
||||
return GD.InitState == GlobalInitState::Initialized;
|
||||
}
|
||||
|
||||
@@ -473,8 +472,7 @@ bool Pointer::isElementInitialized(unsigned Index) const {
|
||||
|
||||
if (isRoot() && BS.Base == sizeof(GlobalInlineDescriptor) &&
|
||||
Offset == BS.Base) {
|
||||
const GlobalInlineDescriptor &GD =
|
||||
*reinterpret_cast<const GlobalInlineDescriptor *>(block()->rawData());
|
||||
const auto &GD = block()->getBlockDesc<GlobalInlineDescriptor>();
|
||||
return GD.InitState == GlobalInitState::Initialized;
|
||||
}
|
||||
|
||||
@@ -499,8 +497,7 @@ void Pointer::initialize() const {
|
||||
|
||||
if (isRoot() && BS.Base == sizeof(GlobalInlineDescriptor) &&
|
||||
Offset == BS.Base) {
|
||||
GlobalInlineDescriptor &GD = *reinterpret_cast<GlobalInlineDescriptor *>(
|
||||
asBlockPointer().Pointee->rawData());
|
||||
auto &GD = BS.Pointee->getBlockDesc<GlobalInlineDescriptor>();
|
||||
GD.InitState = GlobalInitState::Initialized;
|
||||
return;
|
||||
}
|
||||
@@ -565,8 +562,7 @@ bool Pointer::allElementsInitialized() const {
|
||||
|
||||
if (isRoot() && BS.Base == sizeof(GlobalInlineDescriptor) &&
|
||||
Offset == BS.Base) {
|
||||
const GlobalInlineDescriptor &GD =
|
||||
*reinterpret_cast<const GlobalInlineDescriptor *>(block()->rawData());
|
||||
const auto &GD = block()->getBlockDesc<GlobalInlineDescriptor>();
|
||||
return GD.InitState == GlobalInitState::Initialized;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user