diff options
author | Sirui Mu <msrlancern@gmail.com> | 2025-04-10 22:41:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-10 22:41:00 +0800 |
commit | 85614e160ba569d719452ec80b842a0edc5ab930 (patch) | |
tree | 7d608338ca8c22c1e85d3f19797630b1a5db0a35 /clang/lib/CIR/CodeGen/CIRGenModule.cpp | |
parent | 4b267bb7c2f1f84e10d3d47d17e0a19de6559de2 (diff) | |
download | llvm-85614e160ba569d719452ec80b842a0edc5ab930.zip llvm-85614e160ba569d719452ec80b842a0edc5ab930.tar.gz llvm-85614e160ba569d719452ec80b842a0edc5ab930.tar.bz2 |
[CIR] Upstream initial function call support (#134673)
This patch upstreams initial support for making function calls in CIR.
Function arguments and return values are not included to keep the patch
small for review.
Related to #132487
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenModule.cpp')
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenModule.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index d2259a9..2f90141 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -194,10 +194,12 @@ void CIRGenModule::emitGlobalFunctionDefinition(clang::GlobalDecl gd, } CIRGenFunction cgf(*this, builder); + curCGF = &cgf; { mlir::OpBuilder::InsertionGuard guard(builder); cgf.generateCode(gd, funcOp, funcType); } + curCGF = nullptr; } void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd, @@ -533,8 +535,18 @@ CIRGenModule::createCIRFunction(mlir::Location loc, StringRef name, { mlir::OpBuilder::InsertionGuard guard(builder); + // Some global emissions are triggered while emitting a function, e.g. + // void s() { x.method() } + // + // Be sure to insert a new function before a current one. + CIRGenFunction *cgf = this->curCGF; + if (cgf) + builder.setInsertionPoint(cgf->curFn); + func = builder.create<cir::FuncOp>(loc, name, funcType); - theModule.push_back(func); + + if (!cgf) + theModule.push_back(func); } return func; } |