Skip to content
Snippets Groups Projects
Commit 171db849 authored by Andrea Gussoni's avatar Andrea Gussoni
Browse files

Use `getCallTo` in `getBasicBlockPC`

We now take advantage of the `getCallTo` helper function in the
`getBasicBlockPC` function defined in `ir-helpes.h`
parent 608b96b5
No related branches found
No related tags found
No related merge requests found
...@@ -365,19 +365,6 @@ static inline std::string getName(const llvm::Value *V) { ...@@ -365,19 +365,6 @@ static inline std::string getName(const llvm::Value *V) {
return SS.str(); return SS.str();
} }
// TODO: this function assumes 0 is not a valid PC
static inline uint64_t getBasicBlockPC(llvm::BasicBlock *BB) {
auto It = BB->begin();
assert(It != BB->end());
if (auto *Call = llvm::dyn_cast<llvm::CallInst>(&*It)) {
auto *Callee = Call->getCalledFunction();
if (Callee && Callee->getName() == "newpc")
return getLimitedValue(Call->getOperand(0));
}
return 0;
}
static inline llvm::LLVMContext &getContext(const llvm::Module *M) { static inline llvm::LLVMContext &getContext(const llvm::Module *M) {
return M->getContext(); return M->getContext();
} }
...@@ -540,6 +527,17 @@ static inline llvm::CallInst *getCallTo(llvm::Instruction *I, ...@@ -540,6 +527,17 @@ static inline llvm::CallInst *getCallTo(llvm::Instruction *I,
return nullptr; return nullptr;
} }
// TODO: this function assumes 0 is not a valid PC
static inline uint64_t getBasicBlockPC(llvm::BasicBlock *BB) {
auto It = BB->begin();
assert(It != BB->end());
if (llvm::CallInst *Call = getCallTo(&*It, "newpc")) {
return getLimitedValue(Call->getOperand(0));
}
return 0;
}
template<typename C> template<typename C>
static inline auto skip(unsigned ToSkip, C &&Container) static inline auto skip(unsigned ToSkip, C &&Container)
-> llvm::iterator_range<decltype(Container.begin())> { -> llvm::iterator_range<decltype(Container.begin())> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment