zjuacompiler / llvm

copy of llvm-3.4 source code
Other
9 stars 4 forks source link

添加对于v64i2的原生支持 #18

Open chouqin opened 10 years ago

chouqin commented 10 years ago

先尝试做一下这个,可以照着v2i64来实现。

应该有三个步骤

添加基础类型的支持

目前在MVT中没有包含v64i2,需要在include/llvm/CodeGen/ValueTypes.hinclude/llvm/CodeGen/ValueTypes.Td中添加相应的支持。

不过老师已经写好了一个脚本,使用这个脚本可以直接生成满足需要的这两个文件。脚本链接在http://parabix.costar.sfu.ca/browser/parabix-LLVM

绑定到寄存器

这很简单,在X86ISelLowering.cpp中添加下面一行就行了:

addRegisterClass(MVT::v64i2, &X86::VR128RegClass);

实现运算

通过``来注册对于v64i2的操作由custom来实现,比如:

setOperationAction(ISD::SHL,               MVT::v64i2, Custom);

然后在对应的函数中实现v64i2,比如上面的运算在LowerShift这个函数中实现:

  if (Subtarget->hasInt256()) {
    if (Op.getOpcode() == ISD::SRL &&
        (VT == MVT::v2i64 || VT == MVT::v4i32 ||
         VT == MVT::v4i64 || VT == MVT::v8i32))
      return Op;
    if (Op.getOpcode() == ISD::SHL &&
        (VT == MVT::v2i64 || VT == MVT::v4i32 ||
         VT == MVT::v4i64 || VT == MVT::v8i32))
      return Op;
    if (Op.getOpcode() == ISD::SRA && (VT == MVT::v4i32 || VT == MVT::v8i32))
      return Op;
  }

照着v2i64或者v4i32来做,应该不难的。

laishzh commented 10 years ago

I just added a pull request #19, hopefully it's helpful to you.

chouqin commented 10 years ago

好的,我看看,谢谢。

chouqin commented 10 years ago

需要实现的运算: add, sub, mul, setcc, build_vector, vector_shuffle, extract_vector_element, insert_vector_element, load, select, vselect, srl, shl

superxiao commented 10 years ago

add 测试代码:

@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1

define i32 @main() #0 { entry: %c = bitcast i128 121 to <64 x i2> ; base 4 number 12310000 %d = bitcast i128 219 to <64 x i2> ; base 4 number 32130000 %e = add <64 x i2> %d, %c %f = extractelement <64 x i2> %e, i32 1 %p = zext i2 %f to i32 %g = call i32 (i8, ...) @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i32 0, i32 0), i32 %p) %h = extractelement <64 x i2> %e, i32 2 %q = zext i2 %h to i32 %i = call i32 (i8, ...) @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i32 0, i32 0), i32 %q)

ret i32 0 }

declare i32 @printf(i8*, ...) #1