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

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Tue Jan 27 06:42:45 PST 2015


================
Comment at: include/llvm/CodeGen/AsmPrinter.h:259
@@ +258,3 @@
+  /// equivalents, i.e., it's only used to hold the address of the latter. One
+  /// (very) minor optimization is to replace accesses to these proxies by using
+  /// the GOT entry for the final global instead. Hence, we select GOT
----------------
the very minor bit is not particularity relevant. 

================
Comment at: include/llvm/Target/TargetLoweringObjectFile.h:160
@@ +159,3 @@
+  /// through another symbol, by accessing the later via a GOT entry instead?
+  virtual bool supportIndirectSymViaGOTPCRel() const {
+    return SupportIndirectSymViaGOTPCRel;
----------------
not virtual.

================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:908
@@ +907,3 @@
+  if (!GV->hasUnnamedAddr() || !GV->hasInitializer() ||
+      !GV->getNumOperands() || !GV->isDiscardableIfUnused())
+    return false;
----------------
getNumOperands is redundant with hasInitializer.

This is missing a call to isConstant.

================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:911
@@ +910,3 @@
+
+  const GlobalVariable *FinalGV = dyn_cast<GlobalVariable>(GV->getOperand(0));
+  if (!FinalGV)
----------------
Why does FinalGV has to be a GlobalVariable? We can have a got-equivalent of a function.

================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:915
@@ +914,3 @@
+
+  const Constant *C = dyn_cast<Constant>(FinalGV);
+  if (!C & !isa<GlobalValue>(C) || !C->getType()->isPointerTy())
----------------
This cast cannot fail. GlobalValue *is* a Constant.

================
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)
----------------
You should just use EvaluateAsRelocatable. It will put the expression in the form Sym_A - Sym_B + C for you.

================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2121
@@ +2120,3 @@
+  if (NumUses)
+    AP.GlobalGOTEquivs[ProxySym] = std::make_pair(GV, --NumUses);
+  else
----------------
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.

http://reviews.llvm.org/D6922

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






More information about the llvm-commits mailing list