Skip to content

Commit 2b4b002

Browse files
committed
- Remove all builtin handling not needed for constant foldable builtin calls
- Address review feedback
1 parent 401dd62 commit 2b4b002

File tree

8 files changed

+39
-482
lines changed

8 files changed

+39
-482
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,40 +1854,6 @@ def FuncOp : CIR_Op<"func", [
18541854
let hasVerifier = 1;
18551855
}
18561856

1857-
//===----------------------------------------------------------------------===//
1858-
// LLVMIntrinsicCallOp
1859-
//===----------------------------------------------------------------------===//
1860-
1861-
def LLVMIntrinsicCallOp : CIR_Op<"llvm.intrinsic"> {
1862-
let summary = "Call to llvm intrinsic functions that is not defined in CIR";
1863-
let description = [{
1864-
The `cir.llvm.intrinsic` operation represents a call-like expression which has
1865-
a return type and arguments that map directly to an llvm intrinsic.
1866-
It only records its own name (`intrinsic_name`).
1867-
}];
1868-
1869-
let results = (outs Optional<CIR_AnyType>:$result);
1870-
let arguments = (ins
1871-
StrAttr:$intrinsic_name, Variadic<CIR_AnyType>:$arg_ops);
1872-
1873-
let skipDefaultBuilders = 1;
1874-
1875-
let assemblyFormat = [{
1876-
$intrinsic_name $arg_ops `:` functional-type($arg_ops, $result) attr-dict
1877-
}];
1878-
1879-
let builders = [
1880-
OpBuilder<(ins "mlir::StringAttr":$intrinsic_name, "mlir::Type":$resType,
1881-
CArg<"mlir::ValueRange", "{}">:$operands), [{
1882-
$_state.addAttribute("intrinsic_name", intrinsic_name);
1883-
$_state.addOperands(operands);
1884-
if (resType)
1885-
$_state.addTypes(resType);
1886-
}]>,
1887-
];
1888-
1889-
}
1890-
18911857
//===----------------------------------------------------------------------===//
18921858
// CallOp
18931859
//===----------------------------------------------------------------------===//

clang/lib/CIR/CodeGen/CIRGenBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ mlir::Value CIRGenBuilderTy::getArrayElement(mlir::Location arrayLocBegin,
4242
cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc,
4343
llvm::APSInt intVal) {
4444
bool isSigned = intVal.isSigned();
45-
auto width = intVal.getBitWidth();
45+
unsigned width = intVal.getBitWidth();
4646
cir::IntType t = isSigned ? getSIntNTy(width) : getUIntNTy(width);
4747
return getConstInt(loc, t,
4848
isSigned ? intVal.getSExtValue() : intVal.getZExtValue());
4949
}
5050

5151
cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc,
5252
llvm::APInt intVal) {
53-
auto width = intVal.getBitWidth();
53+
unsigned width = intVal.getBitWidth();
5454
cir::IntType t = getUIntNTy(width);
5555
return getConstInt(loc, t, intVal.getZExtValue());
5656
}

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h"
1717
#include "clang/CIR/MissingFeatures.h"
18+
#include "llvm/ADT/APFloat.h"
1819
#include "llvm/ADT/STLExtras.h"
1920

2021
namespace clang::CIRGen {
@@ -235,11 +236,28 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
235236

236237
cir::ConstantOp getConstInt(mlir::Location loc, mlir::Type t, uint64_t c);
237238

238-
cir::ConstantOp getConstFP(mlir::Location loc, mlir::Type t,
239-
llvm::APFloat fpVal) {
240-
assert((mlir::isa<cir::SingleType, cir::DoubleType>(t)) &&
241-
"expected cir::SingleType or cir::DoubleType");
242-
return create<cir::ConstantOp>(loc, getAttr<cir::FPAttr>(t, fpVal));
239+
mlir::Type getFPType(llvm::fltSemantics const &sem) {
240+
switch (llvm::APFloat::SemanticsToEnum(sem)) {
241+
case llvm::APFloat::S_IEEEhalf:
242+
return cir::FP16Type::get(getContext(), typeCache.FP16Ty);
243+
case llvm::APFloat::S_BFloat:
244+
return cir::BF16Type::get(getContext(), typeCache.BFloat16Ty);
245+
case llvm::APFloat::S_IEEEsingle:
246+
return cir::SingleType::get(getContext(), typeCache.FloatTy);
247+
case llvm::APFloat::S_IEEEdouble:
248+
return cir::DoubleType::get(getContext(), typeCache.DoubleTy);
249+
case llvm::APFloat::S_IEEEquad:
250+
return cir::FP128Type::get(getContext(), typeCache.FP128Ty);
251+
case llvm::APFloat::S_x87DoubleExtended:
252+
return cir::FP80Type::get(getContext(), typeCache.FP80Ty);
253+
default:
254+
llvm_unreachable("Unrecognized floating semantics");
255+
}
256+
}
257+
258+
cir::ConstantOp getConstFP(mlir::Location loc, llvm::APFloat fpVal) {
259+
mlir::Type type = getFPType(fpVal.getSemantics());
260+
return create<cir::ConstantOp>(loc, getAttr<cir::FPAttr>(type, fpVal));
243261
}
244262

245263
bool isInt8Ty(mlir::Type i) {

0 commit comments

Comments
 (0)