接続数

COUNTER267933FROM 2012/5/16

MISRA-C diary(C言語日誌)

MISRA-C >> 記事詳細

2017/10/12

initializePromotePassPass link error on "LLVM to understand even by fox" Mochiko Kashiwagi

Tweet ThisSend to Facebook | by kaizen


make

mkdir -p ./obj

clang++ -g ./src/dcc.cpp -I./inc `llvm-config --cxxflags --ldflags --libs -std=c++03  -stdlib=libc++ -Wall -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wnon-virtual-dtor -std=c++11   -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -L/usr/local/Cellar/llvm/3.6.2/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names -lLLVMLTO -lLLVMObjCARCOpts -lLLVMLinker -lLLVMBitWriter -lLLVMIRReader -lLLVMAsmParser -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSystemZAsmPrinter -lLLVMSparcDisassembler -lLLVMSparcCodeGen -lLLVMSparcAsmParser -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMSparcAsmPrinter -lLLVMR600CodeGen -lLLVMipo -lLLVMVectorize -lLLVMR600AsmParser -lLLVMR600Desc -lLLVMR600Info -lLLVMR600AsmPrinter -lLLVMPowerPCDisassembler -lLLVMPowerPCCodeGen -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMSP430AsmPrinter -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMMipsAsmPrinter -lLLVMHexagonDisassembler -lLLVMHexagonCodeGen -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMCppBackendCodeGen -lLLVMCppBackendInfo -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMAArch64Disassembler -lLLVMAArch64CodeGen -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMTableGen -lLLVMDebugInfo -lLLVMOption -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMLineEditor -lLLVMInstrumentation -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMCodeGen -lLLVMScalarOpts -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMCore -lLLVMSupport` -c -o ./obj/dcc.o

usage: llvm-config <OPTION>... [<COMPONENT>...]


Get various configuration information needed to compile programs which use

LLVM.  Typically called from 'configure' scripts.  Examples:

  llvm-config --cxxflags

  llvm-config --ldflags

  llvm-config --libs engine bcreader scalaropts


Options:

  --version         Print LLVM version.

  --prefix          Print the installation prefix.

  --src-root        Print the source root LLVM was built from.

  --obj-root        Print the object root used to build LLVM.

  --bindir          Directory containing LLVM executables.

  --includedir      Directory containing LLVM headers.

  --libdir          Directory containing LLVM libraries.

  --cmakedir        Directory containing LLVM cmake modules.

  --cppflags        C preprocessor flags for files that include LLVM headers.

  --cflags          C compiler flags for files that include LLVM headers.

  --cxxflags        C++ compiler flags for files that include LLVM headers.

  --ldflags         Print Linker flags.

  --system-libs     System Libraries needed to link against LLVM components.

  --libs            Libraries needed to link against LLVM components.

  --libnames        Bare library names for in-tree builds.

  --libfiles        Fully qualified library filenames for makefile depends.

  --components      List of all possible components.

  --targets-built   List of all targets currently built.

  --host-target     Target triple used to configure LLVM.

  --build-mode      Print build mode of LLVM tree (e.g. Debug or Release).

  --assertion-mode  Print assertion mode of LLVM tree (ON or OFF).

  --build-system    Print the build system used to build LLVM (always cmake).

  --has-rtti        Print whether or not LLVM was built with rtti (YES or NO).

  --has-global-isel Print whether or not LLVM was built with global-isel support (ON or OFF).

  --shared-mode     Print how the provided components can be collectively linked (`shared` or `static`).

  --link-shared     Link the components as shared libraries.

  --link-static     Link the component libraries statically.

  --ignore-libllvm  Ignore libLLVM and link component libraries instead.

Typical components:

  all               All LLVM libraries (default).

  engine            Either a native JIT or a bitcode interpreter.

clang: warning: -Wl,-search_paths_first: 'linker' input unused [-Wunused-command-line-argument]

clang: warning: -Wl,-headerpad_max_install_names: 'linker' input unused [-Wunused-command-line-argument]

clang: warning: argument unused during compilation: '-L/usr/local/lib' [-Wunused-command-line-argument]

In file included from ./src/dcc.cpp:13:

