Manish Gupta
2014-Sep-01 20:50 UTC
[LLVMdev] Instrumenting Various Types Using Single Instrumentation Function
Hi All, My instrumentation code needs to insert calls to transmit Value list. Each element in this list could be of different type. The list is sent to instrumenting function say void recordVarInputValues(int num, ...) . So, I have created a Union type in Tracing.cpp, which I link with my benchmark module at compile time. These steps are similar to giri instrumentation https://github.com/liuml07/giri union NumericType { int iValue; long lValue; double dValue; ... }; Now, I would like to convert all the llvm Values, required by recordVarInputValues function, to be of NumericType. So that a variable length list of NumerricType values can be passed to my instrumentation function. This way I will not have to create different instrumentation functions for different data types. Can I cast say i32 value to NumericType value in my instrumentation code, without inserting additional instructions in my benchmark code. I tried inserting bitcast instructions and it doesn't work for me... if(!CastInst::isCastable(Lvals[j]->getType(), UnionVar->getType())){ errs()<<"CAST TO NumericType NOT POSSIBLE\n"; exit(0); } CastInst *I = CastInst::CreateZExtOrBitCast(Lvals[j], UnionVar->getType(), "", F); Is this even possible or some other method will be better? Thanks! Manish -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140901/7454021b/attachment.html>
John Criswell
2014-Sep-02 00:13 UTC
[LLVMdev] Instrumenting Various Types Using Single Instrumentation Function
Dear Manish, Union types in LLVM are points to structures, so casting 8, 16, 32, and 64 bit values to a union pointer is probably not what you want. I think the easiest thing to do is to: 1) Change the function in your run-time library to take the largest integer size supported by your target. 2) Change the instrumentation code to cast all values (including pointers) to this type. I'm not sure if CastInst::isCastable() is what you want to use to check to see that the casting can be done. I would just go ahead and use the bit-cast since, for the call, you should always be casting from a type with lower bit-width to higher bit-width. If you enable assertions when you build LLVM, then you should get an assertion if you try to create a Bitcast instruction that isn't going to work. Regards, John Criswell On 9/1/14, 4:50 PM, Manish Gupta wrote:> Hi All, > > > My instrumentation code needs to insert calls to transmit Value list. > Each element in this list could be of different type. The list is sent > to instrumenting function say void recordVarInputValues(int num, ...) > . So, I have created a Union type in Tracing.cpp, which I link with my > benchmark module at compile time. These steps are similar to giri > instrumentation https://github.com/liuml07/giri > > union NumericType > { > int iValue; > long lValue; > double dValue; > ... > }; > > Now, I would like to convert all the llvm Values, required by > recordVarInputValues function, to be of NumericType. So that a > variable length list of NumerricType values can be passed to my > instrumentation function. This way I will not have to create different > instrumentation functions for different data types. > > Can I cast say i32 value to NumericType value in my instrumentation > code, without inserting additional instructions in my benchmark code. > I tried inserting bitcast instructions and it doesn't work for me... > > if(!CastInst::isCastable(Lvals[j]->getType(), UnionVar->getType())){ > errs()<<"CAST TO NumericType NOT POSSIBLE\n"; > exit(0); > } > CastInst *I = CastInst::CreateZExtOrBitCast(Lvals[j], > UnionVar->getType(), "", F); > > Is this even possible or some other method will be better? > > Thanks! > Manish > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140901/23a75e18/attachment.html>
Manish Gupta
2014-Sep-02 23:08 UTC
[LLVMdev] Instrumenting Various Types Using Single Instrumentation Function
Thanks again John. I am working on it. Once I get it working. I will post the relevant instructions for others to take a look, in future, and complete the loop. Thanks again. On Mon, Sep 1, 2014 at 5:13 PM, John Criswell <jtcriswel at gmail.com> wrote:> Dear Manish, > > Union types in LLVM are points to structures, so casting 8, 16, 32, and 64 > bit values to a union pointer is probably not what you want. > > I think the easiest thing to do is to: > > 1) Change the function in your run-time library to take the largest > integer size supported by your target. > > 2) Change the instrumentation code to cast all values (including pointers) > to this type. > > I'm not sure if CastInst::isCastable() is what you want to use to check to > see that the casting can be done. I would just go ahead and use the > bit-cast since, for the call, you should always be casting from a type with > lower bit-width to higher bit-width. If you enable assertions when you > build LLVM, then you should get an assertion if you try to create a Bitcast > instruction that isn't going to work. > > Regards, > > John Criswell > > > > On 9/1/14, 4:50 PM, Manish Gupta wrote: > > Hi All, > > > My instrumentation code needs to insert calls to transmit Value list. > Each element in this list could be of different type. The list is sent to > instrumenting function say void recordVarInputValues(int num, ...) . So, I > have created a Union type in Tracing.cpp, which I link with my benchmark > module at compile time. These steps are similar to giri instrumentation > https://github.com/liuml07/giri > > union NumericType > { > int iValue; > long lValue; > double dValue; > ... > }; > > Now, I would like to convert all the llvm Values, required by > recordVarInputValues function, to be of NumericType. So that a variable > length list of NumerricType values can be passed to my instrumentation > function. This way I will not have to create different instrumentation > functions for different data types. > > Can I cast say i32 value to NumericType value in my instrumentation > code, without inserting additional instructions in my benchmark code. I > tried inserting bitcast instructions and it doesn't work for me... > > if(!CastInst::isCastable(Lvals[j]->getType(), UnionVar->getType())){ > errs()<<"CAST TO NumericType NOT POSSIBLE\n"; > exit(0); > } > CastInst *I = CastInst::CreateZExtOrBitCast(Lvals[j], > UnionVar->getType(), "", F); > > > Is this even possible or some other method will be better? > > Thanks! > Manish > > > _______________________________________________ > LLVM Developers mailing listLLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140902/c7c07cf4/attachment.html>
Apparently Analagous Threads
- [LLVMdev] assert in InnerLoopVectorizer::createEmptyLoop
- [LLVMdev] assert in InnerLoopVectorizer::createEmptyLoop
- [LLVMdev] Inserting Calls to var args Functions
- [LLVMdev] [llvm-commits] [PATCH] BasicBlock Autovectorization Pass
- [LLVMdev] How to create arguments CallInst