Subzero. Adds symbolic references to RelocInitializer.

BUG=
R=kschimpf@google.com, stichnot@chromium.org

Review URL: https://codereview.chromium.org/1661193004 .
diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
index 99c55ac..5c43562 100644
--- a/src/IceCfg.cpp
+++ b/src/IceCfg.cpp
@@ -148,7 +148,8 @@
 
   const RelocOffsetT NodeNameDeclarationOffset = 0;
   Var->addInitializer(VariableDeclaration::RelocInitializer::create(
-      NodeNameDeclaration, NodeNameDeclarationOffset));
+      NodeNameDeclaration,
+      {RelocOffset::create(Ctx, NodeNameDeclarationOffset)}));
   Var->setAlignment(Int64ByteSize);
   return Var;
 }
diff --git a/src/IceConverter.cpp b/src/IceConverter.cpp
index e54dd2a..4cd7091 100644
--- a/src/IceConverter.cpp
+++ b/src/IceConverter.cpp
@@ -787,8 +787,8 @@
       assert(GV);
       const Ice::GlobalDeclaration *Addr =
           getConverter().getGlobalDeclaration(GV);
-      Global.addInitializer(
-          Ice::VariableDeclaration::RelocInitializer::create(Addr, Offset));
+      Global.addInitializer(Ice::VariableDeclaration::RelocInitializer::create(
+          Addr, {Ice::RelocOffset::create(Ctx, Offset)}));
       return;
     }
     default:
diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
index df5206a..88519d1 100644
--- a/src/IceGlobalContext.cpp
+++ b/src/IceGlobalContext.cpp
@@ -357,18 +357,6 @@
 
 namespace {
 
-void addBlockInfoPtrs(const VariableDeclarationList &Globals,
-                      VariableDeclaration *ProfileBlockInfo) {
-  for (const VariableDeclaration *Global : Globals) {
-    if (Cfg::isProfileGlobal(*Global)) {
-      constexpr RelocOffsetT BlockExecutionCounterOffset = 0;
-      ProfileBlockInfo->addInitializer(
-          VariableDeclaration::RelocInitializer::create(
-              Global, BlockExecutionCounterOffset));
-    }
-  }
-}
-
 // Ensure Pending is large enough that Pending[Index] is valid.
 void resizePending(std::vector<EmitterWorkItem *> &Pending, uint32_t Index) {
   if (Index >= Pending.size())
@@ -394,6 +382,18 @@
 
 void GlobalContext::lowerJumpTables() { DataLowering->lowerJumpTables(); }
 
+void GlobalContext::addBlockInfoPtrs(VariableDeclaration *ProfileBlockInfo) {
+  for (const VariableDeclaration *Global : Globals) {
+    if (Cfg::isProfileGlobal(*Global)) {
+      constexpr RelocOffsetT BlockExecutionCounterOffset = 0;
+      ProfileBlockInfo->addInitializer(
+          VariableDeclaration::RelocInitializer::create(
+              Global,
+              {RelocOffset::create(this, BlockExecutionCounterOffset)}));
+    }
+  }
+}
+
 void GlobalContext::lowerGlobals(const IceString &SectionSuffix) {
   TimerMarker T(TimerStack::TT_emitGlobalInitializers, this);
   const bool DumpGlobalVariables =
@@ -409,7 +409,7 @@
   if (Flags.getDisableTranslation())
     return;
 
-  addBlockInfoPtrs(Globals, ProfileBlockInfoVarDecl);
+  addBlockInfoPtrs(ProfileBlockInfoVarDecl);
   // If we need to shuffle the layout of global variables, shuffle them now.
   if (getFlags().shouldReorderGlobalVariables()) {
     // Create a random number generator for global variable reordering.
diff --git a/src/IceGlobalContext.h b/src/IceGlobalContext.h
index 9c12549..fe71fa7 100644
--- a/src/IceGlobalContext.h
+++ b/src/IceGlobalContext.h
@@ -538,6 +538,8 @@
     HasSeenCode = true;
   }
 
+  void addBlockInfoPtrs(VariableDeclaration *ProfileBlockInfo);
+
   llvm::SmallVector<ThreadContext *, 128> AllThreadContexts;
   llvm::SmallVector<std::thread, 128> TranslationThreads;
   llvm::SmallVector<std::thread, 128> EmitterThreads;
diff --git a/src/IceGlobalInits.cpp b/src/IceGlobalInits.cpp
index 94a38a1..6787eaf 100644
--- a/src/IceGlobalInits.cpp
+++ b/src/IceGlobalInits.cpp
@@ -230,6 +230,7 @@
                                                  Ostream &Stream) const {
   if (!Ice::BuildDefs::dump())
     return;
+  const RelocOffsetT Offset = getOffset();
   if (Offset != 0) {
     dumpType(Stream);
     Stream << " add (";
diff --git a/src/IceGlobalInits.h b/src/IceGlobalInits.h
index 711a563..902e335 100644
--- a/src/IceGlobalInits.h
+++ b/src/IceGlobalInits.h
@@ -22,6 +22,7 @@
 #include "IceDefs.h"
 #include "IceGlobalContext.h"
 #include "IceIntrinsics.h"
+#include "IceOperand.h"
 #include "IceTypes.h"
 
 #ifdef __clang__
@@ -318,11 +319,19 @@
 
   public:
     static std::unique_ptr<RelocInitializer>
-    create(const GlobalDeclaration *Declaration, RelocOffsetT Offset) {
-      return makeUnique<RelocInitializer>(Declaration, Offset);
+    create(const GlobalDeclaration *Declaration,
+           const RelocOffsetArray &OffsetExpr) {
+      return makeUnique<RelocInitializer>(Declaration, OffsetExpr);
     }
 
-    RelocOffsetT getOffset() const { return Offset; }
+    RelocOffsetT getOffset() const {
+      RelocOffsetT Offset = 0;
+      for (const auto *RelocOffset : OffsetExpr) {
+        Offset += RelocOffset->getOffset();
+      }
+      return Offset;
+    }
+
     const GlobalDeclaration *getDeclaration() const { return Declaration; }
     SizeT getNumBytes() const final { return RelocAddrSize; }
     void dump(GlobalContext *Ctx, Ostream &Stream) const final;
@@ -334,13 +343,15 @@
   private:
     ENABLE_MAKE_UNIQUE;
 
-    RelocInitializer(const GlobalDeclaration *Declaration, RelocOffsetT Offset)
-        : Initializer(RelocInitializerKind), Declaration(Declaration),
-          Offset(Offset) {} // The global declaration used in the relocation.
+    RelocInitializer(const GlobalDeclaration *Declaration,
+                     const RelocOffsetArray &OffsetExpr)
+        : Initializer(RelocInitializerKind),
+          Declaration(Declaration), // The global declaration used in the reloc.
+          OffsetExpr(OffsetExpr) {}
 
     const GlobalDeclaration *Declaration;
     /// The offset to add to the relocation.
-    const RelocOffsetT Offset;
+    const RelocOffsetArray OffsetExpr;
   };
 
   /// Models the list of initializers.
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index 13e0870..97b8c34 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -1211,9 +1211,10 @@
         Error(StrBuf.str());
       }
     }
+    Ice::GlobalContext *Ctx = getTranslator().getContext();
     CurGlobalVar->addInitializer(
         Ice::VariableDeclaration::RelocInitializer::create(
-            getGlobalDeclByID(Index), Offset));
+            getGlobalDeclByID(Index), {Ice::RelocOffset::create(Ctx, Offset)}));
     return;
   }
   default: