Rename Reactor namespace to rr.

We were using sw, the namespace used in the rest of SwiftShader, as the
namespace for Reactor. Putting Reactor code into its own namespace
makes it easier to untangle dependencies.

Bug swiftshader:16
Bug b/115344057

Change-Id: Iea4e049a4796323bf80b4f5e6e17778ccf17b995
Reviewed-on: https://swiftshader-review.googlesource.com/c/21308
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index 92e4586..b702ec9 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -107,14 +107,14 @@
 }
 #endif
 
-namespace sw
+namespace rr
 {
 	class LLVMReactorJIT;
 }
 
 namespace
 {
-	sw::LLVMReactorJIT *reactorJIT = nullptr;
+	rr::LLVMReactorJIT *reactorJIT = nullptr;
 	llvm::IRBuilder<> *builder = nullptr;
 	llvm::LLVMContext *context = nullptr;
 	llvm::Module *module = nullptr;
@@ -441,24 +441,26 @@
 #endif  // SWIFTSHADER_LLVM_VERSION >= 7
 }
 
-namespace sw
+namespace rr
 {
+	using namespace sw;
+
 #if SWIFTSHADER_LLVM_VERSION < 7
 	class LLVMReactorJIT
 	{
 	private:
 		std::string arch;
 		llvm::SmallVector<std::string, 16> mattrs;
-		sw::LLVMRoutineManager *routineManager;
 		llvm::ExecutionEngine *executionEngine;
+		LLVMRoutineManager *routineManager;
 
 	public:
 		LLVMReactorJIT(const std::string &arch_,
 		               const llvm::SmallVectorImpl<std::string> &mattrs_) :
 			arch(arch_),
 			mattrs(mattrs_.begin(), mattrs_.end()),
-			routineManager(nullptr),
-			executionEngine(nullptr)
+			executionEngine(nullptr),
+			routineManager(nullptr)
 		{
 		}
 
@@ -6910,7 +6912,7 @@
 	}
 }
 
