llvm 学习总结

Type define

int类型 IntegerType::get(mod->getContext(), 32)

long类型 IntegerType::get(mod->getContext(), 64)

double类型 Type::getDoubleTy(mod->getContext())

float类型 Type::getFloatTy(mod->getContext())

char类型 IntegerType::get(mod->getContext(), 8)

enum类型 IntegerType::get(mod->getContext(), 32)

指针和引用类型
int* int&     PointerType* PointerTy_Int_Pointer = PointerType::get(IntegerType::get(mod->getContext(), 32), 0);
long* long&  PointerType* PointerTy_Long_Pointer = PointerType::get(IntegerType::get(mod->getContext(), 64), 0);
double* double& PointerType* PointerTy_Double_Pointer = PointerType::get(Type::getDoubleTy(mod->getContext()), 0);
float* float&  PointerType* PointerTy_Double_Pointer = PointerType::get(Type::getFloatTy(mod->getContext()), 0);
char* char& PointerType* PointerTy_Char_Pointer = PointerType::get(IntegerType::get(mod->getContext(), 8), 0);
void* PointerType* PointerTy_Char_Pointer = PointerType::get(IntegerType::get(mod->getContext(), 8), 0);
结构体类型
struct struct_1
{
int int_1;
long long_1;
double double_1;
char char_1;
};
无指针
StructType *StructTy_struct = mod->getTypeByName("struct1");//结构体名
if (!StructTy_struct_struct_1) {
StructTy_struct = StructType::create(mod->getContext(), "struct1");
}
std::vector<Type*>StructTy_struct_1_fields;
StructTy_struct_1_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_struct_1_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_struct_1_fields.push_back(Type::getDoubleTy(mod->getContext()));
StructTy_struct_1_fields.push_back(IntegerType::get(mod->getContext(), 8));
if (StructTy_struct->isOpaque()) {
StructTy_struct->setBody(StructTy_struct_1_fields, /*isPacked=*/false);
} struct struct_2
{
int *int_ptr;
long *long_ptr;
double *double_ptr;
int int_1;
long long_1;
double double_1;
int int_array[100];
int **int_2;
}; 有指针
PointerType* PointerTy_Int = PointerType::get(IntegerType::get(mod->getContext(), 32), 0);
PointerType* PointerTy_Long = PointerType::get(IntegerType::get(mod->getContext(), 64), 0);
PointerType* PointerTy_Double = PointerType::get(Type::getDoubleTy(mod->getContext()), 0);
PointerType* PointerTy_Int_Pointer = PointerType::get(PointerTy_Int, 0);
StructType *StructTy_struct_struct_2 = mod->getTypeByName("struct.struct_2");
if (!StructTy_struct_struct_2) {
StructTy_struct_struct_2 = StructType::create(mod->getContext(), "struct.struct_2");
}
std::vector<Type*>StructTy_struct_struct_2_fields;
StructTy_struct_struct_2_fields.push_back(PointerTy_Int);
StructTy_struct_struct_2_fields.push_back(PointerTy_Long);
StructTy_struct_struct_2_fields.push_back(PointerTy_Double);
StructTy_struct_struct_2_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_struct_struct_2_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_struct_struct_2_fields.push_back(Type::getDoubleTy(mod->getContext()));
ArrayType* ArrayTy = ArrayType::get(IntegerType::get(mod->getContext(), 32), 100);//数组 StructTy_struct_struct_2_fields.push_back(ArrayTy);
StructTy_struct_struct_2_fields.push_back(PointerTy_Int_Pointer);
if (StructTy_struct_struct_2->isOpaque()) {
StructTy_struct_struct_2->setBody(StructTy_struct_struct_2_fields, /*isPacked=*/false);
} 类类型 class class_1
{
int int_1;
long long_1;
double double_1;
char char_1;
}; 无函数
StructType *StructTy_class_class_1 = mod->getTypeByName("class.class_1");
if (!StructTy_class_class_1) {
StructTy_class_class_1 = StructType::create(mod->getContext(), "class.class_1");
}
std::vector<Type*>StructTy_class_class_1_fields;
StructTy_class_class_1_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_class_class_1_fields.push_back(IntegerType::get(mod->getContext(), 64));
StructTy_class_class_1_fields.push_back(Type::getDoubleTy(mod->getContext()));
StructTy_class_class_1_fields.push_back(IntegerType::get(mod->getContext(), 8));
if (StructTy_class_class_1->isOpaque()) {
StructTy_class_class_1->setBody(StructTy_class_class_1_fields, /*isPacked=*/false);
} 有函数
class class_2
{
int int_1;
int *int_ptr; class_2(){}
void fun(int int_arg)
{
int_1 =int_arg;
int_ptr = &int_arg;
}
};
PointerType* PointerTy_Int_Pointer = PointerType::get(IntegerType::get(mod->getContext(), 32), 0);
StructType *StructTy_class_class_2 = mod->getTypeByName("class.class_2");
if (!StructTy_class_class_2) {
StructTy_class_class_2 = StructType::create(mod->getContext(), "class.class_2");
}
std::vector<Type*>StructTy_class_class_2_fields;
StructTy_class_class_2_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_class_class_2_fields.push_back(PointerTy_Int_Pointer);
if (StructTy_class_class_2->isOpaque()) {
StructTy_class_class_2->setBody(StructTy_class_class_2_fields, /*isPacked=*/false);
}

