split scalarization out to its own file.
[oota-llvm.git] / lib / CodeGen / DwarfWriter.cpp
index e6ed8f0bffa544f8539db64daf6bcfa3bd06bd0a..d1f195d55672aea08c5dd8b0aa5c6ee699a628d2 100644 (file)
@@ -968,7 +968,7 @@ public:
   /// EmitFrameMoves - Emit frame instructions to describe the layout of the
   /// frame.
   void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
-                      const std::vector<MachineMove> &Moves) {
+                      const std::vector<MachineMove> &Moves, bool isEH) {
     int stackGrowth =
         Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
           TargetFrameInfo::StackGrowsUp ?
@@ -1010,7 +1010,7 @@ public:
           } else {
             Asm->EmitInt8(DW_CFA_def_cfa);
             Asm->EOL("DW_CFA_def_cfa");
-            Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister()));
+            Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister(), isEH));
             Asm->EOL("Register");
           }
           
@@ -1026,13 +1026,13 @@ public:
         if (Dst.isRegister()) {
           Asm->EmitInt8(DW_CFA_def_cfa_register);
           Asm->EOL("DW_CFA_def_cfa_register");
-          Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getRegister()));
+          Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getRegister(), isEH));
           Asm->EOL("Register");
         } else {
           assert(0 && "Machine move no supported yet.");
         }
       } else {
-        unsigned Reg = RI->getDwarfRegNum(Src.getRegister());
+        unsigned Reg = RI->getDwarfRegNum(Src.getRegister(), isEH);
         int Offset = Dst.getOffset() / stackGrowth;
         
         if (Offset < 0) {
@@ -1340,7 +1340,7 @@ private:
   /// provided.
   void AddAddress(DIE *Die, unsigned Attribute,
                             const MachineLocation &Location) {
-    unsigned Reg = RI->getDwarfRegNum(Location.getRegister());
+    unsigned Reg = RI->getDwarfRegNum(Location.getRegister(), false);
     DIEBlock *Block = new DIEBlock();
     
     if (Location.isRegister()) {
@@ -1971,19 +1971,6 @@ private:
     if (didInitial) return;
     didInitial = true;
     
-    // Print out .file directives to specify files for .loc directives.
-    if (TAI->hasDotLocAndDotFile()) {
-      const UniqueVector<SourceFileInfo> &SourceFiles = MMI->getSourceFiles();
-      const UniqueVector<std::string> &Directories = MMI->getDirectories();
-      for (unsigned i = 1, e = SourceFiles.size(); i <= e; ++i) {
-        sys::Path FullPath(Directories[SourceFiles[i].getDirectoryID()]);
-        bool AppendOk = FullPath.appendComponent(SourceFiles[i].getName());
-        assert(AppendOk && "Could not append filename to directory!");
-        Asm->EmitFile(i, FullPath.toString());
-        Asm->EOL();
-      }
-    }
-
     // Dwarf sections base addresses.
     if (TAI->doesDwarfRequireFrameSection()) {
       Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
@@ -2383,13 +2370,13 @@ private:
     Asm->EOL("CIE Code Alignment Factor");
     Asm->EmitSLEB128Bytes(stackGrowth);
     Asm->EOL("CIE Data Alignment Factor");   
-    Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister()));
+    Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), false));
     Asm->EOL("CIE RA Column");
     
     std::vector<MachineMove> Moves;
     RI->getInitialFrameState(Moves);
 
-    EmitFrameMoves(NULL, 0, Moves);
+    EmitFrameMoves(NULL, 0, Moves, false);
 
     Asm->EmitAlignment(2);
     EmitLabel("debug_frame_common_end", 0);
@@ -2422,7 +2409,7 @@ private:
                    "func_begin", DebugFrameInfo.Number);
     Asm->EOL("FDE address range");
     
-    EmitFrameMoves("func_begin", DebugFrameInfo.Number, DebugFrameInfo.Moves);
+    EmitFrameMoves("func_begin", DebugFrameInfo.Number, DebugFrameInfo.Moves, false);
     
     Asm->EmitAlignment(2);
     EmitLabel("debug_frame_end", DebugFrameInfo.Number);
@@ -2626,9 +2613,6 @@ public:
       MMI = mmi;
       shouldEmit = true;
       
-      // Emit initial sections
-      EmitInitial();
-    
       // Create all the compile unit DIEs.
       ConstructCompileUnitDIEs();
       
@@ -2640,6 +2624,23 @@ public:
       
       // Prime section data.
       SectionMap.insert(TAI->getTextSection());
