1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
//===-- ArrayExprOptimizer.h ----------------------------------------------===//
//
// The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef KLEE_ARRAYEXPROPTIMIZER_H
#define KLEE_ARRAYEXPROPTIMIZER_H
#include <cstdint>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "klee/Expr/Expr.h"
#include "klee/Expr/ExprHashMap.h"
#include "klee/util/Ref.h"
namespace klee {
enum ArrayOptimizationType { NONE, ALL, INDEX, VALUE };
using array2idx_ty = std::map<const Array *, std::vector<ref<Expr>>>;
using mapIndexOptimizedExpr_ty = std::map<ref<Expr>, std::vector<ref<Expr>>>;
class ExprOptimizer {
private:
ExprHashMap<ref<Expr>> cacheExprOptimized;
ExprHashSet cacheExprUnapplicable;
ExprHashMap<ref<Expr>> cacheReadExprOptimized;
public:
/// Returns the optimised version of e.
/// @param e expression to optimise
/// @param valueOnly XXX document
/// @return optimised expression
ref<Expr> optimizeExpr(const ref<Expr> &e, bool valueOnly);
private:
bool computeIndexes(array2idx_ty &arrays, const ref<Expr> &e,
mapIndexOptimizedExpr_ty &idx_valIdx) const;
ref<Expr> getSelectOptExpr(
const ref<Expr> &e, std::vector<const ReadExpr *> &reads,
std::map<const ReadExpr *, std::pair<ref<Expr>, Expr::Width>> &readInfo,
bool isSymbolic);
ref<Expr> buildConstantSelectExpr(const ref<Expr> &index,
std::vector<uint64_t> &arrayValues,
Expr::Width width,
unsigned elementsInArray) const;
ref<Expr>
buildMixedSelectExpr(const ReadExpr *re,
std::vector<std::pair<uint64_t, bool>> &arrayValues,
Expr::Width width, unsigned elementsInArray) const;
};
} // namespace klee
#endif /* KLEE_ARRAYEXPROPTIMIZER_H */
|