Skip to content

Commit

Permalink
merge main into amd-stg-open
Browse files Browse the repository at this point in the history
Change-Id: I12a3cd880fadbc1d9a86e29a6345afe694e89111
  • Loading branch information
ronlieb committed Nov 19, 2023
2 parents 7f8d562 + 42204c9 commit 95385ef
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 124 deletions.
1 change: 1 addition & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
if: github.repository == 'llvm/llvm-project'
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
Expand Down
5 changes: 0 additions & 5 deletions clang/include/clang/CodeGen/ConstantInitBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ class ConstantAggregateBuilderBase {
add(llvm::ConstantPointerNull::get(ptrTy));
}

/// Add a bitcast of a value to a specific type.
void addBitCast(llvm::Constant *value, llvm::Type *type) {
add(llvm::ConstantExpr::getBitCast(value, type));
}

/// Add a bunch of new values to this initializer.
void addAll(llvm::ArrayRef<llvm::Constant *> values) {
assert(!Finished && "cannot add more values after finishing builder");
Expand Down
16 changes: 15 additions & 1 deletion clang/lib/Basic/Targets/OSTargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo<Target> {
Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion));
Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
DefineStd(Builder, "unix", Opts);
if (this->HasFloat128)
Builder.defineMacro("__FLOAT128__");

// On FreeBSD, wchar_t contains the number of the code point as
// used by the character set of the locale. These character sets are
Expand All @@ -204,9 +206,11 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo<Target> {
FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: OSTargetInfo<Target>(Triple, Opts) {
switch (Triple.getArch()) {
default:
case llvm::Triple::x86:
case llvm::Triple::x86_64:
this->HasFloat128 = true;
[[fallthrough]];
default:
this->MCountName = ".mcount";
break;
case llvm::Triple::mips:
Expand Down Expand Up @@ -372,12 +376,22 @@ class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo : public OSTargetInfo<Target> {
Builder.defineMacro("__unix__");
if (Opts.POSIXThreads)
Builder.defineMacro("_REENTRANT");
if (this->HasFloat128)
Builder.defineMacro("__FLOAT128__");
}

public:
NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: OSTargetInfo<Target>(Triple, Opts) {
this->MCountName = "__mcount";
switch (Triple.getArch()) {
default:
break;
case llvm::Triple::x86:
case llvm::Triple::x86_64:
this->HasFloat128 = true;
break;
}
}
};

Expand Down
56 changes: 24 additions & 32 deletions clang/lib/CodeGen/CGObjCGNU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,9 +1725,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
SmallVector<ObjCMethodDecl*, 16> ClassMethods;
ClassMethods.insert(ClassMethods.begin(), OID->classmeth_begin(),
OID->classmeth_end());
metaclassFields.addBitCast(
GenerateMethodList(className, "", ClassMethods, true),
PtrTy);
metaclassFields.add(
GenerateMethodList(className, "", ClassMethods, true));
}
// void *dtable;
metaclassFields.addNullPointer(PtrTy);
Expand Down Expand Up @@ -1894,9 +1893,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
if (InstanceMethods.size() == 0)
classFields.addNullPointer(PtrTy);
else
classFields.addBitCast(
GenerateMethodList(className, "", InstanceMethods, false),
PtrTy);
classFields.add(
GenerateMethodList(className, "", InstanceMethods, false));

// void *dtable;
classFields.addNullPointer(PtrTy);
// IMP cxx_construct;
Expand Down Expand Up @@ -2887,14 +2886,14 @@ GenerateMethodList(StringRef ClassName,
assert(FnPtr && "Can't generate metadata for method that doesn't exist");
auto Method = MethodArray.beginStruct(ObjCMethodTy);
if (isV2ABI) {
Method.addBitCast(FnPtr, IMPTy);
Method.add(FnPtr);
Method.add(GetConstantSelector(OMD->getSelector(),
Context.getObjCEncodingForMethodDecl(OMD)));
Method.add(MakeConstantString(Context.getObjCEncodingForMethodDecl(OMD, true)));
} else {
Method.add(MakeConstantString(OMD->getSelector().getAsString()));
Method.add(MakeConstantString(Context.getObjCEncodingForMethodDecl(OMD)));
Method.addBitCast(FnPtr, IMPTy);
Method.add(FnPtr);
}
Method.finishAndAddTo(MethodArray);
}
Expand Down Expand Up @@ -2993,7 +2992,7 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
// Fill in the structure

// isa
Elements.addBitCast(MetaClass, PtrToInt8Ty);
Elements.add(MetaClass);
// super_class
Elements.add(SuperClass);
// name
Expand Down Expand Up @@ -3022,7 +3021,7 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
// sibling_class
Elements.add(NULLPtr);
// protocols
Elements.addBitCast(Protocols, PtrTy);
Elements.add(Protocols);
// gc_object_type
Elements.add(NULLPtr);
// abi_version
Expand Down Expand Up @@ -3094,7 +3093,7 @@ CGObjCGNU::GenerateProtocolList(ArrayRef<std::string> Protocols) {
} else {
protocol = value->getValue();
}
Elements.addBitCast(protocol, PtrToInt8Ty);
Elements.add(protocol);
}
Elements.finishAndAddTo(ProtocolList);
return ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
Expand Down Expand Up @@ -3224,11 +3223,9 @@ void CGObjCGNU::GenerateProtocolHolderCategory() {
Elements.add(MakeConstantString(CategoryName));
Elements.add(MakeConstantString(ClassName));
// Instance method list
Elements.addBitCast(GenerateMethodList(
ClassName, CategoryName, {}, false), PtrTy);
Elements.add(GenerateMethodList(ClassName, CategoryName, {}, false));
// Class method list
Elements.addBitCast(GenerateMethodList(
ClassName, CategoryName, {}, true), PtrTy);
Elements.add(GenerateMethodList(ClassName, CategoryName, {}, true));

// Protocol list
ConstantInitBuilder ProtocolListBuilder(CGM);
Expand All @@ -3238,13 +3235,11 @@ void CGObjCGNU::GenerateProtocolHolderCategory() {
auto ProtocolElements = ProtocolList.beginArray(PtrTy);
for (auto iter = ExistingProtocols.begin(), endIter = ExistingProtocols.end();
iter != endIter ; iter++) {
ProtocolElements.addBitCast(iter->getValue(), PtrTy);
ProtocolElements.add(iter->getValue());
}
ProtocolElements.finishAndAddTo(ProtocolList);
Elements.addBitCast(
ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
CGM.getPointerAlign()),
PtrTy);
Elements.add(ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
CGM.getPointerAlign()));
Categories.push_back(
Elements.finishAndCreateGlobal("", CGM.getPointerAlign()));
}
Expand Down Expand Up @@ -3321,27 +3316,26 @@ void CGObjCGNU::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
SmallVector<ObjCMethodDecl*, 16> InstanceMethods;
InstanceMethods.insert(InstanceMethods.begin(), OCD->instmeth_begin(),
OCD->instmeth_end());
Elements.addBitCast(
GenerateMethodList(ClassName, CategoryName, InstanceMethods, false),
PtrTy);
Elements.add(
GenerateMethodList(ClassName, CategoryName, InstanceMethods, false));

