FLANG
Public Member Functions | Static Public Member Functions | List of all members
fir::factory::CharacterExprHelper Class Reference

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

#include <flang/Optimizer/Builder/Character.h>

Public Member Functions

 CharacterExprHelper (FirOpBuilder &builder, mlir::Location loc)
 Constructor.
 
 CharacterExprHelper (const CharacterExprHelper &)=delete
 
void createCopy (const fir::CharBoxValue &dest, const fir::CharBoxValue &src, mlir::Value count)
 
void createPadding (const fir::CharBoxValue &str, mlir::Value lower, mlir::Value upper)
 
fir::CharBoxValue createSubstring (const fir::CharBoxValue &str, llvm::ArrayRef< mlir::Value > bounds)
 
mlir::Value genSubstringBase (mlir::Value stringRawAddr, mlir::Value lowerBound, mlir::Type substringAddrType, mlir::Value one={})
 
mlir::Value createBlankConstant (fir::CharacterType type)
 Return blank character of given type !fir.char<kind>
 
void createAssign (const fir::ExtendedValue &lhs, const fir::ExtendedValue &rhs)
 
fir::CharBoxValue createConcatenate (const fir::CharBoxValue &lhs, const fir::CharBoxValue &rhs)
 Create lhs // rhs in temp obtained with fir.alloca.
 
fir::CharBoxValue createCharExtremum (bool predIsMin, llvm::ArrayRef< fir::CharBoxValue > opCBVs)
 Create {max,min}(lhs,rhs) in temp obtained with fir.alloca.
 
mlir::Value createLenTrim (const fir::CharBoxValue &str)
 LEN_TRIM intrinsic.
 
mlir::Value createEmboxChar (mlir::Value addr, mlir::Value len)
 
mlir::Value createEmbox (const fir::CharBoxValue &str)
 
mlir::Value createEmbox (const fir::CharArrayBoxValue &str)
 
fir::CharBoxValue toScalarCharacter (const fir::CharArrayBoxValue &)
 
std::pair< mlir::Value, mlir::Value > createUnboxChar (mlir::Value boxChar)
 Unbox boxchar into (fir.ref<fir.char<kind>>, character length type).
 
fir::CharBoxValue createCharacterTemp (mlir::Type type, mlir::Value len)
 
fir::CharBoxValue createCharacterTemp (mlir::Type type, int len)
 
fir::CharBoxValue createTempFrom (const fir::ExtendedValue &source)
 Create a temporary with the same kind, length, and value as source.
 
fir::ExtendedValue toExtendedValue (mlir::Value character, mlir::Value len={})
 
fir::ExtendedValue cleanUpCharacterExtendedValue (const fir::ExtendedValue &)
 
mlir::Value createSingletonFromCode (mlir::Value code, int kind)
 Create fir.char<kind> singleton from code integer value.
 
mlir::Value extractCodeFromSingleton (mlir::Value singleton)
 Returns integer value held in a character singleton.
 
mlir::Value getLength (mlir::Value memref)
 
mlir::Value readLengthFromBox (mlir::Value box)
 
mlir::Value readLengthFromBox (mlir::Value box, fir::CharacterType charTy)
 Same as readLengthFromBox but the CharacterType is provided.
 

Static Public Member Functions

static bool isCharacterLiteral (mlir::Type type)
 
static bool isCharacterScalar (mlir::Type type)
 
static bool hasConstantLengthInType (const fir::ExtendedValue &)
 
static fir::KindTy getCharacterKind (mlir::Type type)
 Extract the kind of a character type.
 
static fir::KindTy getCharacterOrSequenceKind (mlir::Type type)
 Extract the kind of a character or array of character type.
 
static fir::CharacterType getCharType (mlir::Type type)
 
static fir::CharacterType getCharacterType (mlir::Type type)
 Get fir.char<kind> type with the same kind as inside str.
 
static fir::CharacterType getCharacterType (const fir::CharBoxValue &box)
 
static fir::CharacterType getCharacterType (mlir::Value str)
 
static bool isArray (mlir::Type type)
 

Detailed Description

Helper to facilitate lowering of CHARACTER in FIR.

Member Function Documentation

◆ cleanUpCharacterExtendedValue()

fir::ExtendedValue fir::factory::CharacterExprHelper::cleanUpCharacterExtendedValue ( const fir::ExtendedValue )

Temporary helper to help migrating towards properties of ExtendedValue containing characters. Mainly, this ensure that characters are always CharArrayBoxValue, CharBoxValue, or BoxValue and that the base address is not a boxchar. Return the argument if this is not a character. TODO: Create and propagate ExtendedValue according to properties listed above instead of fixing it when needed.

◆ createAssign()

void fir::factory::CharacterExprHelper::createAssign ( const fir::ExtendedValue lhs,
const fir::ExtendedValue rhs 
)

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

◆ createCharacterTemp() [1/2]