函数参数函数返回值

格式:

一个参数:
int fun_int_1(int a); std::vector<Type*>FuncTy_0_args;
FuncTy_0_args.push_back(IntegerType::get(mod->getContext(), 32));
两个参数:
int fun_int_2(int a, int b); std::vector<Type*>FuncTy_8_args;
FuncTy_8_args.push_back(IntegerType::get(mod->getContext(), 32));
FuncTy_8_args.push_back(IntegerType::get(mod->getContext(), 32));
三个参数:
int fun_int_3(int a, int b, int c); std::vector<Type*>FuncTy_9_args;
FuncTy_9_args.push_back(IntegerType::get(mod->getContext(), 32));
FuncTy_9_args.push_back(IntegerType::get(mod->getContext(), 32));
FuncTy_9_args.push_back(IntegerType::get(mod->getContext(), 32)); 函数返回值
当函数返回值为char*时
ArrayType* ArrayTy_0 = ArrayType::get(IntegerType::get(mod->getContext(), 8), 12);
PointerType* PointerTy_2 = PointerType::get(IntegerType::get(mod->getContext(), 8), 0);
std::vector<Type*>FuncTy_3_args;
FunctionType* FuncTy_3 = FunctionType::get(
/*Result=*/PointerTy_2,//函数的返回值为PointerTy_2
/*Params=*/FuncTy_3_args,
/*isVarArg=*/false);

常量类型及常量定义

int类型 ConstantInt* const_int32 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("100"), 10)); //int int_1 = 100;

long类型 ConstantInt* const_int64 = ConstantInt::get(mod->getContext(), APInt(64, StringRef("100000"), 10)); //long long_1 = 100000;

float类型 ConstantFP* const_float_4 = ConstantFP::get(mod->getContext(), APFloat(4.342340e+02f)); //float float_1 = 434.234

double类型 ConstantFP* const_double = ConstantFP::get(mod->getContext(), APFloat(1.344000e+02)); // double double_1 = 134.4

char类型 ConstantInt* const_int8 = ConstantInt::get(mod->getContext(), APInt(8, StringRef("97"), 10)); // char char_1 = 'a';

