Skip to content

Commit

Permalink
[chore] Optimized KBlock mem
Browse files Browse the repository at this point in the history
  • Loading branch information
Columpio committed Oct 5, 2023
1 parent 90e8cbf commit 43a8d70
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions include/klee/Module/KModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ enum KBlockType { Base, Call, Return };
struct KBlock {
KFunction *parent;
llvm::BasicBlock *basicBlock;

unsigned numInstructions;
KInstruction **instructions;

public:
Expand All @@ -76,9 +74,10 @@ struct KBlock {
virtual KBlockType getKBlockType() const { return KBlockType::Base; }
static bool classof(const KBlock *) { return true; }

unsigned getNumInstructions() const noexcept { return basicBlock->size(); }
KInstruction *getFirstInstruction() const noexcept { return instructions[0]; }
KInstruction *getLastInstruction() const noexcept {
return instructions[numInstructions - 1];
return instructions[getNumInstructions() - 1];
}
std::string getLabel() const;
std::string toString() const;
Expand Down
2 changes: 1 addition & 1 deletion lib/Core/Searcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ weight_type TargetedSearcher::getWeight(ExecutionState *es) {
KBlock *kb = es->pc->parent;
KInstruction *ki = es->pc;
weight_type weight;
if (!target->shouldFailOnThisTarget() && kb->numInstructions &&
if (!target->shouldFailOnThisTarget() && kb->getNumInstructions() &&
!isa<KCallBlock>(kb) && kb->getFirstInstruction() != ki &&
states->tryGetWeight(es, weight)) {
return weight;
Expand Down
2 changes: 1 addition & 1 deletion lib/Core/TypeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void TypeManager::initTypesFromInstructions() {
auto kf = parent->functionMap[&function];

for (auto &BasicBlock : function) {
unsigned numInstructions = kf->blockMap[&BasicBlock]->numInstructions;
unsigned numInstructions = kf->blockMap[&BasicBlock]->getNumInstructions();
KBlock *kb = kf->blockMap[&BasicBlock];

for (unsigned i = 0; i < numInstructions; ++i) {
Expand Down
5 changes: 2 additions & 3 deletions lib/Module/KModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ KFunction::KFunction(llvm::Function *_function, KModule *_km,
kb = new KBlock(this, &*bbit, parent, instructionToRegisterMap,
&instructions[n], globalIndexInc);
}
for (unsigned i = 0; i < kb->numInstructions; i++, n++) {
for (unsigned i = 0, ie = kb->getNumInstructions(); i < ie; i++, n++) {
instructionMap[instructions[n]->inst] = instructions[n];
}
blockMap[&*bbit] = kb;
Expand Down Expand Up @@ -639,8 +639,7 @@ KBlock::KBlock(
KFunction *_kfunction, llvm::BasicBlock *block, KModule *km,
const std::unordered_map<Instruction *, unsigned> &instructionToRegisterMap,
KInstruction **instructionsKF, unsigned &globalIndexInc)
: parent(_kfunction), basicBlock(block), numInstructions(0) {
numInstructions += block->size();
: parent(_kfunction), basicBlock(block) {
instructions = instructionsKF;

for (auto &it : *block) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Module/SarifReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ bool Location::isInside(KBlock *block, const Instructions &origInsts) const {
return false;
return startLine <= last->getLine(); // and `first <= line` from above
} else {
for (size_t i = 0; i < block->numInstructions; ++i) {
for (unsigned i = 0, ie = block->getNumInstructions(); i < ie; ++i) {
auto inst = block->instructions[i];
auto opCode = block->instructions[i]->inst->getOpcode();
if (!isa<DbgInfoIntrinsic>(block->instructions[i]->inst) &&
Expand Down

0 comments on commit 43a8d70

Please sign in to comment.