-
Notifications
You must be signed in to change notification settings - Fork 13.4k
clang/OpenCL: Fix special casing OpenCL in call emission #138864
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
clang/OpenCL: Fix special casing OpenCL in call emission #138864
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Matt Arsenault (arsenm) ChangesThis essentially reverts 1bf1a15. OpenCL's handling of address spaces has always been a mess, but it's None of the code here should really depend on the language or language The below usage of LangAS::Default and getASTAllocaAddressSpace are also Full diff: https://github.com/llvm/llvm-project/pull/138864.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 82a24f7c295a2..1404bdfd69647 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5366,7 +5366,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
NeedCopy = true;
} else if (I->hasLValue()) {
auto LV = I->getKnownLValue();
- auto AS = LV.getAddressSpace();
bool isByValOrRef =
ArgInfo.isIndirectAliased() || ArgInfo.getIndirectByVal();
@@ -5375,17 +5374,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
(LV.getAlignment() < getContext().getTypeAlignInChars(I->Ty))) {
NeedCopy = true;
}
- if (!getLangOpts().OpenCL) {
- if ((isByValOrRef && (AS != LangAS::Default &&
- AS != CGM.getASTAllocaAddressSpace()))) {
- NeedCopy = true;
- }
- }
- // For OpenCL even if RV is located in default or alloca address space
- // we don't want to perform address space cast for it.
- else if ((isByValOrRef && Addr.getType()->getAddressSpace() !=
- IRFuncTy->getParamType(FirstIRArg)
- ->getPointerAddressSpace())) {
+
+ if (isByValOrRef && Addr.getType()->getAddressSpace() !=
+ ArgInfo.getIndirectAddrSpace()) {
NeedCopy = true;
}
}
@@ -5396,6 +5387,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
auto *T = llvm::PointerType::get(
CGM.getLLVMContext(), CGM.getDataLayout().getAllocaAddrSpace());
+ // FIXME: This should not depend on the language address spaces, and
+ // only the contextual values. If the address space mismatches, see if
+ // we can look through a cast to a compatible address space value,
+ // otherwise emit a copy.
llvm::Value *Val = getTargetHooks().performAddrSpaceCast(
*this, V, LangAS::Default, CGM.getASTAllocaAddressSpace(), T,
true);
|
@llvm/pr-subscribers-backend-amdgpu Author: Matt Arsenault (arsenm) ChangesThis essentially reverts 1bf1a15. OpenCL's handling of address spaces has always been a mess, but it's None of the code here should really depend on the language or language The below usage of LangAS::Default and getASTAllocaAddressSpace are also Full diff: https://github.com/llvm/llvm-project/pull/138864.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 82a24f7c295a2..1404bdfd69647 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5366,7 +5366,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
NeedCopy = true;
} else if (I->hasLValue()) {
auto LV = I->getKnownLValue();
- auto AS = LV.getAddressSpace();
bool isByValOrRef =
ArgInfo.isIndirectAliased() || ArgInfo.getIndirectByVal();
@@ -5375,17 +5374,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
(LV.getAlignment() < getContext().getTypeAlignInChars(I->Ty))) {
NeedCopy = true;
}
- if (!getLangOpts().OpenCL) {
- if ((isByValOrRef && (AS != LangAS::Default &&
- AS != CGM.getASTAllocaAddressSpace()))) {
- NeedCopy = true;
- }
- }
- // For OpenCL even if RV is located in default or alloca address space
- // we don't want to perform address space cast for it.
- else if ((isByValOrRef && Addr.getType()->getAddressSpace() !=
- IRFuncTy->getParamType(FirstIRArg)
- ->getPointerAddressSpace())) {
+
+ if (isByValOrRef && Addr.getType()->getAddressSpace() !=
+ ArgInfo.getIndirectAddrSpace()) {
NeedCopy = true;
}
}
@@ -5396,6 +5387,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
auto *T = llvm::PointerType::get(
CGM.getLLVMContext(), CGM.getDataLayout().getAllocaAddrSpace());
+ // FIXME: This should not depend on the language address spaces, and
+ // only the contextual values. If the address space mismatches, see if
+ // we can look through a cast to a compatible address space value,
+ // otherwise emit a copy.
llvm::Value *Val = getTargetHooks().performAddrSpaceCast(
*this, V, LangAS::Default, CGM.getASTAllocaAddressSpace(), T,
true);
|
662e6fe
to
b9fe3c1
Compare
e48afb5
to
8593287
Compare
9dae809
to
8593c30
Compare
8593287
to
f0dd54a
Compare
This essentially reverts 1bf1a15. OpenCL's handling of address spaces has always been a mess, but it's better than it used to be so this hack appears to be unnecessary now. None of the code here should really depend on the language or language address space. The ABI address space to use is already explicit in the ABIArgInfo, so use that instead of guessing it has anything to do with LangAS::Default or getASTAllocaAddressSpace. The below usage of LangAS::Default and getASTAllocaAddressSpace are also suspect, but appears to be a more involved and separate fix.
f0dd54a
to
4a054e4
Compare
This essentially reverts 1bf1a15.
OpenCL's handling of address spaces has always been a mess, but it's
better than it used to be so this hack appears to be unnecessary now.
None of the code here should really depend on the language or language
address space. The ABI address space to use is already explicit in the
ABIArgInfo, so use that instead of guessing it has anything to do with
LangAS::Default or getASTAllocaAddressSpace.
The below usage of LangAS::Default and getASTAllocaAddressSpace are also
suspect, but appears to be a more involved and separate fix.