Skip to content
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

[CIR][CodeGen] Support static local variables #1224

Open
wants to merge 14 commits into
base: spr/lanza/main.circodegen-static-local-variables
Choose a base branch
from

Conversation

lanza
Copy link
Member

@lanza lanza commented Dec 11, 2024

Support static local variable. Emit the initialization code into the
ctor region of the GlobalOp that represents the static local. During
LoweringPrepare expand that ctor region into the guardAcquire/release
walk.

Follow ups need to support exceptions and guardAbort.

Created using spr 1.3.5
Created using spr 1.3.5
return $_attr.getAst()->getLocation();
}]
>,
InterfaceMethod<"", "const clang::VarDecl *", "getRawDecl", (ins), [{}],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcardosolopes Thoughts on this? This wasn't scaling to the real world. e.g. functions that take a VarDecl as an argument.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After you latest update you can probably ditch this altogether

// CHECK: declare i32 @__cxa_guard_acquire(ptr)
// CHECK: declare void @__cxa_guard_release(ptr)

// CHECK: define dso_local void @_Z3foov()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be dso_local

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a FIXME in the testcase?

Created using spr 1.3.5
Created using spr 1.3.5
Created using spr 1.3.5
clang/lib/CIR/CodeGen/CIRGenFunction.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenFunction.h Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenStmt.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/LoweringPrepare.cpp Show resolved Hide resolved
clang/lib/CIR/CodeGen/LoweringPrepare.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/LoweringPrepare.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/LoweringPrepare.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/LoweringPrepare.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/LoweringPrepare.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/LoweringPrepare.cpp Outdated Show resolved Hide resolved
@bcardosolopes
Copy link
Member

Thanks so much for working on this, I gotta say this PR is huge though, we should probably talk about a way to split this down a bit, maybe we can incrementally converge faster if this is done in pieces.

Created using spr 1.3.5
Created using spr 1.3.5
Created using spr 1.3.5
lanza added a commit that referenced this pull request Dec 12, 2024
Created using spr 1.3.5
Created using spr 1.3.5
Created using spr 1.3.5
Created using spr 1.3.5
@lanza lanza marked this pull request as ready for review December 12, 2024 05:52
@lanza lanza changed the title [CIR][CodeGen] Static local variables [CIR][CodeGen] Support simple static local variables Dec 12, 2024
Created using spr 1.3.5
@lanza lanza changed the title [CIR][CodeGen] Support simple static local variables [CIR][CodeGen] Support static local variables Dec 12, 2024
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to already create the threadsafe attribute while here

// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-cir -clangir-disable-passes %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIRGEN
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=LLVM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the testcase to reflect what you can currently emit? It's fine if you want to leave the other things around for now, just add TODOs or FIXMEs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you already did, nevermind!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I got confused because lowering prepare changes were so big I they got folded by github. Reinstating my point: please remove the lowering prepare changes from this PR and change the testcase to only cover CIRGen. I think there's more we can move to CIRGen that don't require all those interfaces (I asked for the threadsafe attribute in the other review but somehow you've missed addressing that)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After ditching interfaces and leaving lowering prepare for another PR, this mostly looks good to me (with the other minor changes requested)

void emitInvariantStart(CharUnits Size);

/// emitCXXGlobalVarDeclInit - Create the initializer for a C++ variable with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the emitCXXGlobalVarDeclInit -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants