[llvm-dev] DICompileUnit duplication in LLVM 4.0.0?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[llvm-dev] DICompileUnit duplication in LLVM 4.0.0?

Gerolf Hoflehner via llvm-dev
All,

I'm seeing duplication of DICompileUnits in a pass that worked in 3.8. I assume I'm doing something wrong. Would someone be willing to point me in the right direction?

The below minimized pass reproduces my issue in 4.0 with the following error:

DICompileUnit not listed in llvm.dbg.cu
!1707 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (tags/RELEASE_400/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !1708)
dsc-opt: /home/moconnor/Source/carte.git/llvm-carte/llvm-4.0.0/llvm/lib/IR/Verifier.cpp:4500: virtual bool {anonymous}::VerifierLegacyPass::doFinalization(llvm::Module&): Assertion `!V->hasBrokenDebugInfo() && "Module contains invalid debug info"' failed.


Pass implementation:

#define DEBUG_TYPE "dupl"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <vector>
using namespace llvm;

struct FunctionDuplication;

namespace llvm {
void initializeFunctionDuplicationPass(PassRegistry &);
}

struct FunctionDuplication : public ModulePass {
  static char ID;
  FunctionDuplication() : ModulePass(ID) {}

  virtual StringRef getPassName() const override {
    return "Duplicate every function";
  }

  virtual void getAnalysisUsage(AnalysisUsage &) const override;

  virtual bool runOnModule(Module &) override;

  Function *duplicate(Module &, Function &Old, FunctionType *NewTy) const;
};

void FunctionDuplication::getAnalysisUsage(AnalysisUsage &AU) const {
  ModulePass::getAnalysisUsage(AU);
}

Function *FunctionDuplication::duplicate(Module &M, Function &Old,
                                         FunctionType *NewTy) const {
  Function *New = Function::Create(NewTy, Old.getLinkage(), "", &M);
  New->setAttributes(Old.getAttributes());
  New->setCallingConv(Old.getCallingConv());

  // Map old arguments to the new arguments.
  ValueToValueMapTy VMap;
  for (auto OldFI = Old.arg_begin(), OldFE = Old.arg_end(),
            NewFI = New->arg_begin();
       OldFI != OldFE; ++OldFI, ++NewFI) {
    Argument &OldA = *OldFI;
    Argument &NewA = *NewFI;
    NewA.setName(OldA.getName());
    VMap[&OldA] = &NewA;
  }

  SmallVector<ReturnInst *, 16> Returns;
  CloneAndPruneFunctionInto(New, &Old, VMap, true, Returns);

  return New;
}

bool FunctionDuplication::runOnModule(Module &M) {
  DataLayout const &DL = M.getDataLayout();
  bool Modified = false;

  std::vector<Function *> Functions;
  for (auto &Fn : M.functions()) {
    Functions.push_back(&Fn);
  }

  for (auto *F : Functions) {
    if (F->size() > 0) {
      dbgs() << "duplicating " << F->getName() << "\n";

      duplicate(M, *F, F->getFunctionType());
      Modified = true;
    }
  }

  return Modified;
}

char FunctionDuplication::ID = 0;
INITIALIZE_PASS(FunctionDuplication, "dupl", "Duplicate every function", false,
                false)
ModulePass *createFunctionDuplicationPass(void) {
  return new FunctionDuplication();
}


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] DICompileUnit duplication in LLVM 4.0.0?

Gerolf Hoflehner via llvm-dev
There have in the past been bugs in the cloner involving duplicate DICompileUnits (see e.g. https://reviews.llvm.org/D29240), this one may need a similar fix.

Peter

On Thu, Jun 8, 2017 at 3:07 PM, Matthew O'Connor via llvm-dev <[hidden email]> wrote:
All,

I'm seeing duplication of DICompileUnits in a pass that worked in 3.8. I assume I'm doing something wrong. Would someone be willing to point me in the right direction?

The below minimized pass reproduces my issue in 4.0 with the following error:

DICompileUnit not listed in llvm.dbg.cu
!1707 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (tags/RELEASE_400/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !1708)
dsc-opt: /home/moconnor/Source/carte.git/llvm-carte/llvm-4.0.0/llvm/lib/IR/Verifier.cpp:4500: virtual bool {anonymous}::VerifierLegacyPass::doFinalization(llvm::Module&): Assertion `!V->hasBrokenDebugInfo() && "Module contains invalid debug info"' failed.


