#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Analysis/ScalarEvolution.h"
class MyPass : public llvm::FunctionPass {
public:
static char ID;
MyPass() : llvm::FunctionPass(ID) {}
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
AU.addRequired<ScalarEvolutionWrapperPass>();
AU.setPreservesAll();
}
bool runOnFunction(llvm::Function &F) override {
ScalarEvolution* SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
for (BasicBlock &BB : F) {
for (Instruction &I : BB) {
if (auto *GEP= dyn_cast<GetElementPtrInst>(&I)){
const SCEV *arrayIndexSCEV = SE->getSCEV(GEP);
// The scevtype obtained here is 0x0
SCEVTypes scevtype = static_cast<SCEVTypes>(arrayIndexSCEV->getSCEVType());
}
}
}
return true;
}
};
char MyPass::ID = 0;
static llvm::RegisterPass<MyPass> X("my-pass", "My Example Pass");
Is there any problem with the registration above? Why did I use this method to obtain a scevtype of 0x0? After investigation, it was confirmed that there was a problem at the registration location, but I couldn’t find the reason. I hope it can provide me with some help again.
I found a case of indirect use of SCEV to get this data, I can get some GEP data with simple offset, but in the face of some complicated ones, such as when the offset is operated by loop traversal and constant, or multiple loop traversal for operation, etc., the conversion to SCEV to get is scUnkonw type
Can you tell me how the new version of PassManager Pass works? I only use the old PassManage Pass, or is there any way to learn to use it?
Thank you for your correction, this is my first time posting to the forum, I am not very good at using it, I will correct this error later - IR & Optimizations - LLVM
I also encountered a problem is how to use LLVM to determine the array is sequential access and read (or understand the array subscript from 0 to n-1 in increasing order by 1, where n-1 is the maximum subscript of the array), the biggest problem is to encounter the subscript of the array has arithmetic case, as I mentioned in the first case.
Finally, thank you again for your reply.