Skip to content

Commit c74ebe7

Browse files
dhruvachakronlieb
authored andcommitted
[OpenMP] [clang] Misc bug fixes in specialized kernels codegen.
Fixed assertion failure with static or global loop variables. Fixed handling different types in big-jump-loop generation. Change-Id: I738aad22e7639129ebf9f0da7e14d466788a280a
1 parent b79b5ce commit c74ebe7

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,18 @@ CodeGenFunction::EmitNoLoopIV(const OMPLoopDirective &LD) {
177177
// Emit the original loop indices
178178
for (const Expr *CE : LD.counters()) {
179179
const auto *CEDecl = cast<VarDecl>(cast<DeclRefExpr>(CE)->getDecl());
180-
if (!hasAddrOfLocalVar(CEDecl))
181-
EmitVarDecl(*CEDecl);
180+
if (!hasAddrOfLocalVar(CEDecl)) {
181+
if (CEDecl->hasLocalStorage())
182+
EmitVarDecl(*CEDecl);
183+
else {
184+
llvm::Type *CEDeclType = ConvertTypeForMem(CEDecl->getType());
185+
llvm::AllocaInst *LocalForGlobal =
186+
Builder.CreateAlloca(CEDeclType, nullptr, "lglobal");
187+
setAddrOfLocalVar(CEDecl, Address(LocalForGlobal, CEDeclType,
188+
getContext().getTypeAlignInChars(
189+
CEDecl->getType())));
190+
}
191+
}
182192
}
183193

184194
// Emit the preinits
@@ -541,14 +551,17 @@ bool CodeGenFunction::EmitXteamRedStmt(const Stmt *S) {
541551
// Compute *xteam_red_local_addr + rhs_value
542552
llvm::Value *RedRHS = nullptr;
543553
llvm::Type *RedVarType = ConvertTypeForMem(RedVarDecl->getType());
544-
if (RedVarType->isFloatTy() || RedVarType->isDoubleTy())
545-
RedRHS =
546-
Builder.CreateFAdd(Builder.CreateLoad(XteamRedLocalAddr), RHSValue);
547-
else if (RedVarType->isIntegerTy())
548-
RedRHS =
549-
Builder.CreateAdd(Builder.CreateLoad(XteamRedLocalAddr),
550-
Builder.CreateIntCast(RHSValue, RedVarType, false));
551-
else
554+
if (RedVarType->isFloatTy() || RedVarType->isDoubleTy()) {
555+
auto RHSOp = RHSValue->getType()->isIntegerTy()
556+
? Builder.CreateUIToFP(RHSValue, RedVarType)
557+
: Builder.CreateFPCast(RHSValue, RedVarType);
558+
RedRHS = Builder.CreateFAdd(Builder.CreateLoad(XteamRedLocalAddr), RHSOp);
559+
} else if (RedVarType->isIntegerTy()) {
560+
auto RHSOp = RHSValue->getType()->isIntegerTy()
561+
? Builder.CreateIntCast(RHSValue, RedVarType, false)
562+
: Builder.CreateFPToUI(RHSValue, RedVarType);
563+
RedRHS = Builder.CreateAdd(Builder.CreateLoad(XteamRedLocalAddr), RHSOp);
564+
} else
552565
llvm_unreachable("Unhandled type");
553566
// *xteam_red_local_addr = *xteam_red_local_addr + rhs_value
554567
Builder.CreateStore(RedRHS, XteamRedLocalAddr);

0 commit comments

Comments
 (0)