summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSteven Perron <stevenperron@google.com>2018-02-15 10:41:01 -0500
committerSteven Perron <31666470+s-perron@users.noreply.github.com>2018-02-16 13:49:47 -0500
commit3756b387f3c5c5e56d3c0d5983082f294f652eb0 (patch)
tree0b4adc32d00e99d8c46218c308766084b5aa31fd /source
parentefe286cd326e80f4a0a0a826cbf6be3be9814894 (diff)
downloadSPIRV-Tools-3756b387f3c5c5e56d3c0d5983082f294f652eb0.tar.gz
SPIRV-Tools-3756b387f3c5c5e56d3c0d5983082f294f652eb0.tar.bz2
SPIRV-Tools-3756b387f3c5c5e56d3c0d5983082f294f652eb0.zip
Get CCP to use the constant floating point rules.
Fixes #1311
Diffstat (limited to 'source')
-rw-r--r--source/opt/fold.cpp16
-rw-r--r--source/opt/fold.h4
-rw-r--r--source/opt/instruction.cpp8
-rw-r--r--source/opt/instruction.h4
4 files changed, 23 insertions, 9 deletions
diff --git a/source/opt/fold.cpp b/source/opt/fold.cpp
index ab7239d9..6cc486a0 100644
--- a/source/opt/fold.cpp
+++ b/source/opt/fold.cpp
@@ -41,11 +41,6 @@ namespace {
#define UINT32_MAX 0xffffffff /* 4294967295U */
#endif
-const ConstantFoldingRules& GetConstantFoldingRules() {
- static ConstantFoldingRules* rules = new ConstantFoldingRules();
- return *rules;
-}
-
// Returns the single-word result from performing the given unary operation on
// the operand value which is passed in as a 32-bit word.
uint32_t UnaryOperate(SpvOp opcode, uint32_t operand) {
@@ -225,6 +220,11 @@ bool FoldInstructionInternal(ir::Instruction* inst) {
} // namespace
+const ConstantFoldingRules& GetConstantFoldingRules() {
+ static ConstantFoldingRules* rules = new ConstantFoldingRules();
+ return *rules;
+}
+
// Returns the result of performing an operation on scalar constant operands.
// This function extracts the operand values as 32 bit words and returns the
// result in 32 bit word. Scalar constants with longer than 32-bit width are
@@ -612,7 +612,7 @@ ir::Instruction* FoldInstructionToConstant(
ir::IRContext* context = inst->context();
analysis::ConstantManager* const_mgr = context->get_constant_mgr();
- if (!inst->IsFoldable() &&
+ if (!inst->IsFoldableByFoldScalar() &&
!GetConstantFoldingRules().HasFoldingRule(inst->opcode())) {
return nullptr;
}
@@ -649,12 +649,12 @@ ir::Instruction* FoldInstructionToConstant(
uint32_t result_val = 0;
bool successful = false;
// If all parameters are constant, fold the instruction to a constant.
- if (!missing_constants && inst->IsFoldable()) {
+ if (!missing_constants && inst->IsFoldableByFoldScalar()) {
result_val = FoldScalars(inst->opcode(), constants);
successful = true;
}
- if (!successful && inst->IsFoldable()) {
+ if (!successful && inst->IsFoldableByFoldScalar()) {
successful = FoldIntegerOpToConstant(inst, id_map, &result_val);
}
diff --git a/source/opt/fold.h b/source/opt/fold.h
index 439ed2b6..9c6028df 100644
--- a/source/opt/fold.h
+++ b/source/opt/fold.h
@@ -18,12 +18,16 @@
#include <cstdint>
#include <vector>
+#include "const_folding_rules.h"
#include "constants.h"
#include "def_use_manager.h"
namespace spvtools {
namespace opt {
+// Returns a reference to the ConstnatFoldingRules instance.
+const ConstantFoldingRules& GetConstantFoldingRules();
+
// Returns the result of folding a scalar instruction with the given |opcode|
// and |operands|. Each entry in |operands| is a pointer to an
// analysis::Constant instance, which should've been created with the constant
diff --git a/source/opt/instruction.cpp b/source/opt/instruction.cpp
index 99e50d35..9510ee9f 100644
--- a/source/opt/instruction.cpp
+++ b/source/opt/instruction.cpp
@@ -12,11 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "instruction.h"
+
#include <initializer_list>
#include "disassemble.h"
#include "fold.h"
-#include "instruction.h"
#include "ir_context.h"
#include "reflect.h"
@@ -470,6 +471,11 @@ bool Instruction::IsOpaqueType() const {
}
bool Instruction::IsFoldable() const {
+ return IsFoldableByFoldScalar() ||
+ opt::GetConstantFoldingRules().HasFoldingRule(opcode());
+}
+
+bool Instruction::IsFoldableByFoldScalar() const {
if (!opt::IsFoldableOpcode(opcode())) {
return false;
}
diff --git a/source/opt/instruction.h b/source/opt/instruction.h
index b04f66d4..fccd4c42 100644
--- a/source/opt/instruction.h
+++ b/source/opt/instruction.h
@@ -368,6 +368,10 @@ class Instruction : public utils::IntrusiveNodeBase<Instruction> {
// constant value.
bool IsFoldable() const;
+ // Returns true if |this| is an instruction which could be folded into a
+ // constant value by |FoldScalar|.
+ bool IsFoldableByFoldScalar() const;
+
inline bool operator==(const Instruction&) const;
inline bool operator!=(const Instruction&) const;
inline bool operator<(const Instruction&) const;