LLVM: ‘AResultsWrapperPass’ was not declared in this scope - llvm

I am a fresh man on LLVM. Now I am trying figure out how to use the "getAnalysisUsage" method under the LLVM 7.0
In my (Module) pass, I just use:
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<AResultsWrapperPass>();
//AU.addRequired<AliasAnalysis>();
//AU.setPreservesAll();
}
When I try to compile it, I receive the following error:
error: ‘AResultsWrapperPass’ was not declared in this scope
error: no matching function for call to ‘llvm::AnalysisUsage::addRequired()’
I have search some similar question in this web:
LLVM Error When Using a Pass from Another Pass
However, it does not work. How can I fix this error?

It seems that you have a typo.
It should be AAResultsWrapperPass instead of AResultsWrapperPass
After adding the requirement, in order to make use of this analysis (e.g. in a runOnFunction method) you should do:
AliasAnalysis &aa = getAnalysis<AAResultsWrapperPass>().getAAResults();

Related

Why has assignment to a gr_complex variable (GNU Radio) stopped working for me?

In the block definition for my custom SDR transceiver hardware I use the following complex variable:
gr_complex complexSample;
In my code, which has worked successfully for two years before a recent upgrade to the latest gnuradio release, I use the following assignments:
complexSample.real() = realInt;
complexSample.imag()= imagInt;
However, when I try to compile now, I get the following error:
error: lvalue required as left operand of assignment
Frustratingly, if I remove the pair of parentheses, I get the following error:
error: invalid use of member function 'void
std::complex::imag(float)' (did you forget the '()'? )
The original version of gnuradio I have been using is 3.7.5-5, and the latest I have upgraded to is: 3.7.10.1-2.
Has something significant changed between these two releases which could explain this difference in behaviour?
If so, what is the solution?
Could this be something to do with 'Volk integration' (whatever that is...).
No, GNU Radio didn't change gr_complex. It's still but an alias for std::complex<float>.
What probably has changed is that you're now using a compiler set to C++14, and that makes std::complex<float>.real() return a const that you can't assign to. (I think that's what happens.)
You should either just construct the value like you mean to, i.e.
gr_complex foo(realpart, imagpart)
or use the setters
gr_complex foo;
foo.real(realpart);
foo.imag(imagpart);
As the error message shows, gr_complex is a typedef for std::complex<float>. That means the .real() and .imag() methods are getters, not setters.
That's not what you want anyway. You just want to assign the number, not its separate components: complexSample = gr_complex{realInt, imagInt}.

LLVM ERROR: Broken function found, compilation aborted! after removeFromParent()

I have a test.c file which has this function call:
functiontest(2,x);
I would like to delete this function call (with an llvm pass) and when I try to use removeFromParent() function like this:
calledFunction1->removeFromParent();
this causes LLVM to produce the following error:
Referencing function in another module!
call void #functiontest(i32 2, float %tmp15)
LLVM ERROR: Broken function found, compilation aborted!
I also tried calling eraseFromParent() but this triggers an assert:
Assertion `use_empty() && "Uses remain when a value is destroyed!"' failed.
I would prefer to use removeFromParent()
Any ideas what's wrong ?
First of all, it would be really helpful if you could post a minimal code sample that demonstrates your problem. Otherwise, we can only guess. Some observations though:
Why do you prefer removeFromParent? The call instruction has to be deleted too, that's what eraseFromParent does.
Did you call replaceAllUsesWith before erasing/removing? Otherwise, uses stick around.
Did you remove the function or the call instruction? This may explain the first error message.

exposing internal c++ function to llvm jit'd c++

I'm trying to experiment with llvm right now. I'd like to use languages that can be compiled to llvm bitcode for scripting. I've managed so far to load an llvm bitcode module and call a function defined in it from my 'internal' c++ code. I've next tried to expose a c++ function from my internal code to the jit'd code - so far in this effort I haven't managed to get anything but SEGFAULT.
My code is as follows. I've tried to create a Function and a global mapping in my execution engine that points to a function I'd like to call.
extern "C" void externGuy()
{
cout << "I'm the extern guy" << endl;
}
void ExposeFunction()
{
std::vector<Type*> NoArgs(0);
FunctionType* FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), NoArgs, false);
Function* fnc = Function::Create(FT, Function::ExternalLinkage, "externGuy", StartModule);
JIT->addGlobalMapping(fnc, (void*)externGuy);
}
// ... Create module, create execution engine
ExposeFunction();
Is the problem that I can't add a function to the module after its been loaded from bitcode file?
Update:
I've refactored my code so that it reads like so instead:
// ... Create module, create execution engine
std::vector<Type*> NoArgs(0);
FunctionType* FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), NoArgs, false);
Function* fnc = Function::Create(FT, Function::ExternalLinkage, "externGuy", m);
fnc->dump();
JIT->addGlobalMapping(fnc, (void*)externGuy);
So instead of segfault I get:
Program used external function 'externGuy' which could not be resolved
Also, the result of dump() prints:
declare void #externGuy1()
If I change my c++ script bitcode thing to call externGuy1() instead of externGuy() it will suggest to me that I meant to use the externGuy. The addGlobalMapping just doesn't seem to be working for me. I'm not sure what I'm missing here. I also added -fPIC to my compilation command like I saw suggested in another question - I'm honestly not sure if its helped anything but no harm in trying.
I finally got this to work. My suspicion is to maybe creating the function, as well as defining it in the script is causing perhaps more than 1 declaration of the functions name and the mapping just wasn't working out. What I did was define the function in the script and then use getFunction to use for mapping instead. Using the dump() method on the function output:
declare void #externGuy() #1
Which is why I think that had something to do with the mapping not working originally. I also remember the Kaleidoscope tutorial saying that getPointerToFunction would do the JIT compiling when its called if it isn't already done so I thought that I would have to do the mapping before this call.
So altogether to get this whole thing working it was as follows:
// Get the function and map it
Function* extrn = m->getFunction("externGuy");
extrn->dump();
JIT->addGlobalMapping(extrn, (void*)&::externGuy);
// Get a pointer to the jit compiled function
Function* mane = m->getFunction("hello");
void* fptr = JIT->getPointerToFunction(mane);
// Make a call to the jit compiled function which contains a call to externGuy
void (*FP)() = (void(*)())(intptr_t)fptr;
FP();

Error when creating a global variable in llvm

I am trying to create a global variable in a function pass. The code is
gVar= new GlobalVariable(
/*Type=*/Int32Type,
/*isConstant=*/false,
/*Linkage=*/GlobalValue::CommonLinkage,
/*Initializer=*/0, // has initializer, specified below
/*Name=*/"gVar",
/*ThreadLocalMode*/GlobalVariable::InitialExecTLSModel);
However, I keep getting the following compiler error:
error: no matching function for call to ‘llvm::GlobalVariable::GlobalVariable(const llvm::Type*&, bool, llvm::GlobalValue::LinkageTypes, int, const char [4], llvm::GlobalVariable::ThreadLocalMode)’
Could you please tell me the right way to declare a global variable in llvm? Thank you very much!
In addition, I've referred to the header file:
http://llvm.org/docs/doxygen/html/GlobalVariable_8h_source.html
and this post
How can I declare a global variable in LLVM?
You need to pass a Module to the constructor. There are plenty of examples in the LLVM code base for creating global vars. For example, in examples/ExceptionDemo/ExceptionDemo.cpp:
new llvm::GlobalVariable(module,
stringConstant->getType(),
true,
llvm::GlobalValue::LinkerPrivateLinkage,
stringConstant,
"");
By the way - important note: you should not be creating new globals or doing anything else that modifies a module in a function pass. If you have to do that, you need a module pass.

Using enum parameter in functions

I'm working on Windows, in C++ with Visual Studio.
I have a class that has a:
enum algorithmStatus { LOADING, DETECTION, TRACKING, LOST };
In the declaration I want to use a setter and getter to change the status, something like:
void MyStatusClass::setAlgorithmStatus(algorithmStatus newStatus)
{
//_Status = newStatus;
//_Status = MyStatusClass::algorithmStatus::LOADING;
}
But I can't compile because I get:
Error 5 error C2511: 'void MyStatusClass::setAlgorithmStatus(MyStatusClass::algorithmStatus)' : overloaded member function not found in 'Nft_Status' c:\MyStatusClass.cpp 197
How can I do that setter correctly?
EDIT:
In header is already declarated:
void setAlgorithmStatus(MyStatusClass::algorithmStatus newStatus);
and:
void setAlgorithmStatus(algorithmStatus newStatus);
In cpp the function is declared just i write on top.
SOLVED
The problem was i used a MyStatusClass::algorithmStatus in the constructor, you don´t need to use the MyStatusClass::, and its advisable don´t use it if you don´t need it.
The MSDN documentation for error code C2511 gives you a good list to lookout for:
identifier : overloaded member function not found in class
No version of the function is declared with the specified parameters. Possible causes:
Wrong parameters passed to function.
Parameters passed in wrong order.
Incorrect spelling of parameter names.
Always, lookup the error codes to get help in resolving compilation errors.