@@ -1056,6 +1056,18 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
1056
1056
}
1057
1057
case ' d' :
1058
1058
if (Name.consume_front (" dbg." )) {
1059
+ // Mark debug intrinsics for upgrade to new debug format.
1060
+ if (F->getParent ()->IsNewDbgInfoFormat ) {
1061
+ if (Name == " addr" || Name == " value" || Name == " assign" ||
1062
+ Name == " declare" || Name == " label" ) {
1063
+ // There's no function to replace these with.
1064
+ NewFn = nullptr ;
1065
+ // But we do want these to get upgraded.
1066
+ return true ;
1067
+ }
1068
+ }
1069
+ // Update llvm.dbg.addr intrinsics even in "new debug mode"; they'll get
1070
+ // converted to DPValues later.
1059
1071
if (Name == " addr" || (Name == " value" && F->arg_size () == 4 )) {
1060
1072
rename (F);
1061
1073
NewFn = Intrinsic::getDeclaration (F->getParent (), Intrinsic::dbg_value);
@@ -2332,6 +2344,59 @@ static Value *upgradeAMDGCNIntrinsicCall(StringRef Name, CallBase *CI,
2332
2344
llvm_unreachable (" Unknown function for AMDGPU intrinsic upgrade." );
2333
2345
}
2334
2346
2347
+ // / Helper to unwrap intrinsic call MetadataAsValue operands.
2348
+ template <typename MDType>
2349
+ static MDType *unwrapMAVOp (CallBase *CI, unsigned Op) {
2350
+ if (MetadataAsValue *MAV = dyn_cast<MetadataAsValue>(CI->getArgOperand (Op)))
2351
+ return dyn_cast<MDType>(MAV->getMetadata ());
2352
+ return nullptr ;
2353
+ }
2354
+
2355
+ // / Convert debug intrinsic calls to non-instruction debug records.
2356
+ // / \p Name - Final part of the intrinsic name, e.g. 'value' in llvm.dbg.value.
2357
+ // / \p CI - The debug intrinsic call.
2358
+ static void upgradeDbgIntrinsicToDbgRecord (StringRef Name, CallBase *CI) {
2359
+ DbgRecord *DR = nullptr ;
2360
+ if (Name == " label" ) {
2361
+ DR = new DPLabel (unwrapMAVOp<DILabel>(CI, 0 ), CI->getDebugLoc ());
2362
+ } else if (Name == " assign" ) {
2363
+ DR = new DPValue (
2364
+ unwrapMAVOp<Metadata>(CI, 0 ), unwrapMAVOp<DILocalVariable>(CI, 1 ),
2365
+ unwrapMAVOp<DIExpression>(CI, 2 ), unwrapMAVOp<DIAssignID>(CI, 3 ),
2366
+ unwrapMAVOp<Metadata>(CI, 4 ), unwrapMAVOp<DIExpression>(CI, 5 ),
2367
+ CI->getDebugLoc ());
2368
+ } else if (Name == " declare" ) {
2369
+ DR = new DPValue (unwrapMAVOp<Metadata>(CI, 0 ),
2370
+ unwrapMAVOp<DILocalVariable>(CI, 1 ),
2371
+ unwrapMAVOp<DIExpression>(CI, 2 ), CI->getDebugLoc (),
2372
+ DPValue::LocationType::Declare);
2373
+ } else if (Name == " addr" ) {
2374
+ // Upgrade dbg.addr to dbg.value with DW_OP_deref.
2375
+ DIExpression *Expr = unwrapMAVOp<DIExpression>(CI, 2 );
2376
+ Expr = DIExpression::append (Expr, dwarf::DW_OP_deref);
2377
+ DR = new DPValue (unwrapMAVOp<Metadata>(CI, 0 ),
2378
+ unwrapMAVOp<DILocalVariable>(CI, 1 ), Expr,
2379
+ CI->getDebugLoc ());
2380
+ } else if (Name == " value" ) {
2381
+ // An old version of dbg.value had an extra offset argument.
2382
+ unsigned VarOp = 1 ;
2383
+ unsigned ExprOp = 2 ;
2384
+ if (CI->arg_size () == 4 ) {
2385
+ auto *Offset = dyn_cast_or_null<Constant>(CI->getArgOperand (1 ));
2386
+ // Nonzero offset dbg.values get dropped without a replacement.
2387
+ if (!Offset || !Offset->isZeroValue ())
2388
+ return ;
2389
+ VarOp = 2 ;
2390
+ ExprOp = 3 ;
2391
+ }
2392
+ DR = new DPValue (unwrapMAVOp<Metadata>(CI, 0 ),
2393
+ unwrapMAVOp<DILocalVariable>(CI, VarOp),
2394
+ unwrapMAVOp<DIExpression>(CI, ExprOp), CI->getDebugLoc ());
2395
+ }
2396
+ assert (DR && " Unhandled intrinsic kind in upgrade to DbgRecord" );
2397
+ CI->getParent ()->insertDbgRecordBefore (DR, CI->getIterator ());
2398
+ }
2399
+
2335
2400
// / Upgrade a call to an old intrinsic. All argument and return casting must be
2336
2401
// / provided to seamlessly integrate with existing context.
2337
2402
void llvm::UpgradeIntrinsicCall (CallBase *CI, Function *NewFn) {
@@ -2357,6 +2422,7 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
2357
2422
bool IsNVVM = Name.consume_front (" nvvm." );
2358
2423
bool IsARM = Name.consume_front (" arm." );
2359
2424
bool IsAMDGCN = Name.consume_front (" amdgcn." );
2425
+ bool IsDbg = Name.consume_front (" dbg." );
2360
2426
2361
2427
if (IsX86 && Name.starts_with (" sse4a.movnt." )) {
2362
2428
SmallVector<Metadata *, 1 > Elts;
@@ -2461,7 +2527,7 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
2461
2527
return ;
2462
2528
}
2463
2529
2464
- Value *Rep;
2530
+ Value *Rep = nullptr ;
2465
2531
// Upgrade packed integer vector compare intrinsics to compare instructions.
2466
2532
if (IsX86 && (Name.starts_with (" sse2.pcmp" ) ||
2467
2533
Name.starts_with (" avx2.pcmp" ))) {
@@ -4196,6 +4262,8 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
4196
4262
Rep = upgradeARMIntrinsicCall (Name, CI, F, Builder);
4197
4263
} else if (IsAMDGCN) {
4198
4264
Rep = upgradeAMDGCNIntrinsicCall (Name, CI, F, Builder);
4265
+ } else if (IsDbg && CI->getModule ()->IsNewDbgInfoFormat ) {
4266
+ upgradeDbgIntrinsicToDbgRecord (Name, CI);
4199
4267
} else {
4200
4268
llvm_unreachable (" Unknown function for CallBase upgrade." );
4201
4269
}
0 commit comments