Pass implementation:

#define DEBUG_TYPE "dupl"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <vector>
using namespace llvm;

struct FunctionDuplication;

namespace llvm {
void initializeFunctionDuplicationPass(PassRegistry &);
}

struct FunctionDuplication : public ModulePass {
  static char ID;
  FunctionDuplication() : ModulePass(ID) {}

  virtual StringRef getPassName() const override {
    return "Duplicate every function";
  }

  virtual void getAnalysisUsage(AnalysisUsage &) const override;

  virtual bool runOnModule(Module &) override;

  Function *duplicate(Module &, Function &Old, FunctionType *NewTy) const;
};

void FunctionDuplication::getAnalysisUsage(AnalysisUsage &AU) const {
  ModulePass::getAnalysisUsage(AU);
}

Function *FunctionDuplication::duplicate(Module &M, Function &Old,
                                         FunctionType *NewTy) const {
  Function *New = Function::Create(NewTy, Old.getLinkage(), "", &M);
  New->setAttributes(Old.getAttributes());
  New->setCallingConv(Old.getCallingConv());

  // Map old arguments to the new arguments.
  ValueToValueMapTy VMap;
  for (auto OldFI = Old.arg_begin(), OldFE = Old.arg_end(),
            NewFI = New->arg_begin();
       OldFI != OldFE; ++OldFI, ++NewFI) {
    Argument &OldA = *OldFI;
    Argument &NewA = *NewFI;
    NewA.setName(OldA.getName());
    VMap[&OldA] = &NewA;
  }

  SmallVector<ReturnInst *, 16> Returns;
  CloneAndPruneFunctionInto(New, &Old, VMap, true, Returns);

  return New;
}

bool FunctionDuplication::runOnModule(Module &M) {
  DataLayout const &DL = M.getDataLayout();
  bool Modified = false;

  std::vector<Function *> Functions;
  for (auto &Fn : M.functions()) {
    Functions.push_back(&Fn);
  }

  for (auto *F : Functions) {
    if (F->size() > 0) {
      dbgs() << "duplicating " << F->getName() << "\n";

      duplicate(M, *F, F->getFunctionType());
      Modified = true;
    }
  }

  return Modified;
}

char FunctionDuplication::ID = 0;
INITIALIZE_PASS(FunctionDuplication, "dupl", "Duplicate every function", false,
                false)
ModulePass *createFunctionDuplicationPass(void) {
  return new FunctionDuplication();
}


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev




--
-- 
Peter

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] DICompileUnit duplication in LLVM 4.0.0?

Gerolf Hoflehner via llvm-dev
Thank you. What I need to do to address this? Open an issue on bugs.llvm.org? I'm not sure what the fix needs to be in the cloner.

