It could come about that we parse the inline ASM before we get a potential
[oota-llvm.git] / tools / lto / LTOModule.cpp
index 97e4e54dce8d2272a5575bace3db38375934d1f5..3bd764cb76a1ba9a0d7a904d333980d6bf1f68c5 100644 (file)
 #include "llvm/Constants.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
-#include "llvm/ADT/OwningPtr.h"
-#include "llvm/ADT/Triple.h"
 #include "llvm/Bitcode/ReaderWriter.h"
-#include "llvm/Support/SystemUtils.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/MathExtras.h"
-#include "llvm/Support/Host.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/Process.h"
-#include "llvm/Support/SourceMgr.h"
-#include "llvm/Support/TargetRegistry.h"
-#include "llvm/Support/TargetSelect.h"
-#include "llvm/Support/system_error.h"
-#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCInst.h"
-#include "llvm/MC/MCParser/MCAsmParser.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/MCSymbol.h"
-#include "llvm/MC/SubtargetFeature.h"
 #include "llvm/MC/MCTargetAsmParser.h"
-#include "llvm/Target/TargetMachine.h"
+#include "llvm/MC/SubtargetFeature.h"
+#include "llvm/MC/MCParser/MCAsmParser.h"
 #include "llvm/Target/TargetRegisterInfo.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/system_error.h"
+#include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/Triple.h"
 using namespace llvm;
 
 LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
@@ -404,10 +399,25 @@ void LTOModule::addAsmGlobalSymbol(const char *name,
 
   NameAndAttributes &info = _undefines[entry.getKey().data()];
 
+  if (info.symbol == 0) {
+    // If we haven't seen this symbol before, save it and we may see it again.
+    StringMap<NameAndAttributes>::value_type
+      &asm_entry = _asm_defines.GetOrCreateValue(name);
+    NameAndAttributes &asm_info = _asm_defines[asm_entry.getKey().data()];
+    asm_info.name = name;
+    asm_info.attributes = scope;
+    asm_info.isFunction = false;
+    asm_info.symbol = 0;
+    return;
+  }
+
   if (info.isFunction)
     addDefinedFunctionSymbol(cast<Function>(info.symbol));
   else
     addDefinedDataSymbol(info.symbol);
+
+  _symbols.back().attributes &= ~LTO_SYMBOL_SCOPE_MASK;
+  _symbols.back().attributes |= scope;
 }
 
 /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the
@@ -454,6 +464,20 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, bool isFunc) {
   if (entry.getValue().name)
     return;
 
+  StringMap<NameAndAttributes>::value_type &asm_entry =
+    _asm_defines.GetOrCreateValue(name);
+
+  if (asm_entry.getValue().name != 0) {
+    if (isFunc)
+      addDefinedFunctionSymbol(cast<Function>(decl));
+    else
+      addDefinedDataSymbol(decl);
+
+    _symbols.back().attributes &= ~LTO_SYMBOL_SCOPE_MASK;
+    _symbols.back().attributes |= asm_entry.getValue().attributes;
+    return;
+  }
+
   NameAndAttributes info;
 
   info.name = entry.getKey().data();