字符串常量
C++源码
const char*s = "hello world";
IR码
ArrayType* ArrayTy_0 = ArrayType::get(IntegerType::get(mod->getContext(), 8), 12);
GlobalVariable* gvar_array__str = new GlobalVariable(/*Module=*/*mod,
/*Type=*/ArrayTy_0,
/*isConstant=*/true,
/*Linkage=*/GlobalValue::PrivateLinkage,
/*Initializer=*/0, // has initializer, specified below
/*Name=*/".str");
gvar_array__str->setAlignment(1); // Constant Definitions
Constant *const_array_5 = ConstantDataArray::getString(mod->getContext(), "hello world", true);
std::vector<Constant*> const_ptr_7_indices;
ConstantInt* const_int32_8 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
const_ptr_7_indices.push_back(const_int32_8);
const_ptr_7_indices.push_back(const_int32_8);
Constant* const_ptr_7 = ConstantExpr::getGetElementPtr(gvar_array__str, const_ptr_7_indices);
gvar_array__str->setInitializer(const_array_5);
一维数组常量
int Array_int[4] = { 1, 2, 4, 5 }; ArrayType* ArrayTy_0 = ArrayType::get(IntegerType::get(mod->getContext(), 32), 4);
GlobalVariable* gvar_array__ZZ10yiweiArrayvE9Array_int = new GlobalVariable(/*Module=*/*mod,
/*Type=*/ArrayTy_0,
/*isConstant=*/true,
/*Linkage=*/GlobalValue::PrivateLinkage,
/*Initializer=*/0, // has initializer, specified below
/*Name=*/"_ZZ10yiweiArrayvE9Array_int");
gvar_array__ZZ10yiweiArrayvE9Array_int->setAlignment(16); std::vector<Constant*> const_array_7_elems;
ConstantInt* const_int32_8 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));
const_array_7_elems.push_back(const_int32_8);
ConstantInt* const_int32_9 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("2"), 10));
const_array_7_elems.push_back(const_int32_9);
ConstantInt* const_int32_10 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("4"), 10));
const_array_7_elems.push_back(const_int32_10);
ConstantInt* const_int32_11 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("5"), 10));
const_array_7_elems.push_back(const_int32_11); Constant* const_array_7 = ConstantArray::get(ArrayTy_0, const_array_7_elems);
Constant* const_ptr_12 = ConstantExpr::getCast(Instruction::BitCast, gvar_array__ZZ10yiweiArrayvE9Array_int, PointerTy_4); gvar_array__ZZ10yiweiArrayvE9Array_int->setInitializer(const_array_7);
二维数组常量 int a[4][4] = {
1, 2, 3, 4,
5, 6, 7, 8,
9,10,11,12,
13,14,15,16 };
ArrayType* ArrayTy_1 = ArrayType::get(IntegerType::get(mod->getContext(), 32), 4);
ArrayType* ArrayTy_0 = ArrayType::get(ArrayTy_1, 4); GlobalVariable* gvar_array__ZZ9fun_arrayvE1a = new GlobalVariable(/*Module=*/*mod,
/*Type=*/ArrayTy_0,
/*isConstant=*/true,
/*Linkage=*/GlobalValue::PrivateLinkage,
/*Initializer=*/0, // has initializer, specified below
/*Name=*/"_ZZ9fun_arrayvE1a");
gvar_array__ZZ9fun_arrayvE1a->setAlignment(16); std::vector<Constant*> const_array_9_elems;
std::vector<Constant*> const_array_10_elems;
ConstantInt* const_int32_11 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));
const_array_10_elems.push_back(const_int32_11);
ConstantInt* const_int32_12 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("2"), 10));
const_array_10_elems.push_back(const_int32_12);
ConstantInt* const_int32_13 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("3"), 10));
const_array_10_elems.push_back(const_int32_13);
ConstantInt* const_int32_14 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("4"), 10));
const_array_10_elems.push_back(const_int32_14);
Constant* const_array_10 = ConstantArray::get(ArrayTy_1, const_array_10_elems);
const_array_9_elems.push_back(const_array_10);
std::vector<Constant*> const_array_15_elems;
ConstantInt* const_int32_16 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("5"), 10));
const_array_15_elems.push_back(const_int32_16);
ConstantInt* const_int32_17 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("6"), 10));
const_array_15_elems.push_back(const_int32_17);
ConstantInt* const_int32_18 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("7"), 10));
const_array_15_elems.push_back(const_int32_18);
ConstantInt* const_int32_19 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("8"), 10));
const_array_15_elems.push_back(const_int32_19);
Constant* const_array_15 = ConstantArray::get(ArrayTy_1, const_array_15_elems);
const_array_9_elems.push_back(const_array_15);
std::vector<Constant*> const_array_20_elems;
ConstantInt* const_int32_21 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("9"), 10));
const_array_20_elems.push_back(const_int32_21);
ConstantInt* const_int32_22 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("10"), 10));
const_array_20_elems.push_back(const_int32_22);
ConstantInt* const_int32_23 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("11"), 10));
const_array_20_elems.push_back(const_int32_23);
ConstantInt* const_int32_24 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("12"), 10));
const_array_20_elems.push_back(const_int32_24);
Constant* const_array_20 = ConstantArray::get(ArrayTy_1, const_array_20_elems);
const_array_9_elems.push_back(const_array_20);
std::vector<Constant*> const_array_25_elems;
ConstantInt* const_int32_26 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("13"), 10));
const_array_25_elems.push_back(const_int32_26);
ConstantInt* const_int32_27 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("14"), 10));
const_array_25_elems.push_back(const_int32_27);
ConstantInt* const_int32_28 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("15"), 10));
const_array_25_elems.push_back(const_int32_28);
ConstantInt* const_int32_29 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("16"), 10));
const_array_25_elems.push_back(const_int32_29);
Constant* const_array_25 = ConstantArray::get(ArrayTy_1, const_array_25_elems);
const_array_9_elems.push_back(const_array_25);
Constant* const_array_9 = ConstantArray::get(ArrayTy_0, const_array_9_elems);
Constant* const_ptr_30 = ConstantExpr::getCast(Instruction::BitCast, gvar_array__ZZ9fun_arrayvE1a, PointerTy_5); gvar_array__ZZ9fun_arrayvE1a->setInitializer(const_array_9);

