Skip to content

Commit

Permalink
llvm14: CallBase::getNumArgOperands was removed
Browse files Browse the repository at this point in the history
  • Loading branch information
lzaoral authored and mchalupa committed May 18, 2022
1 parent 497e29e commit 565a386
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 28 deletions.
13 changes: 9 additions & 4 deletions include/dg/llvm/CallGraph/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,20 @@ callIsCompatible(const llvm::Function *F, const llvm::CallInst *CI,
CallCompatibility policy = CallCompatibility::LOOSE) {
using namespace llvm;

#if LLVM_VERSION_MAJOR >= 8
auto max_idx = CI->arg_size();
#else
auto max_idx = CI->getNumArgOperands();
#endif

if (policy != CallCompatibility::MATCHING_ARGS) {
if (F->isVarArg()) {
if (F->arg_size() > CI->getNumArgOperands()) {
if (F->arg_size() > max_idx) {
return false;
}
} else if (F->arg_size() != CI->getNumArgOperands()) {
} else if (F->arg_size() != max_idx) {
if (policy == CallCompatibility::STRICT ||
F->arg_size() > CI->getNumArgOperands()) {
F->arg_size() > max_idx) {
// too few arguments
return false;
}
Expand All @@ -159,7 +165,6 @@ callIsCompatible(const llvm::Function *F, const llvm::CallInst *CI,
}

size_t idx = 0;
auto max_idx = CI->getNumArgOperands();
for (auto A = F->arg_begin(), E = F->arg_end(); idx < max_idx && A != E;
++A, ++idx) {
Type *CTy = CI->getArgOperand(idx)->getType();
Expand Down
12 changes: 7 additions & 5 deletions lib/llvm/PointerAnalysis/Interprocedural.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@

#include "dg/llvm/PointerAnalysis/PointerGraph.h"

#include "llvm/llvm-utils.h"

namespace dg {
namespace pta {

void LLVMPointerGraphBuilder::addArgumentOperands(const llvm::CallInst *CI,
PSNode *arg, unsigned idx) {
assert(idx < CI->getNumArgOperands());
assert(idx < llvmutils::getNumArgOperands(CI));
PSNode *op = tryGetOperand(CI->getArgOperand(idx));
if (op && !arg->hasOperand(op)) {
// NOTE: do not add an operand multiple-times
Expand All @@ -29,9 +31,8 @@ void LLVMPointerGraphBuilder::addArgumentOperands(const llvm::CallInst *CI,

void LLVMPointerGraphBuilder::addArgumentOperands(const llvm::CallInst &CI,
PSNode &node) {
auto sentinel = CI.getNumArgOperands();
for (unsigned i = 0; i < sentinel; ++i) {
PSNode *operand = tryGetOperand(CI.getArgOperand(i));
for (const auto &arg : llvmutils::args(CI)) {
PSNode *operand = tryGetOperand(arg);
if (operand && !node.hasOperand(operand)) {
node.addOperand(operand);
}
Expand Down Expand Up @@ -75,7 +76,8 @@ void LLVMPointerGraphBuilder::addArgumentsOperands(const llvm::Function *F,

void LLVMPointerGraphBuilder::addVariadicArgumentOperands(
const llvm::Function *F, const llvm::CallInst *CI, PSNode *arg) {
for (unsigned idx = F->arg_size() - 1; idx < CI->getNumArgOperands(); ++idx)
for (unsigned idx = F->arg_size() - 1;
idx < llvmutils::getNumArgOperands(CI); ++idx)
addArgumentOperands(CI, arg, idx);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/llvm/PointerAnalysis/PointerAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ LLVMPointerAnalysis::getAccessedMemory(const llvm::Instruction *I) {

// check which operands are pointers and get the information for them
bool hasUnknown = false;
for (unsigned i = 0; i < CI->getNumArgOperands(); ++i) {
if (hasPointsTo(CI->getArgOperand(i))) {
auto tmp = getLLVMPointsToChecked(CI->getArgOperand(i));
for (const auto &arg : llvmutils::args(CI)) {
if (hasPointsTo(arg)) {
auto tmp = getLLVMPointsToChecked(arg);
hasUnknown |= tmp.first;
// translate to regions
for (const auto &ptr : tmp.second) {
Expand Down
10 changes: 4 additions & 6 deletions lib/llvm/ReadWriteGraph/Calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ LLVMReadWriteGraphBuilder::createUnknownCall(const llvm::CallInst *CInst) {

// every pointer we pass into the undefined call may be defined
// in the function
for (unsigned int i = 0; i < CInst->getNumArgOperands(); ++i) {
const Value *llvmOp = CInst->getArgOperand(i);

for (const auto &arg : llvmutils::args(CInst)) {
// constants cannot be redefined except for global variables
// (that are constant, but may point to non constant memory
const Value *strippedValue = llvmOp->stripPointerCasts();
const Value *strippedValue = arg->stripPointerCasts();
if (isa<Constant>(strippedValue)) {
const GlobalVariable *GV = dyn_cast<GlobalVariable>(strippedValue);
// if the constant is not global variable,
Expand All @@ -125,7 +123,7 @@ LLVMReadWriteGraphBuilder::createUnknownCall(const llvm::CallInst *CInst) {
continue;
}

auto pts = PTA->getLLVMPointsToChecked(llvmOp);
auto pts = PTA->getLLVMPointsToChecked(arg);
// if we do not have a pts, this is not pointer
// relevant instruction. We must do it this way
// instead of type checking, due to the inttoptr.
Expand Down Expand Up @@ -275,7 +273,7 @@ RWNode *LLVMReadWriteGraphBuilder::funcFromModel(const FunctionModel *model,
const llvm::CallInst *CInst) {
RWNode *node = &create(RWNodeType::GENERIC);

for (unsigned int i = 0; i < CInst->getNumArgOperands(); ++i) {
for (unsigned int i = 0; i < llvmutils::getNumArgOperands(CInst); ++i) {
if (!model->handles(i))
continue;

Expand Down
7 changes: 4 additions & 3 deletions lib/llvm/SystemDependenceGraph/SystemDependenceGraph.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "dg/llvm/SystemDependenceGraph/SystemDependenceGraph.h"
#include "dg/util/debug.h"

#include "llvm/llvm-utils.h"

namespace dg {
namespace llvmdg {

Expand Down Expand Up @@ -49,9 +51,8 @@ struct SDGBuilder {

// create actual parameters
auto &params = node.getParameters();
for (unsigned i = 0; i < CI->getNumArgOperands(); ++i) {
auto *A = CI->getArgOperand(i);
llvm::errs() << "Act: " << *A << "\n";
for (const auto &arg : llvmutils::args(CI)) {
llvm::errs() << "Act: " << *arg << "\n";
params.createParameter();
}
return node;
Expand Down
4 changes: 3 additions & 1 deletion lib/llvm/ValueRelations/StructureAnalyzer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "dg/llvm/ValueRelations/StructureAnalyzer.h"

#include "llvm/llvm-utils.h"

#include <llvm/IR/Constants.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/IntrinsicInst.h>
Expand Down Expand Up @@ -689,7 +691,7 @@ void StructureAnalyzer::initializeCallRelations() {
// set formal parameters equal to real
unsigned argCount = 0;
for (const llvm::Argument &formalArg : function.args()) {
if (argCount >= call->getNumArgOperands())
if (argCount >= llvmutils::getNumArgOperands(call))
break;
const llvm::Value *realArg = call->getArgOperand(argCount);

Expand Down
44 changes: 39 additions & 5 deletions lib/llvm/llvm-utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef DG_LLVM_UTILS_H_
#define DG_LLVM_UTILS_H_

#include <llvm/ADT/iterator_range.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Instructions.h>
Expand All @@ -15,6 +16,39 @@ namespace llvmutils {

using namespace llvm;

/* ----------------------------------------------
* -- COMPAT
* ---------------------------------------------- */

// FIXME: Remove this when LLVM 8 is the minimal version for DG!
inline iterator_range<User::op_iterator> args(CallInst *CI) {
return make_range(CI->arg_begin(), CI->arg_end());
}

inline iterator_range<User::const_op_iterator> args(const CallInst *CI) {
return make_range(CI->arg_begin(), CI->arg_end());
}

inline iterator_range<User::op_iterator> args(CallInst &CI) {
return args(&CI);
}

inline iterator_range<User::const_op_iterator> args(const CallInst &CI) {
return args(&CI);
}

inline unsigned getNumArgOperands(const CallInst *CI) {
#if LLVM_VERSION_MAJOR >= 8
return CI->arg_size();
#else
return CI->getNumArgOperands();
#endif
}

inline unsigned getNumArgOperands(const CallInst &CI) {
return getNumArgOperands(&CI);
}

/* ----------------------------------------------
* -- PRINTING
* ---------------------------------------------- */
Expand Down Expand Up @@ -58,14 +92,15 @@ callIsCompatible(const Function *F, const CallInst *CI,
CallCompatibility policy = CallCompatibility::LOOSE) {
using namespace llvm;

auto ci_arg_size = getNumArgOperands(CI);
if (policy != CallCompatibility::MATCHING_ARGS) {
if (F->isVarArg()) {
if (F->arg_size() > CI->getNumArgOperands()) {
if (F->arg_size() > ci_arg_size) {
return false;
}
} else if (F->arg_size() != CI->getNumArgOperands()) {
} else if (F->arg_size() != ci_arg_size) {
if (policy == CallCompatibility::STRICT ||
F->arg_size() > CI->getNumArgOperands()) {
F->arg_size() > ci_arg_size) {
// too few arguments
return false;
}
Expand All @@ -82,8 +117,7 @@ callIsCompatible(const Function *F, const CallInst *CI,
}

size_t idx = 0;
auto max_idx = CI->getNumArgOperands();
for (auto A = F->arg_begin(), E = F->arg_end(); idx < max_idx && A != E;
for (auto A = F->arg_begin(), E = F->arg_end(); idx < ci_arg_size && A != E;
++A, ++idx) {
Type *CTy = CI->getArgOperand(idx)->getType();
Type *ATy = A->getType();
Expand Down
6 changes: 5 additions & 1 deletion tools/llvm-pta-ben.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "dg/util/TimeMeasure.h"

#include "llvm/llvm-utils.h"

using namespace dg;
using namespace dg::pta;
using dg::debug::TimeMeasure;
Expand Down Expand Up @@ -247,8 +249,10 @@ static void evalPSNode(DGLLVMPointerAnalysis *pta, PSNode *node) {

const llvm::Function *called = llvm::cast<llvm::Function>(v);
const llvm::StringRef &fun = called->getName();
if (call->getNumArgOperands() != 2)

if (llvmutils::getNumArgOperands(call) != 2)
return;

if (!test_checkfunc(fun))
return;

Expand Down

0 comments on commit 565a386

Please sign in to comment.