+
+      // Print out .file directives to specify files for .loc directives. These
+      // are printed out early so that they precede any .loc directives.
+      if (TAI->hasDotLocAndDotFile()) {
+        const UniqueVector<SourceFileInfo> &SourceFiles = MMI->getSourceFiles();
+        const UniqueVector<std::string> &Directories = MMI->getDirectories();
+        for (unsigned i = 1, e = SourceFiles.size(); i <= e; ++i) {
+          sys::Path FullPath(Directories[SourceFiles[i].getDirectoryID()]);
+          bool AppendOk = FullPath.appendComponent(SourceFiles[i].getName());
+          assert(AppendOk && "Could not append filename to directory!");
+          Asm->EmitFile(i, FullPath.toString());
+          Asm->EOL();
+        }
+      }
+
+      // Emit initial sections
+      EmitInitial();
     }
   }
 
@@ -2763,12 +2764,15 @@ private:
     bool hasCalls;
     bool hasLandingPads;
     std::vector<MachineMove> Moves;
+    Function::LinkageTypes linkage;
 
     FunctionEHFrameInfo(const std::string &FN, unsigned Num, unsigned P,
                         bool hC, bool hL,
-                        const std::vector<MachineMove> &M):
+                        const std::vector<MachineMove> &M,
+                        Function::LinkageTypes l):
       FnName(FN), Number(Num), PersonalityIndex(P),
-      hasCalls(hC), hasLandingPads(hL), Moves(M) { }
+      hasCalls(hC), hasLandingPads(hL), Moves(M),
+      linkage(l) { }
   };
 
   std::vector<FunctionEHFrameInfo> EHFrames;
@@ -2816,7 +2820,7 @@ private:
     Asm->EOL("CIE Code Alignment Factor");
     Asm->EmitSLEB128Bytes(stackGrowth);
     Asm->EOL("CIE Data Alignment Factor");   
-    Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister()));
+    Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), true));
     Asm->EOL("CIE RA Column");
     
     // If there is a personality, we need to indicate the functions location.
@@ -2852,7 +2856,7 @@ private:
     // Indicate locations of general callee saved registers in frame.
     std::vector<MachineMove> Moves;
     RI->getInitialFrameState(Moves);
-    EmitFrameMoves(NULL, 0, Moves);
+    EmitFrameMoves(NULL, 0, Moves, true);
 
     Asm->EmitAlignment(2);
     EmitLabel("eh_frame_common_end", Index);
@@ -2866,15 +2870,25 @@ private:
     Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
 
     // Externally visible entry into the functions eh frame info.
-    if (const char *GlobalDirective = TAI->getGlobalDirective())
-      O << GlobalDirective << EHFrameInfo.FnName << "\n";
-    
+    // If the corresponding function is static, this should not be
+    // externally visible.
+    if (EHFrameInfo.linkage != Function::InternalLinkage) {
+      if (const char *GlobalEHDirective = TAI->getGlobalEHDirective())
+        O << GlobalEHDirective << EHFrameInfo.FnName << "\n";
+    }
+
     // If there are no calls then you can't unwind.
     if (!EHFrameInfo.hasCalls) { 
       O << EHFrameInfo.FnName << " = 0\n";
     } else {
       O << EHFrameInfo.FnName << ":\n";
-      
+
+      // If corresponding function is weak definition, this should be too.
+      if ((EHFrameInfo.linkage == Function::WeakLinkage || 
+           EHFrameInfo.linkage == Function::LinkOnceLinkage) &&
+          TAI->getWeakDefDirective())
+        O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n";
+
       // EH frame header.
       EmitDifference("eh_frame_end", EHFrameInfo.Number,
                      "eh_frame_begin", EHFrameInfo.Number, true);
@@ -2914,7 +2928,7 @@ private:
       
       // Indicate locations of function specific  callee saved registers in
       // frame.
-      EmitFrameMoves("eh_func_begin", EHFrameInfo.Number, EHFrameInfo.Moves);
+      EmitFrameMoves("eh_func_begin", EHFrameInfo.Number, EHFrameInfo.Moves, true);
       
       Asm->EmitAlignment(2);
       EmitLabel("eh_frame_end", EHFrameInfo.Number);
@@ -3361,7 +3375,8 @@ public:
                                     MMI->getPersonalityIndex(),
                                     MF->getFrameInfo()->hasCalls(),
                                     !MMI->getLandingPads().empty(),
-                                    MMI->getFrameMoves()));
+                                    MMI->getFrameMoves(),
+                                    MF->getFunction()->getLinkage()));
   }
 };