-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[OpenMP] Remove dependency on libffi
from offloading runtime
#91264
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
Open
jhuber6
wants to merge
1
commit into
llvm:main
Choose a base branch
from
jhuber6:RemoveFFI
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -629,6 +629,102 @@ static llvm::Function *emitOutlinedFunctionPrologue( | |
return F; | ||
} | ||
|
||
static llvm::Function *emitOutlinedFunctionPrologueAggregate( | ||
CodeGenFunction &CGF, FunctionArgList &Args, | ||
llvm::MapVector<const Decl *, std::pair<const VarDecl *, Address>> | ||
&LocalAddrs, | ||
llvm::DenseMap<const Decl *, std::pair<const Expr *, llvm::Value *>> | ||
&VLASizes, | ||
llvm::Value *&CXXThisValue, const CapturedStmt &CS, SourceLocation Loc, | ||
StringRef FunctionName) { | ||
const CapturedDecl *CD = CS.getCapturedDecl(); | ||
const RecordDecl *RD = CS.getCapturedRecordDecl(); | ||
|
||
CXXThisValue = nullptr; | ||
// Build the argument list. | ||
CodeGenModule &CGM = CGF.CGM; | ||
ASTContext &Ctx = CGM.getContext(); | ||
Args.append(CD->param_begin(), CD->param_end()); | ||
|
||
// Create the function declaration. | ||
const CGFunctionInfo &FuncInfo = | ||
CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Args); | ||
llvm::FunctionType *FuncLLVMTy = CGM.getTypes().GetFunctionType(FuncInfo); | ||
|
||
auto *F = | ||
llvm::Function::Create(FuncLLVMTy, llvm::GlobalValue::InternalLinkage, | ||
FunctionName, &CGM.getModule()); | ||
CGM.SetInternalFunctionAttributes(CD, F, FuncInfo); | ||
if (CD->isNothrow()) | ||
F->setDoesNotThrow(); | ||
F->setDoesNotRecurse(); | ||
|
||
// Generate the function. | ||
CGF.StartFunction(CD, Ctx.VoidTy, F, FuncInfo, Args, Loc, Loc); | ||
Address ContextAddr = CGF.GetAddrOfLocalVar(CD->getContextParam()); | ||
llvm::Value *ContextV = CGF.Builder.CreateLoad(ContextAddr); | ||
LValue ContextLV = CGF.MakeNaturalAlignAddrLValue( | ||
ContextV, CGM.getContext().getTagDeclType(RD)); | ||
auto I = CS.captures().begin(); | ||
for (const FieldDecl *FD : RD->fields()) { | ||
LValue FieldLV = CGF.EmitLValueForFieldInitialization(ContextLV, FD); | ||
// Do not map arguments if we emit function with non-original types. | ||
Address LocalAddr = FieldLV.getAddress(CGF); | ||
// If we are capturing a pointer by copy we don't need to do anything, just | ||
// use the value that we get from the arguments. | ||
if (I->capturesVariableByCopy() && FD->getType()->isAnyPointerType()) { | ||
const VarDecl *CurVD = I->getCapturedVar(); | ||
LocalAddrs.insert({FD, {CurVD, LocalAddr}}); | ||
++I; | ||
continue; | ||
} | ||
|
||
LValue ArgLVal = | ||
CGF.MakeAddrLValue(LocalAddr, FD->getType(), AlignmentSource::Decl); | ||
if (FD->hasCapturedVLAType()) { | ||
llvm::Value *ExprArg = CGF.EmitLoadOfScalar(ArgLVal, I->getLocation()); | ||
const VariableArrayType *VAT = FD->getCapturedVLAType(); | ||
VLASizes.try_emplace(FD, VAT->getSizeExpr(), ExprArg); | ||
} else if (I->capturesVariable()) { | ||
const VarDecl *Var = I->getCapturedVar(); | ||
QualType VarTy = Var->getType(); | ||
Address ArgAddr = ArgLVal.getAddress(CGF); | ||
if (ArgLVal.getType()->isLValueReferenceType()) { | ||
ArgAddr = CGF.EmitLoadOfReference(ArgLVal); | ||
} else if (!VarTy->isVariablyModifiedType() || !VarTy->isPointerType()) { | ||
assert(ArgLVal.getType()->isPointerType()); | ||
ArgAddr = CGF.EmitLoadOfPointer( | ||
ArgAddr, ArgLVal.getType()->castAs<PointerType>()); | ||
} | ||
LocalAddrs.insert( | ||
{FD, | ||
{Var, Address(ArgAddr.getBasePointer(), ArgAddr.getElementType(), | ||
Ctx.getDeclAlign(Var))}}); | ||
} else if (I->capturesVariableByCopy()) { | ||
assert(!FD->getType()->isAnyPointerType() && | ||
"Not expecting a captured pointer."); | ||
const VarDecl *Var = I->getCapturedVar(); | ||
Address CopyAddr = CGF.CreateMemTemp(FD->getType(), Ctx.getDeclAlign(FD), | ||
Var->getName()); | ||
LValue CopyLVal = | ||
CGF.MakeAddrLValue(CopyAddr, FD->getType(), AlignmentSource::Decl); | ||
|
||
RValue ArgRVal = CGF.EmitLoadOfLValue(ArgLVal, I->getLocation()); | ||
CGF.EmitStoreThroughLValue(ArgRVal, CopyLVal); | ||
|
||
LocalAddrs.insert({FD, {Var, CopyAddr}}); | ||
} else { | ||
// If 'this' is captured, load it into CXXThisValue. | ||
assert(I->capturesThis()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a message |
||
CXXThisValue = CGF.EmitLoadOfScalar(ArgLVal, I->getLocation()); | ||
LocalAddrs.insert({FD, {nullptr, ArgLVal.getAddress(CGF)}}); | ||
} | ||
++I; | ||
} | ||
|
||
return F; | ||
} | ||
|
||
llvm::Function * | ||
CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S, | ||
SourceLocation Loc) { | ||
|
@@ -711,6 +807,36 @@ CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S, | |
return WrapperF; | ||
} | ||
|
||
llvm::Function *CodeGenFunction::GenerateOpenMPCapturedStmtFunctionAggregate( | ||
const CapturedStmt &S, SourceLocation Loc) { | ||
assert( | ||
CapturedStmtInfo && | ||
"CapturedStmtInfo should be set when generating the captured function"); | ||
const CapturedDecl *CD = S.getCapturedDecl(); | ||
// Build the argument list. | ||
FunctionArgList Args; | ||
llvm::MapVector<const Decl *, std::pair<const VarDecl *, Address>> LocalAddrs; | ||
llvm::DenseMap<const Decl *, std::pair<const Expr *, llvm::Value *>> VLASizes; | ||
StringRef FunctionName = CapturedStmtInfo->getHelperName(); | ||
llvm::Function *F = emitOutlinedFunctionPrologueAggregate( | ||
*this, Args, LocalAddrs, VLASizes, CXXThisValue, S, Loc, FunctionName); | ||
CodeGenFunction::OMPPrivateScope LocalScope(*this); | ||
for (const auto &LocalAddrPair : LocalAddrs) { | ||
if (LocalAddrPair.second.first) { | ||
LocalScope.addPrivate(LocalAddrPair.second.first, | ||
LocalAddrPair.second.second); | ||
} | ||
} | ||
(void)LocalScope.Privatize(); | ||
for (const auto &VLASizePair : VLASizes) | ||
VLASizeMap[VLASizePair.second.first] = VLASizePair.second.second; | ||
PGO.assignRegionCounters(GlobalDecl(CD), F); | ||
CapturedStmtInfo->EmitBody(*this, CD->getBody()); | ||
(void)LocalScope.ForceCleanup(); | ||
FinishFunction(CD->getBodyRBrace()); | ||
return F; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// OpenMP Directive Emission | ||
//===----------------------------------------------------------------------===// | ||
|
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.