[英]LLVM pass to count vector type instructions
I am trying to write an LLVM pass that counts instructions of vector type. 我正在尝试编写一个计算向量类型指令的LLVM传递。
for instructions like : 对于像这样的说明:
%24 = or <2 x i64> %21, %23
%25 = bitcast <16 x i8> %12 to <8 x i16>
%26 = shl <8 x i16> %25, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
%27 = bitcast <8 x i16> %26 to <2 x i64>
I wrote this code: 我写了这段代码:
for (auto &F : M) {
for (auto &B : F) {
for (auto &I : B) {
if (auto* VI = dyn_cast<InsertElementInst>(&I)) {
Value* op = VI->getOperand(0);
if (op->getType()->isVectorTy()){
++vcount;
}
}
But for some reason if (auto* VI = dyn_cast<InsertElementInst>(&I))
is never satisfied. 但由于某种原因,
if (auto* VI = dyn_cast<InsertElementInst>(&I))
永远不会满足。 Any idea why? 知道为什么吗?
Thanks in advance. 提前致谢。
InsertElementInst
is one specific instruction (that inserts an element into a vector) - and there is none in your list of instructiokns. InsertElementInst
是一个特定的指令(将一个元素插入一个向量) - 并且在你的指令列表中没有。
You probably want to
use the dyn_cast
to a regular
Instruction
in I
as it is. 您可能希望
使用dyn_cast
定期
I
的Instruction
。
[I personally would use a one of the function or module pass classes as a base, so you only need to implement the inner loops of your code, but that's more of a "it's how you're supposed to do things", not something you HAVE to do to make it work]. [我个人会使用一个函数或模块传递类作为基础,所以你只需要实现代码的内部循环,但这更像是“你应该如何做事”,而不是你必须要做到这一点]。
In LLVM, the instruction is the same as it's result. 在LLVM,指令是一样的,因为它的结果。 so for an example
所以举个例子
%25 = bitcast <16 x i8> %12 to <8 x i16>
when you cast Instruction I to value you get %25 当您将指令I转换为值时,您将得到%25
Value* psVal = cast<Value>(&I);
and then you can check if it is of vector type or not by getType()->isVectorTy(). 然后你可以通过getType() - > isVectorTy()检查它是否是矢量类型。
Also i suggest you look at inheritance diagram of llvm Value for more clarification 另外,我建议你查看llvm值的继承图,以获得更多说明
here http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html 这里http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.