函数类型

//函数类型有3个参数 @1 Result 返回值类型
@2 Params 参数类型
@3 isVarArg 是否是可变参数 /bool
FunctionType* FuncTy_0 = FunctionType::get(
/*Result=*/IntegerType::get(mod->getContext(), 32),
/*Params=*/FuncTy_0_args,
/*isVarArg=*/false);
Result类型
void类型 Type::getVoidTy(mod->getContext())
其他与类型定义一致
Params类型
void类型 std::vector<Type*>FuncTy_0_args;
其他与类型定义一致

函数声明

Function* func__Z9fun_int_1i = mod->getFunction("_Z9fun_int_1i");
if (!func__Z9fun_int_1i) {
func__Z9fun_int_1i = Function::Create(
/*Type=*/FuncTy_0,
/*Linkage=*/GlobalValue::ExternalLinkage,
/*Name=*/"_Z9fun_int_1i", mod);
func__Z9fun_int_1i->setCallingConv(CallingConv::C);
} AttributeSet func__Z9fun_int_1i_PAL;
{
SmallVector<AttributeSet, 4> Attrs;
AttributeSet PAS;
{
AttrBuilder B;
B.addAttribute(Attribute::NoUnwind);
B.addAttribute(Attribute::UWTable);//C语言库函数Attribute::ReadNone
PAS = AttributeSet::get(mod->getContext(), ~0U, B);
} Attrs.push_back(PAS);
func__Z9fun_int_1i_PAL = AttributeSet::get(mod->getContext(), Attrs); }
func__Z9fun_int_1i->setAttributes(func__Z9fun_int_1i_PAL);

函数定义

