[LLVMdev] newbie question for type comparison

Lu Zhao luzhao at cs.utah.edu
Sun Apr 20 21:05:47 PDT 2008


Hi,

I want to extract all instruction of the form "alloca %struct.S", where
$struct.S is defined as a struct 

	%struct.S = type { i32, i32 }

I'm using the following loop:

for(inst_iterator i = inst_begin(F), e = inst_end(F); i!= e; i++)
{
	AllocaInst* ai;
        if( (ai = dyn_cast<AllocaInst>(&*i))){
          if(ai->getOperand(0)->getType()->getTypeID() ==
		Type::StructTyID) 
			allocs.push_back(ai);
         }
}

However, I had the impression that the type comparison can be done by a
pointer comparison. Can anyone please suggest me a better way to do it?

Also, I want to get the size of %struct.S, should I use the following
code?

const TargetData &TD = getAnalysis<TargetData>();
unsigned StructSize =
         TD.getABITypeSizeInBits(ai->getOperand(0)->getType());

Thanks a lot.
Lu



More information about the llvm-dev mailing list