Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support opaque pointers #172

Merged
merged 8 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup after merge
  • Loading branch information
dpaoliello committed Jul 19, 2023
commit a3b67aa81256a9ab82374e00dfcfc34a5425f4e2
38 changes: 0 additions & 38 deletions lib/Target/CBackend/CBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ extern "C" void LLVMInitializeCBackendTarget() {
// Register the target.
RegisterTargetMachine<CTargetMachine> X(TheCBackendTarget);
}
#if LLVM_VERSION_MAJOR > 10
bool IsPowerOfTwo(unsigned long x) { return (x & (x - 1)) == 0; }
#endif

unsigned int NumberOfElements(VectorType *TheType) {
return TheType->getElementCount().getFixedValue();
Expand Down Expand Up @@ -776,12 +773,8 @@ raw_ostream &CWriter::printFunctionProto(raw_ostream &Out,

AttributeList PAL = GetAttributes(FIV);

#if LLVM_VERSION_MAJOR >= 16
if (PAL.hasAttributeAtIndex(AttributeList::FunctionIndex,
Attribute::NoReturn)) {
#else
if (PAL.hasAttribute(AttributeList::FunctionIndex, Attribute::NoReturn)) {
#endif
headerUseNoReturn();
Out << "__noreturn ";
}
Expand All @@ -804,7 +797,6 @@ raw_ostream &CWriter::printFunctionProto(raw_ostream &Out,
printTypeName(
Out, RetTy,
/*isSigned=*/
#if LLVM_VERSION_MAJOR >= 16
PAL.hasAttributeAtIndex(AttributeList::ReturnIndex, Attribute::SExt));
}

Expand Down Expand Up @@ -871,11 +863,7 @@ raw_ostream &CWriter::printFunctionProto(raw_ostream &Out,
Out << MainArgs.begin()[Idx].first;
else
printTypeName(Out, ArgTy,
#if LLVM_VERSION_MAJOR >= 16
/*isSigned=*/PAL.hasAttributeAtIndex(Idx, Attribute::SExt));
#else
/*isSigned=*/PAL.hasAttribute(Idx, Attribute::SExt));
#endif
PrintedArg = true;
if (ArgName) {
Out << ' ';
Expand Down Expand Up @@ -2350,12 +2338,8 @@ bool CWriter::doInitialization(Module &M) {

TAsm = new CBEMCAsmInfo();
MRI = new MCRegisterInfo();
#if LLVM_VERSION_MAJOR > 12
TCtx = new MCContext(llvm::Triple(TheModule->getTargetTriple()), TAsm, MRI,
nullptr);
#else
TCtx = new MCContext(TAsm, MRI, nullptr);
#endif
return false;
}

Expand Down Expand Up @@ -2701,17 +2685,10 @@ void CWriter::generateHeader(Module &M) {
printTypeString(Out, *it, false);
Out << "(";
if (isa<VectorType>(*it))
#if LLVM_VERSION_MAJOR >= 12
printTypeName(Out,
VectorType::get(Type::getInt1Ty((*it)->getContext()),
cast<VectorType>(*it)->getElementCount()),
false);
#else
printTypeName(Out,
VectorType::get(Type::getInt1Ty((*it)->getContext()),
cast<VectorType>(*it)->getNumElements()),
false);
#endif
else
Out << "bool";
Out << " condition, ";
Expand Down Expand Up @@ -2752,12 +2729,8 @@ void CWriter::generateHeader(Module &M) {
// }
unsigned n, l = NumberOfElements((*it).second);
VectorType *RTy =
#if LLVM_VERSION_MAJOR >= 12
VectorType::get(Type::getInt1Ty((*it).second->getContext()), l,
(*it).second->getElementCount().isScalar());
#else
VectorType::get(Type::getInt1Ty((*it).second->getContext()), l);
#endif
bool isSigned = CmpInst::isSigned((*it).first);
Out << "static __forceinline ";
printTypeName(Out, RTy, isSigned);
Expand Down Expand Up @@ -3713,12 +3686,7 @@ void CWriter::printFunction(Function &F) {

// If this is a struct return function, handle the result with magic.
if (isStructReturn) {
#if LLVM_VERSION_MAJOR >= 16
Type *StructTy = F.getParamStructRetType(0);
#else
Type *StructTy =
cast<PointerType>(F.arg_begin()->getType())->getElementType();
#endif
Out << " ";
printTypeName(Out, StructTy, false)
<< " StructReturn; /* Struct return temporary */\n";
Expand All @@ -3737,11 +3705,6 @@ void CWriter::printFunction(Function &F) {
bool IsOveraligned =
Alignment &&
Alignment > TD->getABITypeAlign(AI->getAllocatedType()).value();
#else
unsigned Alignment = AI->getAlignment();
bool IsOveraligned = Alignment && Alignment > TD->getABITypeAlignment(
AI->getAllocatedType());
#endif
Out << " ";
if (IsOveraligned) {
headerUseAligns();
Expand Down Expand Up @@ -4636,7 +4599,6 @@ void CWriter::printIntrinsicDefinition(FunctionType *funT, unsigned Opcode,
Out << ";\n";
break;

#if LLVM_VERSION_MAJOR >= 16
case Intrinsic::umax:
case Intrinsic::maximum:
Out << " r = a > b ? a : b;\n";
Expand Down
8 changes: 1 addition & 7 deletions lib/Target/CBackend/CBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,7 @@ class CWriter : public FunctionPass, public InstVisitor<CWriter> {
errorWithMessage("unsupported LLVM instruction");
}

#if LLVM_VERSION_MAJOR >= 16
[[noreturn]]
#else
LLVM_ATTRIBUTE_NORETURN
#endif
void
errorWithMessage(const char *message);
[[noreturn]] void errorWithMessage(const char *message);

bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To);
bool canDeclareLocalLate(Instruction &I);
Expand Down
34 changes: 5 additions & 29 deletions lib/Target/CBackend/CTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ class CTargetSubtargetInfo : public TargetSubtargetInfo {
public:
CTargetSubtargetInfo(const TargetMachine &TM, const Triple &TT, StringRef CPU,
StringRef TuneCPU, StringRef FS)
#else
CTargetSubtargetInfo(const TargetMachine &TM, const Triple &TT, StringRef CPU,
StringRef FS)
#endif
#if LLVM_VERSION_MAJOR >= 9
#if LLVM_VERSION_MAJOR >= 12
: TargetSubtargetInfo(TT, CPU, TuneCPU, FS,
ArrayRef<SubtargetFeatureKV>(),
ArrayRef<SubtargetSubTypeKV>(), nullptr, nullptr,
Expand All @@ -51,31 +45,13 @@ class CTargetSubtargetInfo : public TargetSubtargetInfo {
class CTargetMachine : public LLVMTargetMachine {
public:
CTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
const TargetOptions &Options,
#if LLVM_VERSION_MAJOR >= 16
std::optional<Reloc::Model> RM,
std::optional<CodeModel::Model> CM,
#else
llvm
: Optional<Reloc::Model> RM, llvm
: Optional<CodeModel::Model> CM,
#endif
CodeGenOpt::Level OL, bool /*JIT*/)
const TargetOptions &Options, std::optional<Reloc::Model> RM,
std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
bool /*JIT*/)
: LLVMTargetMachine(T, "", TT, CPU, FS, Options,
RM.value_or(Reloc::Static),
CM.value_or(CodeModel::Small),
#else
RM.hasValue() ? RM.getValue() : Reloc::Static,
CM.hasValue() ? CM.getValue() : CodeModel::Small,
#endif
OL),
#if LLVM_VERSION_MAJOR >= 12
SubtargetInfo(*this, TT, CPU, "", FS) {
}
#else
SubtargetInfo(*this, TT, CPU, FS) {
}
#endif
CM.value_or(CodeModel::Small), OL),
SubtargetInfo(*this, TT, CPU, "", FS) {}

/// Add passes to the specified pass manager to get the specified file
/// emitted. Typically this will involve several steps of code generation.
Expand Down
20 changes: 1 addition & 19 deletions tools/llvm-cbe/llvm-cbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,6 @@ static int compileModule(char **argv, LLVMContext &Context) {
auto MAttrs = codegen::getMAttrs();
bool SkipModule = codegen::getMCPU() == "help" ||
(!MAttrs.empty() && MAttrs.front() == "help");
#else
bool SkipModule =
MCPU == "help" || (!MAttrs.empty() && MAttrs.front() == "help");
#endif

// If user just wants to list available options, skip module loading
if (!SkipModule) {
Expand Down Expand Up @@ -302,13 +298,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
// Jackson Korba 9/30/14
// OwningPtr<targetMachine>
std::unique_ptr<TargetMachine> target(TheTarget->createTargetMachine(
#if LLVM_VERSION_MAJOR > 10
TheTriple.getTriple(), codegen::getMCPU(), FeaturesStr, Options,
llvm::codegen::getRelocModel()));
#else
TheTriple.getTriple(), MCPU, FeaturesStr, Options, getRelocModel(),
getCodeModel(), OLvl));
#endif
assert(target.get() && "Could not allocate target machine!");
assert(mod && "Should have exited after outputting help!");
TargetMachine &Target = *target.get();
Expand Down Expand Up @@ -346,16 +337,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
}

// Ask the target to add backend passes as necessary.
if (Target.addPassesToEmitFile(PM, Out->os(),
#if LLVM_VERSION_MAJOR >= 7
nullptr,
#endif
#if LLVM_VERSION_MAJOR > 10
codegen::getFileType()
#else
FileType
#endif
,
if (Target.addPassesToEmitFile(PM, Out->os(), nullptr, codegen::getFileType(),
NoVerify)) {
errs() << argv[0] << ": target does not support generation of this"
<< " file type!\n";
Expand Down