]> granicus.if.org Git - clang/commitdiff
Address review feedback for r228003.
authorAdrian Prantl <aprantl@apple.com>
Tue, 3 Feb 2015 20:00:54 +0000 (20:00 +0000)
committerAdrian Prantl <aprantl@apple.com>
Tue, 3 Feb 2015 20:00:54 +0000 (20:00 +0000)
- use named constructors
- get rid of MarkAsPrologue

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228021 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CGCleanup.cpp
lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h
lib/CodeGen/CGDecl.cpp
lib/CodeGen/CGDeclCXX.cpp
lib/CodeGen/CGException.cpp
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CGStmt.cpp
lib/CodeGen/CGStmtOpenMP.cpp

index ffc6e57b074f0cd1c4879ae3df1e70114e4f913c..968c54ef849388dc20cc9e800bd68cf95bbcd9b7 100644 (file)
@@ -1178,7 +1178,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
     Alloca->setAlignment(Align);
     // Set the DebugLocation to empty, so the store is recognized as a
     // frame setup instruction by llvm::DwarfDebug::beginFunction().
-    ApplyDebugLocation NL(*this, ApplyDebugLocation::MarkAsPrologue);
+    auto NL = ApplyDebugLocation::CreateEmpty(*this);
     Builder.CreateAlignedStore(BlockPointer, Alloca, Align);
     BlockPointerDbgLoc = Alloca;
   }
@@ -1328,11 +1328,10 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) {
                                           nullptr, SC_Static,
                                           false,
                                           false);
-  ApplyDebugLocation NL(*this, ApplyDebugLocation::MarkAsPrologue);
+  auto NL = ApplyDebugLocation::CreateEmpty(*this);
   StartFunction(FD, C.VoidTy, Fn, FI, args);
   // Create a scope with an artificial location for the body of this function.
-  ApplyDebugLocation AL(*this, ApplyDebugLocation::Artificial);
-
+  auto AL = ApplyDebugLocation::CreateArtificial(*this);
   llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
 
   llvm::Value *src = GetAddrOfLocalVar(&srcDecl);
@@ -1500,9 +1499,9 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) {
                                           nullptr, SC_Static,
                                           false, false);
   // Create a scope with an artificial location for the body of this function.
-  ApplyDebugLocation NL(*this, ApplyDebugLocation::MarkAsPrologue);
+  auto NL = ApplyDebugLocation::CreateEmpty(*this);
   StartFunction(FD, C.VoidTy, Fn, FI, args);
-  ApplyDebugLocation AL(*this, ApplyDebugLocation::Artificial);
+  auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
 
index a75a7af453e579f0ae9dcc799ae07120abb8ca34..bda8d8e942c14568df031879545a9b5fdde2309a 100644 (file)
@@ -861,7 +861,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
 
   // Emit the EH cleanup if required.
   if (RequiresEHCleanup) {
-    ApplyDebugLocation AL(*this, ApplyDebugLocation::Artificial, CurEHLocation);
+    auto AL = ApplyDebugLocation::CreateDefaultArtificial(*this, CurEHLocation);
 
     CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
 
index 3fb839369dbece1bf91a602ffd802d24793bd845..de424ba1bb40ba7af46ea3eb501de8d636d7bb64 100644 (file)
@@ -60,18 +60,18 @@ ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF,
 }
 
 ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF,