{
//参数获取
Function::arg_iterator args = func__Z9fun_int_1i->arg_begin();
Value* int32_a = args++;
int32_a->setName("a"); BasicBlock* label_entry = BasicBlock::Create(mod->getContext(), "entry",func__Z9fun_int_1i,0); // Block entry (label_entry)
AllocaInst* ptr_a_addr = new AllocaInst(IntegerType::get(mod->getContext(), 32), "a.addr", label_entry);
ptr_a_addr->setAlignment(4);
StoreInst* void_39 = new StoreInst(int32_a, ptr_a_addr, false, label_entry);
void_39->setAlignment(4);
LoadInst* int32_40 = new LoadInst(ptr_a_addr, "", false, label_entry);
int32_40->setAlignment(4);
ReturnInst::Create(mod->getContext(), int32_40, label_entry); }

BasicBlock定义

if
{}
else
{}
//BasicBlock有4个参数: @1:mod->getContext(), @2:"字符串"//char*, @3:函数名//Function*, @4:0
BasicBlock* label_entry_70 = BasicBlock::Create(mod->getContext(), "entry",func__Z4dayuv,0);
BasicBlock* label_if_then = BasicBlock::Create(mod->getContext(), "if.then",func__Z4dayuv,0);
BasicBlock* label_if_else = BasicBlock::Create(mod->getContext(), "if.else",func__Z4dayuv,0);
BasicBlock* label_if_end = BasicBlock::Create(mod->getContext(), "if.end",func__Z4dayuv,0); for
{}
BasicBlock* label_entry = BasicBlock::Create(mod->getContext(), "entry",func__Z5cyclev,0);
BasicBlock* label_for_cond = BasicBlock::Create(mod->getContext(), "for.cond",func__Z5cyclev,0);
BasicBlock* label_for_body = BasicBlock::Create(mod->getContext(), "for.body",func__Z5cyclev,0);
BasicBlock* label_for_inc = BasicBlock::Create(mod->getContext(), "for.inc",func__Z5cyclev,0);
BasicBlock* label_for_end = BasicBlock::Create(mod->getContext(), "for.end",func__Z5cyclev,0); while
{}
BasicBlock* label_entry = BasicBlock::Create(mod->getContext(), "entry",func__Z3funf,0);
BasicBlock* label_while_cond = BasicBlock::Create(mod->getContext(), "while.cond",func__Z3funf,0);
BasicBlock* label_while_body = BasicBlock::Create(mod->getContext(), "while.body",func__Z3funf,0);
BasicBlock* label_while_end = BasicBlock::Create(mod->getContext(), "while.end",func__Z3funf,0);

跳转指令

BranchInst::Create(label_for_cond, label_entry);//直接跳转由label_entry >>> label_for_cond

BranchInst::Create(label_for_body, label_for_end, int1_cmp, label_for_cond); //条件跳转 label_for_cond >>>> label_for_body or label_for_end
//由int_cmp 决定, 不等于0 跳 label_for_body
等于0 跳 label_for_end
#9结束指令
ReturnInst::Create(mod->getContext(), int32_17, label_for_end);
三个参数@1: mod->getContext(), @2: 返回值 , @3:BasicBlock

调用函数

LoadInst* int32_12 = new LoadInst(ptr_x_addr, "", false, label_entry_9);
int32_12->setAlignment(4);
LoadInst* int32_13 = new LoadInst(ptr_y_addr, "", false, label_entry_9);
int32_13->setAlignment(4);
std::vector<Value*> int32_call_params;//参数
int32_call_params.push_back(int32_12);
int32_call_params.push_back(int32_13);
CallInst* int32_call = CallInst::Create(func__Z3addii, int32_call_params, "call", label_entry_9);//调用指令
//4个参数:@1:函数名//Function* @2:参数 @3:字符串 @4所在BasicBlock
int32_call->setCallingConv(CallingConv::C);
int32_call->setTailCall(false);
AttributeSet int32_call_PAL;
int32_call->setAttributes(int32_call_PAL);

11指令

