-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RFC][RISCV] Support the large code model.
Implement large code model for GlobalAddressSDNode, BlockAddressSDNode and ExternalSymbolSDNode. See discussion on riscv-non-isa/riscv-elf-psabi-doc#388. co-authored by: Kuan-Lin Chen <[email protected]>
- Loading branch information
Showing
10 changed files
with
1,798 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
//===------- RISCVConstantPoolValue.cpp - RISC-V constantpool value -------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements the RISC-V specific constantpool value class. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "RISCVConstantPoolValue.h" | ||
#include "llvm/ADT/FoldingSet.h" | ||
#include "llvm/IR/Constants.h" | ||
#include "llvm/IR/DerivedTypes.h" | ||
#include "llvm/IR/GlobalValue.h" | ||
#include "llvm/IR/Type.h" | ||
#include "llvm/Support/Casting.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
using namespace llvm; | ||
|
||
RISCVConstantPoolValue::RISCVConstantPoolValue( | ||
LLVMContext &C, RISCVCP::RISCVCPKind Kind, | ||
RISCVCP::RISCVCPModifier Modifier) | ||
: MachineConstantPoolValue((Type *)Type::getInt64Ty(C)), Kind(Kind), | ||
Modifier(Modifier) {} | ||
|
||
RISCVConstantPoolValue::RISCVConstantPoolValue( | ||
Type *Ty, RISCVCP::RISCVCPKind Kind, RISCVCP::RISCVCPModifier Modifier) | ||
: MachineConstantPoolValue(Ty), Kind(Kind), Modifier(Modifier) {} | ||
|
||
int RISCVConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP, | ||
Align Alignment) { | ||
llvm_unreachable("Shouldn't be calling this directly!"); | ||
} | ||
|
||
StringRef RISCVConstantPoolValue::getModifierText() const { | ||
switch (Modifier) { | ||
case RISCVCP::None: | ||
return ""; | ||
} | ||
llvm_unreachable("Unknown modifier!"); | ||
} | ||
|
||
void RISCVConstantPoolValue::print(raw_ostream &O) const { | ||
if (hasModifier()) | ||
O << "@" << getModifierText(); | ||
} | ||
|
||
RISCVConstantPoolConstant::RISCVConstantPoolConstant(Type *Ty, | ||
const Constant *GV, | ||
RISCVCP::RISCVCPKind Kind) | ||
: RISCVConstantPoolValue(Ty, Kind, RISCVCP::None), CVal(GV) {} | ||
|
||
RISCVConstantPoolConstant * | ||
RISCVConstantPoolConstant::Create(const GlobalValue *GV, | ||
RISCVCP::RISCVCPKind Kind) { | ||
return new RISCVConstantPoolConstant(GV->getType(), GV, Kind); | ||
} | ||
|
||
RISCVConstantPoolConstant * | ||
RISCVConstantPoolConstant::Create(const Constant *C, | ||
RISCVCP::RISCVCPKind Kind) { | ||
return new RISCVConstantPoolConstant(C->getType(), C, Kind); | ||
} | ||
|
||
int RISCVConstantPoolConstant::getExistingMachineCPValue( | ||
MachineConstantPool *CP, Align Alignment) { | ||
return getExistingMachineCPValueImpl<RISCVConstantPoolConstant>(CP, | ||
Alignment); | ||
} | ||
|
||
void RISCVConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) { | ||
ID.AddPointer(CVal); | ||
} | ||
|
||
void RISCVConstantPoolConstant::print(raw_ostream &O) const { | ||
O << CVal->getName(); | ||
RISCVConstantPoolValue::print(O); | ||
} | ||
|
||
const GlobalValue *RISCVConstantPoolConstant::getGlobalValue() const { | ||
return dyn_cast_or_null<GlobalValue>(CVal); | ||
} | ||
|
||
const BlockAddress *RISCVConstantPoolConstant::getBlockAddress() const { | ||
return dyn_cast_or_null<BlockAddress>(CVal); | ||
} | ||
|
||
RISCVConstantPoolSymbol::RISCVConstantPoolSymbol( | ||
LLVMContext &C, StringRef s, RISCVCP::RISCVCPModifier Modifier) | ||
: RISCVConstantPoolValue(C, RISCVCP::ExtSymbol, Modifier), S(s) {} | ||
|
||
RISCVConstantPoolSymbol * | ||
RISCVConstantPoolSymbol::Create(LLVMContext &C, StringRef s, | ||
RISCVCP::RISCVCPModifier Modifier) { | ||
return new RISCVConstantPoolSymbol(C, s, Modifier); | ||
} | ||
|
||
int RISCVConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP, | ||
Align Alignment) { | ||
return getExistingMachineCPValueImpl<RISCVConstantPoolSymbol>(CP, Alignment); | ||
} | ||
|
||
void RISCVConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) { | ||
ID.AddString(S); | ||
} | ||
|
||
void RISCVConstantPoolSymbol::print(raw_ostream &O) const { | ||
O << S; | ||
RISCVConstantPoolValue::print(O); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
//===--- RISCVConstantPoolValue.h - RISC-V constantpool value ---*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements the RISC-V specific constantpool value class. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_TARGET_RISCV_RISCVCONSTANTPOOLVALUE_H | ||
#define LLVM_LIB_TARGET_RISCV_RISCVCONSTANTPOOLVALUE_H | ||
|
||
#include "llvm/CodeGen/MachineConstantPool.h" | ||
#include "llvm/Support/Casting.h" | ||
#include "llvm/Support/ErrorHandling.h" | ||
|
||
namespace llvm { | ||
|
||
class LLVMContext; | ||
class GlobalValue; | ||
class BlockAddress; | ||
|
||
namespace RISCVCP { | ||
|
||
enum RISCVCPKind { ExtSymbol, GlobalValue, BlockAddress }; | ||
|
||
enum RISCVCPModifier { | ||
None, | ||
}; | ||
} // end namespace RISCVCP | ||
|
||
/// A RISCV-specific constant pool value. | ||
class RISCVConstantPoolValue : public MachineConstantPoolValue { | ||
RISCVCP::RISCVCPKind Kind; | ||
RISCVCP::RISCVCPModifier Modifier; | ||
|
||
protected: | ||
RISCVConstantPoolValue(LLVMContext &C, RISCVCP::RISCVCPKind Kind, | ||
RISCVCP::RISCVCPModifier Modifier); | ||
|
||
RISCVConstantPoolValue(Type *Ty, RISCVCP::RISCVCPKind Kind, | ||
RISCVCP::RISCVCPModifier Modifier); | ||
|
||
template <typename Derived> | ||
int getExistingMachineCPValueImpl(MachineConstantPool *CP, Align Alignment) { | ||
const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants(); | ||
for (unsigned i = 0, e = Constants.size(); i != e; ++i) { | ||
if (Constants[i].isMachineConstantPoolEntry() && | ||
Constants[i].getAlign() >= Alignment) { | ||
auto *CPV = static_cast<RISCVConstantPoolValue *>( | ||
Constants[i].Val.MachineCPVal); | ||
if (Derived *APC = dyn_cast<Derived>(CPV)) | ||
if (cast<Derived>(this)->equals(APC)) | ||
return i; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
public: | ||
~RISCVConstantPoolValue() = default; | ||
|
||
RISCVCP::RISCVCPModifier getModifier() const { return Modifier; } | ||
StringRef getModifierText() const; | ||
bool hasModifier() const { return Modifier != RISCVCP::None; } | ||
|
||
bool isExtSymbol() const { return Kind == RISCVCP::ExtSymbol; } | ||
bool isGlobalValue() const { return Kind == RISCVCP::GlobalValue; } | ||
bool isBlockAddress() const { return Kind == RISCVCP::BlockAddress; } | ||
|
||
int getExistingMachineCPValue(MachineConstantPool *CP, | ||
Align Alignment) override; | ||
|
||
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override {} | ||
|
||
bool equals(const RISCVConstantPoolValue *A) const { | ||
return this->Modifier == A->Modifier; | ||
} | ||
|
||
void print(raw_ostream &O) const override; | ||
}; | ||
|
||
class RISCVConstantPoolConstant : public RISCVConstantPoolValue { | ||
const Constant *CVal; | ||
|
||
RISCVConstantPoolConstant(Type *Ty, const Constant *GV, | ||
RISCVCP::RISCVCPKind Kind); | ||
|
||
public: | ||
static RISCVConstantPoolConstant *Create(const GlobalValue *GV, | ||
RISCVCP::RISCVCPKind Kind); | ||
static RISCVConstantPoolConstant *Create(const Constant *C, | ||
RISCVCP::RISCVCPKind Kind); | ||
|
||
const GlobalValue *getGlobalValue() const; | ||
const BlockAddress *getBlockAddress() const; | ||
|
||
int getExistingMachineCPValue(MachineConstantPool *CP, | ||
Align Alignment) override; | ||
|
||
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override; | ||
|
||
void print(raw_ostream &O) const override; | ||
|
||
bool equals(const RISCVConstantPoolConstant *A) const { | ||
return CVal == A->CVal && RISCVConstantPoolValue::equals(A); | ||
} | ||
|
||
static bool classof(const RISCVConstantPoolValue *RCPV) { | ||
return RCPV->isGlobalValue() || RCPV->isBlockAddress(); | ||
} | ||
}; | ||
|
||
class RISCVConstantPoolSymbol : public RISCVConstantPoolValue { | ||
const std::string S; | ||
|
||
RISCVConstantPoolSymbol(LLVMContext &C, StringRef s, | ||
RISCVCP::RISCVCPModifier Modifier); | ||
|
||
public: | ||
static RISCVConstantPoolSymbol *Create(LLVMContext &C, StringRef s, | ||
RISCVCP ::RISCVCPModifier Modifier); | ||
|
||
std::string getSymbol() const { return S; } | ||
|
||
int getExistingMachineCPValue(MachineConstantPool *CP, | ||
Align Alignment) override; | ||
|
||
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override; | ||
|
||
void print(raw_ostream &O) const override; | ||
|
||
bool equals(const RISCVConstantPoolSymbol *A) const { | ||
return S == A->S && RISCVConstantPoolValue::equals(A); | ||
} | ||
static bool classof(const RISCVConstantPoolValue *RCPV) { | ||
return RCPV->isExtSymbol(); | ||
} | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif |
Oops, something went wrong.