-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang][bytecode] Save a per-Block IsWeak bit #111248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Checking the decl for every load is rather expensive.
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesChecking the decl for every load is rather expensive. Full diff: https://github.com/llvm/llvm-project/pull/111248.diff 5 Files Affected:
diff --git a/clang/lib/AST/ByteCode/InterpBlock.cpp b/clang/lib/AST/ByteCode/InterpBlock.cpp
index 0ce88ca7e52365..9ef44cd29ff875 100644
--- a/clang/lib/AST/ByteCode/InterpBlock.cpp
+++ b/clang/lib/AST/ByteCode/InterpBlock.cpp
@@ -100,8 +100,8 @@ bool Block::hasPointer(const Pointer *P) const {
#endif
DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
- : Root(Root),
- B(~0u, Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) {
+ : Root(Root), B(~0u, Blk->Desc, Blk->IsStatic, Blk->IsExtern, Blk->IsWeak,
+ /*isDead=*/true) {
// Add the block to the chain of dead blocks.
if (Root)
Root->Prev = this;
diff --git a/clang/lib/AST/ByteCode/InterpBlock.h b/clang/lib/AST/ByteCode/InterpBlock.h
index a5cd58e3a655a0..985e4c152191c6 100644
--- a/clang/lib/AST/ByteCode/InterpBlock.h
+++ b/clang/lib/AST/ByteCode/InterpBlock.h
@@ -50,16 +50,17 @@ class Block final {
public:
/// Creates a new block.
Block(unsigned EvalID, const std::optional<unsigned> &DeclID,
- const Descriptor *Desc, bool IsStatic = false, bool IsExtern = false)
+ const Descriptor *Desc, bool IsStatic = false, bool IsExtern = false,
+ bool IsWeak = false)
: EvalID(EvalID), DeclID(DeclID), IsStatic(IsStatic), IsExtern(IsExtern),
- IsDynamic(false), Desc(Desc) {
+ IsDynamic(false), IsWeak(IsWeak), Desc(Desc) {
assert(Desc);
}
Block(unsigned EvalID, const Descriptor *Desc, bool IsStatic = false,
- bool IsExtern = false)
+ bool IsExtern = false, bool IsWeak = false)
: EvalID(EvalID), DeclID((unsigned)-1), IsStatic(IsStatic),
- IsExtern(IsExtern), IsDynamic(false), Desc(Desc) {
+ IsExtern(IsExtern), IsDynamic(false), IsWeak(IsWeak), Desc(Desc) {
assert(Desc);
}
@@ -73,6 +74,7 @@ class Block final {
bool isStatic() const { return IsStatic; }
/// Checks if the block is temporary.
bool isTemporary() const { return Desc->IsTemporary; }
+ bool isWeak() const { return IsWeak; }
bool isDynamic() const { return IsDynamic; }
/// Returns the size of the block.
unsigned getSize() const { return Desc->getAllocSize(); }
@@ -135,9 +137,9 @@ class Block final {
friend class DynamicAllocator;
Block(unsigned EvalID, const Descriptor *Desc, bool IsExtern, bool IsStatic,
- bool IsDead)
+ bool IsWeak, bool IsDead)
: EvalID(EvalID), IsStatic(IsStatic), IsExtern(IsExtern), IsDead(true),
- IsDynamic(false), Desc(Desc) {
+ IsDynamic(false), IsWeak(IsWeak), Desc(Desc) {
assert(Desc);
}
@@ -170,6 +172,7 @@ class Block final {
/// Flag indicating if this block has been allocated via dynamic
/// memory allocation (e.g. malloc).
bool IsDynamic = false;
+ bool IsWeak = false;
/// Pointer to the stack slot descriptor.
const Descriptor *Desc;
};
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index 08bc4b7e40b636..72e255dba13f6b 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -524,9 +524,7 @@ class Pointer {
return false;
assert(isBlockPointer());
- if (const ValueDecl *VD = getDeclDesc()->asValueDecl())
- return VD->isWeak();
- return false;
+ return asBlockPointer().Pointee->isWeak();
}
/// Checks if an object was initialized.
bool isInitialized() const;
diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp
index 79c645257306e0..969f523db51dfe 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -152,10 +152,12 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {
return It->second;
QualType QT;
+ bool IsWeak = false;
if (const auto *E = D.dyn_cast<const Expr *>()) {
QT = E->getType();
} else {
const ValueDecl *VD = cast<ValueDecl>(D.get<const Decl *>());
+ IsWeak = VD->isWeak();
QT = VD->getType();
if (const auto *RT = QT->getAs<ReferenceType>())
QT = RT->getPointeeType();
@@ -182,7 +184,7 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {
auto *G = new (Allocator, Desc->getAllocSize())
Global(Ctx.getEvalID(), getCurrentDecl(), Desc, /*IsStatic=*/true,
- /*IsExtern=*/false);
+ /*IsExtern=*/false, IsWeak);
G->block()->invokeCtor();
Globals.push_back(G);
@@ -193,6 +195,7 @@ std::optional<unsigned> Program::getOrCreateDummy(const DeclTy &D) {
std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
const Expr *Init) {
bool IsStatic, IsExtern;
+ bool IsWeak = VD->isWeak();
if (const auto *Var = dyn_cast<VarDecl>(VD)) {
IsStatic = Context::shouldBeGloballyIndexed(VD);
IsExtern = Var->hasExternalStorage();
@@ -207,7 +210,8 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
// Register all previous declarations as well. For extern blocks, just replace
// the index with the new variable.
- if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern, Init)) {
+ if (auto Idx =
+ createGlobal(VD, VD->getType(), IsStatic, IsExtern, IsWeak, Init)) {
for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
if (P != VD) {
unsigned PIdx = GlobalIndices[P];
@@ -225,7 +229,7 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) {
if (auto Idx = getGlobal(E))
return Idx;
if (auto Idx = createGlobal(E, E->getType(), /*isStatic=*/true,
- /*isExtern=*/false)) {
+ /*isExtern=*/false, /*IsWeak=*/false)) {
GlobalIndices[E] = *Idx;
return *Idx;
}
@@ -234,7 +238,7 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) {
std::optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty,
bool IsStatic, bool IsExtern,
- const Expr *Init) {
+ bool IsWeak, const Expr *Init) {
// Create a descriptor for the global.
Descriptor *Desc;
const bool IsConst = Ty.isConstQualified();
@@ -251,8 +255,8 @@ std::optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty,
// Allocate a block for storage.
unsigned I = Globals.size();
- auto *G = new (Allocator, Desc->getAllocSize())
- Global(Ctx.getEvalID(), getCurrentDecl(), Desc, IsStatic, IsExtern);
+ auto *G = new (Allocator, Desc->getAllocSize()) Global(
+ Ctx.getEvalID(), getCurrentDecl(), Desc, IsStatic, IsExtern, IsWeak);
G->block()->invokeCtor();
// Initialize InlineDescriptor fields.
diff --git a/clang/lib/AST/ByteCode/Program.h b/clang/lib/AST/ByteCode/Program.h
index bd2672a762b82a..be84c40714a60b 100644
--- a/clang/lib/AST/ByteCode/Program.h
+++ b/clang/lib/AST/ByteCode/Program.h
@@ -152,7 +152,7 @@ class Program final {
std::optional<unsigned> createGlobal(const DeclTy &D, QualType Ty,
bool IsStatic, bool IsExtern,
- const Expr *Init = nullptr);
+ bool IsWeak, const Expr *Init = nullptr);
/// Reference to the VM context.
Context &Ctx;
|
Kyvangka1610
pushed a commit
to Kyvangka1610/llvm-project
that referenced
this pull request
Oct 5, 2024
Checking the decl for every load is rather expensive.
Kyvangka1610
added a commit
to Kyvangka1610/llvm-project
that referenced
this pull request
Oct 5, 2024
* commit 'FETCH_HEAD': [clang][bytecode] Handle UETT_OpenMPRequiredSimdAlign (llvm#111259) [mlir][polynomial] Add and verify constraints of coefficientModulus for ringAttr (llvm#111016) [clang][bytecode] Save a per-Block IsWeak bit (llvm#111248) [analyzer] Fix wrong `builtin_*_overflow` return type (llvm#111253) [SelectOpt] Don't convert constant selects to branches. (llvm#110858) [InstCombine] Update and-or-icmps.ll after 574266c. NFC [Instcombine] Test for more gep canonicalization [NFC][TableGen] Change `CodeGenIntrinsics` to use const references (llvm#111219) Add warning message to `session save` when transcript isn't saved. (llvm#109020) [RISCV][TTI] Recognize CONCAT_VECTORS if a shufflevector mask is multiple insert subvector. (llvm#110457) Revert "[InstCombine] Folding `(icmp eq/ne (and X, -P2), INT_MIN)`" (llvm#111236) [NFC][lsan] Add SuspendAllThreads traces [lsan] Add `thread_suspend_fail` flag Signed-off-by: kyvangka1610 <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checking the decl for every load is rather expensive.