@@ -5741,21 +5741,23 @@ static void addAllocasForDeclareTargetFunctionPointerArgs(
5741
5741
// below. The users are updated accordingly.
5742
5742
for (auto &Arg : Fn->args ()) {
5743
5743
if (Arg.getType ()->isPointerTy ()) {
5744
- llvm::Value *V = builder.CreateAlloca (Arg.getType (), allocaAS, nullptr );
5745
- if (allocaAS != defaultAS)
5746
- V = ompBuilder->Builder .CreateAddrSpaceCast (
5747
- V, builder.getPtrTy (defaultAS));
5748
- llvm::StoreInst *Store = builder.CreateStore (&Arg, V);
5749
- llvm::Value *Load = builder.CreateLoad (Arg.getType (), V);
5744
+ llvm::Value *AllocaV =
5745
+ builder.CreateAlloca (Arg.getType (), allocaAS, nullptr );
5746
+ llvm::Value *GenericV = allocaAS == defaultAS
5747
+ ? AllocaV
5748
+ : ompBuilder->Builder .CreateAddrSpaceCast (
5749
+ AllocaV, builder.getPtrTy (defaultAS));
5750
+ llvm::StoreInst *Store = builder.CreateStore (&Arg, GenericV);
5751
+ llvm::Value *Load = builder.CreateLoad (Arg.getType (), GenericV);
5750
5752
llvm::SmallVector<llvm::DbgVariableIntrinsic *> DbgUsers;
5751
5753
llvm::SmallVector<llvm::DbgVariableRecord *> DPUsers;
5752
5754
llvm::findDbgUsers (DbgUsers, &Arg, &DPUsers);
5753
5755
for (auto *DVI : DbgUsers) {
5754
- DVI->replaceVariableLocationOp (&Arg, V );
5756
+ DVI->replaceVariableLocationOp (&Arg, AllocaV );
5755
5757
DVI->setExpression (Expr);
5756
5758
}
5757
5759
for (auto *DVR : DPUsers) {
5758
- DVR->replaceVariableLocationOp (&Arg, V );
5760
+ DVR->replaceVariableLocationOp (&Arg, AllocaV );
5759
5761
DVR->setExpression (Expr);
5760
5762
}
5761
5763
Arg.replaceUsesWithIf (Load, [&](const llvm::Use &U) -> bool {
@@ -5785,16 +5787,21 @@ static void updateDebugInfoForDeclareTargetFunctions(
5785
5787
// Skip if an expression is already present.
5786
5788
if ((Old != nullptr ) && (Old->getNumElements () != 0 ))
5787
5789
return ;
5788
- for (auto Loc : DR->location_ops ()) {
5789
- llvm::Type *Ty = Loc->getType ();
5790
- if (auto *Ref = dyn_cast<llvm::AddrSpaceCastInst>(Loc))
5791
- Ty = Ref->getPointerOperand ()->getType ();
5792
- llvm::DIExprBuilder EB (Fn->getContext ());
5793
- EB.append <llvm::DIOp::Arg>(0u , Ty);
5794
- EB.append <llvm::DIOp::Deref>(Loc->getType ());
5795
- DR->setExpression (EB.intoExpression ());
5796
- break ;
5797
- }
5790
+ // Skip if the there are multiple inputs.
5791
+ // FIXME: Could this be an assert? More to the point, can we do this at the
5792
+ // point of generating the intrinsics to begin with, rather than fixing them
5793
+ // up here?
5794
+ if (DR->getNumVariableLocationOps () != 1u )
5795
+ return ;
5796
+ auto Loc = DR->getVariableLocationOp (0u );
5797
+ if (!isa<llvm::AllocaInst>(Loc->stripPointerCasts ()))
5798
+ return ;
5799
+ llvm::AllocaInst *AI = cast<llvm::AllocaInst>(Loc->stripPointerCasts ());
5800
+ DR->replaceVariableLocationOp (0u , AI);
5801
+ llvm::DIExprBuilder EB (Fn->getContext ());
5802
+ EB.append <llvm::DIOp::Arg>(0u , AI->getType ());
5803
+ EB.append <llvm::DIOp::Deref>(AI->getAllocatedType ());
5804
+ DR->setExpression (EB.intoExpression ());
5798
5805
};
5799
5806
5800
5807
for (llvm::Instruction &I : instructions (Fn)) {
0 commit comments