我正在尝试
但是,我目前的提取方法只复制部分信息,之后我无法重新构建该功能。我主要担心IR Reader抱怨:
error: use of undefined type named 'class.std::allocator'
...
error: use of undefined comdat '$_ZNSt10_Iter_baseIPiLb0EE7_S_baseES0_'
可以通过在提取的IR顶部添加适当的声明(comdat和type)来解决这个问题。
在:
; Function Attrs: noinline nounwind uwtable
define linkonce_odr i64 @_ZNK9__gnu_cxx13new_allocatorIiE8max_sizeEv(%"class.__gnu_cxx::new_allocator"*) #4 comdat align 2 {
ret i64 4611686018427387903
}
在:
%"class.__gnu_cxx::new_allocator" = type { i8 }
$_ZNK9__gnu_cxx13new_allocatorIiE8max_sizeEv = comdat any
; Function Attrs: noinline nounwind uwtable
define linkonce_odr i64 @_ZNK9__gnu_cxx13new_allocatorIiE8max_sizeEv(%"class.__gnu_cxx::new_allocator"*) #4 comdat align 2 {
ret i64 4611686018427387903
}
我目前正在使用以下内容实施步骤1,2,3,4:
#include "llvm/IR/Module.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/SourceMgr.h" // SMDDiagnostic
#include "llvm/Support/MemoryBuffer.h"
using namespace llvm;
...
// A method receives a LLVM::Function& F as its argument
// Steps 1 and 2
std::string IRString;
raw_string_ostream os(IRString);
F.print(os, nullptr);
os.flush();
// IRString has the LLVM IR for the function (currently with the BEFORE version)
// Now it is necessary to read back this IR
// Steps 3 and 4
SMDiagnostic Err;
LLVMContext Context;
std::unique_ptr<llvm::MemoryBuffer> buff =
llvm::MemoryBuffer::getMemBuffer(SU.getIRInfo());
std::unique_ptr<Module> Mod(parseIR(buff->getMemBufferRef(), Err, Context));
if (!Mod) {
Err.print("Reading Problems", errs());
return 1;
}
...
如何自动完成此过程?
答案 0 :(得分:1)
看一下llvm-extract或GVExtraction类(由llvm-extract使用)。