[LLVMdev] Initialising global Array

Andreas Neustifter e0325716 at student.tuwien.ac.at
Thu Jun 18 06:22:44 PDT 2009


Hi,

I try to create a array that has a nonzero initialiser:

What i do is, first create the array type.

 > const ArrayType *ATy = ArrayType::get(Type::Int32Ty, NumEdges);

Then create some constant values for the initializer.

 > std::vector<Constant*> Initializer; Initializer.reserve(NumEdges);
 > APInt zero(32,0);      Constant* zeroc = ConstantInt::get(zero);
 > APInt minusone(32,-1); Constant* minusonec = ConstantInt::get(minusone);

Create the global array, there is no initializer yet.

 > GlobalVariable *Counters =
 >   new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
 >                      Constant::getNullValue(ATy), "OptimalEdgeProfCounters", &M);

Then exactly "NumEdges" constants are pushed to the "Initializer":

 > Initializer[i] = zeroc;
 > ..
 > Initializer[i] = minusonec;
 > ..

And then I set the initializer for the array:

 > Constant *init = llvm::ConstantArray::get(ATy, Initializer);
 > Counters->setInitializer(init);


What am I doing wrong? I still get:

 > @OptimalEdgeProfCounters = internal global [2 x i32] zeroinitializer; <[2 x i32]*> [#uses=2]

Thanks, Andi




More information about the llvm-dev mailing list