21#include <mlir/Dialect/SCF/IR/SCF.h>
22#include <mlir/Interfaces/CallInterfaces.h>
24#include <llvm/ADT/DenseMap.h>
25#include <llvm/ADT/DenseSet.h>
26#include <llvm/ADT/SetVector.h>
27#include <llvm/ADT/SmallVector.h>
64 return llvm::hash_combine(
73 static_cast<uint8_t
>(lhs) |
static_cast<uint8_t
>(rhs)
85 return static_cast<uint8_t
>(influence) != 0;
91 return (
static_cast<uint8_t
>(influence) &
static_cast<uint8_t
>(flag)) != 0;
104template <
typename T,
typename... Args>
105inline ForbiddenPreconditionInfluenceInfo
135 return {llvm::DenseMapInfo<mlir::Operation *>::getEmptyKey(), {}, 0};
139 return {llvm::DenseMapInfo<mlir::Operation *>::getTombstoneKey(), {}, 0};
143 return llvm::hash_combine(
174 llvm::SmallVector<IncludedContractFailure>
failures;
176 explicit operator bool()
const {
return !
failures.empty(); }
198 return {llvm::DenseMapInfo<mlir::Operation *>::getEmptyKey(), {}};
202 return {llvm::DenseMapInfo<mlir::Operation *>::getTombstoneKey(), {}};
206 return llvm::hash_combine(
241 mlir::CallableOpInterface callableOp, llvm::ArrayRef<InfluenceInfo> argInfluences,
242 unsigned resultNumber
265 class AnalysisFrame {
270 llvm::ArrayRef<InfluenceInfo> argInfluenceInfos,
290 InfluenceInfo analyzeAncestorControl(mlir::Operation *ancestor, mlir::Operation *nestedOp);
293 InfluenceInfo analyzeBlockArgument(mlir::BlockArgument blockArg);
296 InfluenceInfo analyzeCallResult(mlir::CallOpInterface call, mlir::OpResult callRes);
299 InfluenceInfo analyzeIfResult(mlir::scf::IfOp ifOp, mlir::OpResult ifRes);
302 InfluenceInfo analyzeForResult(mlir::scf::ForOp forOp, mlir::OpResult forRes);
307 analyzeExecuteRegionResult(mlir::scf::ExecuteRegionOp execOp, mlir::OpResult execRes);
310 InfluenceInfo analyzeWhileResult(mlir::scf::WhileOp whileOp, mlir::OpResult whileRes);
313 llvm::DenseMap<mlir::Value, InfluenceInfo> valueCache;
314 llvm::DenseMap<mlir::Operation *, InfluenceInfo> controlAncestorCache;
315 llvm::DenseSet<mlir::Value> activeValues;
324 mlir::ModuleOp module;
325 llvm::DenseMap<CallableSummaryKey, InfluenceInfo, CallableSummaryKeyInfo> callableSummaryCache;
326 llvm::DenseSet<CallableSummaryKey, CallableSummaryKeyInfo> activeSummaries;
328 IncludedContractSummaryKey, IncludedContractSummary, IncludedContractSummaryKeyInfo>
329 includedContractSummaryCache;
330 llvm::DenseSet<IncludedContractSummaryKey, IncludedContractSummaryKeyInfo>
331 activeIncludedSummaries;
332 llvm::DenseMap<ContractOp, AnalysisFrame> cachedFrames;
363 mlir::ModuleOp module, mlir::CallableOpInterface callableOp,
364 llvm::ArrayRef<ForbiddenPreconditionInfluenceInfo> argInfluences,
unsigned resultNumber
367 callableOp, argInfluences, resultNumber
374 mlir::ModuleOp module, mlir::CallableOpInterface callableOp,
375 llvm::ArrayRef<ForbiddenPreconditionInfluenceInfo> argInfluences,
unsigned resultNumber
378 module, callableOp, argInfluences, resultNumber
387 llvm::ArrayRef<ForbiddenPreconditionInfluenceInfo> argInfluences
390 calleeContract, argInfluences
Interprocedural verifier-local analysis for forbidden precondition influence.
InfluenceInfo analyzeCallableResult(mlir::CallableOpInterface callableOp, llvm::ArrayRef< InfluenceInfo > argInfluences, unsigned resultNumber)
Summarize the forbidden influence of one callable result under the given argument influences.
IncludedContractSummary analyzeIncludedOp(verif::ContractOp contract, verif::IncludeOp includeOp)
Check whether an include op becomes invalid under its caller's operand bindings and enclosing SCF con...
InfluenceInfo analyzePreconditionOp(verif::ContractOp contract, verif::PreconditionOpInterface preCondOp)
Classify the forbidden influence reaching a precondition op, including both the condition operand and...
InfluenceInfo analyzeContractValue(verif::ContractOp contract, mlir::Value value)
Classify the forbidden influence reaching a value inside a contract body.
IncludedContractSummary analyzeIncludedContract(verif::ContractOp calleeContract, llvm::ArrayRef< InfluenceInfo > argInfluences, InfluenceInfo inheritedControlInfluence=InfluenceInfo::None())
Check whether an included contract becomes invalid under caller-provided operand influences,...
ForbiddenInfluenceAnalyzer(mlir::ModuleOp owningModule)
Create a verifier-local analyzer for one LLZK module.
ForbiddenPreconditionInfluence Influence
ForbiddenPreconditionInfluenceInfo InfluenceInfo
ForbiddenPreconditionInfluence analyzeForbiddenPreconditionCallableResult(mlir::ModuleOp module, mlir::CallableOpInterface callableOp, llvm::ArrayRef< ForbiddenPreconditionInfluenceInfo > argInfluences, unsigned resultNumber)
Analyze whether a callable result depends on forbidden precondition sources under a caller-provided a...
ForbiddenPreconditionInfluenceInfo analyzeForbiddenPreconditionCallableResultInfo(mlir::ModuleOp module, mlir::CallableOpInterface callableOp, llvm::ArrayRef< ForbiddenPreconditionInfluenceInfo > argInfluences, unsigned resultNumber)
Analyze whether a callable result depends on forbidden precondition sources under a caller-provided a...
detail::IncludedContractSummary analyzeForbiddenIncludedContractSummary(mlir::ModuleOp module, verif::ContractOp calleeContract, llvm::ArrayRef< ForbiddenPreconditionInfluenceInfo > argInfluences)
Analyze whether including a contract with caller-provided operand influence summaries would trigger a...
ForbiddenPreconditionInfluenceInfo mergeInfluenceInfo(ForbiddenPreconditionInfluenceInfo lhs, const ForbiddenPreconditionInfluenceInfo &rhs)
Merge two forbidden-influence summaries, preserving the first known source location for each forbidde...
detail::IncludedContractSummary analyzeForbiddenIncludedOpSummary(mlir::ModuleOp module, verif::ContractOp contract, verif::IncludeOp includeOp)
Analyze whether a specific include op triggers forbidden preconditions in the callee,...
ForbiddenPreconditionInfluenceInfo analyzeForbiddenPreconditionInfluenceInfo(mlir::ModuleOp module, verif::ContractOp contract, mlir::Value value)
Analyze whether a contract value depends on forbidden precondition sources and recover representative...
ForbiddenPreconditionInfluence operator|(ForbiddenPreconditionInfluence lhs, ForbiddenPreconditionInfluence rhs)
ForbiddenPreconditionInfluence
Sources of information that are not allowed in contract preconditions.
bool hasInfluence(ForbiddenPreconditionInfluence influence, ForbiddenPreconditionInfluence flag)
Return true when influence contains the requested flag.
ForbiddenPreconditionInfluenceInfo analyzeForbiddenPreconditionOpInfluenceInfo(mlir::ModuleOp module, verif::ContractOp contract, verif::PreconditionOpInterface preCondOp)
Analyze whether a precondition op depends on forbidden sources, including both its condition operand ...
ForbiddenPreconditionInfluence analyzeForbiddenPreconditionInfluence(mlir::ModuleOp module, verif::ContractOp contract, mlir::Value value)
Analyze whether a contract value depends on forbidden precondition sources.
llvm::hash_code hash_value(const ForbiddenPreconditionInfluenceInfo &info)
ForbiddenPreconditionInfluence & operator|=(ForbiddenPreconditionInfluence &lhs, ForbiddenPreconditionInfluence rhs)
bool any(ForbiddenPreconditionInfluence influence)
Return true when the influence set contains at least one classification.
Summary of forbidden precondition influence along with representative source locations for each forbi...
static ForbiddenPreconditionInfluenceInfo StructMember()
ForbiddenPreconditionInfluence influence
llvm::SmallSetVector< mlir::Location, 2 > structMemberLocs
bool operator==(const ForbiddenPreconditionInfluenceInfo &other) const
static ForbiddenPreconditionInfluenceInfo None()
static ForbiddenPreconditionInfluenceInfo FunctionReturn()
static CallableSummaryKey getTombstoneKey()
static unsigned getHashValue(const CallableSummaryKey &key)
static bool isEqual(const CallableSummaryKey &lhs, const CallableSummaryKey &rhs)
static CallableSummaryKey getEmptyKey()
Cache key for one interprocedural callable-result summary query.
bool operator==(const CallableSummaryKey &other) const
llvm::SmallVector< InfluenceInfo > argInfluences
mlir::Operation * callable
One included precondition that becomes illegal under a specific caller binding.
InfluenceInfo influenceInfo
std::optional< mlir::Location > preconditionLoc
static bool isEqual(const IncludedContractSummaryKey &lhs, const IncludedContractSummaryKey &rhs)
static IncludedContractSummaryKey getTombstoneKey()
static IncludedContractSummaryKey getEmptyKey()
static unsigned getHashValue(const IncludedContractSummaryKey &key)
Cache key for one interprocedural included-contract summary query.
llvm::SmallVector< InfluenceInfo > argInfluences
InfluenceInfo inheritedControlInfluence
mlir::Operation * contract
bool operator==(const IncludedContractSummaryKey &other) const
Summary of all included-contract precondition failures under a specific caller binding.
llvm::SmallVector< IncludedContractFailure > failures