pub struct GlobalOperation<'c> { /* private fields */ }
Expand description

A mlir.global operation. LLVM dialect global..

Since MLIR allows for arbitrary operations to be present at the top level, global variables are defined using the llvm.mlir.global operation. Both global constants and variables can be defined, and the value may also be initialized in both cases.

There are two forms of initialization syntax. Simple constants that can be represented as MLIR attributes can be given in-line:

llvm.mlir.global @variable(32.0 : f32) : f32

This initialization and type syntax is similar to llvm.mlir.constant and may use two types: one for MLIR attribute and another for the LLVM value. These types must be compatible.

More complex constants that cannot be represented as MLIR attributes can be given in an initializer region:

// This global is initialized with the equivalent of:
//   i32* getelementptr (i32* @g2, i32 2)
llvm.mlir.global constant @int_gep() : !llvm.ptr<i32> {
  %0 = llvm.mlir.addressof @g2 : !llvm.ptr<i32>
  %1 = llvm.mlir.constant(2 : i32) : i32
  %2 = llvm.getelementptr %0[%1]
     : (!llvm.ptr<i32>, i32) -> !llvm.ptr<i32>
  // The initializer region must end with `llvm.return`.
  llvm.return %2 : !llvm.ptr<i32>
}

Only one of the initializer attribute or initializer region may be provided.

llvm.mlir.global must appear at top-level of the enclosing module. It uses an @-identifier for its value, which will be uniqued by the module with respect to other @-identifiers in it.

Examples:

// Global values use @-identifiers.
llvm.mlir.global constant @cst(42 : i32) : i32

// Non-constant values must also be initialized.
llvm.mlir.global @variable(32.0 : f32) : f32

// Strings are expected to be of wrapped LLVM i8 array type and do not
// automatically include the trailing zero.
llvm.mlir.global @string("abc") : !llvm.array<3 x i8>

// For strings globals, the trailing type may be omitted.
llvm.mlir.global constant @no_trailing_type("foo bar")

// A complex initializer is constructed with an initializer region.
llvm.mlir.global constant @int_gep() : !llvm.ptr<i32> {
  %0 = llvm.mlir.addressof @g2 : !llvm.ptr<i32>
  %1 = llvm.mlir.constant(2 : i32) : i32
  %2 = llvm.getelementptr %0[%1]
     : (!llvm.ptr<i32>, i32) -> !llvm.ptr<i32>
  llvm.return %2 : !llvm.ptr<i32>
}

Similarly to functions, globals have a linkage attribute. In the custom syntax, this attribute is placed between llvm.mlir.global and the optional constant keyword. If the attribute is omitted, external linkage is assumed by default.

Examples:

// A constant with internal linkage will not participate in linking.
llvm.mlir.global internal constant @cst(42 : i32) : i32

// By default, "external" linkage is assumed and the global participates in
// symbol resolution at link-time.
llvm.mlir.global @glob(0 : f32) : f32

// Alignment is optional
llvm.mlir.global private constant @y(dense<1.0> : tensor<8xf32>) : !llvm.array<8 x f32>

Like global variables in LLVM IR, globals can have an (optional) alignment attribute using keyword alignment. The integer value of the alignment must be a positive integer that is a power of 2.

Examples:

// Alignment is optional
llvm.mlir.global private constant @y(dense<1.0> : tensor<8xf32>) { alignment = 32 : i64 } : !llvm.array<8 x f32>

Implementations§

source§

impl<'c> GlobalOperation<'c>

source

pub fn name() -> &'static str

Returns a name.

source

pub fn as_operation(&self) -> &Operation<'c>

Returns a generic operation.

source

pub fn builder( context: &'c Context, location: Location<'c> ) -> GlobalOperationBuilder<'c, Unset, Unset, Unset, Unset>

Creates a builder.

source

pub fn initializer(&self) -> Result<RegionRef<'c, '_>, Error>

source

pub fn global_type(&self) -> Result<TypeAttribute<'c>, Error>

source

pub fn set_global_type(&mut self, value: TypeAttribute<'c>)

source

pub fn constant(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_constant(&mut self, value: Attribute<'c>)

source

pub fn remove_constant(&mut self) -> Result<(), Error>

source

pub fn sym_name(&self) -> Result<StringAttribute<'c>, Error>

source

pub fn set_sym_name(&mut self, value: StringAttribute<'c>)

source

pub fn linkage(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_linkage(&mut self, value: Attribute<'c>)

source

pub fn dso_local(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_dso_local(&mut self, value: Attribute<'c>)

source

pub fn remove_dso_local(&mut self) -> Result<(), Error>

source

pub fn thread_local(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_thread_local(&mut self, value: Attribute<'c>)

source

pub fn remove_thread_local(&mut self) -> Result<(), Error>

source

pub fn value(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_value(&mut self, value: Attribute<'c>)

source

pub fn remove_value(&mut self) -> Result<(), Error>

source

pub fn alignment(&self) -> Result<IntegerAttribute<'c>, Error>

source

pub fn set_alignment(&mut self, value: IntegerAttribute<'c>)

source

pub fn remove_alignment(&mut self) -> Result<(), Error>

source

pub fn addr_space(&self) -> Result<IntegerAttribute<'c>, Error>

source

pub fn set_addr_space(&mut self, value: IntegerAttribute<'c>)

source

pub fn remove_addr_space(&mut self) -> Result<(), Error>

source

pub fn unnamed_addr(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_unnamed_addr(&mut self, value: Attribute<'c>)

source

pub fn remove_unnamed_addr(&mut self) -> Result<(), Error>

source

pub fn section(&self) -> Result<StringAttribute<'c>, Error>

source

pub fn set_section(&mut self, value: StringAttribute<'c>)

source

pub fn remove_section(&mut self) -> Result<(), Error>

source

pub fn comdat(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_comdat(&mut self, value: Attribute<'c>)

source

pub fn remove_comdat(&mut self) -> Result<(), Error>

source

pub fn visibility(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_visibility(&mut self, value: Attribute<'c>)

source

pub fn remove_visibility(&mut self) -> Result<(), Error>

Trait Implementations§

source§

impl<'c> From<GlobalOperation<'c>> for Operation<'c>

source§

fn from(operation: GlobalOperation<'c>) -> Self

Converts to this type from the input type.
source§

impl<'c> TryFrom<Operation<'c>> for GlobalOperation<'c>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(operation: Operation<'c>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'c> RefUnwindSafe for GlobalOperation<'c>

§

impl<'c> !Send for GlobalOperation<'c>

§

impl<'c> !Sync for GlobalOperation<'c>

§

impl<'c> Unpin for GlobalOperation<'c>

§

impl<'c> UnwindSafe for GlobalOperation<'c>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.