// Class method list

SmallVector<ObjCMethodDecl*, 16> ClassMethods;
ClassMethods.insert(ClassMethods.begin(), OCD->classmeth_begin(),
OCD->classmeth_end());
Elements.addBitCast(
GenerateMethodList(ClassName, CategoryName, ClassMethods, true),
PtrTy);
Elements.add(GenerateMethodList(ClassName, CategoryName, ClassMethods, true));

// Protocol list
Elements.addBitCast(GenerateCategoryProtocolList(CatDecl), PtrTy);
Elements.add(GenerateCategoryProtocolList(CatDecl));
if (isRuntime(ObjCRuntime::GNUstep, 2)) {
const ObjCCategoryDecl *Category =
Class->FindCategoryDeclaration(OCD->getIdentifier());
if (Category) {
// Instance properties
Elements.addBitCast(GeneratePropertyList(OCD, Category, false), PtrTy);
Elements.add(GeneratePropertyList(OCD, Category, false));
// Class properties
Elements.addBitCast(GeneratePropertyList(OCD, Category, true), PtrTy);
Elements.add(GeneratePropertyList(OCD, Category, true));
} else {
Elements.addNullPointer(PtrTy);
Elements.addNullPointer(PtrTy);
Expand Down Expand Up @@ -3677,11 +3671,9 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
GenerateProtocolHolderCategory();

llvm::StructType *selStructTy = dyn_cast<llvm::StructType>(SelectorElemTy);
llvm::Type *selStructPtrTy = SelectorTy;
if (!selStructTy) {
selStructTy = llvm::StructType::get(CGM.getLLVMContext(),
{ PtrToInt8Ty, PtrToInt8Ty });
selStructPtrTy = llvm::PointerType::getUnqual(selStructTy);
}

// Generate statics list:
Expand Down Expand Up @@ -3785,7 +3777,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
// Number of static selectors
symtab.addInt(LongTy, selectorCount);

symtab.addBitCast(selectorList, selStructPtrTy);
symtab.add(selectorList);

// Number of classes defined.
symtab.addInt(CGM.Int16Ty, Classes.size());
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,12 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
if (CurFnInfo->getMaxVectorWidth() > LargestVectorWidth)
LargestVectorWidth = CurFnInfo->getMaxVectorWidth();

// Add the required-vector-width attribute. This contains the max width from:
// Add the min-legal-vector-width attribute. This contains the max width from:
// 1. min-vector-width attribute used in the source program.
// 2. Any builtins used that have a vector width specified.
// 3. Values passed in and out of inline assembly.
// 4. Width of vector arguments and return types for this function.
// 5. Width of vector aguments and return types for functions called by this
// 5. Width of vector arguments and return types for functions called by this
// function.
if (getContext().getTargetInfo().getTriple().isX86())
CurFn->addFnAttr("min-legal-vector-width",
Expand Down
12 changes: 10 additions & 2 deletions clang/test/CodeGenCXX/float128-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86
// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu -std=c++11 \
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86
// RUN: %clang_cc1 -emit-llvm -triple i686-pc-openbsd -std=c++11 \
// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-freebsd -std=c++11 \
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86
// RUN: %clang_cc1 -emit-llvm -triple amd64-pc-openbsd -std=c++11 \
// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-freebsd -std=c++11 \
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86
// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-netbsd -std=c++11 \
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86
// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-netbsd -std=c++11 \
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86
// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-openbsd -std=c++11 \
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86
// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-openbsd -std=c++11 \
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86
// RUN: %clang_cc1 -emit-llvm -triple i386-pc-solaris2.11 -std=c++11 \
// RUN: %s -o - | FileCheck %s -check-prefix=CHECK-X86
Expand Down
10 changes: 0 additions & 10 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2188,16 +2188,6 @@ class TargetInstrInfo : public MCInstrInfo {
// Get the call frame size just before MI.
unsigned getCallFrameSizeAt(MachineInstr &MI) const;

/// Fills in the necessary MachineOperands to refer to a frame index.
/// The best way to understand this is to print `asm(""::"m"(x));` after
/// finalize-isel. Example:
/// INLINEASM ... 262190 /* mem:m */, %stack.0.x.addr, 1, $noreg, 0, $noreg
/// we would add placeholders for: ^ ^ ^ ^
virtual void
getFrameIndexOperands(SmallVectorImpl<MachineOperand> &Ops) const {
llvm_unreachable("unknown number of operands necessary");
}

private:
mutable std::unique_ptr<MIRFormatter> Formatter;
unsigned CallFrameSetupOpcode, CallFrameDestroyOpcode;
Expand Down
7 changes: 5 additions & 2 deletions llvm/include/llvm/IR/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DbgDeclareInst;
class DbgValueInst;
class DbgVariableIntrinsic;
class DbgDefKillIntrinsic;
class DPValue;
class Instruction;
class Module;

Expand All @@ -43,10 +44,12 @@ class Module;
TinyPtrVector<DbgDeclareInst *> FindDbgDeclareUses(Value *V);

/// Finds the llvm.dbg.value intrinsics describing a value.
void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V);
void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues,
Value *V, SmallVectorImpl<DPValue *> *DPValues = nullptr);

/// Finds the debug info intrinsics describing a value.
void findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgInsts, Value *V);
void findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgInsts,
Value *V, SmallVectorImpl<DPValue *> *DPValues = nullptr);

