Skip to content

Commit

Permalink
Temporary fix memset intrinsic, fix negative label offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
leadpogrommer committed Apr 22, 2024
1 parent 4fb6c7e commit a84169c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions llvm/lib/Target/CDM/CDMAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ void CDMAsmPrinter::emitStartOfAsmFile(Module &module) {
auto Linkage = GV.getLinkage();
if (GV.isDeclaration() and std::find_if(prefixes_to_ignore.begin(), prefixes_to_ignore.end(), [&](auto pref){return GV.getName().starts_with(pref);}) == prefixes_to_ignore.end()){
OutStreamer ->emitRawText(llvm::formatv("{0}: ext\n", GV.getName()));
} else if(GV.isDeclaration() and GV.getName() == "llvm.memset.p0.i16") { // TODO: handle intrinsics correctly, this is temporary fix
OutStreamer ->emitRawText(llvm::formatv("{0}: ext\n", "memset"));
}
}

Expand Down
14 changes: 10 additions & 4 deletions llvm/lib/Target/CDM/CDMISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,17 @@ SDValue CDMISelLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
}

// We only support calling global addresses.
GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
assert(G && "We only support the calling of global addresses");

EVT PtrVT = getPointerTy(DAG.getDataLayout());
Callee = DAG.getTargetGlobalAddress(G->getGlobal(), Loc, PtrVT, 0);

if(GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)){
Callee = DAG.getTargetGlobalAddress(G->getGlobal(), Loc, PtrVT, 0);
} else if(ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)){
Callee = DAG.getTargetExternalSymbol(S->getSymbol(), PtrVT, 0);
} else{
llvm_unreachable("We only support the calling of global addresses and external symbols");
}



std::vector<SDValue> Ops;
Ops.push_back(Chain);
Expand Down
15 changes: 10 additions & 5 deletions llvm/lib/Target/CDM/CDMMCInstLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void CDMMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
}
}
MCOperand CDMMCInstLower::LowerOperand(const MachineOperand &MO,
unsigned int offset) const {
int offset) const {
auto MOType = MO.getType();
switch (MOType) {
default:
Expand All @@ -40,19 +40,24 @@ MCOperand CDMMCInstLower::LowerOperand(const MachineOperand &MO,
break;
case MachineOperand::MO_MachineBasicBlock:
case MachineOperand::MO_GlobalAddress:
case MachineOperand::MO_ExternalSymbol:
case MachineOperand::MO_JumpTableIndex:
return LowerSymbolOperand(MO, offset);
}
return MCOperand();
}
MCOperand CDMMCInstLower::LowerSymbolOperand(const MachineOperand &MO,
unsigned int Offset) const {
int Offset) const {
MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None;
const MCSymbol *Symbol;



switch (MO.getType()) {
case MachineOperand::MO_ExternalSymbol:
Symbol = AsmPrinter.GetExternalSymbolSymbol(MO.getSymbolName());
Offset += MO.getOffset();
break;
case MachineOperand::MO_GlobalAddress:
Symbol = AsmPrinter.getSymbol(MO.getGlobal());
Offset += MO.getOffset(); // Wtf is offset
Expand Down Expand Up @@ -80,9 +85,9 @@ MCOperand CDMMCInstLower::LowerSymbolOperand(const MachineOperand &MO,
if (Offset) {
// Assume offset is never negative.
// llvm_unreachable("I am still unsure what is an offset");
assert(Offset > 0);
Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(Offset, *Ctx),
*Ctx);

Expr = Offset > 0 ? MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(Offset, *Ctx),
*Ctx) : MCBinaryExpr::createSub(Expr, MCConstantExpr::create(-Offset, *Ctx), *Ctx);
}


Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/CDM/CDMMCInstLower.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class CDMMCInstLower {
CDMMCInstLower(CDMAsmPrinter &asmPrinter);
void Initialize(MCContext* C);
void Lower(const MachineInstr *MI, MCInst &OutMI) const;
MCOperand LowerOperand(const MachineOperand& MO, unsigned offset = 0) const;
MCOperand LowerSymbolOperand(const MachineOperand& MO, unsigned offset = 0) const;
MCOperand LowerOperand(const MachineOperand& MO, int offset = 0) const;
MCOperand LowerSymbolOperand(const MachineOperand& MO, int offset = 0) const;
};

} // namespace llvm
Expand Down

0 comments on commit a84169c

Please sign in to comment.