Patch up omissions in DebugLoc propagation.
[oota-llvm.git] / lib / Target / TargetAsmInfo.cpp
index edbacb3d497ed09c47b20a76b281ad6a802ae22b..d687e2f44cfd7787a2b541d66fe0ade02550f762 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/Function.h"
 #include "llvm/Module.h"
@@ -85,6 +86,7 @@ void TargetAsmInfo::fillDefaultValues() {
   COMMDirective = "\t.comm\t";
   COMMDirectiveTakesAlignment = true;
   HasDotTypeDotSizeDirective = true;
+  HasSingleParameterDotFile = true;
   UsedDirective = 0;
   WeakRefDirective = 0;
   WeakDefDirective = 0;
@@ -98,6 +100,8 @@ void TargetAsmInfo::fillDefaultValues() {
   SupportsDebugInformation = false;
   SupportsExceptionHandling = false;
   DwarfRequiresFrameSection = true;
+  SupportsMacInfoSection = true;
+  NonLocalEHFrameLabel = false;
   GlobalEHDirective = 0;
   SupportsWeakOmittedEHFrame = true;
   DwarfSectionOffsetDirective = 0;
@@ -119,11 +123,8 @@ void TargetAsmInfo::fillDefaultValues() {
   DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
 }
 
-TargetAsmInfo::TargetAsmInfo() {
-  fillDefaultValues();
-}
-
-TargetAsmInfo::TargetAsmInfo(const TargetMachine &TM) {
+TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) 
+  : TM(tm) {
   fillDefaultValues();
 }
 
@@ -170,6 +171,25 @@ static bool isSuitableForBSS(const GlobalVariable *GV) {
   return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
 }
 
+static bool isConstantString(const Constant *C) {
+  // First check: is we have constant array of i8 terminated with zero
+  const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
+  // Check, if initializer is a null-terminated string
+  if (CVA && CVA->isCString())
+    return true;
+
+  // Another possibility: [1 x i8] zeroinitializer
+  if (isa<ConstantAggregateZero>(C)) {
+    if (const ArrayType *Ty = dyn_cast<ArrayType>(C->getType())) {
+      return (Ty->getElementType() == Type::Int8Ty &&
+              Ty->getNumElements() == 1);
+    }
+  }
+
+  return false;
+}
+
+
 SectionKind::Kind
 TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
   // Early exit - functions should be always in text sections.
@@ -191,9 +211,8 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
     if (C->ContainsRelocations())
       return SectionKind::ROData;
     else {
-      const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
       // Check, if initializer is a null-terminated string
-      if (CVA && CVA->isCString())
+      if (isConstantString(C))
         return SectionKind::RODataMergeStr;
       else
         return SectionKind::RODataMergeConst;
@@ -341,6 +360,7 @@ TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
    default:
     assert(0 && "Unknown section kind");
   }
+  return NULL;
 }
 
 const Section*