On Thu, Jun 8, 2017 at 4:19 PM, Peter Collingbourne <[hidden email]> wrote:
There have in the past been bugs in the cloner involving duplicate DICompileUnits (see e.g. https://reviews.llvm.org/D29240), this one may need a similar fix.

Peter

On Thu, Jun 8, 2017 at 3:07 PM, Matthew O'Connor via llvm-dev <[hidden email]> wrote:
All,

I'm seeing duplication of DICompileUnits in a pass that worked in 3.8. I assume I'm doing something wrong. Would someone be willing to point me in the right direction?

The below minimized pass reproduces my issue in 4.0 with the following error:

DICompileUnit not listed in llvm.dbg.cu
!1707 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (tags/RELEASE_400/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !1708)
dsc-opt: /home/moconnor/Source/carte.git/llvm-carte/llvm-4.0.0/llvm/lib/IR/Verifier.cpp:4500: virtual bool {anonymous}::VerifierLegacyPass::doFinalization(llvm::Module&): Assertion `!V->hasBrokenDebugInfo() && "Module contains invalid debug info"' failed.


Pass implementation:

#define DEBUG_TYPE "dupl"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <vector>
using namespace llvm;

struct FunctionDuplication;

namespace llvm {
void initializeFunctionDuplicationPass(PassRegistry &);
}

struct FunctionDuplication : public ModulePass {
  static char ID;
  FunctionDuplication() : ModulePass(ID) {}

  virtual StringRef getPassName() const override {
    return "Duplicate every function";
  }

  virtual void getAnalysisUsage(AnalysisUsage &) const override;

  virtual bool runOnModule(Module &) override;

  Function *duplicate(Module &, Function &Old, FunctionType *NewTy) const;
};

void FunctionDuplication::getAnalysisUsage(AnalysisUsage &AU) const {
  ModulePass::getAnalysisUsage(AU);
}

Function *FunctionDuplication::duplicate(Module &M, Function &Old,
                                         FunctionType *NewTy) const {
  Function *New = Function::Create(NewTy, Old.getLinkage(), "", &M);
  New->setAttributes(Old.getAttributes());
  New->setCallingConv(Old.getCallingConv());

  // Map old arguments to the new arguments.
  ValueToValueMapTy VMap;
  for (auto OldFI = Old.arg_begin(), OldFE = Old.arg_end(),
            NewFI = New->arg_begin();
       OldFI != OldFE; ++OldFI, ++NewFI) {
    Argument &OldA = *OldFI;
    Argument &NewA = *NewFI;
    NewA.setName(OldA.getName());
    VMap[&OldA] = &NewA;
  }

  SmallVector<ReturnInst *, 16> Returns;
  CloneAndPruneFunctionInto(New, &Old, VMap, true, Returns);

  return New;
}

bool FunctionDuplication::runOnModule(Module &M) {
  DataLayout const &DL = M.getDataLayout();
  bool Modified = false;

  std::vector<Function *> Functions;
  for (auto &Fn : M.functions()) {
    Functions.push_back(&Fn);
  }

  for (auto *F : Functions) {
    if (F->size() > 0) {
      dbgs() << "duplicating " << F->getName() << "\n";

      duplicate(M, *F, F->getFunctionType());
      Modified = true;
    }
  }

  return Modified;
}

char FunctionDuplication::ID = 0;
INITIALIZE_PASS(FunctionDuplication, "dupl", "Duplicate every function", false,
                false)
ModulePass *createFunctionDuplicationPass(void) {
  return new FunctionDuplication();
}


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev




--
-- 
Peter


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] DICompileUnit duplication in LLVM 4.0.0?

Gerolf Hoflehner via llvm-dev
+ Adrian to take a look

On Thu, Jun 8, 2017 at 4:06 PM Matthew O'Connor via llvm-dev <[hidden email]> wrote:
Thank you. What I need to do to address this? Open an issue on bugs.llvm.org? I'm not sure what the fix needs to be in the cloner.

On Thu, Jun 8, 2017 at 4:19 PM, Peter Collingbourne <[hidden email]> wrote:
There have in the past been bugs in the cloner involving duplicate DICompileUnits (see e.g. https://reviews.llvm.org/D29240), this one may need a similar fix.

Peter

On Thu, Jun 8, 2017 at 3:07 PM, Matthew O'Connor via llvm-dev <[hidden email]> wrote:
All,

I'm seeing duplication of DICompileUnits in a pass that worked in 3.8. I assume I'm doing something wrong. Would someone be willing to point me in the right direction?

The below minimized pass reproduces my issue in 4.0 with the following error:

DICompileUnit not listed in llvm.dbg.cu
!1707 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (tags/RELEASE_400/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !1708)
dsc-opt: /home/moconnor/Source/carte.git/llvm-carte/llvm-4.0.0/llvm/lib/IR/Verifier.cpp:4500: virtual bool {anonymous}::VerifierLegacyPass::doFinalization(llvm::Module&): Assertion `!V->hasBrokenDebugInfo() && "Module contains invalid debug info"' failed.


Pass implementation:

#define DEBUG_TYPE "dupl"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <vector>
using namespace llvm;

struct FunctionDuplication;

namespace llvm {
void initializeFunctionDuplicationPass(PassRegistry &);
}

struct FunctionDuplication : public ModulePass {
  static char ID;
  FunctionDuplication() : ModulePass(ID) {}

  virtual StringRef getPassName() const override {
    return "Duplicate every function";
  }

  virtual void getAnalysisUsage(AnalysisUsage &) const override;

  virtual bool runOnModule(Module &) override;

  Function *duplicate(Module &, Function &Old, FunctionType *NewTy) const;
};

void FunctionDuplication::getAnalysisUsage(AnalysisUsage &AU) const {
  ModulePass::getAnalysisUsage(AU);
}

Function *FunctionDuplication::duplicate(Module &M, Function &Old,
                                         FunctionType *NewTy) const {
  Function *New = Function::Create(NewTy, Old.getLinkage(), "", &M);
  New->setAttributes(Old.getAttributes());
  New->setCallingConv(Old.getCallingConv());

  // Map old arguments to the new arguments.
  ValueToValueMapTy VMap;
  for (auto OldFI = Old.arg_begin(), OldFE = Old.arg_end(),
            NewFI = New->arg_begin();
       OldFI != OldFE; ++OldFI, ++NewFI) {
    Argument &OldA = *OldFI;
    Argument &NewA = *NewFI;
    NewA.setName(OldA.getName());
    VMap[&OldA] = &NewA;
  }

  SmallVector<ReturnInst *, 16> Returns;
  CloneAndPruneFunctionInto(New, &Old, VMap, true, Returns);

  return New;
}

bool FunctionDuplication::runOnModule(Module &M) {
  DataLayout const &DL = M.getDataLayout();
  bool Modified = false;

  std::vector<Function *> Functions;
  for (auto &Fn : M.functions()) {
    Functions.push_back(&Fn);
  }

  for (auto *F : Functions) {
    if (F->size() > 0) {
      dbgs() << "duplicating " << F->getName() << "\n";

      duplicate(M, *F, F->getFunctionType());
      Modified = true;
    }
  }

  return Modified;
}

char FunctionDuplication::ID = 0;
INITIALIZE_PASS(FunctionDuplication, "dupl", "Duplicate every function", false,
                false)
ModulePass *createFunctionDuplicationPass(void) {
  return new FunctionDuplication();
}


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev




--
-- 
Peter

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] DICompileUnit duplication in LLVM 4.0.0?

