Skip to content

Commit

Permalink
Add dataflowAPI/src/liveness.C
Browse files Browse the repository at this point in the history
  • Loading branch information
hainest committed Apr 3, 2024
1 parent 82ff982 commit 9eda5ee
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
6 changes: 0 additions & 6 deletions dataflowAPI/src/liveness.C
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ using namespace Dyninst;
using namespace Dyninst::ParseAPI;
using namespace Dyninst::InstructionAPI;

// Code for register liveness detection

LivenessAnalyzer::LivenessAnalyzer(int w): errorno((ErrorType)-1) {
width = w;
abi = ABI::getABI(width);
Expand Down Expand Up @@ -185,8 +183,6 @@ void LivenessAnalyzer::summarizeBlockLivenessInfo(Function* func, Block *block,
return;
}

/* This is used to do fixed point iteration until
the in and out don't change anymore */
bool LivenessAnalyzer::updateBlockLivenessInfo(Block* block, bitArray &allRegsDefined)
{
bool change = false;
Expand Down Expand Up @@ -219,8 +215,6 @@ bool LivenessAnalyzer::updateBlockLivenessInfo(Block* block, bitArray &allRegsDe
return change;
}

// Calculate basic block summaries of liveness information

void LivenessAnalyzer::analyze(Function *func) {
if (liveFuncCalculated.find(func) != liveFuncCalculated.end()) return;
liveness_printf("Caculate basic block level liveness information for function %s (%lx)\n", func->name().c_str(), func->addr());
Expand Down
1 change: 1 addition & 0 deletions docs/dataflowAPI/developer/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Documentation for the internal classes of the DataflowAPI toolkit.

debug_dataflow.h
ExpressionConversionVisitor.h
liveness.h
RegisterMap.h
RoseInsnFactory.h
stackanalysis.h
Expand Down
32 changes: 32 additions & 0 deletions docs/dataflowAPI/developer/liveness.h.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.. _`sec-dev:liveness.h`:

liveness.h
##########

.. cpp:namespace:: dev


.. cpp:class:: LivenessAnalyzer

.. cpp:member:: private std::map<ParseAPI::Block*, livenessData> blockLiveInfo
.. cpp:member:: private std::map<ParseAPI::Function*, bool> liveFuncCalculated
.. cpp:member:: private std::map<ParseAPI::Function*, bitArray> funcRegsDefined
.. cpp:member:: private InstructionCache cachedLivenessInfo
.. cpp:function:: private const bitArray& getLivenessIn(ParseAPI::Block *block)
.. cpp:function:: private const bitArray& getLivenessOut(ParseAPI::Block *block, bitArray &allRegsDefined)
.. cpp:function:: private void processEdgeLiveness(ParseAPI::Edge* e, livenessData& data, ParseAPI::Block* block, const bitArray& allRegsDefined)
.. cpp:function:: private void summarizeBlockLivenessInfo(ParseAPI::Function* func, ParseAPI::Block *block, bitArray &allRegsDefined)
.. cpp:function:: private bool updateBlockLivenessInfo(ParseAPI::Block *block, bitArray &allRegsDefined)

This is used to do fixed point iteration until the in and out don't change anymore.

.. cpp:function:: private ReadWriteInfo calcRWSets(Instruction curInsn, ParseAPI::Block *blk, Address a)
.. cpp:function:: private void* getPtrToInstruction(ParseAPI::Block *block, Address addr) const
.. cpp:function:: private bool isExitBlock(ParseAPI::Block *block)
.. cpp:function:: private bool isMMX(MachRegister machReg)
.. cpp:function:: private MachRegister changeIfMMX(MachRegister machReg)
.. cpp:member:: private int width
.. cpp:member:: private ABI* abi

.. cpp:member:: private ErrorType errorno

41 changes: 26 additions & 15 deletions docs/dataflowAPI/public/liveness.h.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,20 @@ liveness.h

Creates an analyzer with an assumed address width ``w``.

.. cpp:enum:: Type

.. cpp:enumerator:: Before

Analyze liveness for registers before the current location.

.. cpp:enumerator:: After

Analyze liveness for registers after the current location.

.. cpp:function:: void analyze(ParseAPI::Function *func)
.. cpp:function:: void analyze(Dyninst::ParseAPI::Function *func)

Calculate basic block summaries of liveness information for all basic blocks in ``func``.

.. cpp:function:: bool query(ParseAPI::Location loc, Type type, const MachRegister &machReg, bool& live)
.. cpp:function:: template <class OutputIterator> bool query(Dyninst::ParseAPI::Location loc, Type type, OutputIterator outIter)

.. cpp:function:: bool query(Dyninst::ParseAPI::Location loc, Type type, const Dyninst::MachRegister &machReg, bool& live)

Calculates liveness for the register ``machReg`` at ``loc`` in the direction ``type`` and stores
the result in ``live``.

Returns ``false`` if no result could be found.

.. cpp:function:: bool query(ParseAPI::Location loc, Type type, bitArray &bitarray)
.. cpp:function:: bool query(Dyninst::ParseAPI::Location loc, Type type, bitArray &bitarray)

Calculates liveness for all registers represented by ``bitarray`` starting at ``loc`` in the direction ``type``.

Expand All @@ -50,18 +42,37 @@ liveness.h

Returns ``false`` if ``loc`` is not valid.

.. cpp:function:: void clean(ParseAPI::Function *func)
.. cpp:function:: ErrorType getLastError()

.. cpp:function:: void clean(Dyninst::ParseAPI::Function *func)

Resets cached liveness information associated with ``func``.

.. cpp:function:: void clean()

Resets all cached liveness information.

.. cpp:function:: int getIndex(MachRegister machReg)
.. cpp:function:: int getIndex(Dyninst::MachRegister machReg)

Returns the cache index of the register ``machReg``.

.. cpp:function:: Dyninst::ABI* getABI()

Returns the :cpp:class:`Dyninst::ABI` associated with the current platform.


.. cpp:enum:: LivenessAnalyzer::Type

.. cpp:enumerator:: Before

Analyze liveness for registers before the current location.

.. cpp:enumerator:: After

Analyze liveness for registers after the current location.


.. cpp:enum:: LivenessAnalyzer::ErrorType

.. cpp:enumerator:: Invalid_Location

0 comments on commit 9eda5ee

Please sign in to comment.