源码路径
llvm\include\llvm\IR\Instruction.h
llvm\include\llvm\IR\Instruction.def
llvm\include\llvm\IR\Instructions.h
llvm\include\llvm\IR\InstrTypes.h
Vector Operations
ExtractElementInst(父类:Instruction)
extractelement指令从vector从取出指定索引位置的标量。
语法
<result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty>
<result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty>
参数说明:
ty:vector中的元素类型
ty2:索引的类型,必须是整型。
语义
extractelement指令从vector从取出idx位置的标量。如果idx超过了vector的长度,则result为Poison Value。
示例
<result> = extractelement <4 x i32> %vec, i32 0 ; yields i32
InsertElementInst(父类:Instruction)
insertelement指令将标量插入vector的指定位置。
语法
<result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>>
<result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>>
参数说明:
ty:vector中的元素类型
ty2:索引的类型,必须是整型。
语义
insertelement指令将标量插入vector中idx指定的位置。如果idx超过了vector的长度,则result为Poison Value。
示例
<result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
ShuffleVectorInst(父类:Instruction)
shufflevector指令从输入的两个vector中,按照mask的指示抽取元素组成一个新的vector。
语法
<result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
<result> = shufflevector <vscale x n x <ty>> <v1>, <vscale x n x <ty>> v2, <vscale x m x i32> <mask> ; yields <vscale x m x <ty>>
参数说明:
mask:元素必须为常量整数或者Undef Value。
语义
shufflevector指令先将两个输入的Vector从左到右顺序排列成一个Shuffle Vector,接着顺序选择mask中的元素作为idx,抽取Shuffle Vector中idx位置的元素,作为result vector idx位置的元素。
示例
<result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
<4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
<result> = shufflevector <4 x i32> %v1, <4 x i32> undef,
<4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
<result> = shufflevector <8 x i32> %v1, <8 x i32> undef,
<4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32>
<result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
<8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32>
Aggregate Operations
ExtractValueInst(父类:UnaryInstruction)
extractvalue指令从聚合类型中取出成员字段的值。
语法
<result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
参数说明:
aggregate type:必须是struct或者array类型。
idx:整型常数。
语义
extractvalue指令从聚合类型val中取出idx位置成员字段的类型和值,作为result的类型和值。
示例
<result> = extractvalue {i32, float} %agg, 0 ; yields i32
InsertValueInst(父类:Instruction)
insertvalue指令将一个值插入到指定的聚合类型成员字段。
语法
<result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type>
参数说明:
aggregate type:必须是struct或者array类型。
ty:成员的类型,必须和aggregate type在idx处的成员类型相同。
idx:整型常数。
语义
insertvalue指令将elt插入到idx指定的聚合类型val成员字段,并返回val。
示例
%agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef}
%agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val}
%agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}}