Gerolf Hoflehner via llvm-dev
I'll certainly take a look (but note that I'm at WWDC this week and may not get to this until Monday-ish).

-- adrian
On Jun 9, 2017, at 10:29 AM, David Blaikie <[hidden email]> wrote:

+ Adrian to take a look

On Thu, Jun 8, 2017 at 4:06 PM Matthew O'Connor via llvm-dev <[hidden email]> wrote:
Thank you. What I need to do to address this? Open an issue on bugs.llvm.org? I'm not sure what the fix needs to be in the cloner.

On Thu, Jun 8, 2017 at 4:19 PM, Peter Collingbourne <[hidden email]> wrote:
There have in the past been bugs in the cloner involving duplicate DICompileUnits (see e.g. https://reviews.llvm.org/D29240), this one may need a similar fix.

Peter

On Thu, Jun 8, 2017 at 3:07 PM, Matthew O'Connor via llvm-dev <[hidden email]> wrote:
All,

I'm seeing duplication of DICompileUnits in a pass that worked in 3.8. I assume I'm doing something wrong. Would someone be willing to point me in the right direction?

The below minimized pass reproduces my issue in 4.0 with the following error:

DICompileUnit not listed in llvm.dbg.cu
!1707 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (tags/RELEASE_400/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !1708)
dsc-opt: /home/moconnor/Source/carte.git/llvm-carte/llvm-4.0.0/llvm/lib/IR/Verifier.cpp:4500: virtual bool {anonymous}::VerifierLegacyPass::doFinalization(llvm::Module&): Assertion `!V->hasBrokenDebugInfo() && "Module contains invalid debug info"' failed.


Pass implementation:

#define DEBUG_TYPE "dupl"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <vector>
using namespace llvm;

struct FunctionDuplication;

namespace llvm {
void initializeFunctionDuplicationPass(PassRegistry &);
}

struct FunctionDuplication : public ModulePass {
  static char ID;
  FunctionDuplication() : ModulePass(ID) {}

  virtual StringRef getPassName() const override {
    return "Duplicate every function";
  }

  virtual void getAnalysisUsage(AnalysisUsage &) const override;

  virtual bool runOnModule(Module &) override;

  Function *duplicate(Module &, Function &Old, FunctionType *NewTy) const;
};

void FunctionDuplication::getAnalysisUsage(AnalysisUsage &AU) const {
  ModulePass::getAnalysisUsage(AU);
}

Function *FunctionDuplication::duplicate(Module &M, Function &Old,
                                         FunctionType *NewTy) const {
  Function *New = Function::Create(NewTy, Old.getLinkage(), "", &M);
  New->setAttributes(Old.getAttributes());
  New->setCallingConv(Old.getCallingConv());

  // Map old arguments to the new arguments.
  ValueToValueMapTy VMap;
  for (auto OldFI = Old.arg_begin(), OldFE = Old.arg_end(),
            NewFI = New->arg_begin();
       OldFI != OldFE; ++OldFI, ++NewFI) {
    Argument &OldA = *OldFI;
    Argument &NewA = *NewFI;
    NewA.setName(OldA.getName());
    VMap[&OldA] = &NewA;
  }

  SmallVector<ReturnInst *, 16> Returns;
  CloneAndPruneFunctionInto(New, &Old, VMap, true, Returns);

  return New;
}

bool FunctionDuplication::runOnModule(Module &M) {
  DataLayout const &DL = M.getDataLayout();
  bool Modified = false;

  std::vector<Function *> Functions;
  for (auto &Fn : M.functions()) {
    Functions.push_back(&Fn);
  }

  for (auto *F : Functions) {
    if (F->size() > 0) {
      dbgs() << "duplicating " << F->getName() << "\n";

      duplicate(M, *F, F->getFunctionType());
      Modified = true;
    }
  }

  return Modified;
}

char FunctionDuplication::ID = 0;
INITIALIZE_PASS(FunctionDuplication, "dupl", "Duplicate every function", false,
                false)
ModulePass *createFunctionDuplicationPass(void) {
  return new FunctionDuplication();
}


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev




--
-- 
Peter

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] DICompileUnit duplication in LLVM 4.0.0?

Gerolf Hoflehner via llvm-dev
In reply to this post by Gerolf Hoflehner via llvm-dev
I see that you are using the clang 4.0 release branch. Does this also reproduce with the current LLVM trunk? We had a lot of churn in the debug info handling in the function cloner in the last couple of weeks.

-- adrian

On Jun 8, 2017, at 3:07 PM, Matthew O'Connor via llvm-dev <[hidden email]> wrote:

All,

I'm seeing duplication of DICompileUnits in a pass that worked in 3.8. I assume I'm doing something wrong. Would someone be willing to point me in the right direction?

The below minimized pass reproduces my issue in 4.0 with the following error:

DICompileUnit not listed in llvm.dbg.cu
!1707 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (tags/RELEASE_400/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !1708)
dsc-opt: /home/moconnor/Source/carte.git/llvm-carte/llvm-4.0.0/llvm/lib/IR/Verifier.cpp:4500: virtual bool {anonymous}::VerifierLegacyPass::doFinalization(llvm::Module&): Assertion `!V->hasBrokenDebugInfo() && "Module contains invalid debug info"' failed.


Pass implementation:

#define DEBUG_TYPE "dupl"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <vector>
using namespace llvm;

struct FunctionDuplication;

namespace llvm {
void initializeFunctionDuplicationPass(PassRegistry &);
}

struct FunctionDuplication : public ModulePass {
  static char ID;
  FunctionDuplication() : ModulePass(ID) {}

  virtual StringRef getPassName() const override {
    return "Duplicate every function";
  }

  virtual void getAnalysisUsage(AnalysisUsage &) const override;

  virtual bool runOnModule(Module &) override;

  Function *duplicate(Module &, Function &Old, FunctionType *NewTy) const;
};

void FunctionDuplication::getAnalysisUsage(AnalysisUsage &AU) const {
  ModulePass::getAnalysisUsage(AU);
}

Function *FunctionDuplication::duplicate(Module &M, Function &Old,
                                         FunctionType *NewTy) const {
  Function *New = Function::Create(NewTy, Old.getLinkage(), "", &M);
  New->setAttributes(Old.getAttributes());
  New->setCallingConv(Old.getCallingConv());

  // Map old arguments to the new arguments.
  ValueToValueMapTy VMap;
  for (auto OldFI = Old.arg_begin(), OldFE = Old.arg_end(),
            NewFI = New->arg_begin();
       OldFI != OldFE; ++OldFI, ++NewFI) {
    Argument &OldA = *OldFI;
    Argument &NewA = *NewFI;
    NewA.setName(OldA.getName());
    VMap[&OldA] = &NewA;
  }

  SmallVector<ReturnInst *, 16> Returns;
  CloneAndPruneFunctionInto(New, &Old, VMap, true, Returns);

  return New;
}

bool FunctionDuplication::runOnModule(Module &M) {
  DataLayout const &DL = M.getDataLayout();
  bool Modified = false;

  std::vector<Function *> Functions;
  for (auto &Fn : M.functions()) {
    Functions.push_back(&Fn);
  }

  for (auto *F : Functions) {
    if (F->size() > 0) {
      dbgs() << "duplicating " << F->getName() << "\n";

      duplicate(M, *F, F->getFunctionType());
      Modified = true;
    }
  }

  return Modified;
}

char FunctionDuplication::ID = 0;
INITIALIZE_PASS(FunctionDuplication, "dupl", "Duplicate every function", false,
                false)
ModulePass *createFunctionDuplicationPass(void) {
  return new FunctionDuplication();
}

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] DICompileUnit duplication in LLVM 4.0.0?

