HomePhabricator

[llvm] Allow GlobalOp to take a region for complex initializers

Authored by jmolloy on Nov 5 2019, 3:10 PM.

Description

[llvm] Allow GlobalOp to take a region for complex initializers

This allows GlobalOp to either take a value attribute (for simple constants) or a region that can
contain IR instructions (that must be constant-foldable) to create a ConstantExpr initializer.

Example:

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

PiperOrigin-RevId: 278717836

Event Timeline

A. Unique TensorFlower <gardener@tensorflow.org> committed rG250a11ae0f9b: [llvm] Allow GlobalOp to take a region for complex initializers (authored by jmolloy).Nov 5 2019, 3:11 PM