-namespace sw
+namespace rr
 {
 #if defined(__i386__) || defined(__x86_64__)
 	namespace x86
diff --git a/src/Reactor/LLVMRoutine.cpp b/src/Reactor/LLVMRoutine.cpp
index 0fb8227..8dbfe07 100644
--- a/src/Reactor/LLVMRoutine.cpp
+++ b/src/Reactor/LLVMRoutine.cpp
@@ -18,12 +18,12 @@
 #include "Common/Thread.hpp"
 #include "Common/Types.hpp"
 
-namespace sw
+namespace rr
 {
 #if SWIFTSHADER_LLVM_VERSION < 7
 	LLVMRoutine::LLVMRoutine(int bufferSize) : bufferSize(bufferSize)
 	{
-		void *memory = allocateExecutable(bufferSize);
+		void *memory = sw::allocateExecutable(bufferSize);
 
 		buffer = memory;
 		entry = memory;
@@ -32,7 +32,7 @@
 
 	LLVMRoutine::~LLVMRoutine()
 	{
-		deallocateExecutable(buffer, bufferSize);
+		sw::deallocateExecutable(buffer, bufferSize);
 	}
 
 	const void *LLVMRoutine::getEntry()
diff --git a/src/Reactor/LLVMRoutine.hpp b/src/Reactor/LLVMRoutine.hpp
index f353891..06aaef6 100644
--- a/src/Reactor/LLVMRoutine.hpp
+++ b/src/Reactor/LLVMRoutine.hpp
@@ -12,14 +12,14 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef sw_LLVMRoutine_hpp
-#define sw_LLVMRoutine_hpp
+#ifndef rr_LLVMRoutine_hpp
+#define rr_LLVMRoutine_hpp
 
 #include "Routine.hpp"
 
 #include <cstdint>
 
-namespace sw
+namespace rr
 {
 #if SWIFTSHADER_LLVM_VERSION < 7
 	class LLVMRoutineManager;
@@ -79,4 +79,4 @@
 #endif  // SWIFTSHADER_LLVM_VERSION < 7
 }
 
-#endif   // sw_LLVMRoutine_hpp
+#endif   // rr_LLVMRoutine_hpp
diff --git a/src/Reactor/LLVMRoutineManager.cpp b/src/Reactor/LLVMRoutineManager.cpp
index a8fceb9..8af37f3 100644
--- a/src/Reactor/LLVMRoutineManager.cpp
+++ b/src/Reactor/LLVMRoutineManager.cpp
@@ -22,7 +22,7 @@
 #include "Common/Thread.hpp"
 #include "Common/Debug.hpp"
 
-namespace sw
+namespace rr
 {
 	using namespace llvm;
 
@@ -67,7 +67,7 @@
 		}
 
 		// Round up to the next page size
-		size_t pageSize = memoryPageSize();
+		size_t pageSize = sw::memoryPageSize();
 		actualSize = (actualSize + pageSize - 1) & ~(pageSize - 1);
 
 		delete routine;
@@ -130,7 +130,7 @@
 
 	void LLVMRoutineManager::setMemoryExecutable()
 	{
-		markExecutable(routine->buffer, routine->bufferSize);
+		sw::markExecutable(routine->buffer, routine->bufferSize);
 	}
 
 	void LLVMRoutineManager::setPoisonMemory(bool poison)
diff --git a/src/Reactor/LLVMRoutineManager.hpp b/src/Reactor/LLVMRoutineManager.hpp
index 28c51c5..e96d85e 100644
--- a/src/Reactor/LLVMRoutineManager.hpp
+++ b/src/Reactor/LLVMRoutineManager.hpp
@@ -12,15 +12,15 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef sw_LLVMRoutineManager_hpp
-#define sw_LLVMRoutineManager_hpp
+#ifndef rr_LLVMRoutineManager_hpp
+#define rr_LLVMRoutineManager_hpp
 
 #if SWIFTSHADER_LLVM_VERSION < 7
 
 #include "llvm/ExecutionEngine/JITMemoryManager.h"
 #include "llvm/GlobalValue.h"
 
-namespace sw
+namespace rr
 {
 	class LLVMRoutine;
 
@@ -58,4 +58,4 @@
 
 #endif  // SWIFTSHADER_LLVM_VERSION < 7
 
-#endif   // sw_LLVMRoutineManager_hpp
+#endif   // rr_LLVMRoutineManager_hpp
diff --git a/src/Reactor/Main.cpp b/src/Reactor/Main.cpp
index 81442b9..2bc9f7e 100644
--- a/src/Reactor/Main.cpp
+++ b/src/Reactor/Main.cpp
@@ -16,7 +16,7 @@
 
 #include "gtest/gtest.h"
 
-using namespace sw;
+using namespace rr;
 
 int reference(int *p, int y)
 {
diff --git a/src/Reactor/Nucleus.hpp b/src/Reactor/Nucleus.hpp
index 21e2571..7f63b96 100644
--- a/src/Reactor/Nucleus.hpp
+++ b/src/Reactor/Nucleus.hpp
@@ -12,15 +12,15 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef sw_Nucleus_hpp
-#define sw_Nucleus_hpp
+#ifndef rr_Nucleus_hpp
+#define rr_Nucleus_hpp
 
 #include <cassert>
 #include <cstdarg>
 #include <cstdint>
 #include <vector>
 
-namespace sw
+namespace rr
 {
 	class Type;
 	class Value;
@@ -171,4 +171,4 @@
 	};
 }
 
-#endif   // sw_Nucleus_hpp
+#endif   // rr_Nucleus_hpp
diff --git a/src/Reactor/Optimizer.cpp b/src/Reactor/Optimizer.cpp
index aac8c04..5d89878 100644
--- a/src/Reactor/Optimizer.cpp
+++ b/src/Reactor/Optimizer.cpp
@@ -826,7 +826,7 @@
 	}
 }
 
-namespace sw
+namespace rr
 {
 	void optimize(Ice::Cfg *function)
 	{
diff --git a/src/Reactor/Optimizer.hpp b/src/Reactor/Optimizer.hpp
index c050717..e6027e9 100644
--- a/src/Reactor/Optimizer.hpp
+++ b/src/Reactor/Optimizer.hpp
@@ -12,14 +12,14 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef sw_Optimizer_hpp
-#define sw_Optimizer_hpp
+#ifndef rr_Optimizer_hpp
+#define rr_Optimizer_hpp
 
 #include "src/IceCfg.h"
 
-namespace sw
+namespace rr
 {
 	void optimize(Ice::Cfg *function);
 }
 
-#endif   // sw_Optimizer_hpp
+#endif   // rr_Optimizer_hpp
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
index f07dfa9..ba67afa 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -12,8 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef sw_Reactor_hpp
-#define sw_Reactor_hpp
+#ifndef rr_Reactor_hpp
+#define rr_Reactor_hpp
 
 #include "Nucleus.hpp"
 #include "Routine.hpp"
@@ -23,7 +23,7 @@
 #include <cwchar>
 #undef Bool
 
-namespace sw
+namespace rr
 {
 	class Bool;
 	class Byte;
@@ -2268,7 +2268,7 @@
 	RValue<Long> Ticks();
 }
 
-namespace sw
+namespace rr
 {
 	template<class T>
 	LValue<T>::LValue(int arraySize)
@@ -2944,4 +2944,4 @@
 	else   // ELSE_BLOCK__
 }
 
-#endif   // sw_Reactor_hpp
+#endif   // rr_Reactor_hpp
diff --git a/src/Reactor/Routine.cpp b/src/Reactor/Routine.cpp
index a048b19..5899c58 100644
--- a/src/Reactor/Routine.cpp
+++ b/src/Reactor/Routine.cpp
@@ -18,7 +18,7 @@
 
 #include <cassert>
 
-namespace sw
+namespace rr
 {
 	Routine::Routine()
 	{
@@ -27,12 +27,12 @@
 
 	void Routine::bind()
 	{
-		atomicIncrement(&bindCount);
+		sw::atomicIncrement(&bindCount);
 	}
 
 	void Routine::unbind()
 	{
-		long count = atomicDecrement(&bindCount);
+		long count = sw::atomicDecrement(&bindCount);
 
 		if(count == 0)
 		{
diff --git a/src/Reactor/Routine.hpp b/src/Reactor/Routine.hpp
index b3ad7f5..2f78b2b 100644
--- a/src/Reactor/Routine.hpp
+++ b/src/Reactor/Routine.hpp
@@ -12,10 +12,10 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef sw_Routine_hpp
-#define sw_Routine_hpp
+#ifndef rr_Routine_hpp
+#define rr_Routine_hpp
 
-namespace sw
+namespace rr
 {
 	class Routine
 	{
@@ -35,4 +35,4 @@
 	};
 }
 
-#endif   // sw_Routine_hpp
+#endif   // rr_Routine_hpp
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index 0103a25..b92005c 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -60,7 +60,7 @@
 	Ice::Cfg *function = nullptr;
 	Ice::CfgNode *basicBlock = nullptr;
 	Ice::CfgLocalAllocatorScope *allocator = nullptr;
-	sw::Routine *routine = nullptr;
+	rr::Routine *routine = nullptr;
 
 	std::mutex codegenMutex;
 
@@ -130,7 +130,7 @@
 	const bool emulateMismatchedBitCast = CPUID::ARM;
 }
 
-namespace sw
+namespace rr
 {
 	enum EmulatedType
 	{
@@ -427,12 +427,12 @@
 
 		T *allocate(size_type n)
 		{
-			return (T*)allocateExecutable(sizeof(T) * n);
+			return (T*)sw::allocateExecutable(sizeof(T) * n);
 		}
 
 		void deallocate(T *p, size_type n)
 		{
-			deallocateExecutable(p, sizeof(T) * n);
+			sw::deallocateExecutable(p, sizeof(T) * n);
 		}
 	};
 
@@ -612,7 +612,7 @@
 
 	void Nucleus::optimize()
 	{
-		sw::optimize(::function);
+		rr::optimize(::function);
 	}
 
 	Value *Nucleus::allocateStackVariable(Type *t, int arraySize)
diff --git a/src/Reactor/x86.hpp b/src/Reactor/x86.hpp
index 1b8786e..6d3e8e8 100644
--- a/src/Reactor/x86.hpp
+++ b/src/Reactor/x86.hpp
@@ -17,7 +17,7 @@
 
 #include "Reactor.hpp"
 
-namespace sw
+namespace rr
 {
 	namespace x86
 	{
@@ -106,4 +106,4 @@
 	}
 }
 
-#endif   // sw_x86_hpp
\ No newline at end of file
+#endif   // rr_x86_hpp
\ No newline at end of file