[llvm] r336560 - [BitcodeReader] Infer the correct runtime preemption for GlobalValue

Steven Wu via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 9 09:52:06 PDT 2018


Author: steven_wu
Date: Mon Jul  9 09:52:05 2018
New Revision: 336560

URL: http://llvm.org/viewvc/llvm-project?rev=336560&view=rev
Log:
[BitcodeReader] Infer the correct runtime preemption for GlobalValue

Summary:
To allow bitcode built by old compiler to pass the current verifer,
BitcodeReader needs to auto infer the correct runtime preemption from
linkage and visibility for GlobalValues.

Since llvm-6.0 bitcode already contains the new field but can be
incorrect in some cases, the attribute needs to be recomputed all the
time in BitcodeReader. This will make all the GVs has dso_local marked
correctly if read from bitcode, and it should still allow the verifier
to catch mistakes in optimization passes.

This should fix PR38009.

Reviewers: sfertile, vsk

Reviewed By: vsk

Subscribers: dexonsmith, llvm-commits

Differential Revision: https://reviews.llvm.org/D49039

Added:
    llvm/trunk/test/Bitcode/Inputs/infer_dso_local.bc
    llvm/trunk/test/Bitcode/infer_dso_local.ll
Modified:
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=336560&r1=336559&r2=336560&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Jul  9 09:52:05 2018
@@ -2831,6 +2831,13 @@ Error BitcodeReader::parseComdatRecord(A
   return Error::success();
 }
 
+static void inferDSOLocal(GlobalValue *GV) {
+  // infer dso_local from linkage and visibility if it is not encoded.
+  if (GV->hasLocalLinkage() ||
+      (!GV->hasDefaultVisibility() && !GV->hasExternalWeakLinkage()))
+    GV->setDSOLocal(true);
+}
+
 Error BitcodeReader::parseGlobalVarRecord(ArrayRef<uint64_t> Record) {
   // v1: [pointer type, isconst, initid, linkage, alignment, section,
   // visibility, threadlocal, unnamed_addr, externally_initialized,
@@ -2923,6 +2930,7 @@ Error BitcodeReader::parseGlobalVarRecor
   if (Record.size() > 13) {
     NewGV->setDSOLocal(getDecodedDSOLocal(Record[13]));
   }
+  inferDSOLocal(NewGV);
 
   return Error::success();
 }
@@ -3007,6 +3015,7 @@ Error BitcodeReader::parseFunctionRecord
   if (Record.size() > 15) {
     Func->setDSOLocal(getDecodedDSOLocal(Record[15]));
   }
+  inferDSOLocal(Func);
 
   ValueList.push_back(Func);
 
@@ -3083,6 +3092,8 @@ Error BitcodeReader::parseGlobalIndirect
   }
   if (OpNum != Record.size())
     NewGA->setDSOLocal(getDecodedDSOLocal(Record[OpNum++]));
+  inferDSOLocal(NewGA);
+
   ValueList.push_back(NewGA);
   IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
   return Error::success();

Added: llvm/trunk/test/Bitcode/Inputs/infer_dso_local.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/Inputs/infer_dso_local.bc?rev=336560&view=auto
==============================================================================
Binary files llvm/trunk/test/Bitcode/Inputs/infer_dso_local.bc (added) and llvm/trunk/test/Bitcode/Inputs/infer_dso_local.bc Mon Jul  9 09:52:05 2018 differ

Added: llvm/trunk/test/Bitcode/infer_dso_local.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/infer_dso_local.ll?rev=336560&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/infer_dso_local.ll (added)
+++ llvm/trunk/test/Bitcode/infer_dso_local.ll Mon Jul  9 09:52:05 2018
@@ -0,0 +1,3 @@
+; RUN: opt -verify %S/Inputs/infer_dso_local.bc | llvm-dis | FileCheck %s
+
+; CHECK: define linkonce_odr hidden void @test()




More information about the llvm-commits mailing list