Skip to content

Commit ea4458a

Browse files
shrikardongrelanza
authored andcommitted
[CIR][CodeGen] Support for BI__rdtsc (#1523)
1 parent 2089f53 commit ea4458a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,12 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
137137
voidTy)
138138
.getResult();
139139
}
140+
case X86::BI__rdtsc: {
141+
mlir::Type intTy = cir::IntType::get(&getMLIRContext(), 64, false);
142+
return builder
143+
.create<cir::LLVMIntrinsicCallOp>(
144+
getLoc(E->getExprLoc()), builder.getStringAttr("x86.rdtsc"), intTy)
145+
.getResult();
146+
}
140147
}
141148
}

clang/test/CIR/CodeGen/X86/builtins-x86.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,11 @@ void test_mm_sfence() {
4646
// LLVM: call void @llvm.x86.sse.sfence()
4747
}
4848

49+
unsigned long long test_rdtsc() {
50+
// CIR-LABEL: @test_rdtsc
51+
// LLVM-LABEL: @test_rdtsc
52+
return __rdtsc();
53+
// CIR: {{%.*}} = cir.llvm.intrinsic "x86.rdtsc" : () -> !u64i
54+
// LLVM: call i64 @llvm.x86.rdtsc
55+
}
4956

0 commit comments

Comments
 (0)