./inc/lexer.hpp:31:57: warning: field 'TokenString' will be initialized after field 'Type' [-Wreorder]

  Token(std::string string, TokenType type, int line) : TokenString(string), Type(type), Line(line){

                                                        ^

./inc/lexer.hpp:83:20: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare]

  for(int i = 0; i < Tokens.size(); i++){

                 ~ ^ ~~~~~~~~~~~~~

In file included from ./src/dcc.cpp:14:

./inc/AST.hpp:125:9: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare]

    if(i<Args.size()){

       ~^~~~~~~~~~~~

./inc/AST.hpp:203:10: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare]

    if(i < Params.size()){

       ~ ^ ~~~~~~~~~~~~~

./inc/AST.hpp:227:62: warning: control reaches end of non-void function [-Wreturn-type]

  bool addStatement(BaseAST *stmt){StmtLists.push_back(stmt);};

                                                             ^

./inc/AST.hpp:230:10: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare]

    if(i < VariableDecls.size()){

       ~ ^ ~~~~~~~~~~~~~~~~~~~~

./inc/AST.hpp:239:10: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare]

    if(i < StmtLists.size()){

       ~ ^ ~~~~~~~~~~~~~~~~

./inc/AST.hpp:283:10: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare]

    if(i < Prototypes.size()){

       ~ ^ ~~~~~~~~~~~~~~~~~

./inc/AST.hpp:292:10: warning: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare]

    if(i < Functions.size()){

       ~ ^ ~~~~~~~~~~~~~~~~

./src/dcc.cpp:68:6: error: use of undeclared identifier 'initializePromotePassPass'; did you mean 'initializeLoopPassPass'?

                          initializePromotePassPass(*PassRegistry::getPassRegistry());

                          ^~~~~~~~~~~~~~~~~~~~~~~~~

                          initializeLoopPassPass

/usr/local/include/llvm/InitializePasses.h:208:6: note: 'initializeLoopPassPass' declared here

void initializeLoopPassPass(PassRegistry&);

     ^

./src/dcc.cpp:90:2: error: out-of-line definition of 'initializePromotePassPass' does not match any declaration in namespace 'llvm'; did you mean 'initializeLoopPassPass'?

 INITIALIZE_PASS_END(PromotePass, "mem2reg", "Promote Memory to Register",  false, false)

 ^

/usr/local/include/llvm/PassSupport.h:63:14: note: expanded from macro 'INITIALIZE_PASS_END'

  void llvm::initialize##passName##Pass(PassRegistry &Registry) {              \

             ^

<scratch space>:34:1: note: expanded from here

initializePromotePassPass

^

/usr/local/include/llvm/InitializePasses.h:208:6: note: 'initializeLoopPassPass' declared here

void initializeLoopPassPass(PassRegistry&);

     ^

9 warnings and 2 errors generated.

make: *** [obj/dcc.o] Error 1

KM-S05:DummyC-master administrato
----dcc.cpp

#include "llvm/IR/IRPrintingPasses.h"

#include "llvm/IR/LLVMContext.h"

#include "llvm/IR/Module.h"

#include "llvm/IR/PassManager.h"

#include "llvm/LinkAllPasses.h"

#include "llvm/Support/Debug.h"

#include "llvm/Support/FormattedStream.h"

#include "llvm/Support/PrettyStackTrace.h"

#include "llvm/Support/Signals.h"

#include "llvm/Support/TargetSelect.h"

#include "llvm/Support/raw_ostream.h"

#include <fcntl.h>

#include "lexer.hpp"

#include "AST.hpp"

#include "APP.hpp"

#include "parser.hpp"

#include "codegen.hpp"

#include "option_parser.hpp"


#include "llvm/Transforms/Scalar.h"

#include "llvm/ADT/Statistic.h"

#include "llvm/IR/Dominators.h"

#include "llvm/IR/Function.h"

#include "llvm/IR/Instructions.h"

#include "llvm/Transforms/Utils/PromoteMemToReg.h"

#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"


#include "llvm/InitializePasses.h"

#include "llvm-c/Initialization.h"

#include "llvm/PassRegistry.h"


//===- Mem2Reg.cpp - The -mem2reg pass, a wrapper around the Utils lib ----===//

// http://legup.eecg.utoronto.ca/doxygen-4.0/Mem2Reg_8cpp_source.html

using namespace llvm;


#define DEBUG_TYPE "mem2reg"

 

 STATISTIC(NumPromoted, "Number of alloca's promoted");


namespace {

 struct PromotePass : public FunctionPass {

 static char ID; // Pass identification, replacement for typeid

 PromotePass() : FunctionPass(ID) {

 initializePromotePassPass(*PassRegistry::getPassRegistry());

 }

 

 // runOnFunction - To run this pass, first we calculate the alloca

 // instructions that are safe for promotion, then we promote each one.

 //

 bool runOnFunction(Function &F) override;

 

 void getAnalysisUsage(AnalysisUsage &AU) const override {

 AU.addRequired<DominatorTreeWrapperPass>();

 AU.setPreservesCFG();

 // This is a cluster of orthogonal Transforms

 AU.addPreserved<UnifyFunctionExitNodes>();

 AU.addPreservedID(LowerSwitchID);

 AU.addPreservedID(LowerInvokePassID);

 }

 };

} // end of anonymous namespace

 

 char PromotePass::ID = 0;

 INITIALIZE_PASS_BEGIN(PromotePass, "mem2reg", "Promote Memory to Register",false, false)

 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)

 INITIALIZE_PASS_END(PromotePass, "mem2reg", "Promote Memory to Register",  false, false)

 

