Skip to content

Commit f3d8e7d

Browse files
committed
Add support for LLVM 15-21
Add back support for LLVM 15
1 parent 85177ef commit f3d8e7d

15 files changed

Lines changed: 59 additions & 39 deletions

File tree

include/remill/Arch/Arch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
#pragma clang diagnostic ignored "-Wswitch-enum"
2626

2727
#include <llvm/ADT/SmallVector.h>
28+
#if LLVM_VERSION_MAJOR < 16
29+
#include <llvm/ADT/Triple.h>
30+
#else
2831
#include <llvm/TargetParser/Triple.h>
32+
#endif // LLVM_VERSION_MAJOR
2933
#include <llvm/IR/DataLayout.h>
3034
#include <llvm/IR/IRBuilder.h>
3135
#include <remill/BC/InstructionLifter.h>

lib/Arch/AArch64/Arch.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <llvm/IR/Function.h>
2222
#include <llvm/IR/IRBuilder.h>
2323
#include <llvm/IR/Module.h>
24-
#include <llvm/TargetParser/Triple.h>
2524

2625
#include <algorithm>
2726
#include <cctype>

lib/Arch/Arch.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <glog/logging.h>
2121
#include <llvm/ADT/APInt.h>
2222
#include <llvm/ADT/SmallVector.h>
23-
#include <llvm/IR/AttributeMask.h>
2423
#include <llvm/IR/BasicBlock.h>
2524
#include <llvm/IR/Function.h>
2625
#include <llvm/IR/IRBuilder.h>
@@ -695,18 +694,10 @@ void Arch::PrepareModuleDataLayout(llvm::Module *mod) const {
695694
// compile this bitcode back into machine code, we may want to use those
696695
// features, and clang will complain if we try to do so if these metadata
697696
// remain present.
698-
auto &context = mod->getContext();
699-
700-
llvm::AttributeSet target_attribs;
701-
702-
target_attribs = target_attribs.addAttribute(context, "target-features");
703-
target_attribs = target_attribs.addAttribute(context, "target-cpu");
704697

705698
for (llvm::Function &func : *mod) {
706-
auto attribs = func.getAttributes();
707-
attribs = attribs.removeFnAttributes(context,
708-
llvm::AttributeMask(target_attribs));
709-
func.setAttributes(attribs);
699+
func.removeFnAttr("target-features");
700+
func.removeFnAttr("target-cpu");
710701
}
711702
}
712703

lib/Arch/Name.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616

1717
#include "remill/Arch/Name.h"
18-
19-
#include <llvm/TargetParser/Triple.h>
18+
#include "remill/Arch/Arch.h"
2019

