[llvm] [mlir] [OpenMP][MLIR] Fix threadprivate lowering when compiling for target when target operations are in use (PR #119310)
Sergio Afonso via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 11 05:45:08 PST 2024
================
@@ -2537,24 +2537,34 @@ convertOmpThreadprivate(Operation &opInst, llvm::IRBuilderBase &builder,
Value symAddr = threadprivateOp.getSymAddr();
auto *symOp = symAddr.getDefiningOp();
+
+ if (auto asCast = dyn_cast<LLVM::AddrSpaceCastOp>(symOp))
+ symOp = asCast.getOperand().getDefiningOp();
+
if (!isa<LLVM::AddressOfOp>(symOp))
return opInst.emitError("Addressing symbol not found");
LLVM::AddressOfOp addressOfOp = dyn_cast<LLVM::AddressOfOp>(symOp);
LLVM::GlobalOp global =
addressOfOp.getGlobal(moduleTranslation.symbolTable());
llvm::GlobalValue *globalValue = moduleTranslation.lookupGlobal(global);
- llvm::Type *type = globalValue->getValueType();
- llvm::TypeSize typeSize =
- builder.GetInsertBlock()->getModule()->getDataLayout().getTypeStoreSize(
- type);
- llvm::ConstantInt *size = builder.getInt64(typeSize.getFixedValue());
- llvm::StringRef suffix = llvm::StringRef(".cache", 6);
- std::string cacheName = (Twine(global.getSymName()).concat(suffix)).str();
- llvm::Value *callInst =
- moduleTranslation.getOpenMPBuilder()->createCachedThreadPrivate(
- ompLoc, globalValue, size, cacheName);
- moduleTranslation.mapValue(opInst.getResult(0), callInst);
+
+ if (!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice()) {
----------------
skatrak wrote:
Nit: Add `llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();` to the start of the function, since there are now two uses of it.
```suggestion
if (!ompBuilder->Config.isTargetDevice()) {
```
https://github.com/llvm/llvm-project/pull/119310
More information about the llvm-commits
mailing list