Gerolf Hoflehner via llvm-dev
I will have to get back to you on that. The APIs have changed enough in LLVM trunk that it will take me a bit to do the upgrade.

On Mon, Jun 12, 2017 at 10:53 AM, Adrian Prantl <[hidden email]> wrote:
I see that you are using the clang 4.0 release branch. Does this also reproduce with the current LLVM trunk? We had a lot of churn in the debug info handling in the function cloner in the last couple of weeks.

-- adrian

On Jun 8, 2017, at 3:07 PM, Matthew O'Connor via llvm-dev <[hidden email]> wrote:

All,

I'm seeing duplication of DICompileUnits in a pass that worked in 3.8. I assume I'm doing something wrong. Would someone be willing to point me in the right direction?

The below minimized pass reproduces my issue in 4.0 with the following error:

DICompileUnit not listed in llvm.dbg.cu
!1707 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (tags/RELEASE_400/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !1708)
dsc-opt: /home/moconnor/Source/carte.git/llvm-carte/llvm-4.0.0/llvm/lib/IR/Verifier.cpp:4500: virtual bool {anonymous}::VerifierLegacyPass::doFinalization(llvm::Module&): Assertion `!V->hasBrokenDebugInfo() && "Module contains invalid debug info"' failed.


Pass implementation:

#define DEBUG_TYPE "dupl"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <vector>
using namespace llvm;

struct FunctionDuplication;

namespace llvm {
void initializeFunctionDuplicationPass(PassRegistry &);
}

struct FunctionDuplication : public ModulePass {
  static char ID;
  FunctionDuplication() : ModulePass(ID) {}

  virtual StringRef getPassName() const override {
    return "Duplicate every function";
  }

  virtual void getAnalysisUsage(AnalysisUsage &) const override;

  virtual bool runOnModule(Module &) override;

  Function *duplicate(Module &, Function &Old, FunctionType *NewTy) const;
};

void FunctionDuplication::getAnalysisUsage(AnalysisUsage &AU) const {
  ModulePass::getAnalysisUsage(AU);
}

Function *FunctionDuplication::duplicate(Module &M, Function &Old,
                                         FunctionType *NewTy) const {
  Function *New = Function::Create(NewTy, Old.getLinkage(), "", &M);
  New->setAttributes(Old.getAttributes());
  New->setCallingConv(Old.getCallingConv());

  // Map old arguments to the new arguments.
  ValueToValueMapTy VMap;
  for (auto OldFI = Old.arg_begin(), OldFE = Old.arg_end(),
            NewFI = New->arg_begin();
       OldFI != OldFE; ++OldFI, ++NewFI) {
    Argument &OldA = *OldFI;
    Argument &NewA = *NewFI;
    NewA.setName(OldA.getName());
    VMap[&OldA] = &NewA;
  }

  SmallVector<ReturnInst *, 16> Returns;
  CloneAndPruneFunctionInto(New, &Old, VMap, true, Returns);

  return New;
}

bool FunctionDuplication::runOnModule(Module &M) {
  DataLayout const &DL = M.getDataLayout();
  bool Modified = false;

  std::vector<Function *> Functions;
  for (auto &Fn : M.functions()) {
    Functions.push_back(&Fn);
  }

  for (auto *F : Functions) {
    if (F->size() > 0) {
      dbgs() << "duplicating " << F->getName() << "\n";

      duplicate(M, *F, F->getFunctionType());
      Modified = true;
    }
  }

  return Modified;
}

char FunctionDuplication::ID = 0;
INITIALIZE_PASS(FunctionDuplication, "dupl", "Duplicate every function", false,
                false)
ModulePass *createFunctionDuplicationPass(void) {
  return new FunctionDuplication();
}

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] DICompileUnit duplication in LLVM 4.0.0?

Gerolf Hoflehner via llvm-dev
I am still seeing the same error with trunk.

On Tue, Jun 13, 2017 at 11:28 AM, Matthew O'Connor <[hidden email]> wrote:
I will have to get back to you on that. The APIs have changed enough in LLVM trunk that it will take me a bit to do the upgrade.

On Mon, Jun 12, 2017 at 10:53 AM, Adrian Prantl <[hidden email]> wrote:
I see that you are using the clang 4.0 release branch. Does this also reproduce with the current LLVM trunk? We had a lot of churn in the debug info handling in the function cloner in the last couple of weeks.

-- adrian

On Jun 8, 2017, at 3:07 PM, Matthew O'Connor via llvm-dev <[hidden email]> wrote:

All,

I'm seeing duplication of DICompileUnits in a pass that worked in 3.8. I assume I'm doing something wrong. Would someone be willing to point me in the right direction?

The below minimized pass reproduces my issue in 4.0 with the following error:

DICompileUnit not listed in llvm.dbg.cu
!1707 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (tags/RELEASE_400/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !1708)
dsc-opt: /home/moconnor/Source/carte.git/llvm-carte/llvm-4.0.0/llvm/lib/IR/Verifier.cpp:4500: virtual bool {anonymous}::VerifierLegacyPass::doFinalization(llvm::Module&): Assertion `!V->hasBrokenDebugInfo() && "Module contains invalid debug info"' failed.