//AllocaInst指令 申请指针 3个参数 @1:类型 @2:字符串区别 @3所在BasicBlock
AllocaInst* ptr_int_1 = new AllocaInst(IntegerType::get(mod->getContext(), 32), "int_1", label_entry);
ptr_int_1->setAlignment(4); //StoreInst指令 ptr_int_1指向const_int32_10 4个参数:@1:值 @2:指针 @3 : @4:所在BasicBlock
StoreInst* void_16 = new StoreInst(const_int32_10, ptr_int_1, false, label_entry);
void_16->setAlignment(4); //LoadInst指令 ptr_81的值为ptr_a_addr_79所指向的值 4个参数: @1:指针 @2: 字符串 @3: bool @4:所在BasicBlock
LoadInst* ptr_81 = new LoadInst(ptr_a_addr_79, "", false, label_entry_78);
ptr_81->setAlignment(8); #12数组和struct取值和赋值
int Array_int[4] = { 1, 2, 4, 5 };
一维数组:
取值: int int_1 = Array_int[0]; //下标只与64位的有关
ConstantInt* const_int32_16 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
ConstantInt* const_int64_17 = ConstantInt::get(mod->getContext(), APInt(64, StringRef("0"), 10));
std::vector<Value*> ptr_arrayidx_indices;
ptr_arrayidx_indices.push_back(const_int32_16);
ptr_arrayidx_indices.push_back(const_int64_17);//获得其指针
Instruction* ptr_arrayidx = GetElementPtrInst::Create(ptr_Array_int, ptr_arrayidx_indices, "arrayidx", label_entry);
LoadInst* int32_21 = new LoadInst(ptr_arrayidx, "", false, label_entry);
int32_21->setAlignment(4); 赋值:Array_int[1] = 4;//下标只与64位的有关
ConstantInt* const_int32_16 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
ConstantInt* const_int64_18 = ConstantInt::get(mod->getContext(), APInt(64, StringRef("1"), 10));
ConstantInt* const_int32_10 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("4"), 10));
std::vector<Value*> ptr_arrayidx1_indices;
ptr_arrayidx1_indices.push_back(const_int32_16);
ptr_arrayidx1_indices.push_back(const_int64_18);//下标只与64位的有关
Instruction* ptr_arrayidx1 = GetElementPtrInst::Create(ptr_Array_int, ptr_arrayidx1_indices, "arrayidx1", label_entry);
StoreInst* void_23 = new StoreInst(const_int32_10, ptr_arrayidx1, false, label_entry);
void_23->setAlignment(4); 二维数组:
int a[4][4] = {
1, 2, 3, 4,
5, 6, 7, 8,
9,10,11,12,
13,14,15,16 }; 取值:int c = a[0][0];//下标只与64位的有关 ConstantInt* const_int64_34 = ConstantInt::get(mod->getContext(), APInt(64, StringRef("0"), 10));
std::vector<Value*> ptr_arrayidx_indices;
ptr_arrayidx_indices.push_back(const_int32_33);
ptr_arrayidx_indices.push_back(const_int64_34);//下标只与64位的有关
Instruction* ptr_arrayidx = GetElementPtrInst::Create(ptr_a, ptr_arrayidx_indices, "arrayidx", label_entry);
std::vector<Value*> ptr_arrayidx1_indices;
ptr_arrayidx1_indices.push_back(const_int32_33);
ptr_arrayidx1_indices.push_back(const_int64_34);//下标只与64位的有关
Instruction* ptr_arrayidx1 = GetElementPtrInst::Create(ptr_arrayidx, ptr_arrayidx1_indices, "arrayidx1", label_entry);
LoadInst* int32_39 = new LoadInst(ptr_arrayidx1, "", false, label_entry);
int32_39->setAlignment(4);
StoreInst* void_40 = new StoreInst(int32_39, ptr_c, false, label_entry);
void_40->setAlignment(4); 赋值: a[2][3] = 5;
ConstantInt* const_int32_33 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
ConstantInt* const_int64_35 = ConstantInt::get(mod->getContext(), APInt(64, StringRef("2"), 10));
ConstantInt* const_int64_36 = ConstantInt::get(mod->getContext(), APInt(64, StringRef("3"), 10));
std::vector<Value*> ptr_arrayidx2_indices;
ptr_arrayidx2_indices.push_back(const_int32_33);
ptr_arrayidx2_indices.push_back(const_int64_35);//下标只与64位的有关
Instruction* ptr_arrayidx2 = GetElementPtrInst::Create(ptr_a, ptr_arrayidx2_indices, "arrayidx2", label_entry);
std::vector<Value*> ptr_arrayidx3_indices;
ptr_arrayidx3_indices.push_back(const_int32_33);
ptr_arrayidx3_indices.push_back(const_int64_36);//下标只与64位的有关
Instruction* ptr_arrayidx3 = GetElementPtrInst::Create(ptr_arrayidx2, ptr_arrayidx3_indices, "arrayidx3", label_entry);
StoreInst* void_41 = new StoreInst(const_int32_16, ptr_arrayidx3, false, label_entry);
void_41->setAlignment(4); 13.结构体的取值和赋值
typedef struct struct_1
{
int int_1;
struct struct_1* next;
}struct_1; void fun_struct()
{
struct_1 st_1 = {1,2,3, 0};
int i = st_1.int_1;
struct_1 *st_2 = st_1.next; st_1.int_1 = 2;
st_1.next = &st_1;
} 取值:
int i = st_1.int_1;
struct_1 *st_2 = st_1.next; ConstantInt* const_int32_14 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
ConstantInt* const_int32_8 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));
std::vector<Value*> ptr_int_1_indices;
ptr_int_1_indices.push_back(const_int32_14);
ptr_int_1_indices.push_back(const_int32_14);//只与二个有关
Instruction* ptr_int_1 = GetElementPtrInst::Create(ptr_st_1, ptr_int_1_indices, "int_1", label_entry);
LoadInst* int32_18 = new LoadInst(ptr_int_1, "", false, label_entry);
int32_18->setAlignment(4);
StoreInst* void_19 = new StoreInst(int32_18, ptr_i, false, label_entry);
void_19->setAlignment(4);
std::vector<Value*> ptr_next_indices;
ptr_next_indices.push_back(const_int32_14);
ptr_next_indices.push_back(const_int32_8);//只与二个有关
Instruction* ptr_next = GetElementPtrInst::Create(ptr_st_1, ptr_next_indices, "next", label_entry);
LoadInst* ptr_20 = new LoadInst(ptr_next, "", false, label_entry);
ptr_20->setAlignment(8);
StoreInst* void_21 = new StoreInst(ptr_20, ptr_st_2, false, label_entry);
void_21->setAlignment(8); 赋值:
st_1.int_1 = 2;
st_1.next = &st_1; ConstantInt* const_int32_14 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
ConstantInt* const_int32_8 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));
std::vector<Value*> ptr_int_11_indices;
ptr_int_11_indices.push_back(const_int32_14);
ptr_int_11_indices.push_back(const_int32_14);//只与二个有关
Instruction* ptr_int_11 = GetElementPtrInst::Create(ptr_st_1, ptr_int_11_indices, "int_11", label_entry);
StoreInst* void_22 = new StoreInst(const_int32_15, ptr_int_11, false, label_entry);
void_22->setAlignment(4);
std::vector<Value*> ptr_next2_indices;
ptr_next2_indices.push_back(const_int32_14);
ptr_next2_indices.push_back(const_int32_8);//只与二个有关
Instruction* ptr_next2 = GetElementPtrInst::Create(ptr_st_1, ptr_next2_indices, "next2", label_entry);
StoreInst* void_23 = new StoreInst(ptr_st_1, ptr_next2, false, label_entry);
void_23->setAlignment(8);

