-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RISCV] Support the large code model. (#70308)
Implement large code model for GlobalAddressSDNode and ExternalSymbolSDNode. See discussion on riscv-non-isa/riscv-elf-psabi-doc#388. --------- Co-authored-by: Kuan-Lin Chen <rufus@andestech.com>
- Loading branch information
Showing
10 changed files
with
1,774 additions
and
2 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,81 @@ | ||
//===------- 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(Type *Ty, const GlobalValue *GV) | ||
: MachineConstantPoolValue(Ty), GV(GV), Kind(RISCVCPKind::GlobalValue) {} | ||
|
||
RISCVConstantPoolValue::RISCVConstantPoolValue(LLVMContext &C, StringRef S) | ||
: MachineConstantPoolValue(Type::getInt64Ty(C)), S(S), | ||
Kind(RISCVCPKind::ExtSymbol) {} | ||
|
||
RISCVConstantPoolValue *RISCVConstantPoolValue::Create(const GlobalValue *GV) { | ||
return new RISCVConstantPoolValue(GV->getType(), GV); | ||
} | ||
|
||
RISCVConstantPoolValue *RISCVConstantPoolValue::Create(LLVMContext &C, | ||
StringRef S) { | ||
return new RISCVConstantPoolValue(C, S); | ||
} | ||
|
||
int RISCVConstantPoolValue::getExistingMachineCPValue(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 (equals(CPV)) | ||
return i; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
void RISCVConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) { | ||
if (isGlobalValue()) | ||
ID.AddPointer(GV); | ||
else { | ||
assert(isExtSymbol() && "unrecognized constant pool type"); | ||
ID.AddString(S); | ||
} | ||
} | ||
|
||
void RISCVConstantPoolValue::print(raw_ostream &O) const { | ||
if (isGlobalValue()) | ||
O << GV->getName(); | ||
else { | ||
assert(isExtSymbol() && "unrecognized constant pool type"); | ||
O << S; | ||
} | ||
} | ||
|
||
bool RISCVConstantPoolValue::equals(const RISCVConstantPoolValue *A) const { | ||
if (isGlobalValue() && A->isGlobalValue()) | ||
return GV == A->GV; | ||
if (isExtSymbol() && A->isExtSymbol()) | ||
return S == A->S; | ||
|
||
return false; | ||
} |
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,63 @@ | ||
//===--- 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/ADT/StringRef.h" | ||
#include "llvm/CodeGen/MachineConstantPool.h" | ||
#include "llvm/Support/Casting.h" | ||
#include "llvm/Support/ErrorHandling.h" | ||
|
||
namespace llvm { | ||
|
||
class BlockAddress; | ||
class GlobalValue; | ||
class LLVMContext; | ||
|
||
/// A RISCV-specific constant pool value. | ||
class RISCVConstantPoolValue : public MachineConstantPoolValue { | ||
const GlobalValue *GV; | ||
const StringRef S; | ||
|
||
RISCVConstantPoolValue(Type *Ty, const GlobalValue *GV); | ||
RISCVConstantPoolValue(LLVMContext &C, StringRef S); | ||
|
||
private: | ||
enum class RISCVCPKind { ExtSymbol, GlobalValue }; | ||
RISCVCPKind Kind; | ||
|
||
public: | ||
~RISCVConstantPoolValue() = default; | ||
|
||
static RISCVConstantPoolValue *Create(const GlobalValue *GV); | ||
static RISCVConstantPoolValue *Create(LLVMContext &C, StringRef S); | ||
|
||
bool isGlobalValue() const { return Kind == RISCVCPKind::GlobalValue; } | ||
bool isExtSymbol() const { return Kind == RISCVCPKind::ExtSymbol; } | ||
|
||
const GlobalValue *getGlobalValue() const { return GV; } | ||
StringRef 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 RISCVConstantPoolValue *A) const; | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif |
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
Oops, something went wrong.