-                                       bool MarkAsPrologue,
+                                       bool DefaultToEmpty,
                                        SourceLocation TemporaryLocation)
     : CGF(CGF) {
-  init(TemporaryLocation, MarkAsPrologue);
+  init(TemporaryLocation, DefaultToEmpty);
 }
 
 void ApplyDebugLocation::init(SourceLocation TemporaryLocation,
-                              bool MarkAsPrologue) {
+                              bool DefaultToEmpty) {
   if (auto *DI = CGF.getDebugInfo()) {
     OriginalLocation = CGF.Builder.getCurrentDebugLocation();
     if (TemporaryLocation.isInvalid()) {
-      if (MarkAsPrologue)
+      if (DefaultToEmpty)
         CGF.Builder.SetCurrentDebugLocation(llvm::DebugLoc());
       else {
         // Construct a location that has a valid scope, but no line info.
index 2f0c3f51d41d3f78c0183f083ccc25900400d606..1d61d14950e292e1ca64069d0b73973a9cf84863 100644 (file)
@@ -447,22 +447,23 @@ private:
 /// location or preferred location of the specified Expr.
 class ApplyDebugLocation {
 private:
-  void init(SourceLocation TemporaryLocation, bool MarkAsPrologue = false);
+  void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
+  ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
+                     SourceLocation TemporaryLocation);
 
-protected:
   llvm::DebugLoc OriginalLocation;
   CodeGenFunction &CGF;
-
 public:
-  enum { Artificial = false, MarkAsPrologue = true, NoLocation = true };
 
   /// \brief Set the location to the (valid) TemporaryLocation.
   ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
-  /// \brief Apply TemporaryLocation if it is valid, or apply a default
-  /// location: If MarkAsPrologue is true, the IRBuilder will be set to not
-  /// attach debug locations, thus marking the instructions as
-  /// prologue. Otherwise this switches to an artificial debug location that has
-  /// a valid scope, but no line information.
+  ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
+  ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
+
+  ~ApplyDebugLocation();
+
+  /// \brief Apply TemporaryLocation if it is valid. Otherwise switch to an
+  /// artificial debug location that has a valid scope, but no line information.
   ///
   /// Artificial locations are useful when emitting compiler-generated helper
   /// functions that have no source location associated with them. The DWARF
@@ -470,11 +471,32 @@ public:
   /// indicate code that can not be attributed to any source location. Note that
   /// passing an empty SourceLocation to CGDebugInfo::setLocation() will result
   /// in the last valid location being reused.
-  ApplyDebugLocation(CodeGenFunction &CGF, bool MarkAsPrologue,
-                     SourceLocation TemporaryLocation = SourceLocation());
-  ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
-  ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
-  ~ApplyDebugLocation();
+  static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF) {
+    return ApplyDebugLocation(CGF, false, SourceLocation());
+  }
+  /// \brief Apply TemporaryLocation if it is valid. Otherwise switch to an
+  /// artificial debug location that has a valid scope, but no line information.
+  static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF,
+                                             SourceLocation TemporaryLocation) {
+    return ApplyDebugLocation(CGF, false, TemporaryLocation);
+  }
+
+  /// \brief Set the IRBuilder to not attach debug locations.  Note that passing
+  /// an empty SourceLocation to CGDebugInfo::setLocation() will result in the
+  /// last valid location being reused.  Note that all instructions that do not
+  /// have a location at the beginning of a function are counted towards to
+  /// funciton prologue.
+  static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF) {
+    return ApplyDebugLocation(CGF, true, SourceLocation());
+  }
+
+  /// \brief Apply TemporaryLocation if it is valid. Otherwise set the IRBuilder
+  /// to not attach debug locations.
+  static ApplyDebugLocation CreateDefaultEmpty(CodeGenFunction &CGF,
+                                             SourceLocation TemporaryLocation) {
+    return ApplyDebugLocation(CGF, true, TemporaryLocation);
+  }
+
 };
 
 
index bada6ea6511b3f0bf96fc53c8b93105de34123e2..fb72a9a54339ba62a69036252c2bb5da0a269a1d 100644 (file)
@@ -1090,7 +1090,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
   if (emission.wasEmittedAsGlobal()) return;
 
   const VarDecl &D = *emission.Variable;
-  ApplyDebugLocation DL(*this, ApplyDebugLocation::Artificial, D.getLocation());
+  auto DL = ApplyDebugLocation::CreateDefaultArtificial(*this, D.getLocation());
   QualType type = D.getType();
 
   // If this local has an initializer, emit it now.
