2015-09-18 74 views
1

我想用Undef值替換指令的所有用法,這是一個我想要刪除的函數調用。用llvm上的Undef值替換要刪除的指令的所有用法?

首先,我聲明我是undef值這樣

UndefValue *undefval; 

,然後我試圖取代我的指令

currentInst->replaceAllUsesWith(undefval); 

currentInst的所有用途是

Instruction* currentInst; 

這是指我當前指令的值。這將導致LLVM產生以下錯誤ANS斷言:

選擇:/home/troulakis/D​​ocuments/LLVM_Project/llvm/llvm/lib/IR/Value.cpp:332:無效LLVM ::值:: replaceAllUsesWith (llvm :: Value *):Assertion`New-> getType()== getType()& &「replaceAllUses使用不同類型的新值的值」失敗。

0 0x160e678 LLVM :: SYS ::的printStackTrace(_IO_FILE *) (在/ usr/local/bin中的/ opt + 0x160e678)1 0x160fbdb (在/ usr/local/bin中的/ opt + 0x160fbdb)2 0x7f7752596340 __restore_rt ( (/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)3 0x7f77515aacc9 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x2fb86)6 0x7f77515a3c32 (/lib/x86_64-linux-gnu/libc.so.6 + 0x2fc32)7 0x15be04f (/ usr/local/bin/opt + 0x15be04f)8 0x7f775136fda7(匿名 命名空間):: MyPass :: runOnFunction(llvm :: Function &) (../../../Release+Asserts/lib/PassRAF.so+0x6da7)9 0x15a1ab4 LLVM :: FPPassManager :: runOnFunction(LLVM ::功能&) (在/ usr/local/bin中的/ opt + 0x15a1ab4)10 0x15a1d3b LLVM :: FPPassManager :: runOnModule(LLVM ::模塊&) (在/ usr/local/bin中的/ opt + 0x15a1d3b)11 0x15a22d7 LLVM ::遺留:: PassManagerImpl ::運行(LLVM ::模塊&) (在/ usr/local/bin中的/ opt + 0x15a22d7)12 0x5af6db主 (在/ usr/local/bin中的/ opt + 0x5af6db)13 0x7f7751595ec5 __libc_start_main (/ LIB/x86_64的-Linux的GNU/libc的。 so.6 + 0x21ec5)14 0x59f559 _start (/ usr/local/bin/opt + 0x59f559)

堆棧轉儲:

  1. 程序參數:選擇-load ../../../Release+Asserts/lib/PassRAF.so - 時間 - 通過-instnamer -PassRAF

  2. 在模塊「'上運行'功能通過管理器'。

  3. 運行通 'R A F' 上函數 '@main'

。/ PassRAF:第15行:7227 Aborted(核心轉儲)

任何想法有什麼不對?我錯誤地聲明瞭undef值?

回答

3

當你這樣寫:

UndefValue *undefval; 

你只是聲明UndefValue類型的指針,而不是存儲在任何事情。相反,您需要使用UndefValue::get工廠函數爲要替換的指令類型獲取UndefValue的實例。類似這樣的:

currentInst->replaceAllUsesWith(UndefValue::get(currentInst->getType())