[PATCH] [RFC][PATCH] Minor opt to access pointers to globals via pcrel GOT entries

Bruno Cardoso Lopes bruno.cardoso at gmail.com
Wed Jan 28 09:25:40 PST 2015


================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2070
@@ +2069,3 @@
+  // where X is the symbol base of the current emission
+  const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(*ME);
+  if (!BE || BE->getOpcode() != MCBinaryExpr::Sub)
----------------
rafael wrote:
> You should just use EvaluateAsRelocatable. It will put the expression in the form Sym_A - Sym_B + C for you.
------------------------
Cool, this makes it a *lot* easier, thanks!

================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2121
@@ +2120,3 @@
+  if (NumUses)
+    AP.GlobalGOTEquivs[ProxySym] = std::make_pair(GV, --NumUses);
+  else
----------------
rafael wrote:
> Why do you need the count?
> 
> You only really need to remember that there was at least one user that could not be replaced with the got and therefore the GOT-like GlobalVariable still has to be printed.
> 
If I do like you suggest, we'd have to still check all MCExpr and its operands for any presence of a global equivalent symbol, even when we know really early that the MCExpr isn't a fit. The case where EvaluateAsRelocatable returns true should be easier to check, but otherwise we'll still need to parse MCExpr once again searching for a GV reference. I believe the current solution is a better approach.

http://reviews.llvm.org/D6922

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list