Skip to content

Commit 85a7bba

Browse files
authored
Cleanup MC/DC intrinsics for #82448 (#95496)
3rd arg of `tvbitmap.update` was made unused. Remove 3rd arg. Sweep `condbitmap.update`, since it is no longer used.
1 parent ecea837 commit 85a7bba

File tree

9 files changed

+9
-144
lines changed

9 files changed

+9
-144
lines changed

clang/lib/CodeGen/CodeGenPGO.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1260,9 +1260,8 @@ void CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder,
12601260
// from a pointer to a dedicated temporary value on the stack that is itself
12611261
// updated via emitMCDCCondBitmapReset() and emitMCDCCondBitmapUpdate(). The
12621262
// index represents an executed test vector.
1263-
llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
1263+
llvm::Value *Args[4] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
12641264
Builder.getInt64(FunctionHash),
1265-
Builder.getInt32(0), // Unused
12661265
Builder.getInt32(MCDCTestVectorBitmapOffset),
12671266
MCDCCondBitmapAddr.emitRawPointer(CGF)};
12681267
Builder.CreateCall(

clang/test/Profile/c-mcdc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int test(int a, int b, int c, int d, int e, int f) {
8282

8383
// UPDATE FINAL BITMASK WITH RESULT.
8484
// NOPROFPASS-LABEL: lor.end:
85-
// NOPROFPASS: call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 [[HASH]], i32 0, i32 0, ptr %mcdc.addr)
85+
// NOPROFPASS: call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 [[HASH]], i32 0, ptr %mcdc.addr)
8686
// MCDC-DAG: %[[TEMP0:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
8787
// MCDC: %[[TEMP:[0-9]+]] = add i32 %[[TEMP0]], 0
8888
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3

llvm/docs/LangRef.rst

+2-51
Original file line numberDiff line numberDiff line change
@@ -14441,52 +14441,6 @@ to generate the appropriate data structures and the code to instrument MC/DC
1444114441
test vectors in a format that can be written out by a compiler runtime and
1444214442
consumed via the ``llvm-profdata`` tool.
1444314443

14444-
'``llvm.instrprof.mcdc.condbitmap.update``' Intrinsic
14445-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14446-
14447-
Syntax:
14448-
"""""""
14449-
14450-
::
14451-
14452-
declare void @llvm.instrprof.mcdc.condbitmap.update(ptr <name>, i64 <hash>,
14453-
i32 <condition-id>,
14454-
ptr <mcdc-temp-addr>,
14455-
i1 <bool-value>)
14456-
14457-
Overview:
14458-
"""""""""
14459-
14460-
The '``llvm.instrprof.mcdc.condbitmap.update``' intrinsic is used to track
14461-
MC/DC condition evaluation for each condition in a boolean expression.
14462-
14463-
Arguments:
14464-
""""""""""
14465-
14466-
The first argument is a pointer to a global variable containing the
14467-
name of the entity being instrumented. This should generally be the
14468-
(mangled) function name for a set of counters.
14469-
14470-
The second argument is a hash value that can be used by the consumer
14471-
of the profile data to detect changes to the instrumented source.
14472-
14473-
The third argument is an ID of a condition to track. This value is used as a
14474-
bit index into the condition bitmap.
14475-
14476-
The fourth argument is the address of the condition bitmap.
14477-
14478-
The fifth argument is the boolean value representing the evaluation of the
14479-
condition (true or false)
14480-
14481-
Semantics:
14482-
""""""""""
14483-
14484-
This intrinsic represents the update of a condition bitmap that is local to a
14485-
function and will cause the ``-instrprof`` pass to generate the code to
14486-
instrument the control flow around each condition in a boolean expression. The
14487-
ID of each condition corresponds to a bit index in the condition bitmap which
14488-
is set based on the evaluation of the condition.
14489-
1449014444
'``llvm.instrprof.mcdc.tvbitmap.update``' Intrinsic
1449114445
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1449214446

@@ -14496,7 +14450,6 @@ Syntax:
1449614450
::
1449714451

1449814452
declare void @llvm.instrprof.mcdc.tvbitmap.update(ptr <name>, i64 <hash>,
14499-
i32 <unused>)
1450014453
i32 <bitmap-index>,
1450114454
ptr <mcdc-temp-addr>)
1450214455

@@ -14520,12 +14473,10 @@ name of the entity being instrumented. This should generally be the
1452014473
The second argument is a hash value that can be used by the consumer
1452114474
of the profile data to detect changes to the instrumented source.
1452214475

14523-
The third argument is not used.
14524-
14525-
The fourth argument is the bit index into the global test vector bitmap
14476+
The third argument is the bit index into the global test vector bitmap
1452614477
corresponding to the function.
1452714478

14528-
The fifth argument is the address of the condition bitmap, which contains a
14479+
The fourth argument is the address of the condition bitmap, which contains a
1452914480
value representing an executed MC/DC test vector. It is loaded and used as the
1453014481
bit index of the test vector bitmap.
1453114482

llvm/include/llvm/IR/IntrinsicInst.h

+2-33
Original file line numberDiff line numberDiff line change
@@ -1455,9 +1455,7 @@ class InstrProfInstBase : public IntrinsicInst {
14551455
public:
14561456
static bool classof(const Value *V) {
14571457
if (const auto *Instr = dyn_cast<IntrinsicInst>(V))
1458-
return isCounterBase(*Instr) || isMCDCBitmapBase(*Instr) ||
1459-
Instr->getIntrinsicID() ==
1460-
Intrinsic::instrprof_mcdc_condbitmap_update;
1458+
return isCounterBase(*Instr) || isMCDCBitmapBase(*Instr);
14611459
return false;
14621460
}
14631461
// The name of the instrumented function.
@@ -1618,43 +1616,14 @@ class InstrProfMCDCTVBitmapUpdate : public InstrProfMCDCBitmapInstBase {
16181616
/// \return The index of the TestVector Bitmap upon which this intrinsic
16191617
/// acts.
16201618
ConstantInt *getBitmapIndex() const {
1621-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1619+
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
16221620
}
16231621

16241622
/// \return The address of the corresponding condition bitmap containing
16251623
/// the index of the TestVector to update within the TestVector Bitmap.
1626-
Value *getMCDCCondBitmapAddr() const {
1627-
return cast<Value>(const_cast<Value *>(getArgOperand(4)));
1628-
}
1629-
};
1630-
1631-
/// This represents the llvm.instrprof.mcdc.condbitmap.update intrinsic.
1632-
/// It does not pertain to global bitmap updates or parameters and so doesn't
1633-
/// inherit from InstrProfMCDCBitmapInstBase.
1634-
class InstrProfMCDCCondBitmapUpdate : public InstrProfInstBase {
1635-
public:
1636-
static bool classof(const IntrinsicInst *I) {
1637-
return I->getIntrinsicID() == Intrinsic::instrprof_mcdc_condbitmap_update;
1638-
}
1639-
static bool classof(const Value *V) {
1640-
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1641-
}
1642-
1643-
/// \return The ID of the condition to update.
1644-
ConstantInt *getCondID() const {
1645-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1646-
}
1647-
1648-
/// \return The address of the corresponding condition bitmap.
16491624
Value *getMCDCCondBitmapAddr() const {
16501625
return cast<Value>(const_cast<Value *>(getArgOperand(3)));
16511626
}
1652-
1653-
/// \return The boolean value to set in the condition bitmap for the
1654-
/// corresponding condition ID. This represents how the condition evaluated.
1655-
Value *getCondBool() const {
1656-
return cast<Value>(const_cast<Value *>(getArgOperand(4)));
1657-
}
16581627
};
16591628

16601629
class PseudoProbeInst : public IntrinsicInst {

llvm/include/llvm/IR/Intrinsics.td

+1-6
Original file line numberDiff line numberDiff line change
@@ -939,12 +939,7 @@ def int_instrprof_mcdc_parameters : Intrinsic<[],
939939
// A test vector bitmap update for instrumentation based MCDC profiling.
940940
def int_instrprof_mcdc_tvbitmap_update : Intrinsic<[],
941941
[llvm_ptr_ty, llvm_i64_ty,
942-
llvm_i32_ty, llvm_i32_ty, llvm_ptr_ty]>;
943-
944-
// A condition bitmap value update for instrumentation based MCDC profiling.
945-
def int_instrprof_mcdc_condbitmap_update : Intrinsic<[],
946-
[llvm_ptr_ty, llvm_i64_ty,
947-
llvm_i32_ty, llvm_ptr_ty, llvm_i1_ty]>;
942+
llvm_i32_ty, llvm_ptr_ty]>;
948943

949944
def int_call_preallocated_setup : DefaultAttrsIntrinsic<[llvm_token_ty], [llvm_i32_ty]>;
950945
def int_call_preallocated_arg : DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_token_ty, llvm_i32_ty]>;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -7576,8 +7576,6 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
75767576
llvm_unreachable("instrprof failed to lower mcdc parameters");
75777577
case Intrinsic::instrprof_mcdc_tvbitmap_update:
75787578
llvm_unreachable("instrprof failed to lower an mcdc tvbitmap update");
7579-
case Intrinsic::instrprof_mcdc_condbitmap_update:
7580-
llvm_unreachable("instrprof failed to lower an mcdc condbitmap update");
75817579
case Intrinsic::localescape: {
75827580
MachineFunction &MF = DAG.getMachineFunction();
75837581
const TargetInstrInfo *TII = DAG.getSubtarget().getInstrInfo();

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

-35
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,6 @@ class InstrLowerer final {
278278
/// using the index represented by the a temp value into a bitmap.
279279
void lowerMCDCTestVectorBitmapUpdate(InstrProfMCDCTVBitmapUpdate *Ins);
280280

281-
/// Replace instrprof.mcdc.temp.update with a shift and or instruction using
282-
/// the corresponding condition ID.
283-
void lowerMCDCCondBitmapUpdate(InstrProfMCDCCondBitmapUpdate *Ins);
284-
285281
/// Compute the address of the counter value that this profiling instruction
286282
/// acts on.
287283
Value *getCounterAddress(InstrProfCntrInstBase *I);
@@ -648,9 +644,6 @@ bool InstrLowerer::lowerIntrinsics(Function *F) {
648644
} else if (auto *IPBU = dyn_cast<InstrProfMCDCTVBitmapUpdate>(&Instr)) {
649645
lowerMCDCTestVectorBitmapUpdate(IPBU);
650646
MadeChange = true;
651-
} else if (auto *IPTU = dyn_cast<InstrProfMCDCCondBitmapUpdate>(&Instr)) {
652-
lowerMCDCCondBitmapUpdate(IPTU);
653-
MadeChange = true;
654647
}
655648
}
656649
}
@@ -1053,34 +1046,6 @@ void InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
10531046
Update->eraseFromParent();
10541047
}
10551048

1056-
void InstrLowerer::lowerMCDCCondBitmapUpdate(
1057-
InstrProfMCDCCondBitmapUpdate *Update) {
1058-
IRBuilder<> Builder(Update);
1059-
auto *Int32Ty = Type::getInt32Ty(M.getContext());
1060-
auto *MCDCCondBitmapAddr = Update->getMCDCCondBitmapAddr();
1061-
1062-
// Load the MCDC temporary value from the stack.
1063-
// %mcdc.temp = load i32, ptr %mcdc.addr, align 4
1064-
auto *Temp = Builder.CreateLoad(Int32Ty, MCDCCondBitmapAddr, "mcdc.temp");
1065-
1066-
// Zero-extend the evaluated condition boolean value (0 or 1) by 32bits.
1067-
// %1 = zext i1 %tobool to i32
1068-
auto *CondV_32 = Builder.CreateZExt(Update->getCondBool(), Int32Ty);
1069-
1070-
// Shift the boolean value left (by the condition's ID) to form a bitmap.
1071-
// %2 = shl i32 %1, <Update->getCondID()>
1072-
auto *ShiftedVal = Builder.CreateShl(CondV_32, Update->getCondID());
1073-
1074-
// Perform logical OR of the bitmap against the loaded MCDC temporary value.
1075-
// %3 = or i32 %mcdc.temp, %2
1076-
auto *Result = Builder.CreateOr(Temp, ShiftedVal);
1077-
1078-
// Store the updated temporary value back to the stack.
1079-
// store i32 %3, ptr %mcdc.addr, align 4
1080-
Builder.CreateStore(Result, MCDCCondBitmapAddr);
1081-
Update->eraseFromParent();
1082-
}
1083-
10841049
/// Get the name of a profiling variable for a particular function.
10851050
static std::string getVarName(InstrProfInstBase *Inc, StringRef Prefix,
10861051
bool &Renamed) {

llvm/test/Instrumentation/InstrProfiling/mcdc.ll

+2-11
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ entry:
2222
%0 = load i32, ptr %A.addr, align 4
2323
%tobool = icmp ne i32 %0, 0
2424

25-
call void @llvm.instrprof.mcdc.condbitmap.update(ptr @__profn_test, i64 99278, i32 0, ptr %mcdc.addr, i1 %tobool)
26-
; CHECK: %[[TEMP:mcdc.*]] = load i32, ptr %mcdc.addr, align 4
27-
; CHECK-NEXT: %[[LAB1:[0-9]+]] = zext i1 %tobool to i32
28-
; CHECK-NEXT: %[[LAB2:[0-9]+]] = shl i32 %[[LAB1]], 0
29-
; CHECK-NEXT: %[[LAB3:[0-9]+]] = or i32 %[[TEMP]], %[[LAB2]]
30-
; CHECK-NEXT: store i32 %[[LAB3]], ptr %mcdc.addr, align 4
31-
32-
call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 99278, i32 1, i32 0, ptr %mcdc.addr)
25+
call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 99278, i32 0, ptr %mcdc.addr)
3326
; CHECK: %[[TEMP0:mcdc.*]] = load i32, ptr %mcdc.addr, align 4
3427
; CHECK-NEXT: %[[TEMP:[0-9]+]] = add i32 %[[TEMP0]], 0
3528
; CHECK-NEXT: %[[LAB4:[0-9]+]] = lshr i32 %[[TEMP]], 3
@@ -47,6 +40,4 @@ declare void @llvm.instrprof.cover(ptr, i64, i32, i32)
4740

4841
declare void @llvm.instrprof.mcdc.parameters(ptr, i64, i32)
4942

50-
declare void @llvm.instrprof.mcdc.condbitmap.update(ptr, i64, i32, ptr, i1)
51-
52-
declare void @llvm.instrprof.mcdc.tvbitmap.update(ptr, i64, i32, i32, ptr)
43+
declare void @llvm.instrprof.mcdc.tvbitmap.update(ptr, i64, i32, ptr)

llvm/unittests/IR/IntrinsicsTest.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ TEST_F(IntrinsicsTest, InstrProfInheritance) {
7777
return isa<TYPE>(I) && is##PARENT(I); \
7878
}
7979
__ISA(InstrProfCntrInstBase, InstrProfInstBase);
80-
__ISA(InstrProfMCDCCondBitmapUpdate, InstrProfInstBase);
8180
__ISA(InstrProfCoverInst, InstrProfCntrInstBase);
8281
__ISA(InstrProfIncrementInst, InstrProfCntrInstBase);
8382
__ISA(InstrProfIncrementInstStep, InstrProfIncrementInst);
@@ -96,8 +95,6 @@ TEST_F(IntrinsicsTest, InstrProfInheritance) {
9695
{Intrinsic::instrprof_increment, isInstrProfIncrementInst},
9796
{Intrinsic::instrprof_increment_step, isInstrProfIncrementInstStep},
9897
{Intrinsic::instrprof_callsite, isInstrProfCallsite},
99-
{Intrinsic::instrprof_mcdc_condbitmap_update,
100-
isInstrProfMCDCCondBitmapUpdate},
10198
{Intrinsic::instrprof_mcdc_parameters,
10299
isInstrProfMCDCBitmapParameters},
103100
{Intrinsic::instrprof_mcdc_tvbitmap_update,

0 commit comments

Comments
 (0)