Skip to content

Commit

Permalink
[chore] Optimized KBlock mem
Browse files Browse the repository at this point in the history
  • Loading branch information
Columpio authored and misonijnik committed Oct 5, 2023
1 parent 90e8cbf commit 27b6ed1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 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
13 changes: 3 additions & 10 deletions lib/Core/TypeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,13 @@ void TypeManager::initTypesFromGlobals() {
*/
void TypeManager::initTypesFromInstructions() {
for (auto &function : *(parent->module)) {
auto kf = parent->functionMap[&function];

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

for (unsigned i = 0; i < numInstructions; ++i) {
llvm::Instruction *inst = kb->instructions[i]->inst;

for (auto &inst : BasicBlock) {
/* Register return type */
getWrappedType(inst->getType());
getWrappedType(inst.getType());

/* Register types for arguments */
for (auto opb = inst->op_begin(), ope = inst->op_end(); opb != ope;
for (auto opb = inst.op_begin(), ope = inst.op_end(); opb != ope;
++opb) {
getWrappedType((*opb)->getType());
}
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 27b6ed1

Please sign in to comment.