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/Common/MutexLock.hpp b/src/Common/MutexLock.hpp
index 65e9fa4..1328e35 100644
--- a/src/Common/MutexLock.hpp
+++ b/src/Common/MutexLock.hpp
@@ -172,7 +172,7 @@
 	using MutexLock = BackoffLock;
 }
 
-#endif   // !__ANDROID__
+#endif   // !__linux__
 
 class LockGuard
 {
diff --git a/src/Device/RoutineCache.hpp b/src/Device/RoutineCache.hpp
index 74dd842..3904acc 100644
--- a/src/Device/RoutineCache.hpp
+++ b/src/Device/RoutineCache.hpp
@@ -21,6 +21,8 @@
 
 namespace sw
 {
+	using namespace rr;
+
 	template<class State>
 	class RoutineCache : public LRUCache<State, Routine>
 	{
diff --git a/src/Device/SwiftConfig.cpp b/src/Device/SwiftConfig.cpp
index 1c22394..aa17aa8 100644
--- a/src/Device/SwiftConfig.cpp
+++ b/src/Device/SwiftConfig.cpp
@@ -652,7 +652,7 @@
 			}
 			else if(sscanf(post, "optimization%d=%d", &index, &integer))
 			{
-				config.optimization[index - 1] = (Optimization)integer;
+				config.optimization[index - 1] = (rr::Optimization)integer;
 			}
 			else if(strstr(post, "disableServer=on"))
 			{
@@ -739,7 +739,7 @@
 
 		for(int pass = 0; pass < 10; pass++)
 		{
-			config.optimization[pass] = (Optimization)ini.getInteger("Optimization", "OptimizationPass" + itoa(pass + 1), pass == 0 ? InstructionCombining : Disabled);
+			config.optimization[pass] = (rr::Optimization)ini.getInteger("Optimization", "OptimizationPass" + itoa(pass + 1), pass == 0 ? rr::InstructionCombining : rr::Disabled);
 		}
 
 		config.disableServer = ini.getBoolean("Testing", "DisableServer", false);
diff --git a/src/Device/SwiftConfig.hpp b/src/Device/SwiftConfig.hpp
index 233b438..ad3dcb5 100644
--- a/src/Device/SwiftConfig.hpp
+++ b/src/Device/SwiftConfig.hpp
@@ -48,7 +48,7 @@
 			bool enableSSE3;
 			bool enableSSSE3;
 			bool enableSSE4_1;
-			Optimization optimization[10];
+			rr::Optimization optimization[10];
 			bool disableServer;
 			bool keepSystemCursor;
 			bool forceWindowed;
diff --git a/src/Main/FrameBuffer.hpp b/src/Main/FrameBuffer.hpp
index dd539e1..f07feb3 100644
--- a/src/Main/FrameBuffer.hpp
+++ b/src/Main/FrameBuffer.hpp
@@ -21,6 +21,8 @@
 
 namespace sw
 {
+	using namespace rr;
+
 	class Surface;
 
 	struct BlitState
diff --git a/src/Main/SwiftConfig.cpp b/src/Main/SwiftConfig.cpp
index 1c22394..aa17aa8 100644
--- a/src/Main/SwiftConfig.cpp
+++ b/src/Main/SwiftConfig.cpp
@@ -652,7 +652,7 @@
 			}
 			else if(sscanf(post, "optimization%d=%d", &index, &integer))
 			{
-				config.optimization[index - 1] = (Optimization)integer;
+				config.optimization[index - 1] = (rr::Optimization)integer;
 			}
 			else if(strstr(post, "disableServer=on"))
 			{
@@ -739,7 +739,7 @@
 
 		for(int pass = 0; pass < 10; pass++)
 		{
-			config.optimization[pass] = (Optimization)ini.getInteger("Optimization", "OptimizationPass" + itoa(pass + 1), pass == 0 ? InstructionCombining : Disabled);
+			config.optimization[pass] = (rr::Optimization)ini.getInteger("Optimization", "OptimizationPass" + itoa(pass + 1), pass == 0 ? rr::InstructionCombining : rr::Disabled);
 		}
 
 		config.disableServer = ini.getBoolean("Testing", "DisableServer", false);
diff --git a/src/Main/SwiftConfig.hpp b/src/Main/SwiftConfig.hpp
index 233b438..ad3dcb5 100644
--- a/src/Main/SwiftConfig.hpp
+++ b/src/Main/SwiftConfig.hpp
@@ -48,7 +48,7 @@
 			bool enableSSE3;
 			bool enableSSSE3;
 			bool enableSSE4_1;
-			Optimization optimization[10];
+			rr::Optimization optimization[10];
 			bool disableServer;
 			bool keepSystemCursor;
 			bool forceWindowed;
diff --git a/src/Pipeline/ShaderCore.hpp b/src/Pipeline/ShaderCore.hpp
index 4dc109f..fd12bf0 100644
--- a/src/Pipeline/ShaderCore.hpp
+++ b/src/Pipeline/ShaderCore.hpp
@@ -21,6 +21,8 @@
 
 namespace sw
 {
+	using namespace rr;
+
 	class Vector4s
 	{
 	public:
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
diff --git a/src/Renderer/Blitter.cpp b/src/Renderer/Blitter.cpp
index 6522a13..f8ce48c 100644
--- a/src/Renderer/Blitter.cpp
+++ b/src/Renderer/Blitter.cpp
@@ -21,6 +21,8 @@
 
 namespace sw
 {
+	using namespace rr;
+
 	Blitter::Blitter()
 	{
 		blitCache = new RoutineCache<State>(1024);
diff --git a/src/Renderer/Rasterizer.hpp b/src/Renderer/Rasterizer.hpp
index 3811a25..4eb637f 100644
--- a/src/Renderer/Rasterizer.hpp
+++ b/src/Renderer/Rasterizer.hpp
@@ -21,6 +21,8 @@
 
 namespace sw
 {
+	using namespace rr;
+
 	class Rasterizer : public Function<Void(Pointer<Byte>, Int, Int, Pointer<Byte>)>
 	{
 	public:
diff --git a/src/Renderer/RoutineCache.hpp b/src/Renderer/RoutineCache.hpp
index 74dd842..3338f85 100644
--- a/src/Renderer/RoutineCache.hpp
+++ b/src/Renderer/RoutineCache.hpp
@@ -21,11 +21,13 @@
 
 namespace sw
 {
+	using namespace rr;
+
 	template<class State>
 	class RoutineCache : public LRUCache<State, Routine>
 	{
 	public:
-		RoutineCache(int n, const char *precache = 0);
+		RoutineCache(int n, const char *precache = nullptr);
 		~RoutineCache();
 
 	private:
diff --git a/src/Shader/ShaderCore.hpp b/src/Shader/ShaderCore.hpp
index 4dc109f..fd12bf0 100644
--- a/src/Shader/ShaderCore.hpp
+++ b/src/Shader/ShaderCore.hpp
@@ -21,6 +21,8 @@
 
 namespace sw
 {
+	using namespace rr;
+
 	class Vector4s
 	{
 	public:
diff --git a/src/WSI/FrameBuffer.hpp b/src/WSI/FrameBuffer.hpp
index dd539e1..f07feb3 100644
--- a/src/WSI/FrameBuffer.hpp
+++ b/src/WSI/FrameBuffer.hpp
@@ -21,6 +21,8 @@
 
 namespace sw
 {
+	using namespace rr;
+
 	class Surface;
 
 	struct BlitState