2017-12-01 07:30:03 +01:00
|
|
|
#pragma once
|
|
|
|
#include "c-opast.hh"
|
2017-12-02 12:18:31 +01:00
|
|
|
#include "c-opcomp.hh"
|
2017-12-01 07:30:03 +01:00
|
|
|
|
|
|
|
#include <ebcl/Algorithms.hh>
|
|
|
|
|
|
|
|
struct T_SyncCurves;
|
|
|
|
|
|
|
|
namespace opopt {
|
|
|
|
|
2017-12-02 10:07:14 +01:00
|
|
|
// Persistent data for the various stages of the optimizer.
|
|
|
|
struct T_OptData
|
|
|
|
{
|
2017-12-02 12:18:31 +01:00
|
|
|
// Logger
|
|
|
|
F_OPLogger logger{ []( auto , auto ) {} };
|
|
|
|
|
2017-12-02 10:07:14 +01:00
|
|
|
// 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.
|
2017-12-02 12:18:31 +01:00
|
|
|
T_SyncCurves const* curves{ nullptr };
|
2017-12-02 10:07:14 +01:00
|
|
|
|
|
|
|
// A visitor to be used for the tree
|
|
|
|
ebcl::T_Visitor< opast::A_Node > visitor{ opast::ASTVisitorBrowser };
|
2017-12-02 10:40:47 +01:00
|
|
|
|
|
|
|
// Table of input declarations; used to fold constant inputs.
|
|
|
|
struct T_InputDecl {
|
|
|
|
ebcl::T_SRDLocation location;
|
|
|
|
float value;
|
|
|
|
};
|
|
|
|
T_Optional< T_KeyValueTable< T_String , T_Array< T_InputDecl > > > inputDecls;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void findInputDecls( T_OpsParserOutput& program ) noexcept;
|
2017-12-02 10:07:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-03 14:59:39 +01:00
|
|
|
/*= INDIVIDUAL OPTIMISATIONS =================================================*/
|
|
|
|
// All functions below return true if transformations were made, false if not.
|
|
|
|
|
|
|
|
// Attempts to fold constant expressions into single constants.
|
|
|
|
//
|
|
|
|
bool FoldConstants(
|
|
|
|
T_OpsParserOutput& program ,
|
|
|
|
T_OptData& optData ) noexcept;
|
|
|
|
|
|
|
|
// Attempts to propagate values from variables that contain constants to the
|
|
|
|
// locations at which they are used.
|
2017-12-01 07:30:03 +01:00
|
|
|
//
|
2017-12-03 14:59:39 +01:00
|
|
|
bool PropagateConstants(
|
|
|
|
T_OpsParserOutput& program ,
|
2017-12-02 10:07:14 +01:00
|
|
|
T_OptData& optData ) noexcept;
|
2017-12-01 07:30:03 +01:00
|
|
|
|
|
|
|
// Attempt to remove blocks of code that will not be executed because of
|
2017-12-03 14:59:39 +01:00
|
|
|
// constant conditions.
|
2017-12-01 07:30:03 +01:00
|
|
|
//
|
2017-12-03 14:59:39 +01:00
|
|
|
bool RemoveDeadCode(
|
|
|
|
T_OpsParserOutput& program ,
|
2017-12-02 10:07:14 +01:00
|
|
|
T_OptData& optData ) noexcept;
|
2017-12-01 07:30:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace opopt
|