2120
namespace remill {
2221

lib/Arch/Sleigh/AArch32Arch.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <llvm/IR/Function.h>
2323
#include <llvm/IR/IRBuilder.h>
2424
#include <llvm/IR/Module.h>
25-
#include <llvm/TargetParser/Triple.h>
2625
#include <remill/Arch/AArch32/ArchContext.h>
2726

2827
#include <iomanip>

lib/Arch/Sleigh/ARMBase.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <llvm/IR/Function.h>
55
#include <llvm/IR/IRBuilder.h>
66
#include <llvm/IR/Module.h>
7-
#include <llvm/TargetParser/Triple.h>
87
#include <remill/Arch/AArch32/AArch32Base.h>
98
#include <remill/Arch/Name.h>
109
#include <remill/BC/ABI.h>

lib/Arch/Sleigh/X86Arch.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <llvm/IR/Function.h>
2121
#include <llvm/IR/IRBuilder.h>
2222
#include <llvm/IR/Module.h>
23-
#include <llvm/TargetParser/Triple.h>
2423
#include <remill/Arch/Context.h>
2524
#include <remill/Arch/Name.h>
2625
#include <remill/Arch/X86/X86Base.h>

lib/Arch/X86/Arch.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <llvm/IR/Function.h>
2121
#include <llvm/IR/IRBuilder.h>
2222
#include <llvm/IR/Module.h>
23-
#include <llvm/TargetParser/Triple.h>
2423
#include <remill/Arch/ArchBase.h> // For `Arch` and `ArchImpl`.
2524
#include <remill/Arch/X86/X86Base.h>
2625

lib/BC/InstructionLifter.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ llvm::Value *InstructionLifter::LoadWordRegValOrZero(llvm::BasicBlock *block,
358358

359359
CHECK(val_type) << "Register " << reg_name << " expected to be an integer.";
360360

361-
auto val_size = val_type->getBitWidth();
362-
auto word_size = word_type->getBitWidth();
361+
auto val_size = val_type->getIntegerBitWidth();
362+
auto word_size = word_type->getIntegerBitWidth();
363363
CHECK_LE(val_size, word_size)
364364
<< "Register " << reg_name << " expected to be no larger than the "
365-
<< "machine word size (" << word_type->getBitWidth() << " bits).";
365+
<< "machine word size (" << word_type->getIntegerBitWidth() << " bits).";
366366

367367
if (val_size < word_size) {
368368
val = new llvm::ZExtInst(val, word_type, llvm::Twine::createNull(), block);
@@ -595,15 +595,19 @@ llvm::Value *InstructionLifter::LiftRegisterOperand(Instruction &inst,
595595
if (val_size < arg_size) {
596596
if (arg_type->isIntegerTy()) {
597597
CHECK(val_type->isIntegerTy())
598-
<< "Expected " << arch_reg.name << " to be an integral type "
598+
<< "Expected " << arch_reg.name << " to be an integral type ("
599+
<< "val_type: " << LLVMThingToString(val_type) << ", "
600+
<< "arg_type: " << LLVMThingToString(arg_type) << ") "
599601
<< "for instruction at " << std::hex << inst.pc;
600602

601603
val =
602604
new llvm::ZExtInst(val, arg_type, llvm::Twine::createNull(), block);
603605

604606
} else if (arg_type->isFloatingPointTy()) {
605607
CHECK(val_type->isFloatingPointTy())
606-
<< "Expected " << arch_reg.name << " to be a floating point type "
608+
<< "Expected " << arch_reg.name << " to be a floating point type ("
609+
<< "val_type: " << LLVMThingToString(val_type) << ", "
610+
<< "arg_type: " << LLVMThingToString(arg_type) << ") "
607611
<< "for instruction at " << std::hex << inst.pc;
608612

609613
val = new llvm::FPExtInst(val, arg_type, llvm::Twine::createNull(),
@@ -613,15 +617,19 @@ llvm::Value *InstructionLifter::LiftRegisterOperand(Instruction &inst,
613617
} else if (val_size > arg_size) {
614618
if (arg_type->isIntegerTy()) {
615619
CHECK(val_type->isIntegerTy())
616-
<< "Expected " << arch_reg.name << " to be an integral type "
620+
<< "Expected " << arch_reg.name << " to be an integral type ("
621+
<< "val_type: " << LLVMThingToString(val_type) << ", "
622+
<< "arg_type: " << LLVMThingToString(arg_type) << ") "
617623
<< "for instruction at " << std::hex << inst.pc;
618624

619625
val = new llvm::TruncInst(val, arg_type, llvm::Twine::createNull(),
620626
block);
621627

622628
} else if (arg_type->isFloatingPointTy()) {
623629
CHECK(val_type->isFloatingPointTy())
624-
<< "Expected " << arch_reg.name << " to be a floating point type "
630+
<< "Expected " << arch_reg.name << " to be a floating point type ("
631+
<< "val_type: " << LLVMThingToString(val_type) << ", "
632+
<< "arg_type: " << LLVMThingToString(arg_type) << ") "
625633
<< "for instruction at " << std::hex << inst.pc;
626634

627635
val = new llvm::FPTruncInst(val, arg_type, llvm::Twine::createNull(),
@@ -876,8 +884,8 @@ InstructionLifter::LiftOperand(Instruction &inst, llvm::BasicBlock *block,
876884

877885
case Operand::kTypeShiftRegister:
878886
CHECK(Operand::kActionRead == arch_op.action)
879-
<< "Can't write to a shift register operand "
880-
<< "for instruction at " << std::hex << inst.pc;
887+
<< "Can't write to a shift register operand " << "for instruction at "
888+
<< std::hex << inst.pc;
881889

882890
return LiftShiftRegisterOperand(inst, block, state_ptr, arg, arch_op);
883891

lib/BC/Optimizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include <llvm/Pass.h>
3636
#include <llvm/Passes/OptimizationLevel.h>
3737
#include <llvm/Passes/PassBuilder.h>
38-
#include <llvm/TargetParser/Triple.h>
3938
#include <llvm/Transforms/IPO.h>
4039
#include <llvm/Transforms/IPO/Inliner.h>
4140
#include <llvm/Transforms/IPO/ModuleInliner.h>
@@ -67,7 +66,9 @@ void OptimizeBareModule(llvm::Module *module, OptimizationGuide guide) {
6766

6867

6968
llvm::PipelineTuningOptions opts;
69+
#if LLVM_VERSION_MAJOR >= 16
7070
opts.InlinerThreshold = 250;
71+
#endif // LLVM_VERSION_MAJOR
7172
llvm::PassBuilder pb(nullptr, opts);
7273

7374
pb.registerModuleAnalyses(mam);

0 commit comments

Comments
 (0)