Sorry I got really overwhelmed by so many classes and member functions in LLVM. So would you please clarify some problems I have? 1. If I see this instruction in the function. %S.i = alloca %struct.SimpleStruct Suppose SimpleStruct is as following: struct.SimpleStruct = type { int, double } When I read the instruction, how can I know the type of simplstruct, should I use 'getType' member function like Inst.getType()? If I use that, I will get a PointerType, how can I use it? 2. Another question is that since we do the scalar replacement on each function. If the program look like this. struct s { int a; float b; } fun1( struct s *ps) { ps->a = 1; ps->b = 2; } main( ) { struct s mystru; fun1( &mystru ); } When we process the function 'fun1', should we change fun1 to something like fun1( int *a, float *b ) then change fun1(&mystru) in main to something like fun1( &mystru.a, &mystru.b)? Thanks, xiaodong
Also sprach xli3 at uiuc.edu: } Sorry I got really overwhelmed by so many classes and member } functions in LLVM. So would you please clarify some problems } I have? } } 1. If I see this instruction in the function. } } %S.i = alloca %struct.SimpleStruct } } Suppose SimpleStruct is as following: } struct.SimpleStruct = type { int, double } } } When I read the instruction, how can I know the type of } simplstruct, should I use 'getType' member function like } Inst.getType()? If I use that, I will get a PointerType, how } can I use it? } I used the "dyn_cast<>" method to dynamically check whether something is of a given type. dyn_cast<> helpfully returns 0 if it's not of that type. So, you can do something like: if (const PointerType *PT = dyn_cast<PointerType>(Inst.getType())) if (const StructType *ST = dyn_cast<StructType>(PT->getType())) // Work with ST... and it'll work. } 2. Another question is that since we do the scalar replacement } on each function. If the program look like this. } } struct s { } int a; } float b; } } } fun1( struct s *ps) { } ps->a = 1; } ps->b = 2; } } } main( ) } { } struct s mystru; } } fun1( &mystru ); } } } } When we process the function 'fun1', should we change fun1 to } something like } fun1( int *a, float *b ) } then change fun1(&mystru) in main to something like } fun1( &mystru.a, &mystru.b)? } I assume that, since "mystru" isn't being used as specified in rules U1-U3, that we shouldn't have to handle it... But I could be wrong... *crosses fingers, hoping he's not wrong* -- || Bill? Wendling wendling at isanbard.org
> I used the "dyn_cast<>" method to dynamically check whether something is > of a given type. dyn_cast<> helpfully returns 0 if it's not of that type. > So, you can do something like: > > if (const PointerType *PT = dyn_cast<PointerType>(Inst.getType())) > if (const StructType *ST = dyn_cast<StructType>(PT->getType())) > // Work with ST...Yup, one typeo though, this should be: if (const PointerType *PT = dyn_cast<PointerType>(Inst.getType())) if (const StructType *ST = dyn_cast<StructType>(PT->getElementType())) // Work with ST...> } When we process the function 'fun1', should we change fun1 to > } something like > } fun1( int *a, float *b ) > } then change fun1(&mystru) in main to something like > } fun1( &mystru.a, &mystru.b)? > } > I assume that, since "mystru" isn't being used as specified in rules > U1-U3, that we shouldn't have to handle it... > But I could be wrong... > *crosses fingers, hoping he's not wrong*You're right. It isn't one of the cases you have to handle, so you ignore it. -Chris http://llvm.cs.uiuc.edu/ http://www.nondot.org/~sabre/Projects/
You do not have to (and should not) transform a struct if it is passed as an argument to a procedure. --Vikram ---------------------------------------------------------------------- VIKRAM S. ADVE Assistant Professor E-MAIL: vadve at cs.uiuc.edu Department of Computer Science PHONE: (217) 244-2016 Univ. of Illinois at Urbana-Champaign FAX: (217) 244-6869 1304 W. Springfield Ave. http://www.cs.uiuc.edu/~vadve Urbana IL 61801. ----------------------------------------------------------------------> -----Original Message----- > From: llvmdev-admin at cs.uiuc.edu [mailto:llvmdev-admin at cs.uiuc.edu]On > Behalf Of Bill? Wendling > Sent: Tuesday, September 17, 2002 11:39 AM > To: xli3 at uiuc.edu > Cc: llvmdev at cs.uiuc.edu > Subject: Re: [LLVMdev] questions > > > Also sprach xli3 at uiuc.edu: > } Sorry I got really overwhelmed by so many classes and member > } functions in LLVM. So would you please clarify some problems > } I have? > } > } 1. If I see this instruction in the function. > } > } %S.i = alloca %struct.SimpleStruct > } > } Suppose SimpleStruct is as following: > } struct.SimpleStruct = type { int, double } > } > } When I read the instruction, how can I know the type of > } simplstruct, should I use 'getType' member function like > } Inst.getType()? If I use that, I will get a PointerType, how > } can I use it? > } > I used the "dyn_cast<>" method to dynamically check whether something is > of a given type. dyn_cast<> helpfully returns 0 if it's not of that type. > So, you can do something like: > > if (const PointerType *PT = dyn_cast<PointerType>(Inst.getType())) > if (const StructType *ST = dyn_cast<StructType>(PT->getType())) > // Work with ST... > > and it'll work. > > } 2. Another question is that since we do the scalar replacement > } on each function. If the program look like this. > } > } struct s { > } int a; > } float b; > } } > } fun1( struct s *ps) { > } ps->a = 1; > } ps->b = 2; > } } > } main( ) > } { > } struct s mystru; > } > } fun1( &mystru ); > } } > } > } When we process the function 'fun1', should we change fun1 to > } something like > } fun1( int *a, float *b ) > } then change fun1(&mystru) in main to something like > } fun1( &mystru.a, &mystru.b)? > } > I assume that, since "mystru" isn't being used as specified in rules > U1-U3, that we shouldn't have to handle it... > > But I could be wrong... > > *crosses fingers, hoping he's not wrong* > > -- > || Bill? Wendling wendling at isanbard.org > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev >