FLANG

Public Member Functions | Static Public Member Functions | List of all members
Fortran::lower::CharacterExprHelper Class Reference

Helper to facilitate lowering of CHARACTER in FIR. More...

`#include <flang/Lower/CharacterExpr.h>`

## Public Member Functions
| CharacterExprHelper (FirOpBuilder &builder, mlir::Location loc)
| Constructor.
| CharacterExprHelper (const CharacterExprHelper &)=delete
void | createCopy (mlir::Value dest, mlir::Value src, mlir::Value count)
void | createPadding (mlir::Value str, mlir::Value lower, mlir::Value upper)
mlir::Value | createSubstring (mlir::Value str, llvm::ArrayRef< mlir::Value > bounds)
mlir::Value | createBlankConstant (fir::CharacterType type)
| Return blank character of given `type` !fir.char<kind>
void | createAssign (mlir::Value lhs, mlir::Value rhs)
void | createAssign (mlir::Value lptr, mlir::Value llen, mlir::Value rptr, mlir::Value rlen)
mlir::Value | createConcatenate (mlir::Value lhs, mlir::Value rhs)
| Create lhs // rhs in temp obtained with fir.alloca.
mlir::Value | createLenTrim (mlir::Value str)
| LEN_TRIM intrinsic.
mlir::Value | createEmboxChar (mlir::Value addr, mlir::Value len)
std::pair< mlir::Value, mlir::Value > | createUnboxChar (mlir::Value boxChar)
| Unbox `boxchar` into (fir.ref<fir.char<kind>>, getLengthType()).
mlir::Value | createCharacterTemp (mlir::Type type, mlir::Value len)
mlir::Value | createCharacterTemp (mlir::Type type, int len)
std::pair< mlir::Value, mlir::Value > | materializeCharacter (mlir::Value str)
mlir::Type | getLengthType ()
fir::ExtendedValue | toExtendedValue (mlir::Value character, mlir::Value len={})

## Static Public Member Functions
static bool | isCharacterLiteral (mlir::Type type)
static bool | isCharacter (mlir::Type type)
static int | getCharacterKind (mlir::Type type)
| Extract the kind of a character type.

## Detailed Description

Helper to facilitate lowering of CHARACTER in FIR.

## Member Function Documentation

## ◆ createAssign() [1/2]

void Fortran::lower::CharacterExprHelper::createAssign | ( | mlir::Value | lhs,
|  | mlir::Value | rhs
| ) |  |

Lower `lhs` = `rhs` where `lhs` and `rhs` are scalar characters. It handles cases where `lhs` and `rhs` may overlap.

## ◆ createAssign() [2/2]

void Fortran::lower::CharacterExprHelper::createAssign | ( | mlir::Value | lptr,
|  | mlir::Value | llen,
|  | mlir::Value | rptr,
|  | mlir::Value | rlen
| ) |  |

Lower an assignment where the buffer and LEN parameter are known and do not need to be unboxed.

## ◆ createCharacterTemp() [1/2]

mlir::Value Fortran::lower::CharacterExprHelper::createCharacterTemp | ( | mlir::Type | type,
|  | int | len
| ) |  |
| inline

Allocate a temp of compile time constant length. Returns related fir.ref<fir.array<len x fir.char<kind>>>.

## ◆ createCharacterTemp() [2/2]

mlir::Value Fortran::lower::CharacterExprHelper::createCharacterTemp | ( | mlir::Type | type,
|  | mlir::Value | len
| ) |  |

Allocate a temp of fir::CharacterType type and length len. Returns related fir.ref<fir.char<kind>>.

## ◆ createCopy()

void Fortran::lower::CharacterExprHelper::createCopy | ( | mlir::Value | dest,
|  | mlir::Value | src,
|  | mlir::Value | count
| ) |  |

Unless otherwise stated, all mlir::Value inputs of these pseudo-fir ops must be of type:

- fir.boxchar<kind> (dynamic length character),
- fir.ref<fir.array<len x fir.char<kind>>> (character with compile time constant length),
- fir.array<len x fir.char<kind>> (compile time constant character) Copy the `count` first characters of `src` into `dest`. `count` can have any integer type.

## ◆ createEmboxChar()

mlir::Value Fortran::lower::CharacterExprHelper::createEmboxChar | ( | mlir::Value | addr,
|  | mlir::Value | len
| ) |  |

Embox `addr` and `len` and return fir.boxchar. Take care of type conversions before emboxing. `len` is converted to the integer type for character lengths if needed.

## ◆ createPadding()

void Fortran::lower::CharacterExprHelper::createPadding | ( | mlir::Value | str,
|  | mlir::Value | lower,
|  | mlir::Value | upper
| ) |  |

Set characters of `str` at position [`lower`, `upper`) to blanks. `lower` and \upper bounds are zero based. If `upper` <= `lower`, no padding is done. `upper` and `lower` can have any integer type.

## ◆ createSubstring()

mlir::Value Fortran::lower::CharacterExprHelper::createSubstring | ( | mlir::Value | str,
|  | llvm::ArrayRef< mlir::Value > | bounds
| ) |  |

Create str(lb:ub), lower bounds must always be specified, upper bound is optional.

## ◆ getLengthType()

mlir::Type Fortran::lower::CharacterExprHelper::getLengthType | ( |  | ) |
| inline

Return the integer type that must be used to manipulate Character lengths. TODO: move this to FirOpBuilder?

## ◆ isCharacter()

bool Fortran::lower::CharacterExprHelper::isCharacter | ( | mlir::Type | type | ) |
| static

Return true if `type` is one of the following type

- fir.boxchar<kind>
- fir.ref<fir.array<len x fir.char<kind>>>
- fir.array<len x fir.char<kind>>

## ◆ isCharacterLiteral()

bool Fortran::lower::CharacterExprHelper::isCharacterLiteral | ( | mlir::Type | type | ) |
| static

Return true if `type` is a character literal type (is fir.array<len x fir.char<kind>>).;

## ◆ materializeCharacter()

std::pair< mlir::Value, mlir::Value > Fortran::lower::CharacterExprHelper::materializeCharacter | ( | mlir::Value | str | ) |

Return buffer/length pair of character str, if str is a constant, it is allocated into a temp, otherwise, its memory reference is returned as the buffer. The buffer type of str is of type:

- fir.ref<fir.array<len x fir.char<kind>>> if str has compile time constant length.
- fir.ref<fir.char<kind>> if str has dynamic length.

## ◆ toExtendedValue()

fir::ExtendedValue Fortran::lower::CharacterExprHelper::toExtendedValue | ( | mlir::Value | character,
|  | mlir::Value | len = `{}`
| ) |  |

Create an extended value from:

- fir.boxchar<kind>
- fir.ref<fir.array<len x fir.char<kind>>>
- fir.array<len x fir.char<kind>>
- fir.char<kind>
- fir.ref<char<kind>> If the no length is passed, it is attempted to be extracted from `character` (or its type). This will crash if this is not possible. The returned value is a CharBoxValue if `character` is a scalar, otherwise it is a CharArrayBoxValue.

The documentation for this class was generated from the following files:

- include/flang/Lower/CharacterExpr.h
- lib/Lower/CharacterExpr.cpp