/// Find subprogram that is enclosing this scope.
DISubprogram *getDISubprogram(const MDNode *Scope);
Expand Down
62 changes: 0 additions & 62 deletions llvm/lib/CodeGen/TargetInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,64 +565,6 @@ static MachineInstr *foldPatchpoint(MachineFunction &MF, MachineInstr &MI,
return NewMI;
}

static void foldInlineAsmMemOperand(MachineInstr *MI, unsigned OpNo, int FI,
const TargetInstrInfo &TII) {
MachineOperand &MO = MI->getOperand(OpNo);
const VirtRegInfo &RI = AnalyzeVirtRegInBundle(*MI, MO.getReg());

// If the machine operand is tied, untie it first.
if (MO.isTied()) {
unsigned TiedTo = MI->findTiedOperandIdx(OpNo);
MI->untieRegOperand(OpNo);
// Intentional recursion!
foldInlineAsmMemOperand(MI, TiedTo, FI, TII);
}

// Change the operand from a register to a frame index.
MO.ChangeToFrameIndex(FI, MO.getTargetFlags());

SmallVector<MachineOperand, 4> NewOps;
TII.getFrameIndexOperands(NewOps);
assert(!NewOps.empty() && "getFrameIndexOperands didn't create any operands");
MI->insert(MI->operands_begin() + OpNo + 1, NewOps);

// Change the previous operand to a MemKind InlineAsm::Flag. The second param
// is the per-target number of operands that represent the memory operand
// excluding this one (MD). This includes MO.
InlineAsm::Flag F(InlineAsm::Kind::Mem, NewOps.size() + 1);
F.setMemConstraint(InlineAsm::ConstraintCode::m);
MachineOperand &MD = MI->getOperand(OpNo - 1);
MD.setImm(F);

// Update mayload/maystore metadata.
MachineOperand &ExtraMO = MI->getOperand(InlineAsm::MIOp_ExtraInfo);
if (RI.Reads)
ExtraMO.setImm(ExtraMO.getImm() | InlineAsm::Extra_MayLoad);
if (RI.Writes)
ExtraMO.setImm(ExtraMO.getImm() | InlineAsm::Extra_MayStore);
}

