IRHelpers: turn some functions into IRBuilder::*

This commit is contained in:
Alessandro Di Federico
2026-06-17 10:30:08 +02:00
parent 63734b7ca0
commit 903617e79e
56 changed files with 154 additions and 117 deletions
@@ -24,6 +24,7 @@
#include "revng/Model/LoadModelPass.h"
#include "revng/Model/ProgramCounterHandler.h"
#include "revng/Support/BlockType.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
// Forward declarations
@@ -10,6 +10,7 @@
#include "revng/EarlyFunctionAnalysis/Outliner.h"
#include "revng/EarlyFunctionAnalysis/TemporaryOpaqueFunction.h"
#include "revng/Model/Binary.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/OpaqueFunctionsPool.h"
#include "revng/Support/OpaqueRegisterUser.h"
@@ -7,6 +7,7 @@
#include <set>
#include "revng/EarlyFunctionAnalysis/AnalyzeRegisterUsage.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/MetaAddress.h"
namespace revng {
@@ -4,6 +4,7 @@
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "revng/Support/IRBuilder.h"
#include "revng/Support/OpaqueFunctionsPool.h"
namespace revng {
+1 -1
View File
@@ -95,7 +95,7 @@ public:
Builder.CreateStore(Undef, V);
}
return createLoadVariable(Builder, V);
return Builder.createLoadVariable(V);
}
/// Get or create the LLVM value associated to a PTC temporary
+6 -9
View File
@@ -9,12 +9,9 @@
#include "revng/Model/Architecture.h"
#include "revng/Support/BlockType.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
namespace revng {
class IRBuilder;
} // namespace revng
inline llvm::IntegerType *getCSVType(llvm::GlobalVariable *CSV) {
using namespace llvm;
return cast<IntegerType>(CSV->getValueType());
@@ -156,7 +153,7 @@ public:
// Load and re-store each CSV affecting the PC and then feed them to
// handleStore
for (GlobalVariable *CSVAffectingPC : CSVsAffectingPC) {
auto *FakeLoad = createLoad(Builder, CSVAffectingPC);
auto *FakeLoad = Builder.createLoad(CSVAffectingPC);
auto *FakeStore = Builder.CreateStore(FakeLoad, CSVAffectingPC);
bool HasInjectedCode = handleStore(Builder, FakeStore);
eraseFromParent(FakeStore);
@@ -183,10 +180,10 @@ public:
llvm::Instruction *composeIntegerPC(revng::IRBuilder &B) const {
return MetaAddress::composeIntegerPC(B,
align(B, createLoad(B, AddressCSV)),
createLoad(B, EpochCSV),
createLoad(B, AddressSpaceCSV),
createLoad(B, TypeCSV));
align(B, B.createLoad(AddressCSV)),
B.createLoad(EpochCSV),
B.createLoad(AddressSpaceCSV),
B.createLoad(TypeCSV));
}
bool isPCSizedType(llvm::Type *T) const {
+45 -9
View File
@@ -4,9 +4,12 @@
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
@@ -14,15 +17,7 @@
#include "revng/Support/Assert.h"
#include "revng/Support/Debug.h"
inline llvm::Type *getVariableType(const llvm::Value *Variable) {
if (auto *Alloca = llvm::dyn_cast<llvm::AllocaInst>(Variable))
return Alloca->getAllocatedType();
else if (auto *GV = llvm::dyn_cast<llvm::GlobalVariable>(Variable))
return GV->getValueType();
else
revng_abort("Either GlobalVariable or AllocaInst expected");
}
#include "revng/Support/IRHelpers.h"
namespace revng {
@@ -183,6 +178,47 @@ public:
return CreateStore(V, Variable);
}
llvm::LoadInst *createLoad(llvm::GlobalVariable *GV) {
return this->CreateLoad(GV->getValueType(), GV);
}
llvm::LoadInst *createLoad(llvm::AllocaInst *Alloca) {
return this->CreateLoad(Alloca->getAllocatedType(), Alloca);
}
llvm::LoadInst *createLoadVariable(llvm::Value *Variable) {
if (auto *Alloca = llvm::dyn_cast<llvm::AllocaInst>(Variable))
return createLoad(Alloca);
if (auto *GV = llvm::dyn_cast<llvm::GlobalVariable>(Variable))
return createLoad(GV);
revng_abort("Either GlobalVariable or AllocaInst expected");
}
void setInsertPointToFirstNonAlloca(llvm::Function &F) {
using namespace llvm;
for (Instruction &I : F.getEntryBlock()) {
if (not isa<AllocaInst>(&I)) {
SetInsertPoint(&I);
return;
}
}
revng_abort();
}
llvm::SmallVector<llvm::Value *, 4> unpack(llvm::Value *V) {
using namespace llvm;
Type *T = V->getType();
if (isa<IntegerType>(T))
return { V };
if (auto *ST = dyn_cast<StructType>(T)) {
SmallVector<Value *, 4> Result;
for (unsigned I = 0; I < ST->getNumElements(); ++I)
Result.push_back(this->CreateExtractValue(V, { I }));
return Result;
}
revng_abort("Cannot unpack the given type");
}
protected:
// NOLINTNEXTLINE
explicit IRBuilder(bool EnableDebugInformationChecks, llvm::LLVMContext &C) :
+7 -49
View File
@@ -31,7 +31,6 @@
#include "revng/Support/BasicBlockID.h"
#include "revng/Support/Debug.h"
#include "revng/Support/Generator.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/MetaAddress.h"
class ProgramCounterHandler;
@@ -1443,18 +1442,13 @@ inline void setPointersMetadata(Value *V,
QMD.tuple(PointerOperandsMD) }));
}
inline void setInsertPointToFirstNonAlloca(revng::IRBuilder &Builder,
llvm::Function &F) {
using namespace llvm;
BasicBlock &Entry = F.getEntryBlock();
for (Instruction &I : Entry) {
if (not isa<AllocaInst>(&I)) {
Builder.SetInsertPoint(&I);
return;
}
}
revng_abort();
inline llvm::Type *getVariableType(const llvm::Value *Variable) {
if (auto *Alloca = llvm::dyn_cast<llvm::AllocaInst>(Variable))
return Alloca->getAllocatedType();
else if (auto *GV = llvm::dyn_cast<llvm::GlobalVariable>(Variable))
return GV->getValueType();
else
revng_abort("Either GlobalVariable or AllocaInst expected");
}
inline llvm::Value *getPointer(llvm::User *U) {
@@ -1495,42 +1489,6 @@ llvm::Function *changeFunctionType(llvm::Function &OldFunction,
llvm::Type *NewReturnType,
llvm::ArrayRef<llvm::Type *> NewArguments);
inline llvm::SmallVector<llvm::Value *, 4> unpack(revng::IRBuilder &Builder,
llvm::Value *V) {
using namespace llvm;
Type *Type = V->getType();
if (isa<IntegerType>(Type)) {
return { V };
} else if (auto *StructType = dyn_cast<llvm::StructType>(Type)) {
llvm::SmallVector<llvm::Value *, 4> Result;
for (unsigned I = 0; I < StructType->getNumElements(); ++I)
Result.push_back(Builder.CreateExtractValue(V, { I }));
return Result;
} else {
revng_abort("Cannot unpack the given type");
}
}
inline llvm::Instruction *createLoad(revng::IRBuilder &Builder,
llvm::GlobalVariable *GV) {
return Builder.CreateLoad(GV->getValueType(), GV);
}
inline llvm::Instruction *createLoad(revng::IRBuilder &Builder,
llvm::AllocaInst *Alloca) {
return Builder.CreateLoad(Alloca->getAllocatedType(), Alloca);
}
inline llvm::Instruction *createLoadVariable(revng::IRBuilder &Builder,
llvm::Value *Variable) {
if (auto *Alloca = llvm::dyn_cast<llvm::AllocaInst>(Variable))
return createLoad(Builder, Alloca);
else if (auto *GV = llvm::dyn_cast<llvm::GlobalVariable>(Variable))
return createLoad(Builder, GV);
else
revng_abort("Either GlobalVariable or AllocaInst expected");
}
void pruneDICompileUnits(llvm::Module &M);
llvm::SmallSet<llvm::Value *, 2> findPhiTreeLeaves(llvm::Value *Root);
+1 -4
View File
@@ -11,14 +11,11 @@
#include "revng/ADT/KeyedObjectContainer.h"
#include "revng/Model/Architecture.h"
#include "revng/Runtime/PlainMetaAddress.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IntegerSerialization.h"
#include "revng/Support/OverflowSafeInt.h"
extern "C" {
#include "revng/Runtime/PlainMetaAddress.h"
}
namespace llvm {
class TypeDefinition;
class Constant;
@@ -9,6 +9,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/Model/Register.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/OpaqueFunctionsPool.h"
namespace revng {
+1
View File
@@ -60,6 +60,7 @@
#include "revng/RestructureCFG/RestructureCFG.h"
#include "revng/Support/Assert.h"
#include "revng/Support/DecompilationHelpers.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/YAMLTraits.h"
#include "revng/TypeNames/LLVMTypeNames.h"
+2 -1
View File
@@ -8,6 +8,7 @@
#include "llvm/ADT/SmallVector.h"
#include "revng/BasicAnalyses/RemoveHelperCalls.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/OpaqueRegisterUser.h"
@@ -49,7 +50,7 @@ RemoveHelperCallsPass::run(llvm::Function &F,
// Assumption: helpers do not leave the stack altered, thus we can save the
// stack pointer and restore it back later.
auto *SP = createLoad(Builder, GCBI->spReg());
auto *SP = Builder.createLoad(GCBI->spReg());
auto *RetTy = cast<CallInst>(I)->getFunctionType()->getReturnType();
auto *OriginalHelperMarker = OFPOriginalHelper.get(RetTy,
+1
View File
@@ -28,6 +28,7 @@
#include "revng/ADT/SmallMap.h"
#include "revng/ADT/ZipMapIterator.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
using namespace llvm;
+1
View File
@@ -12,6 +12,7 @@
#include "llvm/Transforms/Utils/Local.h"
#include "revng/Model/FunctionTags.h"
#include "revng/Support/IRBuilder.h"
using namespace llvm;
+1
View File
@@ -16,6 +16,7 @@
#include "revng/Model/LoadModelPass.h"
#include "revng/Support/Assert.h"
#include "revng/Support/DecompilationHelpers.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/YAMLTraits.h"
static Logger Log{ "fold-model-gep" };
+1
View File
@@ -15,6 +15,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/Model/IRHelpers.h"
#include "revng/Model/LoadModelPass.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/OpaqueFunctionsPool.h"
struct MakeLocalVariables : public llvm::FunctionPass {
+1
View File
@@ -19,6 +19,7 @@
#include "revng/Model/IRHelpers.h"
#include "revng/Model/LoadModelPass.h"
#include "revng/Support/Assert.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/YAMLTraits.h"
#include "revng/TypeNames/LLVMTypeNames.h"
+1
View File
@@ -46,6 +46,7 @@
#include "revng/Model/VerifyHelper.h"
#include "revng/Support/BlockType.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/YAMLTraits.h"
@@ -15,6 +15,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/Support/Assert.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/OpaqueFunctionsPool.h"
@@ -20,6 +20,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/Model/IRHelpers.h"
#include "revng/Model/LoadModelPass.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/OpaqueFunctionsPool.h"
+1
View File
@@ -16,6 +16,7 @@
#include "revng/Model/LoadModelPass.h"
#include "revng/Support/Assert.h"
#include "revng/Support/DecompilationHelpers.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/OpaqueFunctionsPool.h"
struct RemoveLoadStore : public llvm::FunctionPass {
+1
View File
@@ -9,6 +9,7 @@
#include "llvm/Pass.h"
#include "revng/Model/FunctionTags.h"
#include "revng/Support/IRBuilder.h"
struct RemovePointerCasts : public llvm::FunctionPass {
public:
@@ -8,6 +8,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/OpaqueFunctionsPool.h"
using namespace llvm;
@@ -13,6 +13,7 @@
#include "llvm/Transforms/Utils/Local.h"
#include "revng/Model/FunctionTags.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/OpaqueFunctionsPool.h"
struct TernaryReductionPass : public llvm::FunctionPass {
@@ -13,6 +13,7 @@
#include "llvm/Transforms/Utils/Local.h"
#include "revng/Model/FunctionTags.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/OpaqueFunctionsPool.h"
struct TwosComplementArithmeticNormalizationPass : public llvm::FunctionPass {
+5 -4
View File
@@ -37,6 +37,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/Support/BasicBlockID.h"
#include "revng/Support/Generator.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/MetaAddress.h"
#include "revng/Support/TemporaryLLVMOption.h"
@@ -382,12 +383,12 @@ CFGAnalyzer::State CFGAnalyzer::loadState(revng::IRBuilder &Builder) const {
LLVMContext &Context = M.getContext();
// Load the stack pointer
auto *SP0 = createLoad(Builder, GCBI.spReg());
auto *SP0 = Builder.createLoad(GCBI.spReg());
// Load the return address
Value *ReturnAddress = nullptr;
if (GlobalVariable *Register = GCBI.raReg()) {
ReturnAddress = createLoad(Builder, Register);
ReturnAddress = Builder.createLoad(Register);
} else {
auto *OpaquePointer = PointerType::get(Context, 0);
auto *StackPointerPointer = Builder.CreateIntToPtr(SP0, OpaquePointer);
@@ -409,7 +410,7 @@ CFGAnalyzer::State CFGAnalyzer::loadState(revng::IRBuilder &Builder) const {
SmallVector<Value *, 16> CSVs;
Type *IsRetTy = Type::getInt128Ty(Context);
for (auto *CSR : ABICSVs) {
auto *V = createLoad(Builder, CSR);
auto *V = Builder.createLoad(CSR);
CSVs.emplace_back(V);
}
@@ -1150,7 +1151,7 @@ void CallSummarizer::handleCall(MetaAddress CallerBlock,
// Adjust back the stack pointer
if (not IsTailCall) {
if (MaybeFSO.has_value()) {
auto *StackPointer = createLoad(Builder, SPCSV);
auto *StackPointer = Builder.createLoad(SPCSV);
Value *Offset = ConstantInt::get(StackPointer->getType(), *MaybeFSO);
auto *AdjustedStackPointer = Builder.CreateAdd(StackPointer, Offset);
Builder.CreateStore(AdjustedStackPointer, SPCSV);
+1
View File
@@ -40,6 +40,7 @@
#include "revng/Pipes/ModelGlobal.h"
#include "revng/Support/BasicBlockID.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/MetaAddress.h"
#include "revng/Support/OpaqueRegisterUser.h"
+2 -1
View File
@@ -16,6 +16,7 @@
#include "revng/EarlyFunctionAnalysis/CallHandler.h"
#include "revng/EarlyFunctionAnalysis/Outliner.h"
#include "revng/Model/IRHelpers.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/MetaAddress.h"
#include "revng/Support/OpaqueRegisterUser.h"
@@ -212,7 +213,7 @@ void Outliner::integrateFunctionCallee(CallHandler *TheCallHandler,
PointeeType = CSV->getValueType();
} else {
PointeeType = GCBI.spReg()->getValueType();
Pointer = Builder.CreateIntToPtr(createLoad(Builder, GCBI.spReg()),
Pointer = Builder.CreateIntToPtr(Builder.createLoad(GCBI.spReg()),
PointeeType->getPointerTo());
}
@@ -8,6 +8,7 @@
#include "revng/EarlyFunctionAnalysis/PromoteGlobalToLocalVars.h"
#include "revng/Model/FunctionTags.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/OpaqueRegisterUser.h"
@@ -48,7 +49,7 @@ PromoteGlobalToLocalPass::run(llvm::Function &F,
// Load all the CSVs and store their value onto the local variables.
for (const auto &[CSV, Alloca] : CSVMap)
Builder.CreateStore(createLoad(Builder, CSV), Alloca);
Builder.CreateStore(Builder.createLoad(CSV), Alloca);
return PreservedAnalyses::none();
}
+2 -1
View File
@@ -39,6 +39,7 @@
#include "revng/Pipes/RootKind.h"
#include "revng/Pipes/TaggedFunctionKind.h"
#include "revng/Support/BlockType.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/MetaAddress.h"
#include "revng/Support/OpaqueFunctionsPool.h"
@@ -292,7 +293,7 @@ static Value *loadCSVOrUndef(revng::IRBuilder &Builder,
auto *Type = IntegerType::get(M->getContext(), Size * 8);
return UndefValue::get(Type);
} else {
return createLoad(Builder, CSV);
return Builder.createLoad(CSV);
}
}
@@ -22,6 +22,7 @@
#include "revng/Pipes/Kinds.h"
#include "revng/Pipes/RootKind.h"
#include "revng/Pipes/TaggedFunctionKind.h"
#include "revng/Support/IRBuilder.h"
using namespace llvm;
using std::tuple;
@@ -167,7 +168,7 @@ public:
auto Name = model::Register::getCSVName(Register);
GlobalVariable *CSV = RootModule.getGlobalVariable(Name, true);
revng_assert(CSV != nullptr);
Arguments.push_back(createLoad(Builder, CSV));
Arguments.push_back(Builder.createLoad(CSV));
}
}
}
@@ -53,6 +53,7 @@
#include "revng/Pipes/StringMap.h"
#include "revng/Pipes/TaggedFunctionKind.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/MetaAddress.h"
#include "revng/Support/SimplePassManager.h"
+4 -3
View File
@@ -17,6 +17,7 @@
#include "revng/Pipes/Kinds.h"
#include "revng/Pipes/RootKind.h"
#include "revng/Pipes/TaggedFunctionKind.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
using namespace llvm;
@@ -227,7 +228,7 @@ Function *PromoteCSVs::createWrapper(const WrapperKey &Key) {
// Update values of the out arguments
unsigned OutArgument = FirstOutArgument;
for (GlobalVariable *CSV : Written) {
Builder.CreateStore(createLoad(Builder, CSV),
Builder.CreateStore(Builder.createLoad(CSV),
HelperWrapper->getArg(OutArgument));
++OutArgument;
}
@@ -283,7 +284,7 @@ void PromoteCSVs::wrap(CallInst *Call,
// Add arguments read
for (GlobalVariable *CSV : Read)
NewArguments.push_back(createLoad(Builder, CSV));
NewArguments.push_back(Builder.createLoad(CSV));
SmallVector<AllocaInst *, 16> WrittenCSVAllocas;
for (GlobalVariable *CSV : Written) {
@@ -300,7 +301,7 @@ void PromoteCSVs::wrap(CallInst *Call,
// Restore into CSV the written registers
for (const auto &[CSV, Alloca] : zip(Written, WrittenCSVAllocas))
Builder.CreateStore(createLoad(Builder, Alloca), CSV);
Builder.CreateStore(Builder.createLoad(Alloca), CSV);
// Erase the old call
eraseFromParent(Call);
@@ -4,6 +4,7 @@
#include "revng/FunctionIsolation/StructInitializers.h"
#include "revng/Model/FunctionTags.h"
#include "revng/Support/IRBuilder.h"
using namespace llvm;
+1
View File
@@ -54,6 +54,7 @@
#include "revng/Model/RawBinaryView.h"
#include "revng/Support/CommandLine.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/SimplePassManager.h"
+2 -1
View File
@@ -11,6 +11,7 @@
#include "llvm/IR/PassManager.h"
#include "revng/Model/FunctionTags.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
using CSVToAllocaMap = llvm::DenseMap<llvm::GlobalVariable *,
@@ -42,7 +43,7 @@ public:
std::back_inserter(Arguments));
for (GlobalVariable *CSV : ReadCSVs)
Arguments.push_back(createLoadVariable(Builder, csvToAlloca(CSV)));
Arguments.push_back(Builder.createLoadVariable(csvToAlloca(CSV)));
CallInst *Result = Builder.CreateCall(getRandom(M, ReturnType), Arguments);
+2 -1
View File
@@ -20,6 +20,7 @@
#include "revng/BasicAnalyses/GeneratedCodeBasicInfo.h"
#include "revng/Model/ProgramCounterHandler.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IRBuilder.h"
#include "ExternalJumpsHandler.h"
@@ -47,7 +48,7 @@ BasicBlock *ExternalJumpsHandler::createReturnFromExternal() {
// Identify the global variables to be serialized
GlobalVariable *SavedRegistersPtr = TheModule.getGlobalVariable("saved_"
"registers");
Instruction *SavedRegisters = createLoad(Builder, SavedRegistersPtr);
Instruction *SavedRegisters = Builder.createLoad(SavedRegistersPtr);
// TODO: if we do not support this architecture, here things will be
// completely broken
+1
View File
@@ -26,6 +26,7 @@
#include "revng/Lift/VariableManager.h"
#include "revng/Model/FunctionTags.h"
#include "revng/Support/Assert.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/RandomAccessIterator.h"
#include "revng/Support/Range.h"
+1
View File
@@ -13,6 +13,7 @@
#include "revng/Lift/LibTcg.h"
#include "revng/Model/ProgramCounterHandler.h"
#include "revng/Support/IRBuilder.h"
#include "JumpTargetManager.h"
+1
View File
@@ -16,6 +16,7 @@
#include "revng/Lift/Lift.h"
#include "revng/Model/FunctionTags.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/MetaAddress.h"
#include "revng/Support/SimplePassManager.h"
#include "revng/Support/Statistics.h"
+2 -1
View File
@@ -28,6 +28,7 @@
#include "revng/ABI/FunctionType/Layout.h"
#include "revng/BasicAnalyses/ShrinkInstructionOperandsPass.h"
#include "revng/FunctionCallIdentification/FunctionCallIdentification.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/OpaqueRegisterUser.h"
#include "revng/Support/Statistics.h"
@@ -546,7 +547,7 @@ RootAnalyzer::promoteCSVsToAlloca(Function *OptimizedFunction) {
replaceAllUsesInFunctionWith(OptimizedFunction, CSV, Alloca);
// Initialize the alloca
InitBuilder.CreateStore(createLoad(InitBuilder, CSV), Alloca);
InitBuilder.CreateStore(InitBuilder.createLoad(CSV), Alloca);
}
return CSVMap;
+1
View File
@@ -11,6 +11,7 @@
#include "llvm/Transforms/Utils/ValueMapper.h"
#include "revng/Model/Binary.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/MetaAddress.h"
#include "DropHelperCallsPass.h"
+4 -3
View File
@@ -32,6 +32,7 @@
#include "revng/Support/Assert.h"
#include "revng/Support/CommandLine.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
// This name corresponds to a function in `early-linked`.
@@ -243,7 +244,7 @@ VariableManager::storeToCPUStateOffset(revng::IRBuilder &Builder,
if (BitMask != 0 and StoreSize != FieldSize) {
// Load the value
auto *LoadEnvField = createLoad(Builder, Target);
auto *LoadEnvField = Builder.createLoad(Target);
auto *Blanked = Builder.CreateAnd(LoadEnvField, BitMask);
@@ -268,7 +269,7 @@ Value *VariableManager::loadFromCPUStateOffset(revng::IRBuilder &Builder,
return nullptr;
// Load the whole field
auto *LoadEnvField = createLoad(Builder, Target);
auto *LoadEnvField = Builder.createLoad(Target);
// Extract the desired part
// Shift right of the desired amount
@@ -351,7 +352,7 @@ void VariableManager::memOpAtEnvOffset(revng::IRBuilder &Builder,
StoreInst *New = nullptr;
if (EnvIsSrc) {
revng_assert(not IsMemset);
New = Builder.CreateStore(createLoad(Builder, EnvVar), OtherPtr);
New = Builder.CreateStore(Builder.createLoad(EnvVar), OtherPtr);
} else {
Type *CSVType = EnvVar->getValueType();
Value *ToStore = nullptr;
+5 -5
View File
@@ -150,7 +150,7 @@ LegacyVB::createLocalVariable(const model::Type &VariableType) {
// Here we should definitely use the builder that checks the debug info,
// but since this going to go away soon, let it stay as is.
revng::NonDebugInfoCheckingIRBuilder B(F->getContext());
setInsertPointToFirstNonAlloca(B, *F);
B.setInsertPointToFirstNonAlloca(*F);
Constant *ReferenceString = toLLVMString(VariableType, *F->getParent());
return B.CreateCall(LocalVarFunction, { ReferenceString });
}
@@ -189,7 +189,7 @@ LegacyVB::createCallStackArgumentVariable(const model::Type &VariableType) {
llvm::Constant *VarTypeString = toLLVMString(VariableType, *F->getParent());
revng::NonDebugInfoCheckingIRBuilder B(F->getContext());
setInsertPointToFirstNonAlloca(B, *F);
B.setInsertPointToFirstNonAlloca(*F);
Value *Size = ConstantInt::get(Types.InputPointerSizedInteger, VariableSize);
Instruction *Reference = B.CreateCall(getCallStackArgumentsAllocator(),
@@ -214,7 +214,7 @@ LegacyVB::createStackFrameVariable(model::UpcastableType FrameType) {
revng_assert(StackSize);
revng::NonDebugInfoCheckingIRBuilder B(F->getContext());
setInsertPointToFirstNonAlloca(B, *F);
B.setInsertPointToFirstNonAlloca(*F);
Instruction
*Reference = B.CreateCall(getStackFrameAllocator(),
@@ -301,7 +301,7 @@ VB::LocalVarType *VB::createLocalVariable(const model::Type &VariableType) {
revng_assert(VariableSize);
revng::NonDebugInfoCheckingIRBuilder B(F->getContext());
setInsertPointToFirstNonAlloca(B, *F);
B.setInsertPointToFirstNonAlloca(*F);
return B.CreateAlloca(llvm::ArrayType::get(Types.Int8Ty, VariableSize));
}
@@ -310,7 +310,7 @@ template<>
std::pair<VB::LocalVarType *, llvm::Instruction *>
VB::createLocalVariableAndTakeIntAddress(const model::Type &VariableType) {
revng::NonDebugInfoCheckingIRBuilder B(F->getContext());
setInsertPointToFirstNonAlloca(B, *F);
B.setInsertPointToFirstNonAlloca(*F);
auto *Variable = createLocalVariable(VariableType);
return {
Variable,
+1
View File
@@ -4,6 +4,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/Model/ProgramCounterHandler.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
namespace FunctionTags {
+17 -16
View File
@@ -10,6 +10,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/Model/ProgramCounterHandler.h"
#include "revng/Support/Assert.h"
#include "revng/Support/IRBuilder.h"
// This name corresponds to a function in `early-linked`.
RegisterIRHelper SetMetaAddressHelper("set_PlainMetaAddress");
@@ -62,7 +63,7 @@ public:
}
Value *loadJumpablePC(revng::IRBuilder &Builder) const final {
return createLoad(Builder, AddressCSV);
return Builder.createLoad(AddressCSV);
}
std::array<Value *, 4>
@@ -156,10 +157,10 @@ private:
}
Value *loadJumpablePC(revng::IRBuilder &Builder) const final {
auto *Address = createLoad(Builder, AddressCSV);
auto *Address = Builder.createLoad(AddressCSV);
auto *AddressType = Address->getType();
return Builder.CreateOr(Address,
Builder.CreateZExt(createLoad(Builder, IsThumb),
Builder.CreateZExt(Builder.createLoad(IsThumb),
AddressType));
}
@@ -411,10 +412,10 @@ static void setPlainMetaAddressImpl(revng::IRBuilder &Builder,
void PCH::setCurrentPCPlainMetaAddress(revng::IRBuilder &Builder) const {
setPlainMetaAddressImpl(Builder,
"current_pc",
createLoad(Builder, EpochCSV),
createLoad(Builder, AddressSpaceCSV),
createLoad(Builder, TypeCSV),
createLoad(Builder, AddressCSV));
Builder.createLoad(EpochCSV),
Builder.createLoad(AddressSpaceCSV),
Builder.createLoad(TypeCSV),
Builder.createLoad(AddressCSV));
}
void PCH::setLastPCPlainMetaAddress(revng::IRBuilder &Builder,
@@ -618,10 +619,10 @@ public:
bool Empty = Root->case_begin() == Root->case_end();
if (Empty) {
revng::NonDebugInfoCheckingIRBuilder Builder(Root);
CurrentEpoch = createLoad(Builder, EpochCSV);
CurrentAddressSpace = createLoad(Builder, AddressSpaceCSV);
CurrentType = createLoad(Builder, TypeCSV);
CurrentAddress = createLoad(Builder, AddressCSV);
CurrentEpoch = Builder.createLoad(EpochCSV);
CurrentAddressSpace = Builder.createLoad(AddressSpaceCSV);
CurrentType = Builder.createLoad(TypeCSV);
CurrentAddress = Builder.createLoad(AddressCSV);
} else {
// Get the switches of the the first MA. This is just in order to get a
// reference to their conditions
@@ -819,10 +820,10 @@ PCH::buildDispatcher(DispatcherTargets &Targets,
});
// First of all, create code to load the components of the MetaAddress
Value *CurrentEpoch = createLoad(Builder, EpochCSV);
Value *CurrentAddressSpace = createLoad(Builder, AddressSpaceCSV);
Value *CurrentType = createLoad(Builder, TypeCSV);
Value *CurrentAddress = createLoad(Builder, AddressCSV);
Value *CurrentEpoch = Builder.createLoad(EpochCSV);
Value *CurrentAddressSpace = Builder.createLoad(AddressSpaceCSV);
Value *CurrentType = Builder.createLoad(TypeCSV);
Value *CurrentAddress = Builder.createLoad(AddressCSV);
SwitchManager SM(Default,
CurrentEpoch,
@@ -952,7 +953,7 @@ void PCH::buildHotPath(revng::IRBuilder &B,
auto &[Address, BB] = CandidateTarget;
auto CreateCmp = [&B](GlobalVariable *CSV, uint64_t Value) {
Instruction *Load = createLoad(B, CSV);
Instruction *Load = B.createLoad(CSV);
Type *LoadType = Load->getType();
return B.CreateICmpEQ(Load, ConstantInt::get(LoadType, Value));
};
@@ -6,6 +6,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/PromoteStackPointer/InjectStackSizeProbesAtCallSites.h"
#include "revng/PromoteStackPointer/InjectStackSizeProbesAtCallSitesPass.h"
#include "revng/Support/IRBuilder.h"
// This name is not present after `CleanupStackSizeMarkers`.
RegisterIRHelper StackSizeAtCallSite("stack_size_at_call_site");
@@ -33,9 +34,9 @@ static bool injectStackSizeProbesAtCallSites(llvm::Module &M,
for (Function &F : FunctionTags::Isolated.functions(&M)) {
if (F.isDeclaration())
continue;
setInsertPointToFirstNonAlloca(B, F);
B.setInsertPointToFirstNonAlloca(F);
auto *SP0 = createLoad(B, SP);
auto *SP0 = B.createLoad(SP);
for (BasicBlock &BB : F) {
for (Instruction &I : BB) {
@@ -45,7 +46,7 @@ static bool injectStackSizeProbesAtCallSites(llvm::Module &M,
B.SetInsertPoint(&I);
// Inject a call to the marker. First argument is sp - sp0
auto *Call = B.CreateCall(SSACS, B.CreateSub(SP0, createLoad(B, SP)));
auto *Call = B.CreateCall(SSACS, B.CreateSub(SP0, B.createLoad(SP)));
Call->copyMetadata(I);
}
}
@@ -8,6 +8,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/Model/IRHelpers.h"
#include "revng/PromoteStackPointer/InstrumentStackAccessesPass.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/OpaqueFunctionsPool.h"
@@ -32,6 +32,7 @@
#include "revng/PromoteStackPointer/PromoteStackPointerPass.h"
#include "revng/Support/Assert.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IRBuilder.h"
// This name is not present after `promote-stack-pointer`.
RegisterIRHelper UndefinedLocalSPMarker("revng_undefined_local_sp");
@@ -77,7 +78,7 @@ static bool adjustStackAfterCalls(const model::Binary &Binary,
Changed = true;
B.SetInsertPoint(I.getNextNode());
B.CreateStore(B.CreateAdd(createLoad(B, GlobalSP), FSO), GlobalSP);
B.CreateStore(B.CreateAdd(B.createLoad(GlobalSP), FSO), GlobalSP);
}
}
}
@@ -169,7 +170,7 @@ static bool promoteStackPointer(const model::Binary &Binary,
AllocaInst *LocalSP = Builder.CreateAlloca(SPType, nullptr, "local_sp");
// Call InitLocalSP, to initialize the value of the local stack pointer.
setInsertPointToFirstNonAlloca(Builder, F);
Builder.setInsertPointToFirstNonAlloca(F);
auto *SPVal = Builder.CreateCall(InitLocalSP);
// Store the initial SP value in the new alloca.
@@ -1230,7 +1230,7 @@ void SegregateFunctionStack<Legacy>::upgrade() {
// TODO: the checks should be enabled conditionally based on the user.
revng::NonDebugInfoCheckingIRBuilder B(NewFunction->getContext());
setInsertPointToFirstNonAlloca(B, *NewFunction);
B.setInsertPointToFirstNonAlloca(*NewFunction);
lowerArguments(B);
@@ -7,6 +7,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/RemoveExtractValues/RemoveExtractValuesPass.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/OpaqueFunctionsPool.h"
using namespace llvm;
@@ -14,6 +14,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/Model/LoadModelPass.h"
#include "revng/RemoveLiftingArtifacts/CleanupIR.h"
#include "revng/Support/IRBuilder.h"
using namespace llvm;
@@ -34,6 +34,7 @@
#include "revng/Pipes/Kinds.h"
#include "revng/RemoveLiftingArtifacts/MakeSegmentRef.h"
#include "revng/Support/Debug.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/MetaAddress.h"
#include "revng/Support/OpaqueFunctionsPool.h"
@@ -11,6 +11,7 @@
#include "revng/RestructureCFG/ScopeGraphGraphTraits.h"
#include "revng/RestructureCFG/ScopeGraphUtils.h"
#include "revng/Support/GraphAlgorithms.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
using namespace llvm;
+1
View File
@@ -10,6 +10,7 @@
#include "revng/Model/FunctionTags.h"
#include "revng/RestructureCFG/ScopeGraphUtils.h"
#include "revng/Support/IRBuilder.h"
#include "revng/Support/IRHelpers.h"
using namespace llvm;
+1
View File
@@ -15,6 +15,7 @@
#include "revng/RestructureCFG/ASTTree.h"
#include "revng/RestructureCFG/ExprNode.h"
#include "revng/Support/Assert.h"
#include "revng/Support/IRBuilder.h"
#include "SimplifyHybridNot.h"