Pass implementation:

#define DEBUG_TYPE "dupl"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <vector>
using namespace llvm;

struct FunctionDuplication;

namespace llvm {
void initializeFunctionDuplicationPass(PassRegistry &);
}

struct FunctionDuplication : public ModulePass {
  static char ID;
  FunctionDuplication() : ModulePass(ID) {}

  virtual StringRef getPassName() const override {
    return "Duplicate every function";
  }

  virtual void getAnalysisUsage(AnalysisUsage &) const override;

  virtual bool runOnModule(Module &) override;

  Function *duplicate(Module &, Function &Old, FunctionType *NewTy) const;
};

void FunctionDuplication::getAnalysisUsage(AnalysisUsage &AU) const {
  ModulePass::getAnalysisUsage(AU);
}

Function *FunctionDuplication::duplicate(Module &M, Function &Old,
                                         FunctionType *NewTy) const {
  Function *New = Function::Create(NewTy, Old.getLinkage(), "", &M);
  New->setAttributes(Old.getAttributes());
  New->setCallingConv(Old.getCallingConv());

  // Map old arguments to the new arguments.
  ValueToValueMapTy VMap;
  for (auto OldFI = Old.arg_begin(), OldFE = Old.arg_end(),
            NewFI = New->arg_begin();
       OldFI != OldFE; ++OldFI, ++NewFI) {
    Argument &OldA = *OldFI;
    Argument &NewA = *NewFI;
    NewA.setName(OldA.getName());
    VMap[&OldA] = &NewA;
  }

  SmallVector<ReturnInst *, 16> Returns;
  CloneAndPruneFunctionInto(New, &Old, VMap, true, Returns);

  return New;
}

bool FunctionDuplication::runOnModule(Module &M) {
  DataLayout const &DL = M.getDataLayout();
  bool Modified = false;

  std::vector<Function *> Functions;
  for (auto &Fn : M.functions()) {
    Functions.push_back(&Fn);
  }

  for (auto *F : Functions) {
    if (F->size() > 0) {
      dbgs() << "duplicating " << F->getName() << "\n";

      duplicate(M, *F, F->getFunctionType());
      Modified = true;
    }
  }

  return Modified;
}

char FunctionDuplication::ID = 0;
INITIALIZE_PASS(FunctionDuplication, "dupl", "Duplicate every function", false,
                false)
ModulePass *createFunctionDuplicationPass(void) {
  return new FunctionDuplication();
}

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev




_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Loading...