// Returns nullptr if not possible to fold.
static MachineInstr *foldInlineAsmMemOperand(MachineInstr &MI,
ArrayRef<unsigned> Ops, int FI,
const TargetInstrInfo &TII) {
assert(MI.isInlineAsm() && "wrong opcode");
if (Ops.size() > 1)
return nullptr;
unsigned Op = Ops[0];
assert(Op && "should never be first operand");
assert(MI.getOperand(Op).isReg() && "shouldn't be folding non-reg operands");

if (!MI.mayFoldInlineAsmRegOp(Op))
return nullptr;

MachineInstr &NewMI = TII.duplicate(*MI.getParent(), MI.getIterator(), MI);

foldInlineAsmMemOperand(&NewMI, Op, FI, TII);

return &NewMI;
}

MachineInstr *TargetInstrInfo::foldMemoryOperand(MachineInstr &MI,
ArrayRef<unsigned> Ops, int FI,
LiveIntervals *LIS,
Expand Down Expand Up @@ -670,8 +612,6 @@ MachineInstr *TargetInstrInfo::foldMemoryOperand(MachineInstr &MI,
NewMI = foldPatchpoint(MF, MI, Ops, FI, *this);
if (NewMI)
MBB->insert(MI, NewMI);
} else if (MI.isInlineAsm()) {
NewMI = foldInlineAsmMemOperand(MI, Ops, FI, *this);
} else {
// Ask the target to do the actual folding.
NewMI = foldMemoryOperandImpl(MF, MI, Ops, MI, FI, LIS, VRM);
Expand Down Expand Up @@ -743,8 +683,6 @@ MachineInstr *TargetInstrInfo::foldMemoryOperand(MachineInstr &MI,
NewMI = foldPatchpoint(MF, MI, Ops, FrameIndex, *this);
if (NewMI)
NewMI = &*MBB.insert(MI, NewMI);
} else if (MI.isInlineAsm() && isLoadFromStackSlot(LoadMI, FrameIndex)) {
NewMI = foldInlineAsmMemOperand(MI, Ops, FrameIndex, *this);
} else {
// Ask the target to do the actual folding.
NewMI = foldMemoryOperandImpl(MF, MI, Ops, MI, LoadMI, LIS);
Expand Down
Loading

0 comments on commit 95385ef

Please sign in to comment.