llvm-summary的更多相关文章

  1. llvm學習(二)————llvm編譯與環境構建

    本文由博主原创,转载请注明出处(保留此处和链接): IT人生(http://blog.csdn.net/robinblog/article/details/17339027) 在2011十月份的时候, ...

  2. Summary of Critical and Exploitable iOS Vulnerabilities in 2016

    Summary of Critical and Exploitable iOS Vulnerabilities in 2016 Author:Min (Spark) Zheng, Cererdlong ...

  3. 三个不常用的HTML元素:<details>、<summary>、<dialog>

    前面的话 HTML5不仅新增了语义型区块级元素及表单类元素,也新增了一些其他的功能性元素,这些元素由于浏览器支持等各种原因,并没有被广泛使用 文档描述 <details>主要用于描述文档或 ...

  4. [LeetCode] Summary Ranges 总结区间

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  5. Network Basic Commands Summary

    Network Basic Commands Summary set or modify hostname a)     temporary ways hostname NEW_HOSTNAME, b ...

  6. Summary - SNMP Tutorial

    30.13 Summary Network management protocols allow a manager to monitor and control routers and hosts. ...

  7. Mac Brew Install Nginx Summary

    ==> Downloading https://homebrew.bintray.com/bottles/nginx-1.10.1.el_capitan.bot################# ...

  8. LLVM 笔记(五)—— LLVM IR

    ilocker:关注 Android 安全(新手) QQ: 2597294287 LLVM 的 IR (Intermediate Representation) 是其设计中的最重要的部分.优化器在进行 ...

  9. LLVM 笔记(四)—— three-phase 设计的收益

    ilocker:关注 Android 安全(新手) QQ: 2597294287 采用 three-phase 的设计方式,便于编译器支持多种语言和多种目标平台. 如果在优化器阶段采用通用的 IR ( ...

  10. LLVM 笔记(二)—— PHI node

    ilocker:关注 Android 安全(新手) QQ: 2597294287 什么是 PHI node? 所有 LLVM 指令都使用 SSA (Static Single Assignment,静 ...

随机推荐

  1. 接口测试 postman

    1.可以应用一些简单的测试点 2. api有多个域名,放进collection里面进行批量测试,点击左上角'runner'

  2. Oracle to_date()函数的用法

    Oracle to_date()函数的用法 to_date()是Oracle数据库函数的代表函数之一,下文对Oracle to_date()函数的几种用法作了详细的介绍说明,供您参考学习. 在Orac ...

  3. linux大文件分割 split命令

    inux split 命令 功能说明:切割文件. 语 法:split [--help][--version][-][-b ][-C ][-l ][要切割的文件][输出文件名] 补充说明:split可将 ...

  4. Linux系统下配置环境变量

    一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登 ...

  5. 配置tomcat系统日志--java eclipse

    控制台那里的日志只是部分,有时候报错了我们并没有显示出来,所以需要找到系统日志... 双击tomcat v.80 Service---点击open lauch Configuration--Argum ...

  6. [Machine Learning & Algorithm]CAML机器学习系列1:深入浅出ML之Regression家族

    声明:本博客整理自博友@zhouyong计算广告与机器学习-技术共享平台,尊重原创,欢迎感兴趣的博友查看原文. 符号定义 这里定义<深入浅出ML>系列中涉及到的公式符号,如无特殊说明,符号 ...

  7. Codility NumberSolitaire Solution

    1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...

  8. linux glances的基本使用

    一.Glances介绍 glances 是一款用于 Linux.BSD 的开源命令行系统监视工具,它使用 Python 语言开发,能够监视 CPU.负载.内存.磁盘 I/O.网络流量.文件系统.系统温 ...

  9. LPC1769 CAN的自测试模式

    一.背景 客户要了一块单路CAN的板子,他希望在没有其他板子的情况下进行自行测试,然后按照我写的 APP选择自收发测试选项,却无法接收到发送的信息,但是外接了一块板子就可以接收到自己发送的 信息:由于 ...

  10. KVC 和 KVO

    KVC 键值编码    全称是Key-value coding,翻译成键值编码.它提供了一种使用字符串而不是访问器方法去访问一个对象实例变量的机制.        1.通过key(成员变量的名称)设置 ...