index 6303db6000e6a1aa5fb40da2fb014f660927497d..0255a92276ecde5fa1db66991c830196931ced83 100644 (file)
@@ -469,11 +469,11 @@ CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
                                            ArrayRef<llvm::Function *> Decls,
                                            llvm::GlobalVariable *Guard) {
   {
-    ApplyDebugLocation NL(*this, ApplyDebugLocation::MarkAsPrologue);
+    auto NL = ApplyDebugLocation::CreateEmpty(*this);
     StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
                   getTypes().arrangeNullaryFunction(), FunctionArgList());
     // Emit an artificial location for this function.
-    ApplyDebugLocation AL(*this, ApplyDebugLocation::Artificial);
+    auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
     llvm::BasicBlock *ExitBlock = nullptr;
     if (Guard) {
@@ -520,11 +520,11 @@ void CodeGenFunction::GenerateCXXGlobalDtorsFunc(llvm::Function *Fn,
                   const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> >
                                                 &DtorsAndObjects) {
   {
-    ApplyDebugLocation NL(*this, ApplyDebugLocation::MarkAsPrologue);
+    auto NL = ApplyDebugLocation::CreateEmpty(*this);
     StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
                   getTypes().arrangeNullaryFunction(), FunctionArgList());
     // Emit an artificial location for this function.
-    ApplyDebugLocation AL(*this, ApplyDebugLocation::Artificial);
+    auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
     // Emit the dtors, in reverse order from construction.
     for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
index 406afb2739d91e59a5e2886c30106b805ee84dd9..28f7449deec827cbc49b7fc646f0ac52bae2f896 100644 (file)
@@ -770,7 +770,7 @@ llvm::BasicBlock *CodeGenFunction::EmitLandingPad() {
 
   // Save the current IR generation state.
   CGBuilderTy::InsertPoint savedIP = Builder.saveAndClearIP();
-  ApplyDebugLocation AL(*this, ApplyDebugLocation::Artificial, CurEHLocation);
+  auto DL = ApplyDebugLocation::CreateDefaultArtificial(*this, CurEHLocation);
 
   const EHPersonality &personality = EHPersonality::get(CGM);
 
index 503f9b171959315d9e2367175257381c66760e3e..49165d550e2e242609fdfa0431baa779c19146d7 100644 (file)
@@ -3043,7 +3043,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
   // Emit an unconditional branch from this block to ContBlock.
   {
     // There is no need to emit line number for unconditional branch.
-    ApplyDebugLocation NL(CGF, ApplyDebugLocation::NoLocation);
+    auto NL = ApplyDebugLocation::CreateEmpty(CGF);
     CGF.EmitBlock(ContBlock);
   }
   // Insert an entry into the phi node for the edge with the value of RHSCond.
index be2ddf673395d596008972849f0e0a9f2578ac01..0d41055bf7ed1b0e469535c2b713e4d6c30168f7 100644 (file)
@@ -565,7 +565,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
   if (const Stmt *Else = S.getElse()) {
     {
       // There is no need to emit line number for an unconditional branch.
-      ApplyDebugLocation NL(*this, ApplyDebugLocation::NoLocation);
+      auto NL = ApplyDebugLocation::CreateEmpty(*this);
       EmitBlock(ElseBlock);
     }
     {
@@ -574,7 +574,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
     }
     {
       // There is no need to emit line number for an unconditional branch.
-      ApplyDebugLocation NL(*this, ApplyDebugLocation::NoLocation);
+      auto NL = ApplyDebugLocation::CreateEmpty(*this);
       EmitBranch(ContBlock);
     }
   }
index 395f6fa69ac1f4cdea8a52b590b739f2b9aa4092..29743282d364eff27de7feb4cb5e9d5ab4d265d3 100644 (file)
@@ -86,13 +86,13 @@ static void EmitOMPIfClause(CodeGenFunction &CGF, const Expr *Cond,
   // Emit the 'else' code if present.
   {
     // There is no need to emit line number for unconditional branch.
-    ApplyDebugLocation NL(CGF, ApplyDebugLocation::NoLocation);
+    auto NL = ApplyDebugLocation::CreateEmpty(CGF);
     CGF.EmitBlock(ElseBlock);
   }
   CodeGen(/*ThenBlock*/ false);
   {
     // There is no need to emit line number for unconditional branch.
-    ApplyDebugLocation NL(CGF, ApplyDebugLocation::NoLocation);
+    auto NL = ApplyDebugLocation::CreateEmpty(CGF);
     CGF.EmitBranch(ContBlock);
   }
   // Emit the continuation block for code after the if.