bool PromotePass::runOnFunction(Function &F) {

std::vector<AllocaInst*> Allocas;

 BasicBlock &BB = F.getEntryBlock(); // Get the entry node for the function

 

 bool Changed = false;

 

 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();

 

 while (1) {

    Allocas.clear();

 

 // Find allocas that are safe to promote, by looking at all instructions in

 // the entry node

for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I)

 if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) // Is it an alloca?

 if (isAllocaPromotable(AI))

 Allocas.push_back(AI);

 

 if (Allocas.empty()) break;

 

 PromoteMemToReg(Allocas, DT);

 NumPromoted += Allocas.size();

 Changed = true;

 }

 

 return Changed;

 }

 // createPromoteMemoryToRegister - Provide an entry point to create this pass.

 //

FunctionPass *llvm::createPromoteMemoryToRegisterPass() {

return new PromotePass();

}


int main(int argc, char **argv){

  llvm::InitializeNativeTarget();

llvm::sys::PrintStackTraceOnErrorSignal(*argv);///  llvm::sys::PrintStackTraceOnErrorSignal();

llvm::PrettyStackTraceProgram X(argc, argv);

  llvm::EnableDebugBuffering = true;


  OptionParser opt(argc, argv);

  if(!opt.parseOption()){

    exit(1);

  }


  if(opt.getInputFileName().length() == 0){

    fprintf(stderr, "入力ファイル名が設定されていません\n");

    exit(1);

  }


  Parser *parser = new Parser(opt.getInputFileName());

  if(parser->doParse()){

    fprintf(stderr, "error at parser or lexer\n");

    SAFE_DELETE(parser);

    exit(1);

  }


  TranslationUnitAST &tunit = parser->getAST();

  if(tunit.empty()){

    fprintf(stderr, "TranslationUnit is empty\n");

    SAFE_DELETE(parser);

    exit(1);

  }


  CodeGen *codegen = new CodeGen();

  if(!codegen->doCodeGen(tunit, opt.getInputFileName())){

    fprintf(stderr, "error at codegen\n");

    SAFE_DELETE(parser);

    SAFE_DELETE(codegen);

    exit(1);

  }


  llvm::Module &mod = codegen->getModule();

  if(mod.empty()){

    fprintf(stderr, "Module is empty\n");

    SAFE_DELETE(parser);

    SAFE_DELETE(codegen);

    exit(1);

  }



  int fd = open(opt.getOutputFileName().c_str(), O_WRONLY | O_CREAT, S_IWRITE);

  if(fd == -1){

    fprintf(stderr, "output file error\n");

    SAFE_DELETE(parser);

    SAFE_DELETE(codegen);

    exit(1);

  }


  llvm::raw_fd_ostream raw_stream(fd, true);

llvm::PrintModulePass pm(raw_stream);

llvm::ModuleAnalysisManager DummyMAM;/// https://llvm.org/doxygen/IRPrintingPasses_8cpp_source.html#l00045

pm.run(mod, DummyMAM);///  pm.run(mod);

  raw_stream.close();


  SAFE_DELETE(parser);

  SAFE_DELETE(codegen);


  return 0;

}




18:34 | 投票する | 投票数(0) | コメント(0)