+Constant *ConstantExpr::getAlignOf(const Type *Ty) {
+ // alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1
+ const Type *AligningTy = StructType::get(Type::Int8Ty, Ty, NULL);
+ Constant *NullPtr = getNullValue(AligningTy->getPointerTo());
+ Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
+ Constant *One = ConstantInt::get(Type::Int32Ty, 1);
+ Constant *Indices[2] = { Zero, One };
+ Constant *GEP = getGetElementPtr(NullPtr, Indices, 2);
+ return getCast(Instruction::PtrToInt, GEP, Type::Int32Ty);
+}
+