@@ -165,6 +165,8 @@ define i32* @test() {
165
165
%1 = bitcast i8* %call2 to i32*
166
166
%call3 = call noalias dereferenceable_or_null(40) i8* @malloc(i64 noundef 40)
167
167
%2 = bitcast i8* %call3 to i32*
168
+ %call4 = call noalias dereferenceable_or_null(40) i8* @malloc(i64 noundef 40)
169
+ %3 = bitcast i8* %call4 to i32*
168
170
ret i32* %1
169
171
}
170
172
declare dso_local noalias noundef i8* @malloc(i64 noundef)
@@ -204,6 +206,18 @@ declare dso_local noalias noundef i8* @malloc(i64 noundef)
204
206
EXPECT_FALSE (Call3->hasMetadata (LLVMContext::MD_memprof));
205
207
EXPECT_TRUE (Call3->hasFnAttr (" memprof" ));
206
208
EXPECT_EQ (Call3->getFnAttr (" memprof" ).getValueAsString (), " hot" );
209
+
210
+ // Fourth call has hot and non-cold contexts. These should be treated as
211
+ // notcold and given a notcold attribute.
212
+ CallStackTrie Trie4;
213
+ Trie4.addCallStack (AllocationType::Hot, {5 , 6 });
214
+ Trie4.addCallStack (AllocationType::NotCold, {5 , 7 , 8 });
215
+ CallBase *Call4 = findCall (*Func, " call4" );
216
+ Trie4.buildAndAttachMIBMetadata (Call4);
217
+
218
+ EXPECT_FALSE (Call4->hasMetadata (LLVMContext::MD_memprof));
219
+ EXPECT_TRUE (Call4->hasFnAttr (" memprof" ));
220
+ EXPECT_EQ (Call4->getFnAttr (" memprof" ).getValueAsString (), " notcold" );
207
221
}
208
222
209
223
// Test CallStackTrie::addCallStack interface taking allocation type and list of
@@ -299,56 +313,8 @@ declare dso_local noalias noundef i8* @malloc(i64 noundef)
299
313
EXPECT_EQ (getMIBAllocType (MIB), AllocationType::Cold);
300
314
else {
301
315
ASSERT_EQ (StackId->getZExtValue (), 3u );
302
- EXPECT_EQ (getMIBAllocType (MIB), AllocationType::Hot);
303
- }
304
- }
305
- }
306
-
307
- // Test CallStackTrie::addCallStack interface taking allocation type and list of
308
- // call stack ids.
309
- // Test that an allocation call reached by both non cold and hot call stacks
310
- // gets memprof metadata representing the different allocation type contexts.
311
- TEST_F (MemoryProfileInfoTest, NotColdAndHotMIB) {
312
- LLVMContext C;
313
- std::unique_ptr<Module> M = makeLLVMModule (C,
314
- R"IR(
315
- target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
316
- target triple = "x86_64-pc-linux-gnu"
317
- define i32* @test() {
318
- entry:
319
- %call = call noalias dereferenceable_or_null(40) i8* @malloc(i64 noundef 40)
320
- %0 = bitcast i8* %call to i32*
321
- ret i32* %0
322
- }
323
- declare dso_local noalias noundef i8* @malloc(i64 noundef)
324
- )IR" );
325
-
326
- Function *Func = M->getFunction (" test" );
327
-
328
- CallStackTrie Trie;
329
- Trie.addCallStack (AllocationType::NotCold, {1 , 2 });
330
- Trie.addCallStack (AllocationType::Hot, {1 , 3 });
331
-
332
- CallBase *Call = findCall (*Func, " call" );
333
- Trie.buildAndAttachMIBMetadata (Call);
334
-
335
- EXPECT_FALSE (Call->hasFnAttr (" memprof" ));
336
- EXPECT_TRUE (Call->hasMetadata (LLVMContext::MD_memprof));
337
- MDNode *MemProfMD = Call->getMetadata (LLVMContext::MD_memprof);
338
- ASSERT_EQ (MemProfMD->getNumOperands (), 2u );
339
- for (auto &MIBOp : MemProfMD->operands ()) {
340
- MDNode *MIB = dyn_cast<MDNode>(MIBOp);
341
- MDNode *StackMD = getMIBStackNode (MIB);
342
- ASSERT_NE (StackMD, nullptr );
343
- ASSERT_EQ (StackMD->getNumOperands (), 2u );
344
- auto *StackId = mdconst::dyn_extract<ConstantInt>(StackMD->getOperand (0 ));
345
- ASSERT_EQ (StackId->getZExtValue (), 1u );
346
- StackId = mdconst::dyn_extract<ConstantInt>(StackMD->getOperand (1 ));
347
- if (StackId->getZExtValue () == 2u )
316
+ // Hot contexts are converted to NotCold when building the metadata.
348
317
EXPECT_EQ (getMIBAllocType (MIB), AllocationType::NotCold);
349
- else {
350
- ASSERT_EQ (StackId->getZExtValue (), 3u );
351
- EXPECT_EQ (getMIBAllocType (MIB), AllocationType::Hot);
352
318
}
353
319
}
354
320
}
@@ -401,7 +367,8 @@ declare dso_local noalias noundef i8* @malloc(i64 noundef)
401
367
EXPECT_EQ (getMIBAllocType (MIB), AllocationType::NotCold);
402
368
} else {
403
369
ASSERT_EQ (StackId->getZExtValue (), 4u );
404
- EXPECT_EQ (getMIBAllocType (MIB), AllocationType::Hot);
370
+ // Hot contexts are converted to NotCold when building the metadata.
371
+ EXPECT_EQ (getMIBAllocType (MIB), AllocationType::NotCold);
405
372
}
406
373
}
407
374
}
@@ -463,7 +430,8 @@ declare dso_local noalias noundef i8* @malloc(i64 noundef)
463
430
EXPECT_EQ (getMIBAllocType (MIB), AllocationType::NotCold);
464
431
else {
465
432
ASSERT_EQ (StackId->getZExtValue (), 8u );
466
- EXPECT_EQ (getMIBAllocType (MIB), AllocationType::Hot);
433
+ // Hot contexts are converted to NotCold when building the metadata.
434
+ EXPECT_EQ (getMIBAllocType (MIB), AllocationType::NotCold);
467
435
}
468
436
}
469
437
}
@@ -606,7 +574,8 @@ declare dso_local noalias noundef i8* @malloc(i64 noundef)
606
574
EXPECT_EQ (getMIBAllocType (MIB), AllocationType::NotCold);
607
575
else {
608
576
ASSERT_EQ (StackId->getZExtValue (), 8u );
609
- EXPECT_EQ (getMIBAllocType (MIB), AllocationType::Hot);
577
+ // Hot contexts are converted to NotCold when building the new metadata.
578
+ EXPECT_EQ (getMIBAllocType (MIB), AllocationType::NotCold);
610
579
}
611
580
}
612
581
}
0 commit comments