Skip to content

Commit

Permalink
Preliminary changes needed to upgrade to LLVM 14
Browse files Browse the repository at this point in the history
  • Loading branch information
shaobo-he committed Mar 28, 2022
1 parent 7aa70b5 commit 1faf5f5
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 37 deletions.
4 changes: 2 additions & 2 deletions bin/versions
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ BOOGIE_VERSION="2.9.6"
CORRAL_VERSION="1.1.8"
SYMBOOGLIX_COMMIT="ccb2e7f2b3"
LOCKPWN_COMMIT="12ba58f1ec"
LLVM_SHORT_VERSION="13"
LLVM_FULL_VERSION="13.0.1"
LLVM_SHORT_VERSION="14"
LLVM_FULL_VERSION="14.0.0"
RUST_VERSION="nightly-2022-01-01"
1 change: 1 addition & 0 deletions include/smack/SmackInstGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/InstVisitor.h"
#include <map>
#include <set>
#include <unordered_set>

Expand Down
1 change: 1 addition & 0 deletions include/smack/SmackRep.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "llvm/Support/GraphWriter.h"
#include "llvm/Support/Regex.h"
#include <list>
#include <map>
#include <sstream>

namespace smack {
Expand Down
6 changes: 3 additions & 3 deletions lib/smack/AddTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ InstructionCost AddTiming::getInstructionCost(const Instruction *I) const {
case Instruction::Select: {
const SelectInst *SI = cast<SelectInst>(I);
Type *CondTy = SI->getCondition()->getType();
return TTI->getCmpSelInstrCost(I->getOpcode(), I->getType(), CondTy);
return TTI->getCmpSelInstrCost(I->getOpcode(), I->getType(), CondTy, CmpInst::BAD_ICMP_PREDICATE);
}
case Instruction::ICmp:
case Instruction::FCmp: {
Type *ValTy = I->getOperand(0)->getType();
return TTI->getCmpSelInstrCost(I->getOpcode(), ValTy);
return TTI->getCmpSelInstrCost(I->getOpcode(), ValTy, nullptr, CmpInst::BAD_ICMP_PREDICATE);
}
case Instruction::Store: {
const StoreInst *SI = cast<StoreInst>(I);
Expand Down Expand Up @@ -224,7 +224,7 @@ InstructionCost AddTiming::getInstructionCost(const Instruction *I) const {
case Instruction::Call: {
if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
SmallVector<Type *, 4> Tys;
for (unsigned J = 0, JE = II->getNumArgOperands(); J != JE; ++J)
for (unsigned J = 0, JE = II->arg_size(); J != JE; ++J)
Tys.push_back(II->getArgOperand(J)->getType());

FastMathFlags FMF;
Expand Down
3 changes: 2 additions & 1 deletion lib/smack/AnnotateLoopExits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// to reach the loop exit.
//

#define DEBUG_TYPE "smack-loop-unroll"
#include "smack/AnnotateLoopExits.h"
#include "smack/Debug.h"
#include "smack/Naming.h"
Expand All @@ -27,6 +26,8 @@

#include "llvm/Support/raw_ostream.h"

#define DEBUG_TYPE "smack-loop-unroll"

namespace smack {

using namespace llvm;
Expand Down
2 changes: 1 addition & 1 deletion lib/smack/CodifyStaticInits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool CodifyStaticInits::runOnModule(Module &M) {
if (V->getType()->isIntegerTy() || V->getType()->isPointerTy() ||
V->getType()->isFloatingPointTy() || V->getType()->isVectorTy())

IRB.CreateStore(V, IRB.CreateGEP(P, ArrayRef<Value *>(I)));
IRB.CreateStore(V, IRB.CreateGEP(P->getType()->getScalarType()->getPointerElementType(), P, ArrayRef<Value *>(I)));

else if (ArrayType *AT = dyn_cast<ArrayType>(V->getType()))
for (unsigned i = AT->getNumElements(); i-- > 0;) {
Expand Down
7 changes: 4 additions & 3 deletions lib/smack/ExtractContracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This file is distributed under the MIT License. See LICENSE for details.
//

#define DEBUG_TYPE "contracts"

#include "smack/ExtractContracts.h"
#include "smack/Debug.h"
Expand All @@ -15,6 +14,8 @@
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/CodeExtractor.h"

#define DEBUG_TYPE "contracts"

#include <map>
#include <set>
#include <stack>
Expand Down Expand Up @@ -247,7 +248,7 @@ bool ExtractContracts::runOnModule(Module &M) {
// function
for (auto Fs : getContractExprs(*newF)) {
std::vector<Value *> Args;
for (auto &A : I->arg_operands())
for (auto &A : I->args())
Args.push_back(A);
auto *E = Builder.CreateCall(std::get<1>(Fs), Args);
Builder.CreateCall(std::get<0>(Fs), {E});
Expand Down Expand Up @@ -276,7 +277,7 @@ bool ExtractContracts::runOnModule(Module &M) {
// insert one invariant invocation per invocation in the original loop
for (auto Fs : getContractExprs(*newF)) {
std::vector<Value *> Args;
for (auto &A : I->arg_operands())
for (auto &A : I->args())
Args.push_back(A);
auto *E = Builder.CreateCall(std::get<1>(Fs), Args);
Builder.CreateCall(std::get<0>(Fs), {E});
Expand Down
2 changes: 1 addition & 1 deletion lib/smack/Regions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void Regions::visitCallInst(CallInst &I) {
idx(&I);

if (name.find("__SMACK_values") != std::string::npos) {
assert(I.getNumArgOperands() == 2 && "Expected two operands.");
assert(I.arg_size() == 2 && "Expected two operands.");
const Value *P = I.getArgOperand(0);
const Value *N = I.getArgOperand(1);

Expand Down
20 changes: 10 additions & 10 deletions lib/smack/SmackInstGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ void SmackInstGenerator::visitCallInst(llvm::CallInst &ci) {

llvm_unreachable("universal quantifiers not implemented.");

// assert(ci.getNumArgOperands() == 2
// assert(ci.arg_size() == 2
// && "Expected contract expression argument to contract function.");
// CallInst* cj = dyn_cast<CallInst>(ci.getArgOperand(1));
// assert(cj && "Expected contract expression argument to contract
Expand All @@ -710,7 +710,7 @@ void SmackInstGenerator::visitCallInst(llvm::CallInst &ci) {
// std::list<const Expr*> args;
//
// auto AX = F->getAttributes();
// for (unsigned i = 0; i < cj->getNumArgOperands(); i++) {
// for (unsigned i = 0; i < cj->arg_size(); i++) {
// std::string var = "";
// if (AX.hasAttribute(i+1, "contract-var"))
// var = AX.getAttribute(i+1, "contract-var").getValueAsString();
Expand All @@ -729,7 +729,7 @@ void SmackInstGenerator::visitCallInst(llvm::CallInst &ci) {
name == Naming::CONTRACT_ENSURES ||
name == Naming::CONTRACT_INVARIANT) {

assert(ci.getNumArgOperands() == 1 &&
assert(ci.arg_size() == 1 &&
"Expected contract expression argument to contract function.");
CallInst *cj = dyn_cast<CallInst>(ci.getArgOperand(0));
assert(cj && "Expected contract expression argument to contract function.");
Expand All @@ -738,7 +738,7 @@ void SmackInstGenerator::visitCallInst(llvm::CallInst &ci) {
"Expected contract expression argument to contract function.");

std::list<const Expr *> args;
for (auto &V : cj->arg_operands())
for (auto &V : cj->args())
args.push_back(rep->expr(V));
for (auto m : rep->memoryMaps())
args.push_back(Expr::id(m.first));
Expand All @@ -757,24 +757,24 @@ void SmackInstGenerator::visitCallInst(llvm::CallInst &ci) {
}

// } else if (name == "result") {
// assert(ci.getNumArgOperands() == 0 && "Unexpected operands to
// assert(ci.arg_size() == 0 && "Unexpected operands to
// result.");
// emit(Stmt::assign(rep->expr(&ci),Expr::id(Naming::RET_VAR)));
//
// } else if (name == "qvar") {
// assert(ci.getNumArgOperands() == 1 && "Unexpected operands to qvar.");
// assert(ci.arg_size() == 1 && "Unexpected operands to qvar.");
// emit(Stmt::assign(rep->expr(&ci),Expr::id(rep->getString(ci.getArgOperand(0)))));
//
// } else if (name == "old") {
// assert(ci.getNumArgOperands() == 1 && "Unexpected operands to old.");
// assert(ci.arg_size() == 1 && "Unexpected operands to old.");
// llvm::LoadInst* LI =
// llvm::dyn_cast<llvm::LoadInst>(ci.getArgOperand(0));
// assert(LI && "Expected value from Load.");
// emit(Stmt::assign(rep->expr(&ci),
// Expr::fn("old",rep->load(LI->getPointerOperand())) ));

// } else if (name == "forall") {
// assert(ci.getNumArgOperands() == 2 && "Unexpected operands to
// assert(ci.arg_size() == 2 && "Unexpected operands to
// forall.");
// Value* var = ci.getArgOperand(0);
// Value* arg = ci.getArgOperand(1);
Expand All @@ -784,7 +784,7 @@ void SmackInstGenerator::visitCallInst(llvm::CallInst &ci) {
// S->getBoogieExpression(naming,rep))));
//
// } else if (name == "exists") {
// assert(ci.getNumArgOperands() == 2 && "Unexpected operands to
// assert(ci.arg_size() == 2 && "Unexpected operands to
// forall.");
// Value* var = ci.getArgOperand(0);
// Value* arg = ci.getArgOperand(1);
Expand All @@ -794,7 +794,7 @@ void SmackInstGenerator::visitCallInst(llvm::CallInst &ci) {
// S->getBoogieExpression(naming,rep))));
//
// } else if (name == "invariant") {
// assert(ci.getNumArgOperands() == 1 && "Unexpected operands to
// assert(ci.arg_size() == 1 && "Unexpected operands to
// invariant.");
// Slice* S = getSlice(ci.getArgOperand(0));
// emit(Stmt::assert_(S->getBoogieExpression(naming,rep)));
Expand Down
12 changes: 6 additions & 6 deletions lib/smack/SmackRep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ const Stmt *SmackRep::valueAnnotation(const CallInst &CI) {
std::list<std::string> rets({naming->get(CI)});
std::list<const Attr *> attrs;

assert(CI.getNumArgOperands() > 0 && "Expected at least one argument.");
assert(CI.getNumArgOperands() <= 2 && "Expected at most two arguments.");
assert(CI.arg_size() > 0 && "Expected at least one argument.");
assert(CI.arg_size() <= 2 && "Expected at most two arguments.");
const Value *V = CI.getArgOperand(0)->stripPointerCastsAndAliases();

if (CI.getNumArgOperands() == 1) {
if (CI.arg_size() == 1) {
name = indexedName(Naming::VALUE_PROC, {type(V->getType())});
if (dyn_cast<const Argument>(V)) {
attrs.push_back(Attr::attr("name", {Expr::id(naming->get(*V))}));
Expand Down Expand Up @@ -441,7 +441,7 @@ const Stmt *SmackRep::valueAnnotation(const CallInst &CI) {
}

const Stmt *SmackRep::returnValueAnnotation(const CallInst &CI) {
assert(CI.getNumArgOperands() == 0 && "Expected no operands.");
assert(CI.arg_size() == 0 && "Expected no operands.");
Type *T = CI.getParent()->getParent()->getReturnType();
std::string name = indexedName(Naming::VALUE_PROC, {type(T)});
return Stmt::call(name, std::list<const Expr *>({Expr::id(Naming::RET_VAR)}),
Expand All @@ -451,7 +451,7 @@ const Stmt *SmackRep::returnValueAnnotation(const CallInst &CI) {

// TODO work the following into SmackRep::returnValueAnnotation
// const Stmt* SmackRep::returnObjectAnnotation(const CallInst& CI) {
// assert(CI.getNumArgOperands() == 1 && "Expected one operand.");
// assert(CI.arg_size() == 1 && "Expected one operand.");
// const Value* V = nullptr; // FIXME GET A VALUE HERE
// assert(V && "Unknown return value.");
// const Value* N = CI.getArgOperand(0);
Expand Down Expand Up @@ -1061,7 +1061,7 @@ ProcDecl *SmackRep::procedure(Function *F, CallInst *CI) {
} else {
FunctionType *T = F->getFunctionType();
name = procName(F, *CI);
for (unsigned i = T->getNumParams(); i < CI->getNumArgOperands(); i++) {
for (unsigned i = T->getNumParams(); i < CI->arg_size(); i++) {
params.push_back(
{indexedName("p", {i}), type(CI->getOperand(i)->getType())});
}
Expand Down
10 changes: 6 additions & 4 deletions lib/smack/SplitAggregateValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool SplitAggregateValue::runOnFunction(Function &F) {
splitConstantReturn(ri, info);
}
} else if (CallInst *ci = dyn_cast<CallInst>(&I)) {
for (unsigned i = 0; i < ci->getNumArgOperands(); ++i) {
for (unsigned i = 0; i < ci->arg_size(); ++i) {
Value *arg = ci->getArgOperand(i);
if (isConstantAggregate(arg)) {
info.clear();
Expand Down Expand Up @@ -88,8 +88,9 @@ Value *SplitAggregateValue::splitAggregateLoad(Type *T, Value *P,
Value *V = UndefValue::get(T);
for (auto &e : info) {
IndexT idxs = std::get<0>(e);
Value *p = irb.CreateGEP(T, P, ArrayRef<Value *>(getFirsts(idxs)));
V = irb.CreateInsertValue(
V, irb.CreateLoad(irb.CreateGEP(P, ArrayRef<Value *>(getFirsts(idxs)))),
V, irb.CreateLoad(p->getType()->getScalarType()->getPointerElementType(), p),
ArrayRef<unsigned>(getSeconds(idxs)));
}
return V;
Expand All @@ -102,12 +103,13 @@ void SplitAggregateValue::splitAggregateStore(Value *P, Value *V,
IndexT idxs = std::get<0>(e);
Constant *c = std::get<1>(e);
std::vector<Value *> vidxs = getFirsts(idxs);
Type *T = P->getType()->getScalarType()->getPointerElementType();
if (c)
irb.CreateStore(c, irb.CreateGEP(P, ArrayRef<Value *>(vidxs)));
irb.CreateStore(c, irb.CreateGEP(T, P, ArrayRef<Value *>(vidxs)));
else
irb.CreateStore(
irb.CreateExtractValue(V, ArrayRef<unsigned>(getSeconds(idxs))),
irb.CreateGEP(P, ArrayRef<Value *>(vidxs)));
irb.CreateGEP(T, P, ArrayRef<Value *>(vidxs)));
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/utils/Devirt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ Devirtualize::makeDirectCall (CallBase *CS) {
if (CallInst* CI = dyn_cast<CallInst>(CS)) {
std::vector<Value*> Params;
Params.push_back(CI->getCalledOperand());
for (unsigned i=0; i<CI->getNumArgOperands(); i++) {
for (unsigned i=0; i<CI->arg_size(); i++) {
Params.push_back(
castTo(CI->getArgOperand(i), NF->getFunctionType()->getParamType(i+1), "", CS)
);
Expand All @@ -412,7 +412,7 @@ Devirtualize::makeDirectCall (CallBase *CS) {
} else if (InvokeInst* CI = dyn_cast<InvokeInst>(CS)) {
std::vector<Value*> Params;
Params.push_back(CI->getCalledOperand());
for (unsigned i=0; i<CI->getNumArgOperands(); i++)
for (unsigned i=0; i<CI->arg_size(); i++)
Params.push_back(
castTo(CI->getArgOperand(i), NF->getFunctionType()->getParamType(i+1), "", CS)
);
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/MergeGEP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ static void simplifyGEP(GetElementPtrInst *GEP) {

if (!Indices.empty()){
GetElementPtrInst *GEPNew = (GEP->isInBounds() && Src->isInBounds()) ?
GetElementPtrInst::CreateInBounds(Src->getOperand(0), Indices,
GetElementPtrInst::CreateInBounds(Src->getOperand(0)->getType()->getScalarType()->getPointerElementType(),
Src->getOperand(0), Indices,
GEP->getName(), GEP) :
GetElementPtrInst::Create(nullptr, Src->getOperand(0), Indices,
GEP->getName(), GEP);
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/SimplifyExtractValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ bool SimplifyEV::runOnModule(Module& M) {
Indices.push_back(ConstantInt::get(Int32Ty, *I));
}

GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(LI->getOperand(0), Indices,
GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(LI->getOperand(0)->getType()->getScalarType()->getPointerElementType(),
LI->getOperand(0), Indices,
LI->getName(), LI) ;
LoadInst *LINew = new LoadInst(GEP->getResultElementType(), GEP, "", LI);
EV->replaceAllUsesWith(LINew);
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/SimplifyInsertValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ bool SimplifyIV::runOnModule(Module& M) {
I != E; ++I) {
Indices.push_back(ConstantInt::get(Int32Ty, *I));
}
GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(SI->getOperand(1), Indices,
GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(SI->getOperand(1)->getType()->getScalarType()->getPointerElementType(),
SI->getOperand(1), Indices,
SI->getName(), SI) ;
new StoreInst(IV->getInsertedValueOperand(), GEP, SI);
IV = dyn_cast<InsertValueInst>(IV->getAggregateOperand());
Expand Down
2 changes: 1 addition & 1 deletion tools/llvm2bpl/llvm2bpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/LinkAllPasses.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
Expand All @@ -18,7 +19,6 @@
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/raw_ostream.h"
Expand Down

0 comments on commit 1faf5f5

Please sign in to comment.