Remove redundant in_block function from Function
authorUmar Arshad <umar@arrayfire.com>
Wed, 1 Jun 2016 22:22:57 +0000 (18:22 -0400)
committerUmar Arshad <umar@arrayfire.com>
Mon, 6 Jun 2016 14:27:40 +0000 (10:27 -0400)
Same test can be done through the get_current_block function

source/validate.h
source/validate_cfg.cpp
source/validate_instruction.cpp
source/validate_types.cpp

index dd93a55..35050cd 100644 (file)
@@ -340,15 +340,11 @@ class Function {
     return undefined_blocks_;
   }
 
-  /// Returns true if called after a label instruction but before a branch
-  /// instruction
-  bool in_block() const;
-
   /// Returns the block that is currently being parsed in the binary
-  BasicBlock& get_current_block();
+  BasicBlock* get_current_block();
 
   /// Returns the block that is currently being parsed in the binary
-  const BasicBlock& get_current_block() const;
+  const BasicBlock* get_current_block() const;
 
   /// Prints a GraphViz digraph of the CFG of the current funciton
   void printDotGraph() const;
index e1f1191..187d820 100644 (file)
@@ -190,7 +190,7 @@ spv_result_t FirstBlockAssert(ValidationState_t& _, uint32_t target) {
            << _.getIdName(_.get_current_function().get_id())
            << " is targeted by block "
            << _.getIdName(
-                  _.get_current_function().get_current_block().get_id());
+                  _.get_current_function().get_current_block()->get_id());
   }
   return SPV_SUCCESS;
 }
index 1a17bd0..b86028d 100644 (file)
@@ -140,7 +140,7 @@ spv_result_t InstructionPass(ValidationState_t& _,
                << "Variables must have a function[7] storage class inside"
                   " of a function";
       }
-      if(_.get_current_function().IsFirstBlock(_.get_current_function().get_current_block().get_id()) == false) {
+      if(_.get_current_function().IsFirstBlock(_.get_current_function().get_current_block()->get_id()) == false) {
         return _.diag(SPV_ERROR_INVALID_CFG)
           << "Variables can only be defined in the first block of a function";
       }
index 88f6ad1..bba979d 100644 (file)
@@ -315,7 +315,7 @@ Function& ValidationState_t::get_current_function() {
 bool ValidationState_t::in_function_body() const { return in_function_; }
 
 bool ValidationState_t::in_block() const {
-  return module_functions_.back().in_block();
+  return module_functions_.back().get_current_block() != nullptr;
 }
 
 void ValidationState_t::RegisterCapability(SpvCapability cap) {
@@ -372,8 +372,6 @@ Function::Function(uint32_t id, uint32_t result_type_id,
       variable_ids_(),
       parameter_ids_() {}
 
-bool Function::in_block() const { return static_cast<bool>(current_block_); }
-
 bool Function::IsFirstBlock(uint32_t id) const {
   return !ordered_blocks_.empty() && *get_first_block() == id;
 }
@@ -409,7 +407,7 @@ spv_result_t Function::RegisterFunctionParameter(uint32_t id,
   assert(module_.in_function_body() == true &&
          "RegisterFunctionParameter can only be called when parsing the binary "
          "outside of another function");
-  assert(in_block() == false &&
+  assert(get_current_block() == nullptr &&
          "RegisterFunctionParameter can only be called when parsing the binary "
          "ouside of a block");
   // TODO(umar): Validate function parameter type order and count
@@ -423,7 +421,7 @@ spv_result_t Function::RegisterLoopMerge(uint32_t merge_id,
                                          uint32_t continue_id) {
   RegisterBlock(merge_id, false);
   RegisterBlock(continue_id, false);
-  cfg_constructs_.emplace_back(&get_current_block(), &blocks_.at(merge_id),
+  cfg_constructs_.emplace_back(get_current_block(), &blocks_.at(merge_id),
                                &blocks_.at(continue_id));
 
   return SPV_SUCCESS;
@@ -431,7 +429,7 @@ spv_result_t Function::RegisterLoopMerge(uint32_t merge_id,
 
 spv_result_t Function::RegisterSelectionMerge(uint32_t merge_id) {
   RegisterBlock(merge_id, false);
-  cfg_constructs_.emplace_back(&get_current_block(), &blocks_.at(merge_id));
+  cfg_constructs_.emplace_back(get_current_block(), &blocks_.at(merge_id));
   return SPV_SUCCESS;
 }
 
@@ -488,7 +486,7 @@ spv_result_t Function::RegisterBlock(uint32_t id, bool is_definition) {
   bool success = false;
   tie(inserted_block, success) = blocks_.insert({id, BasicBlock(id)});
   if (is_definition) {  // new block definition
-    assert(in_block() == false &&
+    assert(get_current_block() == nullptr &&
            "Register Block can only be called when parsing a binary outside of "
            "a BasicBlock");
 
@@ -509,7 +507,7 @@ void Function::RegisterBlockEnd(vector<uint32_t> next_list,
          "RegisterBlockEnd can only be called when parsing a binary in a "
          "function");
   assert(
-      in_block() == true &&
+      get_current_block() &&
       "RegisterBlockEnd can only be called when parsing a binary in a block");
 
   vector<BasicBlock*> next_blocks;
@@ -542,10 +540,8 @@ const vector<BasicBlock*>& Function::get_blocks() const {
 }
 vector<BasicBlock*>& Function::get_blocks() { return ordered_blocks_; }
 
-const BasicBlock& Function::get_current_block() const {
-  return *current_block_;
-}
-BasicBlock& Function::get_current_block() { return *current_block_; }
+const BasicBlock* Function::get_current_block() const { return current_block_; }
+BasicBlock* Function::get_current_block() { return current_block_; }
 
 const list<CFConstruct>& Function::get_constructs() const {
   return cfg_constructs_;