LLVM 24.0.0git
FixedPointBuilder.h
Go to the documentation of this file.
1//===- llvm/FixedPointBuilder.h - Builder for fixed-point ops ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the FixedPointBuilder class, which is used as a convenient
10// way to lower fixed-point arithmetic operations to LLVM IR.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_FIXEDPOINTBUILDER_H
15#define LLVM_IR_FIXEDPOINTBUILDER_H
16
18#include "llvm/IR/Constant.h"
19#include "llvm/IR/Constants.h"
20#include "llvm/IR/IRBuilder.h"
21#include "llvm/IR/InstrTypes.h"
22#include "llvm/IR/Instruction.h"
24#include "llvm/IR/Intrinsics.h"
25#include "llvm/IR/Type.h"
26#include "llvm/IR/Value.h"
27
28#include <cmath>
29
30namespace llvm {
31
32template <class IRBuilderTy> class FixedPointBuilder {
33 IRBuilderTy &B;
34
35 Value *Convert(Value *Src, const FixedPointSemantics &SrcSema,
36 const FixedPointSemantics &DstSema, bool DstIsInteger) {
37 unsigned SrcWidth = SrcSema.getWidth();
38 unsigned DstWidth = DstSema.getWidth();
39 unsigned SrcScale = SrcSema.getScale();
40 unsigned DstScale = DstSema.getScale();
41 bool SrcIsSigned = SrcSema.isSigned();
42 bool DstIsSigned = DstSema.isSigned();
43
44 Type *DstIntTy = B.getIntNTy(DstWidth);
45
46 Value *Result = Src;
47 unsigned ResultWidth = SrcWidth;
48
49 // Downscale.
50 if (DstScale < SrcScale) {
51 // When converting to integers, we round towards zero. For negative
52 // numbers, right shifting rounds towards negative infinity. In this case,
53 // we can just round up before shifting.
54 if (DstIsInteger && SrcIsSigned) {
55 Value *Zero = Constant::getNullValue(Result->getType());
56 Value *IsNegative = B.CreateICmpSLT(Result, Zero);
57 Value *LowBits = ConstantInt::get(
58 B.getContext(), APInt::getLowBitsSet(ResultWidth, SrcScale));
59 Value *Rounded = B.CreateAdd(Result, LowBits);
60 Result = B.CreateSelect(IsNegative, Rounded, Result);
61 }
62
63 unsigned Shift = SrcScale - DstScale;
64 assert(Shift <= ResultWidth && "Shift cannot exceed result width");
65 if (Shift < ResultWidth) {
66 Result = SrcIsSigned ? B.CreateAShr(Result, Shift, "downscale")
67 : B.CreateLShr(Result, Shift, "downscale");
68 } else {
69 Result = Constant::getNullValue(Result->getType());
70 }
71 }
72
73 if (!DstSema.isSaturated()) {
74 // Resize.
75 Result = B.CreateIntCast(Result, DstIntTy, SrcIsSigned, "resize");
76
77 // Upscale.
78 if (DstScale > SrcScale)
79 Result = B.CreateShl(Result, DstScale - SrcScale, "upscale");
80 } else {
81 // Adjust the number of fractional bits.
82 if (DstScale > SrcScale) {
83 // Compare to DstWidth to prevent resizing twice.
84 ResultWidth = std::max(SrcWidth + DstScale - SrcScale, DstWidth);
85 Type *UpscaledTy = B.getIntNTy(ResultWidth);
86 Result = B.CreateIntCast(Result, UpscaledTy, SrcIsSigned, "resize");
87 Result = B.CreateShl(Result, DstScale - SrcScale, "upscale");
88 }
89
90 // Handle saturation.
91 bool LessIntBits = DstSema.getIntegralBits() < SrcSema.getIntegralBits();
92 if (LessIntBits) {
93 Value *Max = ConstantInt::get(
94 B.getContext(),
95 APFixedPoint::getMax(DstSema).getValue().extOrTrunc(ResultWidth));
96 Value *TooHigh = SrcIsSigned ? B.CreateICmpSGT(Result, Max)
97 : B.CreateICmpUGT(Result, Max);
98 Result = B.CreateSelect(TooHigh, Max, Result, "satmax");
99 }
100 // Cannot overflow min to dest type if src is unsigned since all fixed
101 // point types can cover the unsigned min of 0.
102 if (SrcIsSigned && (LessIntBits || !DstIsSigned)) {
103 Value *Min = ConstantInt::get(
104 B.getContext(),
105 APFixedPoint::getMin(DstSema).getValue().extOrTrunc(ResultWidth));
106 Value *TooLow = B.CreateICmpSLT(Result, Min);
107 Result = B.CreateSelect(TooLow, Min, Result, "satmin");
108 }
109
110 // Resize the integer part to get the final destination size.
111 if (ResultWidth != DstWidth)
112 Result = B.CreateIntCast(Result, DstIntTy, SrcIsSigned, "resize");
113 }
114 return Result;
115 }
116
117 /// Get the common semantic for two semantics, with the added imposition that
118 /// saturated padded types retain the padding bit.
120 getCommonBinopSemantic(const FixedPointSemantics &LHSSema,
121 const FixedPointSemantics &RHSSema) {
122 auto C = LHSSema.getCommonSemantics(RHSSema);
123 bool BothPadded =
124 LHSSema.hasUnsignedPadding() && RHSSema.hasUnsignedPadding();
125 return FixedPointSemantics(
126 C.getWidth() + (unsigned)(BothPadded && C.isSaturated()), C.getScale(),
127 C.isSigned(), C.isSaturated(), BothPadded);
128 }
129
130 /// Given a floating point type and a fixed-point semantic, return a floating
131 /// point type which can accommodate the fixed-point semantic. This is either
132 /// \p Ty, or a floating point type with a larger exponent than Ty.
133 Type *getAccommodatingFloatType(Type *Ty, const FixedPointSemantics &Sema) {
134 const fltSemantics *FloatSema = &Ty->getFltSemantics();
135 while (!Sema.fitsInFloatSemantics(*FloatSema))
136 FloatSema = APFixedPoint::promoteFloatSemantics(FloatSema);
137 return Type::getFloatingPointTy(Ty->getContext(), *FloatSema);
138 }
139
140public:
141 FixedPointBuilder(IRBuilderTy &Builder) : B(Builder) {}
142
143 /// Convert an integer value representing a fixed-point number from one
144 /// fixed-point semantic to another fixed-point semantic.
145 /// \p Src - The source value
146 /// \p SrcSema - The fixed-point semantic of the source value
147 /// \p DstSema - The resulting fixed-point semantic
149 const FixedPointSemantics &DstSema) {
150 return Convert(Src, SrcSema, DstSema, false);
151 }
152
153 /// Convert an integer value representing a fixed-point number to an integer
154 /// with the given bit width and signedness.
155 /// \p Src - The source value
156 /// \p SrcSema - The fixed-point semantic of the source value
157 /// \p DstWidth - The bit width of the result value
158 /// \p DstIsSigned - The signedness of the result value
160 unsigned DstWidth, bool DstIsSigned) {
161 return Convert(
162 Src, SrcSema,
163 FixedPointSemantics::GetIntegerSemantics(DstWidth, DstIsSigned), true);
164 }
165
166 /// Convert an integer value with the given signedness to an integer value
167 /// representing the given fixed-point semantic.
168 /// \p Src - The source value
169 /// \p SrcIsSigned - The signedness of the source value
170 /// \p DstSema - The resulting fixed-point semantic
171 Value *CreateIntegerToFixed(Value *Src, unsigned SrcIsSigned,
172 const FixedPointSemantics &DstSema) {
173 return Convert(Src,
175 Src->getType()->getScalarSizeInBits(), SrcIsSigned),
176 DstSema, false);
177 }
178
180 Type *DstTy) {
181 Value *Result;
182 Type *OpTy = getAccommodatingFloatType(DstTy, SrcSema);
183 // Convert the raw fixed-point value directly to floating point. If the
184 // value is too large to fit, it will be rounded, not truncated.
185 Result = SrcSema.isSigned() ? B.CreateSIToFP(Src, OpTy)
186 : B.CreateUIToFP(Src, OpTy);
187 // Rescale the integral-in-floating point by the scaling factor. This is
188 // lossless, except for overflow to infinity which is unlikely.
189 Result = B.CreateFMul(Result,
190 ConstantFP::get(OpTy, std::pow(2, -(int)SrcSema.getScale())));
191 if (OpTy != DstTy)
192 Result = B.CreateFPTrunc(Result, DstTy);
193 return Result;
194 }
195
197 bool UseSigned = DstSema.isSigned() || DstSema.hasUnsignedPadding();
198 Value *Result = Src;
199 Type *OpTy = getAccommodatingFloatType(Src->getType(), DstSema);
200 if (OpTy != Src->getType())
201 Result = B.CreateFPExt(Result, OpTy);
202 // Rescale the floating point value so that its significant bits (for the
203 // purposes of the conversion) are in the integral range.
204 Result = B.CreateFMul(Result,
205 ConstantFP::get(OpTy, std::pow(2, DstSema.getScale())));
206
207 Type *ResultTy = B.getIntNTy(DstSema.getWidth());
208 if (DstSema.isSaturated()) {
209 Intrinsic::ID IID =
210 UseSigned ? Intrinsic::fptosi_sat : Intrinsic::fptoui_sat;
211 Result = B.CreateIntrinsic(IID, {ResultTy, OpTy}, {Result});
212 } else {
213 Result = UseSigned ? B.CreateFPToSI(Result, ResultTy)
214 : B.CreateFPToUI(Result, ResultTy);
215 }
216
217 // When saturating unsigned-with-padding using signed operations, we may
218 // get negative values. Emit an extra clamp to zero.
219 if (DstSema.isSaturated() && DstSema.hasUnsignedPadding()) {
220 Constant *Zero = Constant::getNullValue(Result->getType());
221 Result =
222 B.CreateSelect(B.CreateICmpSLT(Result, Zero), Zero, Result, "satmin");
223 }
224
225 return Result;
226 }
227
228 /// Add two fixed-point values and return the result in their common semantic.
229 /// \p LHS - The left hand side
230 /// \p LHSSema - The semantic of the left hand side
231 /// \p RHS - The right hand side
232 /// \p RHSSema - The semantic of the right hand side
234 Value *RHS, const FixedPointSemantics &RHSSema) {
235 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
236 bool UseSigned = CommonSema.isSigned() || CommonSema.hasUnsignedPadding();
237
238 Value *WideLHS = CreateFixedToFixed(LHS, LHSSema, CommonSema);
239 Value *WideRHS = CreateFixedToFixed(RHS, RHSSema, CommonSema);
240
241 Value *Result;
242 if (CommonSema.isSaturated()) {
243 Intrinsic::ID IID = UseSigned ? Intrinsic::sadd_sat : Intrinsic::uadd_sat;
244 Result = B.CreateBinaryIntrinsic(IID, WideLHS, WideRHS);
245 } else {
246 Result = B.CreateAdd(WideLHS, WideRHS);
247 }
248
249 return CreateFixedToFixed(Result, CommonSema,
250 LHSSema.getCommonSemantics(RHSSema));
251 }
252
253 /// Subtract two fixed-point values and return the result in their common
254 /// semantic.
255 /// \p LHS - The left hand side
256 /// \p LHSSema - The semantic of the left hand side
257 /// \p RHS - The right hand side
258 /// \p RHSSema - The semantic of the right hand side
260 Value *RHS, const FixedPointSemantics &RHSSema) {
261 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
262 bool UseSigned = CommonSema.isSigned() || CommonSema.hasUnsignedPadding();
263
264 Value *WideLHS = CreateFixedToFixed(LHS, LHSSema, CommonSema);
265 Value *WideRHS = CreateFixedToFixed(RHS, RHSSema, CommonSema);
266
267 Value *Result;
268 if (CommonSema.isSaturated()) {
269 Intrinsic::ID IID = UseSigned ? Intrinsic::ssub_sat : Intrinsic::usub_sat;
270 Result = B.CreateBinaryIntrinsic(IID, WideLHS, WideRHS);
271 } else {
272 Result = B.CreateSub(WideLHS, WideRHS);
273 }
274
275 // Subtraction can end up below 0 for padded unsigned operations, so emit
276 // an extra clamp in that case.
277 if (CommonSema.isSaturated() && CommonSema.hasUnsignedPadding()) {
278 Constant *Zero = Constant::getNullValue(Result->getType());
279 Result =
280 B.CreateSelect(B.CreateICmpSLT(Result, Zero), Zero, Result, "satmin");
281 }
282
283 return CreateFixedToFixed(Result, CommonSema,
284 LHSSema.getCommonSemantics(RHSSema));
285 }
286
287 /// Multiply two fixed-point values and return the result in their common
288 /// semantic.
289 /// \p LHS - The left hand side
290 /// \p LHSSema - The semantic of the left hand side
291 /// \p RHS - The right hand side
292 /// \p RHSSema - The semantic of the right hand side
294 Value *RHS, const FixedPointSemantics &RHSSema) {
295 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
296 bool UseSigned = CommonSema.isSigned() || CommonSema.hasUnsignedPadding();
297
298 Value *WideLHS = CreateFixedToFixed(LHS, LHSSema, CommonSema);
299 Value *WideRHS = CreateFixedToFixed(RHS, RHSSema, CommonSema);
300
301 Intrinsic::ID IID;
302 if (CommonSema.isSaturated()) {
303 IID = UseSigned ? Intrinsic::smul_fix_sat : Intrinsic::umul_fix_sat;
304 } else {
305 IID = UseSigned ? Intrinsic::smul_fix : Intrinsic::umul_fix;
306 }
307 Value *Result = B.CreateIntrinsic(
308 IID, {WideLHS->getType()},
309 {WideLHS, WideRHS, B.getInt32(CommonSema.getScale())});
310
311 return CreateFixedToFixed(Result, CommonSema,
312 LHSSema.getCommonSemantics(RHSSema));
313 }
314
315 /// Divide two fixed-point values and return the result in their common
316 /// semantic.
317 /// \p LHS - The left hand side
318 /// \p LHSSema - The semantic of the left hand side
319 /// \p RHS - The right hand side
320 /// \p RHSSema - The semantic of the right hand side
322 Value *RHS, const FixedPointSemantics &RHSSema) {
323 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
324 bool UseSigned = CommonSema.isSigned() || CommonSema.hasUnsignedPadding();
325
326 Value *WideLHS = CreateFixedToFixed(LHS, LHSSema, CommonSema);
327 Value *WideRHS = CreateFixedToFixed(RHS, RHSSema, CommonSema);
328
329 Intrinsic::ID IID;
330 if (CommonSema.isSaturated()) {
331 IID = UseSigned ? Intrinsic::sdiv_fix_sat : Intrinsic::udiv_fix_sat;
332 } else {
333 IID = UseSigned ? Intrinsic::sdiv_fix : Intrinsic::udiv_fix;
334 }
335 Value *Result = B.CreateIntrinsic(
336 IID, {WideLHS->getType()},
337 {WideLHS, WideRHS, B.getInt32(CommonSema.getScale())});
338
339 return CreateFixedToFixed(Result, CommonSema,
340 LHSSema.getCommonSemantics(RHSSema));
341 }
342
343 /// Left shift a fixed-point value by an unsigned integer value. The integer
344 /// value can be any bit width.
345 /// \p LHS - The left hand side
346 /// \p LHSSema - The semantic of the left hand side
347 /// \p RHS - The right hand side
349 bool UseSigned = LHSSema.isSigned() || LHSSema.hasUnsignedPadding();
350
351 RHS = B.CreateIntCast(RHS, LHS->getType(), /*IsSigned=*/false);
352
353 Value *Result;
354 if (LHSSema.isSaturated()) {
355 Intrinsic::ID IID = UseSigned ? Intrinsic::sshl_sat : Intrinsic::ushl_sat;
356 Result = B.CreateBinaryIntrinsic(IID, LHS, RHS);
357 } else {
358 Result = B.CreateShl(LHS, RHS);
359 }
360
361 return Result;
362 }
363
364 /// Right shift a fixed-point value by an unsigned integer value. The integer
365 /// value can be any bit width.
366 /// \p LHS - The left hand side
367 /// \p LHSSema - The semantic of the left hand side
368 /// \p RHS - The right hand side
370 RHS = B.CreateIntCast(RHS, LHS->getType(), false);
371
372 return LHSSema.isSigned() ? B.CreateAShr(LHS, RHS) : B.CreateLShr(LHS, RHS);
373 }
374
375 /// Compare two fixed-point values for equality.
376 /// \p LHS - The left hand side
377 /// \p LHSSema - The semantic of the left hand side
378 /// \p RHS - The right hand side
379 /// \p RHSSema - The semantic of the right hand side
381 Value *RHS, const FixedPointSemantics &RHSSema) {
382 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
383
384 Value *WideLHS = CreateFixedToFixed(LHS, LHSSema, CommonSema);
385 Value *WideRHS = CreateFixedToFixed(RHS, RHSSema, CommonSema);
386
387 return B.CreateICmpEQ(WideLHS, WideRHS);
388 }
389
390 /// Compare two fixed-point values for inequality.
391 /// \p LHS - The left hand side
392 /// \p LHSSema - The semantic of the left hand side
393 /// \p RHS - The right hand side
394 /// \p RHSSema - The semantic of the right hand side
396 Value *RHS, const FixedPointSemantics &RHSSema) {
397 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
398
399 Value *WideLHS = CreateFixedToFixed(LHS, LHSSema, CommonSema);
400 Value *WideRHS = CreateFixedToFixed(RHS, RHSSema, CommonSema);
401
402 return B.CreateICmpNE(WideLHS, WideRHS);
403 }
404
405 /// Compare two fixed-point values as LHS < RHS.
406 /// \p LHS - The left hand side
407 /// \p LHSSema - The semantic of the left hand side
408 /// \p RHS - The right hand side
409 /// \p RHSSema - The semantic of the right hand side
411 Value *RHS, const FixedPointSemantics &RHSSema) {
412 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
413
414 Value *WideLHS = CreateFixedToFixed(LHS, LHSSema, CommonSema);
415 Value *WideRHS = CreateFixedToFixed(RHS, RHSSema, CommonSema);
416
417 return CommonSema.isSigned() ? B.CreateICmpSLT(WideLHS, WideRHS)
418 : B.CreateICmpULT(WideLHS, WideRHS);
419 }
420
421 /// Compare two fixed-point values as LHS <= RHS.
422 /// \p LHS - The left hand side
423 /// \p LHSSema - The semantic of the left hand side
424 /// \p RHS - The right hand side
425 /// \p RHSSema - The semantic of the right hand side
427 Value *RHS, const FixedPointSemantics &RHSSema) {
428 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
429
430 Value *WideLHS = CreateFixedToFixed(LHS, LHSSema, CommonSema);
431 Value *WideRHS = CreateFixedToFixed(RHS, RHSSema, CommonSema);
432
433 return CommonSema.isSigned() ? B.CreateICmpSLE(WideLHS, WideRHS)
434 : B.CreateICmpULE(WideLHS, WideRHS);
435 }
436
437 /// Compare two fixed-point values as LHS > RHS.
438 /// \p LHS - The left hand side
439 /// \p LHSSema - The semantic of the left hand side
440 /// \p RHS - The right hand side
441 /// \p RHSSema - The semantic of the right hand side
443 Value *RHS, const FixedPointSemantics &RHSSema) {
444 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
445
446 Value *WideLHS = CreateFixedToFixed(LHS, LHSSema, CommonSema);
447 Value *WideRHS = CreateFixedToFixed(RHS, RHSSema, CommonSema);
448
449 return CommonSema.isSigned() ? B.CreateICmpSGT(WideLHS, WideRHS)
450 : B.CreateICmpUGT(WideLHS, WideRHS);
451 }
452
453 /// Compare two fixed-point values as LHS >= RHS.
454 /// \p LHS - The left hand side
455 /// \p LHSSema - The semantic of the left hand side
456 /// \p RHS - The right hand side
457 /// \p RHSSema - The semantic of the right hand side
459 Value *RHS, const FixedPointSemantics &RHSSema) {
460 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
461
462 Value *WideLHS = CreateFixedToFixed(LHS, LHSSema, CommonSema);
463 Value *WideRHS = CreateFixedToFixed(RHS, RHSSema, CommonSema);
464
465 return CommonSema.isSigned() ? B.CreateICmpSGE(WideLHS, WideRHS)
466 : B.CreateICmpUGE(WideLHS, WideRHS);
467 }
468};
469
470} // end namespace llvm
471
472#endif // LLVM_IR_FIXEDPOINTBUILDER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Defines the fixed point number interface.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Value * RHS
Value * LHS
static LLVM_ABI APFixedPoint getMin(const FixedPointSemantics &Sema)
static LLVM_ABI const fltSemantics * promoteFloatSemantics(const fltSemantics *S)
Given a floating point semantic, return the next floating point semantic with a larger exponent and l...
static LLVM_ABI APFixedPoint getMax(const FixedPointSemantics &Sema)
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
Definition APInt.h:302
This is an important base class in LLVM.
Definition Constant.h:44
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Value * CreateFixedToFloating(Value *Src, const FixedPointSemantics &SrcSema, Type *DstTy)
Value * CreateDiv(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS, const FixedPointSemantics &RHSSema)
Divide two fixed-point values and return the result in their common semantic.
Value * CreateFloatingToFixed(Value *Src, const FixedPointSemantics &DstSema)
Value * CreateGT(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS, const FixedPointSemantics &RHSSema)
Compare two fixed-point values as LHS > RHS.
Value * CreateFixedToInteger(Value *Src, const FixedPointSemantics &SrcSema, unsigned DstWidth, bool DstIsSigned)
Convert an integer value representing a fixed-point number to an integer with the given bit width and...
Value * CreateShl(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS)
Left shift a fixed-point value by an unsigned integer value.
Value * CreateNE(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS, const FixedPointSemantics &RHSSema)
Compare two fixed-point values for inequality.
Value * CreateLT(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS, const FixedPointSemantics &RHSSema)
Compare two fixed-point values as LHS < RHS.
FixedPointBuilder(IRBuilderTy &Builder)
Value * CreateEQ(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS, const FixedPointSemantics &RHSSema)
Compare two fixed-point values for equality.
Value * CreateShr(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS)
Right shift a fixed-point value by an unsigned integer value.
Value * CreateLE(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS, const FixedPointSemantics &RHSSema)
Compare two fixed-point values as LHS <= RHS.
Value * CreateAdd(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS, const FixedPointSemantics &RHSSema)
Add two fixed-point values and return the result in their common semantic.
Value * CreateGE(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS, const FixedPointSemantics &RHSSema)
Compare two fixed-point values as LHS >= RHS.
Value * CreateMul(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS, const FixedPointSemantics &RHSSema)
Multiply two fixed-point values and return the result in their common semantic.
Value * CreateIntegerToFixed(Value *Src, unsigned SrcIsSigned, const FixedPointSemantics &DstSema)
Convert an integer value with the given signedness to an integer value representing the given fixed-p...
Value * CreateSub(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS, const FixedPointSemantics &RHSSema)
Subtract two fixed-point values and return the result in their common semantic.
Value * CreateFixedToFixed(Value *Src, const FixedPointSemantics &SrcSema, const FixedPointSemantics &DstSema)
Convert an integer value representing a fixed-point number from one fixed-point semantic to another f...
The fixed point semantics work similarly to fltSemantics.
unsigned getWidth() const
bool hasUnsignedPadding() const
unsigned getScale() const
unsigned getIntegralBits() const
Return the number of integral bits represented by these semantics.
LLVM_ABI FixedPointSemantics getCommonSemantics(const FixedPointSemantics &Other) const
Return the FixedPointSemantics that allows for calculating the full precision semantic that can preci...
LLVM_ABI bool fitsInFloatSemantics(const fltSemantics &FloatSema) const
Returns true if this fixed-point semantic with its value bits interpreted as an integer can fit in th...
static FixedPointSemantics GetIntegerSemantics(unsigned Width, bool IsSigned)
Return the FixedPointSemantics for an integer type.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI Type * getFloatingPointTy(LLVMContext &C, const fltSemantics &S)
Definition Type.cpp:115
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:298
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
This is an optimization pass for GlobalISel generic memory operations.