demotool/c-opopt.hh
Emmanuel BENOîT f1b51f564d Optimizer - Errors when folding bad operations
Errors will be added to an array if the optimizer finds invalid
operations involving constants (e.g. (inv 0))
2017-12-02 10:07:14 +01:00

43 lines
1.2 KiB
C++

#pragma once
#include "c-opast.hh"
#include <ebcl/Algorithms.hh>
struct T_OpsParserOutput;
struct T_SyncCurves;
namespace opopt {
// Persistent data for the various stages of the optimizer.
struct T_OptData
{
// List of errors generated by the optimizer
T_Array< ebcl::T_SRDError > errors;
// If the size of the ouput is fixed, this field contains it as a
// <width,height> pair.
T_Optional< std::pair< uint32_t , uint32_t > > fixedSize;
// The curves that will be bound to the inputs.
T_SyncCurves const* curves;
// A visitor to be used for the tree
ebcl::T_Visitor< opast::A_Node > visitor{ opast::ASTVisitorBrowser };
};
/*----------------------------------------------------------------------------*/
// Attempts to fold constant expressions into single constants. Returns true if
// transformations were made, false if not.
//
bool FoldConstants( T_OpsParserOutput& program ,
T_OptData& optData ) noexcept;
// Attempt to remove blocks of code that will not be executed because of
// constant conditions. Returns true if transformations were made, false if not.
//
bool RemoveDeadCode( T_OpsParserOutput& program ,
T_OptData& optData ) noexcept;
} // namespace opopt