Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -4171,6 +4171,16 @@ def CIR_ATanOp : CIR_UnaryFPToFPBuiltinOp<"atan", "ATanOp"> {
}];
}

def CIR_CeilOp : CIR_UnaryFPToFPBuiltinOp<"ceil", "FCeilOp"> {
let summary = "Computes the ceiling of the specified value";
let description = [{
`cir.ceil` computes the ceiling of a given value and returns a result
of the same type.

Floating-point exceptions are ignored, and it does not set `errno`.
}];
}

def CIR_CosOp : CIR_UnaryFPToFPBuiltinOp<"cos", "CosOp"> {
let summary = "Computes the floating-point cosine value";
let description = [{
Expand Down
11 changes: 11 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
assert(!cir::MissingFeatures::fastMathFlags());
return emitUnaryMaybeConstrainedFPBuiltin<cir::CosOp>(*this, *e);

case Builtin::BIceil:
case Builtin::BIceilf:
case Builtin::BIceill:
case Builtin::BI__builtin_ceil:
case Builtin::BI__builtin_ceilf:
case Builtin::BI__builtin_ceilf16:
case Builtin::BI__builtin_ceill:
case Builtin::BI__builtin_ceilf128:
assert(!cir::MissingFeatures::fastMathFlags());
return emitUnaryMaybeConstrainedFPBuiltin<cir::CeilOp>(*this, *e);

case Builtin::BIfabs:
case Builtin::BIfabsf:
case Builtin::BIfabsl:
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,14 @@ mlir::LogicalResult CIRToLLVMATanOpLowering::matchAndRewrite(
return mlir::success();
}

mlir::LogicalResult CIRToLLVMCeilOpLowering::matchAndRewrite(
cir::CeilOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
mlir::Type resTy = typeConverter->convertType(op.getType());
rewriter.replaceOpWithNewOp<mlir::LLVM::FCeilOp>(op, resTy, adaptor.getSrc());
return mlir::success();
}

mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite(
cir::AllocaOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
Expand Down
11 changes: 9 additions & 2 deletions clang/test/CIR/CodeGen/builtins-floating-point.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@

float cosf(float f) {
return __builtin_cosf(f);
// CHECK: %{{.*}} = cir.cos {{.*}} : !cir.float
// CIR: %{{.*}} = cir.cos %{{.*}} : !cir.float
// LLVM: %{{.*}} = call float @llvm.cos.f32(float %{{.*}})
// OGCG: %{{.*}} = call float @llvm.cos.f32(float %{{.*}})
}

double cos(double f) {
return __builtin_cos(f);
// CIR: {{.+}} = cir.cos {{.+}} : !cir.double
// CIR: %{{.*}} = cir.cos %{{.*}} : !cir.double
// LLVM: %{{.*}} = call double @llvm.cos.f64(double %{{.*}})
// OGCG: %{{.*}} = call double @llvm.cos.f64(double %{{.*}})
}

float ceil(float f) {
return __builtin_ceilf(f);
// CIR: %{{.*}} = cir.ceil %{{.*}} : !cir.float
// LLVM: %{{.*}} = call float @llvm.ceil.f32(float %{{.*}})
// OGCG: %{{.*}} = call float @llvm.ceil.f32(float %{{.*}})
}
Loading