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