fir::CharBoxValue fir::factory::CharacterExprHelper::createCharacterTemp ( mlir::Type  type,
int  len 
)

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

◆ createCharacterTemp() [2/2]

fir::CharBoxValue fir::factory::CharacterExprHelper::createCharacterTemp ( mlir::Type  type,
mlir::Value  len 
)

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

◆ createCopy()

void fir::factory::CharacterExprHelper::createCopy ( const fir::CharBoxValue dest,
const fir::CharBoxValue src,
mlir::Value  count 
)

Copy the count first characters of src into dest. count can have any integer type.

Create a loop to copy count characters from src to dest. Note that the KIND indicates the number of bits in a code point. (ASCII, UCS-2, or UCS-4.)

◆ createEmbox() [1/2]

mlir::Value fir::factory::CharacterExprHelper::createEmbox ( const fir::CharArrayBoxValue str)

Embox a string array. Note that the size/shape of the array is not retrievable from the resulting mlir::Value.

◆ createEmbox() [2/2]

mlir::Value fir::factory::CharacterExprHelper::createEmbox ( const fir::CharBoxValue str)

Create a fir.boxchar for str. If str is not in memory, a temp is allocated to create the fir.boxchar.

◆ createEmboxChar()

mlir::Value fir::factory::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 fir::factory::CharacterExprHelper::createPadding ( const fir::CharBoxValue 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()

fir::CharBoxValue fir::factory::CharacterExprHelper::createSubstring ( const fir::CharBoxValue str,
llvm::ArrayRef< mlir::Value >  bounds 
)

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

◆ genSubstringBase()

mlir::Value fir::factory::CharacterExprHelper::genSubstringBase ( mlir::Value  stringRawAddr,
mlir::Value  lowerBound,
mlir::Type  substringAddrType,
mlir::Value  one = {} 
)

Compute substring base address given the raw address (not fir.boxchar) of a scalar string, a substring / lower bound, and the substring type.

◆ getCharType()

fir::CharacterType fir::factory::CharacterExprHelper::getCharType ( mlir::Type  type)
static

Determine the inner character type. Unwraps references, boxes, and sequences to find the !fir.char element type.

◆ getLength()

mlir::Value fir::factory::CharacterExprHelper::getLength ( mlir::Value  memref)

Create a value for the length of a character based on its memory reference that may be a boxchar, box or !fir.[ptr|ref|heap]<fir.char<kind, len>>. If the memref is a simple address and the length is not constant in type, the returned length will be empty.

◆ hasConstantLengthInType()

bool fir::factory::CharacterExprHelper::hasConstantLengthInType ( const fir::ExtendedValue exv)
static

Does this extended value base type is fir.char<kind,len> where len is not the unknown extent ?

◆ isArray()

bool fir::factory::CharacterExprHelper::isArray ( mlir::Type  type)
static

Is type a sequence (array) of CHARACTER type? Return true for any of the following cases:

  • !fir.array<dim x ... x !fir.char<kind, len>>
  • !fir.ref<T> where T is either of the first case
  • !fir.box<T> where T is either of the first case

In certain contexts, Fortran allows an array of CHARACTERs to be treated as if it were one longer CHARACTER scalar, each element append to the previous.

◆ isCharacterLiteral()

bool fir::factory::CharacterExprHelper::isCharacterLiteral ( mlir::Type  type)
static

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

◆ isCharacterScalar()

bool fir::factory::CharacterExprHelper::isCharacterScalar ( mlir::Type  type)
static

Return true if type is one of the following type

  • fir.boxchar<kind>
  • fir.ref<fir.char<kind,len>>
  • fir.char<kind,len>

◆ readLengthFromBox()

mlir::Value fir::factory::CharacterExprHelper::readLengthFromBox ( mlir::Value  box)

Compute length given a fir.box describing a character entity. It adjusts the length from the number of bytes per the descriptor to the number of characters per the Fortran KIND.

◆ toExtendedValue()

fir::ExtendedValue fir::factory::CharacterExprHelper::toExtendedValue ( mlir::Value  character,
mlir::Value  len = {} 
)

Create an extended value from a value of type:

  • fir.boxchar<kind>
  • fir.ref<fir.char<kind,len>>
  • fir.char<kind,len> or the array versions:
  • fir.ref<fir.array<n x...x fir.char<kind,len>>>
  • fir.array<n x...x fir.char<kind,len>>

Does the heavy lifting of converting the value character (along with an optional len value) to an extended value. If len is null, a length value is extracted from character (or its type). This will produce an error if it's not possible. The returned value is a CharBoxValue if character is a scalar, otherwise it is a CharArrayBoxValue.

◆ toScalarCharacter()

fir::CharBoxValue fir::factory::CharacterExprHelper::toScalarCharacter ( const fir::CharArrayBoxValue box)

Convert character array to a scalar by reducing the extents into the length. Will fail if call on non reference like base.


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